-
Notifications
You must be signed in to change notification settings - Fork 20
Pressure masking tool fixes, tests, and docs #406
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?
Conversation
The metadata reading and writing needs to be finalized now that the history files are being written with the variable attribute updates.
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.
some clarity could help in current spots
and added comment to explain the if statement logic.
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! I added a few comments.
- moved setup to its own fixture - added reference test with known good output - modified input file's metadata to turn on the masking - added type to docstring
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #406 +/- ##
==========================================
+ Coverage 65.48% 66.88% +1.39%
==========================================
Files 63 64 +1
Lines 4532 4560 +28
==========================================
+ Hits 2968 3050 +82
+ Misses 1564 1510 -54
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 close to being merge-able.
I think we need this code in a folder like the other fre app
commands, otherwise the testing file pattern is broken with mask-atmos-plevel
being the exception.
Does the tool require nco
? Do requirements in meta.yaml
, environment.yml
, or setup.py
need to be changed because of 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.
fre/app/README.md
should be a README
for fre app
generally, and not for fre app mask-atmos-plevel
/
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.
Thanks Ian on all counts.
- moved the mask-atmos-plevel code to its own subdirectory which is more consistent with others, agreed.
- Great catch on the prereqs, which are xarray and netCDF4. xarray is already there but netcdf is not. I'll add it
- README.md already ok
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 you should move this readme to fre/app/mask_atmos_plevel directory and keep it subtool specific, similar to what Dana did in fre/app/remap_pp_components/README.md and https://github.com/NOAA-GFDL/fre-cli/blob/main/fre/app/regrid_xy/README.md
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.
First round of reviews hehehe
# mask-atmos-plevel: Mask pressure-level diagnostic output below land surface | ||
Quickstart: | ||
|
||
First, obtain an input file that has a pressure coordinate variable and |
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'm not a fan of using first and second person in official documents.. :)
Also may I suggest, input file containing pressure coordinate variable and data variable that is to be masked. The mask value will be set to 1 at points where the pressure is greater than the surface pressure.
I'm not sure what "which is specified in either the first file or a second" is referring to..
@@ -0,0 +1,27 @@ | |||
# fre app - Loose standalone tools | |||
|
|||
# mask-atmos-plevel: Mask pressure-level diagnostic output below land surface |
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'ts not clear what mask-atmos-plevel does. Does it compute? Evaluate? Determine?
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.
Thanks, I'll improve the summary line. It applies a boolean mask for pressure-level input data where the condition is surface pressure. For pressures above (lower) than the condition, the data is set to the missing value. For pressures equal or less than surface pressure, use the input data.
atmos_cmip.200501-200512.ps.nc atmos_cmip.200501-200512.ua_unmsk.nc | ||
``` | ||
|
||
Then, add a variable attribute "pressure_mask" to the data variable you wish to mask. |
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.
Maybe instead of sequences of "ten", each step can be enumerated such as (1) something (2) something ...
:raises FileNotFound: Input file does not exist | ||
:rtype: None | ||
|
||
.. note:: Input variables must have an attribute `pressure_mask` set to `False`. Output variables have the attribute set to `True`. |
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.
Input variables must have the attribute pressure_mask
that is set to False
. The resulting output variable will have this attribute set to True
.
fre_logger = logging.getLogger(__name__) | ||
|
||
def mask_atmos_plevel_subtool(infile: str, psfile: str, outfile: str) -> None: | ||
"""Mask pressure-level diagnostic output below land surface |
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.
new line after """
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.
Thank you! I didn't realize the distinction and have been doing it wrong until now.
|
||
|
||
def pressure_coordinate(ds: xr.Dataset, varname: str) -> xr.DataArray: | ||
"""Check if dataArray has pressure coordinate fitting requirements |
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.
new line
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.
should also be Checks instead of check?
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's not sure what "return it" means, perhaps replace "it" with what it is referring to
|
||
|
||
def write_dataset(ds: xr.Dataset, template: xr.Dataset, outfile: str) -> None: | ||
"""Prepare the dataset and write output NetCDF file |
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.
new line
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.
"write output" can be simplified to "outputs"
|
||
@pytest.fixture() | ||
def create_input_files(tmp_path): | ||
"""Create input data file atmos_cmip.ua_unmsk.nc and ps file atmos_cmip.ps.nc |
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.
new line
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.
also instead of "returning the temporary directory", "returning the name of the temporary directory"
|
||
|
||
def test_mask_atmos_plevel(create_input_files): | ||
"""Do the pressure masking on the test input file, |
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.
new line
|
||
def test_mask_atmos_plevel(create_input_files): | ||
"""Do the pressure masking on the test input file, | ||
and then compare to the known reference output file. |
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.
not sure what it is comparing to
Also, this tool is using both Xarray and Netcdf, perhaps there should be an effort to swap all Netcdf usage to Xarray. |
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 you should move this readme to fre/app/mask_atmos_plevel directory and keep it subtool specific, similar to what Dana did in fre/app/remap_pp_components/README.md and https://github.com/NOAA-GFDL/fre-cli/blob/main/fre/app/regrid_xy/README.md
@ceblanton merge conflict fixed. |
The metadata reading and writing needs to be finalized now that the history files are being written with the intended variable attributes.
Describe your changes
Issue ticket number and link (if applicable)
Checklist before requesting a review