Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 70 #72

Merged
merged 4 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Internal changes
* Small bugfixes in aggregate.py (:pull:`55`, :pull:`56`).
* Default method of `xs.extract.resample` now depends on frequency. (:issue:`57`, :pull:`58`).
* Bugfix for `_restrict_by_resolution` with CMIP6 datasets (:pull:`71`).
* More complete check of coverage in ``_subset_file_coverage`` (:issue: `70`, :pull: `72`)

v0.3.0 (2022-08-23)
-------------------
Expand Down
13 changes: 12 additions & 1 deletion xscen/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ def _subset_file_coverage(

# Very rough guess of the coverage relative to the requested period,
# without having to open the files or checking day-by-day
# This is only checking that you have the first and last time point, not that you have everything in between.
guessed_nb_hrs = np.min(
[
df[files_in_range]["date_end"].max(),
Expand All @@ -1009,12 +1010,22 @@ def _subset_file_coverage(
date_parser(str(period[0]), freq="H"),
]
)

# This checks the sum of hours in all selected files
guessed_nb_hrs_sum = (
df[files_in_range]["date_end"] - df[files_in_range]["date_start"]
).sum()

period_nb_hrs = date_parser(
str(period[1]), end_of_period=True, freq="H"
) - date_parser(str(period[0]), freq="H")

# 'coverage' adds some leeway, for example to take different calendars into account or missing 2100-12-31
if guessed_nb_hrs / period_nb_hrs < coverage or len(df[files_in_range]) == 0:
if (
guessed_nb_hrs / period_nb_hrs < coverage
or len(df[files_in_range]) == 0
or guessed_nb_hrs_sum / period_nb_hrs < coverage
):
logging.warning(
f"{df['id'].iloc[0] + ': ' if 'id' in df.columns else ''}Insufficient coverage."
)
Expand Down