-
Notifications
You must be signed in to change notification settings - Fork 10
Update schism.data to correctly handle DataBlob #159
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,18 +261,29 @@ def get( | |
|
||
""" | ||
ret = {} | ||
destdir = Path(destdir) / "sflux" | ||
destdir = Path(destdir) | ||
destdir.mkdir(parents=True, exist_ok=True) | ||
namelistargs = {} | ||
anydatablobs = False | ||
for variable in ["air_1", "air_2", "rad_1", "rad_2", "prc_1", "prc_2"]: | ||
data = getattr(self, variable) | ||
if data is None: | ||
continue | ||
data.id = variable | ||
logger.info(f"Fetching {variable}") | ||
namelistargs.update(data.namelist) | ||
ret[variable] = data.get(destdir, grid, time) | ||
ret["nml"] = Sflux_Inputs(**namelistargs).write_nml(destdir) | ||
if isinstance(data, DataBlob): | ||
anydatablobs = True | ||
ret[variable] = data.get(destdir, name='sflux') | ||
existing_nml = ret[variable] / 'sflux_inputs.txt' | ||
else: | ||
dd = destdir / "sflux" | ||
dd.mkdir(parents=True, exist_ok=True) | ||
ret[variable] = data.get(dd, grid, time) | ||
namelistargs.update(data.namelist) | ||
if anydatablobs: | ||
ret["nml"] = existing_nml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And with line 276 and 277 this also means you can't mix and match datablobs with other data objects like say some sfluxair datablobs and with sfluxrad data objects. That might be fine but it would be nice to inform the user somehow they need either an all or nothing approach with using datablobs in sflux There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively I wonder whether ret["nml"] = Sflux_Inputs(**namelistargs).write_nml(destdir) would work even if some of the inputs are datablobs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is a bit poor, but without interrogating the sflux_input.txt file you dont know how to populate https://github.com/rom-py/rompy/blob/main/rompy/schism/namelists/sflux.py#L8 |
||
else: | ||
ret["nml"] = Sflux_Inputs(**namelistargs).write_nml(destdir) | ||
return ret | ||
|
||
@model_validator(mode="after") | ||
|
@@ -287,11 +298,15 @@ def check_weights(v): | |
ValueError: If the relative weights for any variable do not add up to 1.0. | ||
|
||
""" | ||
|
||
for variable in ["air", "rad", "prc"]: | ||
weight = 0 | ||
active = False | ||
for i in [1, 2]: | ||
data = getattr(v, f"{variable}_{i}") | ||
# Check if DataBlob is used | ||
if isinstance(data, DataBlob): | ||
continue | ||
if data is None: | ||
continue | ||
if data.fail_if_missing: | ||
|
@@ -759,8 +774,8 @@ def get( | |
for datatype in ["atmos", "ocean", "wave", "tides"]: | ||
data = getattr(self, datatype) | ||
if data is None: | ||
continue | ||
if type(data) is DataBlob: | ||
output = None | ||
elif type(data) is DataBlob: | ||
output = data.get(destdir) | ||
else: | ||
output = data.get(destdir, grid, time) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 276, a datablob data.get(destdir, name='sflux') returns either a file or a directory based on data.source but on Line 277, ret[variable] is expected to be a directory in that it is used to define existing_nml as an sflux_inputs.txt in that directory location. That may not be a problem if datablob is always a directory in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah there has to be an sflux_inputs.txt which describes to some extent what the sflux netcdf files contain. If the files are already generated it is assumed this file.