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

Modified cutout creation #114

Merged
merged 2 commits into from
Jan 15, 2021
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
15 changes: 5 additions & 10 deletions atlite/cutout.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,9 @@ def __init__(self, path, **cutoutparams):
if path.is_file():
data = xr.open_dataset(str(path), chunks=chunks)
data.attrs.update(storable_chunks)
if 'module' in cutoutparams:
module = cutoutparams.pop('module')
if module != data.attrs.get('module'):
logger.warning(
f"Overwriting dataset module "
f"{data.attrs.get('module')} with module {module}.")
data.attrs['module'] = module
if cutoutparams:
warn(f'Arguments {", ".join(cutoutparams)} are ignored, since '
'cutout is already built.')
elif 'data' in cutoutparams:
data = cutoutparams.pop('data')
else:
Expand Down Expand Up @@ -255,9 +251,8 @@ def dt(self):

@property
def prepared(self):
warn("The `prepared` attribute is deprecated in favour of the "
"fine-grained `prepared_features` list", DeprecationWarning)
return self.prepared_features == self.available_features
return (self.prepared_features.sort_index()
.equals(self.available_features.sort_index()))

@property
def prepared_features(self):
Expand Down
4 changes: 4 additions & 0 deletions atlite/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def cutout_prepare(cutout, features=None, tmpdir=None, overwrite=False):
Cutout with prepared data. The variables are stored in `cutout.data`.

"""
if cutout.prepared and not overwrite:
logger.info('Cutout already prepared.')
return cutout

logger.info(f'Storing temporary files in {tmpdir}')

modules = atleast_1d(cutout.module)
Expand Down
9 changes: 9 additions & 0 deletions test/test_preparation_and_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def update_feature_test(cutout, red):
assert_equal(red.data.influx_direct, cutout.data.influx_direct)


def wrong_recreation(cutout):
with pytest.warns(UserWarning):
Cutout(path=cutout.path, module='somethingelse')


def pv_test(cutout):
'''
Test the atlite.Cutout.pv function with different settings. Compare
Expand Down Expand Up @@ -204,6 +209,10 @@ def test_prepared_features_era5(cutout_era5):
def test_update_feature_era5(cutout_era5, cutout_era5_reduced):
return update_feature_test(cutout_era5, cutout_era5_reduced)

@staticmethod
def test_wrong_loading(cutout_era5):
wrong_recreation(cutout_era5)

@staticmethod
def test_pv_era5(cutout_era5):
return pv_test(cutout_era5)
Expand Down