-
Notifications
You must be signed in to change notification settings - Fork 33
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
Updates to CESM-FV Reader #228
base: develop
Are you sure you want to change the base?
Conversation
…ariables because open_mfdataset seems to be adding the 'time' dimension to them. Added 'dset_load = dset_load.rename({...})' because variables were not being saved to dset_load.
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.
Hi @noribeth-m, some initial comments here. Also maybe we can come up with a new test file/case by selecting a few levels from data here since currently we're only testing a surf-only case.
Co-authored-by: Zachary Moon <[email protected]>
Co-authored-by: Zachary Moon <[email protected]>
Co-authored-by: Zachary Moon <[email protected]>
Co-authored-by: Zachary Moon <[email protected]>
Co-authored-by: Zachary Moon <[email protected]>
Co-authored-by: Zachary Moon <[email protected]>
@noribeth-m the automatic formatters want some changes. If you want to address this yourself, install
and commit the result. Or I can do it for you if you'd prefer. |
Hi @zmoon! I installed and ran the pre-commit. It says that the _cesm_fv_mm.py file was reformatted, but I still get "Failed" in 2 places (see image attached). I'm not sure what I'm supposed to do from here. |
@noribeth-m if you run |
@zmoon Thanks! That worked and the checks have 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.
A few more comments
raise Exception( | ||
"Expected default CESM behaviour:" | ||
+ "pressure levels should be in increasing order, height in decreasing order" | ||
) |
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.
raise Exception( | |
"Expected default CESM behaviour:" | |
+ "pressure levels should be in increasing order, height in decreasing order" | |
) | |
raise ValueError( | |
"Expected default CESM behaviour " | |
"(pressure levels should be in increasing order, height in decreasing order)" | |
) |
var_list = var_list + ["pres_pa_mid"] | ||
if "Z3" not in dset_load.keys(): | ||
warnings.warn("Geopotential height Z3 is not in model keys. Assuming hydrostatic runs") | ||
dset_load["Z3"] = _calc_hydrostatic_height(dset_load) | ||
var_list = var_list + ["alt_msl_m_mid"] |
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.
It looks like pres_pa_mid
and alt_msl_m_mid
are also added to the var list later. So perhaps remove the two lines here. xarray seems to just ignore duplicates but it's confusing to have it added twice.
var_list = var_list + ["alt_msl_m_mid"] | ||
|
||
# calc layer thickness if hyai and hybi exist | ||
if "hyai" and "hybi" in dset_load.keys(): |
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.
As it is, it's only actually checking for 'hybi'
(since 'hyai'
is always true). This is the concise way to check for both:
if "hyai" and "hybi" in dset_load.keys(): | |
if {"hyai", "hybi"} <= dset_load.keys(): |
if "hyai" and "hybi" in dset_load.keys(): | ||
dset_load["pres_pa_int"] = _calc_pressure_i(dset_load) | ||
dset_load["dz_m"] = _calc_layer_thickness_i(dset_load) | ||
var_list.append("dz_m") |
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.
You could add an else
branch here with a warning message about skipping this calculation.
because it has a dimension of 'ilev' instead of 'z'. Add a correction | ||
for this last part. |
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 made some updates to the CESM-FV reader to have the capability to calculate the layer thickness (dz_m) if the interface pressures (hyai, hybi) are provided in the model output. The script will now calculate the variable, 'pres_pa_int', and use this variable to calculate the interface layer height, which is then used to calculate the layer thickness. These calculations are based on the default vertical structure of CESM, where the pressure is in increasing order and altitude in decreasing order. Once this is calculated, the script reorders the vertical levels so that the surface is first. This is done by default in the original code, but I added a line so that 'pres_pa_int' is also treated this way, as the original code does this based on vertical dimension 'z', which is not what is used for 'pres_pa_int' since it has an extra vertical level (33 instead of 32). 'pres_pa_int' has a vertical dimension called 'ilev'. This is currently only used in the CESM_FV reader, but is saved in the processed dataset. Moving forward, if needed, renaming the 'ilev' dimension to something like 'z_i' may be more consistent with the monetio/melodies-monet formatting, but not necessary for now.
In addition to this, the pyresample dependency was removed and now deals with the wrap longitudes using numpy.