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

CMIP6 tests allow tests to pass for datasets without 'time' dimension. #59

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 27 additions & 12 deletions leap_data_management_utils/cmip_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,26 @@ def test_time(ds: xr.Dataset, verbose):
- That time increases strictly monotonically
- That no large gaps in time (e.g. missing file) are present
"""
if verbose:
print('Testing - Time Dimension')
time_diff = ds.time.diff('time').astype(int)
# assert that time increases monotonically
if verbose:
print(time_diff)
assert (time_diff > 0).all()
if 'time' not in ds.dims:
if verbose:
print('No time dimension found')
else:
if verbose:
print('Testing - Time Dimension')

# check that the time range is the same as
# indicated in the ESGF API dataset response

time_diff = ds.time.diff('time').astype(int)
# assert that time increases monotonically
if verbose:
print(time_diff)
assert (time_diff > 0).all()

# assert that there are no large time gaps
mean_time_diff = time_diff.mean()
normalized_time_diff = abs((time_diff - mean_time_diff) / mean_time_diff)
assert (normalized_time_diff < 0.05).all()
# assert that there are no large time gaps
mean_time_diff = time_diff.mean()
normalized_time_diff = abs((time_diff - mean_time_diff) / mean_time_diff)
assert (normalized_time_diff < 0.05).all()


def test_attributes(ds: xr.Dataset, iid: str, verbose):
Expand All @@ -72,9 +80,16 @@ def test_attributes(ds: xr.Dataset, iid: str, verbose):
print(f'Checking {facet = } in dataset attributes')
assert ds.attrs[facet] == facet_value

# check that the esgf api response is stored in the dataset attributes
assert 'pangeo_forge_api_responses' in ds.attrs
assert len(ds.attrs['pangeo_forge_api_responses']['dataset']) == 1
assert len(ds.attrs['pangeo_forge_api_responses']['files']) >= 1


def test_all(store: zarr.storage.FSStore, iid: str, verbose=True) -> zarr.storage.FSStore:
ds = test_open_store(store, verbose=verbose)
test_time(ds, verbose=verbose)
# attributes need to be tested before because
# time tests depend on newly added attributes
test_attributes(ds, iid, verbose=verbose)
test_time(ds, verbose=verbose)
return store