Skip to content

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

ceblanton
Copy link
Collaborator

@ceblanton ceblanton commented Apr 22, 2025

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

  • I ran my code
  • I tried to make my code readable
  • I tried to comment my code
  • I wrote a new test, if applicable
  • I wrote new instructions/documentation, if applicable
  • I ran pytest and inspected it's output
  • I ran pylint and attempted to implement some of it's feedback
  • No print statements; all user-facing info uses logging module

The metadata reading and writing needs to be finalized now that
the history files are being written with the variable attribute updates.
@ilaflott ilaflott self-requested a review May 6, 2025 16:34
Copy link
Member

@ilaflott ilaflott left a 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

@ceblanton ceblanton changed the title Adjustments for pressure masking tool Pressure masking tool fixes, tests, and docs Jul 2, 2025
Copy link
Contributor

@laurenchilutti laurenchilutti left a 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.

Chris Blanton added 3 commits July 8, 2025 18:33
- 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
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 93.44262% with 4 lines in your changes missing coverage. Please review.

Project coverage is 66.88%. Comparing base (e4ee6cf) to head (7597ab0).

Files with missing lines Patch % Lines
fre/app/mask_atmos_plevel.py 82.35% 3 Missing ⚠️
fre/app/freapp.py 66.66% 1 Missing ⚠️
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     
Flag Coverage Δ
unittests 66.88% <93.44%> (+1.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@ilaflott ilaflott left a 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?

Copy link
Member

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/

Copy link
Collaborator Author

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

Copy link
Contributor

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

Copy link

@mlee03 mlee03 left a 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
Copy link

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
Copy link

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?

Copy link
Collaborator Author

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.
Copy link

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`.
Copy link

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line after """

Copy link
Collaborator Author

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Copy link

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?

Copy link

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Copy link

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Copy link

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,
Copy link

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.
Copy link

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

@mlee03
Copy link

mlee03 commented Jul 24, 2025

Also, this tool is using both Xarray and Netcdf, perhaps there should be an effort to swap all Netcdf usage to Xarray.
The test input files could also be generated on the fly too...

Copy link
Contributor

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

@ilaflott ilaflott added documentation Improvements or additions to documentation new functioning New feature or request clean up labels Aug 15, 2025
@ilaflott
Copy link
Member

@ceblanton merge conflict fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean up documentation Improvements or additions to documentation new functioning New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants