-
Notifications
You must be signed in to change notification settings - Fork 30
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
Dataclass fixes #317
Dataclass fixes #317
Conversation
Add check for existing variable file for climo year info. Update hist_strs object
Bring in changes from PR NCAR#316 Update time fix for old CESM time series files
Organize the adf_dataset methods into file type sections: time series, climo, and regridded. These methods weren't working with obs, fix reference methods to correctly gather obs data.
Fix check for vertical levels, initially based on `pres_levs` instead of `has_lev`. Update data grab to include obs
Fix check for vertical levels, and reorganize plotting block. Only log-p plots were being made for variables with vertical levels. Update data grab to include obs
@brianpm I needed to make some adjustments to the methods in |
@justin-richling -- Let's discuss the changes. I think they are mostly fine. There are two things that I'm not liking at first glance. First is the method Second is related, and is the logic in |
lib/adf_info.py
Outdated
for var in var_list: | ||
ts_files = sorted(input_location.glob(f"{case_name}*h0*.{var}.*nc")) | ||
if ts_files: | ||
print(var) | ||
break | ||
else: | ||
logmsg = "get years for time series:" | ||
logmsg = f"\tVar '{var}' not in dataset, skip to next to try and find climo years..." | ||
self.debug_log(logmsg) |
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.
This is in case the first variable in the yaml file doesn't have a history file, we need to keep looking for the next available one.
Finalize fixes to keep to original data class workflow
lib/adf_dataset.py
Outdated
da = da * vres.get("scale_factor",1) + vres.get("add_offset", 0) | ||
da.attrs['units'] = vres.get("new_unit", da.attrs.get('units', 'none')) | ||
|
||
da = da * kwargs["scale_factor"] + kwargs["add_offset"] |
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.
I think we probably just need to make this a bit more robust with something like
scale_factor = kwargs.get('scale_factor', 1)
add_offset = kwargs.get('add_offset', 0)
Just in case it gets used without the kwargs being passed.
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.
Actually, maybe use get_defaults
to do this?
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.
That's what I was attempting to do with get_defaults
, it should be setting those to the defaults before it becomes the kwargs
I have the offset set to 0 and scale factor to 1 initially, then the check if variablename in res
should grab the values and if not it will default to 0/1 respectively with vres.get
.
And if the variable is not in self.adf.variable_defaults
, the original values for new_unit
, add_offset
, and scale_factor
will take on the original set values of none, 0, and 1.
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.
I agree with @brianpm's original suggestion here. Right now if someone tried to use this function without passing in the scale_factor
and add_offset
keywords I believe the function would crash with a dictionary key error.
Since the units need to be checked from the data array, the `new_units` arg needs to be in `load_da` method. `get_defaults` only gets metadata from variable defaults and not a data array
@nusbaume I think this is all good for your final review., let me know if you see anything that needs addressing. |
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.
Looks good, but do have some (hopefully easy) change requests.
lib/adf_dataset.py
Outdated
"""Return Dataset for climo of variablename""" | ||
fils = self.get_climo_file(case, variablename) | ||
if not fils: | ||
warnings.warn(f"ERROR: Did not find climo file for variable: {variablename}. Will try to skip.") |
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.
I would change ERROR
to WARNING
here, so that users realize that the ADF will keep going.
warnings.warn(f"ERROR: Did not find climo file for variable: {variablename}. Will try to skip.") | |
warnings.warn(f"WARNING: Did not find climo file for variable: {variablename}. Will try to skip.") |
The same request holds for the other warnings in this file as well.
lib/adf_dataset.py
Outdated
da = da * vres.get("scale_factor",1) + vres.get("add_offset", 0) | ||
da.attrs['units'] = vres.get("new_unit", da.attrs.get('units', 'none')) | ||
|
||
da = da * kwargs["scale_factor"] + kwargs["add_offset"] |
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.
I agree with @brianpm's original suggestion here. Right now if someone tried to use this function without passing in the scale_factor
and add_offset
keywords I believe the function would crash with a dictionary key error.
@nusbaume I believe I addressed all the suggestions. If you wouldn't mind just giving it one last glance, I think it's on its way, thanks! |
Add check for value converters for data arrays
Fix issues from recent data class PR #269:
adf_info.py
global_latlon_map.py
pres_levs
instead ofhas_lev
.zonal_mean.py
adf_dataset.py
tape_recorder.py
:adf_dataset.py
structure.