-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from cedadev/edit_view
2024.11.6
- Loading branch information
Showing
26 changed files
with
1,492 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
def pytest_collection_modifyitems(items): | ||
|
||
CLASS_ORDER = [ | ||
"TestPath" | ||
"TestCFAWrite", | ||
"TestCFARead", | ||
"TestCleanup" | ||
] | ||
|
||
sorted_items = items.copy() | ||
# read the class names from default items | ||
class_mapping = {item: item.cls.__name__ for item in items} | ||
|
||
|
||
# Iteratively move tests of each class to the end of the test queue | ||
for class_ in CLASS_ORDER: | ||
sorted_items = [it for it in sorted_items if class_mapping[it] != class_] + [ | ||
it for it in sorted_items if class_mapping[it] == class_ | ||
] | ||
|
||
|
||
items[:] = sorted_items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
TESTDIR = 'cfapyx/tests/test_space' | ||
|
||
class TestPath: | ||
def testpath(self, tests=TESTDIR): | ||
logger.error(os.getcwd()) | ||
logger.error(tests) | ||
|
||
class TestCleanup: | ||
def test_cleanup(self, testdir=TESTDIR): | ||
os.system(f'rm {testdir}/testrain.nca') | ||
print('Integration tests: Cleanup - complete') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# All routines for testing CFA general methods. | ||
import xarray as xr | ||
import os | ||
import pytest | ||
|
||
TESTDIR = 'cfapyx/tests/test_space' | ||
|
||
class TestCFARead: | ||
|
||
def test_cfa_pure(self, testdir=TESTDIR, active=False): | ||
|
||
FILE = f'{testdir}/testrain.nca' | ||
|
||
# Local testing: Add CFAPyX before tests | ||
try: | ||
ds = xr.open_dataset(FILE, engine='CFA', | ||
cfa_options={ | ||
'use_active':active | ||
}) | ||
except Exception as err: | ||
assert isinstance(err, ImportError) | ||
print(f'Integration tests: Read(pure, active={active}) - skipped') | ||
return | ||
|
||
## Test global dataset | ||
assert not hasattr(ds,'address') | ||
assert not hasattr(ds,'shape') | ||
assert not hasattr(ds,'location') | ||
|
||
assert 'p' in ds | ||
assert ds['p'].shape == (20, 180, 360) | ||
|
||
# Using selection with lat/lon values NOT index values | ||
p_sel = ds['p'].isel(time=slice(0,3),latitude=slice(140,145), longitude=slice(90,100)) | ||
|
||
assert p_sel.shape == (3, 5, 10) | ||
assert not hasattr(p_sel, 'aggregated_data') | ||
assert not hasattr(p_sel, 'aggregated_dimensions') | ||
|
||
p_mean = p_sel.mean(dim='time') | ||
|
||
assert p_mean.shape == (5, 10) | ||
assert (p_mean[0][0].to_numpy() - 0.635366) < 0.01 | ||
|
||
p_value = p_sel.mean() | ||
|
||
assert p_value.shape == () | ||
assert (p_value.to_numpy() - 0.511954) < 0.01 | ||
|
||
print(f'Integration tests: Read(pure, active={active}) - complete') | ||
|
||
def test_cfa_chunks(self, testdir=TESTDIR): | ||
|
||
FILE = f'{testdir}/testrain.nca' | ||
|
||
ds = xr.open_dataset(FILE, engine='CFA', | ||
cfa_options={ | ||
'chunks': {'longitude':180}, | ||
'chunk_limits':False}) | ||
|
||
## Test global dataset | ||
assert not hasattr(ds,'address') | ||
assert not hasattr(ds,'shape') | ||
assert not hasattr(ds,'location') | ||
|
||
assert 'p' in ds | ||
assert ds['p'].shape == (20, 180, 360) | ||
|
||
# Using selection with lat/lon values NOT index values | ||
p_sel = ds['p'].isel(time=slice(0,3),latitude=slice(140,145), longitude=slice(100,300)) | ||
|
||
assert p_sel.shape == (3, 5, 200) | ||
assert not hasattr(p_sel, 'aggregated_data') | ||
assert not hasattr(p_sel, 'aggregated_dimensions') | ||
|
||
p_mean = p_sel.mean(dim='time') | ||
|
||
assert p_mean.shape == (5, 200) | ||
assert (p_mean[0][0].to_numpy() - 0.664414) < 0.01 | ||
|
||
p_value = p_sel.mean() | ||
|
||
assert p_value.shape == () | ||
assert (p_value.to_numpy() - 0.490389) < 0.01 | ||
|
||
print(f'Integration tests: Read(chunked) - complete') | ||
|
||
if __name__ == '__main__': | ||
|
||
print('Run with poetry run pytest -v -s') |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
from cfapyx import CFANetCDF | ||
|
||
TESTDIR = 'cfapyx/tests/test_space' | ||
|
||
class TestCFAWrite: | ||
def test_cfa_write(self, testdir=TESTDIR): | ||
|
||
|
||
os.system(f'touch {testdir.replace("/","_")}') | ||
|
||
filepattern = f'{testdir}/rain/example*.nc' | ||
|
||
ds = CFANetCDF(filepattern, concat_msg='ThisIsATests') | ||
|
||
ds.create( | ||
updates={'test_name':'alpha', 'test_remove':'not removed'}, | ||
removals={'test_remove'} | ||
) | ||
|
||
assert ds.agg_dims == ('time',) | ||
assert ds.coord_dims == ('time', 'latitude', 'longitude') | ||
assert ds.pure_dims == () | ||
assert ds.aggregated_vars == ('p',) | ||
assert ds.identical_vars == () | ||
assert ds.scalar_vars == () | ||
|
||
ds.write(f'{testdir}/testrain.nca') | ||
|
||
print('Integration tests: Write - complete') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.