Skip to content

Conversation

georgemccabe
Copy link
Collaborator

Read WRF Fire subgrid field natively in MET instead of using Python Embedding script

Pull Request Testing

  • Describe testing already performed for these changes:

Ran fire use case using MET branch to test that it can read the WRF Fire subgrid field without Python Embedding
Reviewed the differences and confirmed they are acceptable (see below)

  • Recommend testing for the reviewer(s) to perform, including the location of input datasets, and any additional instructions:

Review code changes and diffs in fire use case output

  • The FCST_LEV value has changed because it was previously passed as a hard-coded string in the Python Embedding script but now it lists the NetCDF format

  • The FCST_UNITS changed because the Python Embedding script passed a hard-coded % value but the units value in the NetCDF WRF file is 1

  • The lat and lon values differ by a small amount due to rounding

  • The field names in the NetCDF output have changed because of the difference in the level values. Should we use set_attr values to change this?

    DIFF_FIRE_AREA_Z0_FIRE_PERIM_all_all_FULL changed to DIFF_FIRE_AREA_0_all_all_FIRE_PERIM_all_all_FULL
    FCST_FIRE_AREA_Z0_FULL changed to FCST_FIRE_AREA_0_all_all_FULL

I confirmed that these fields look the same despite the name change

  • Do these changes include sufficient documentation updates, ensuring that no errors or warnings exist in the build of the documentation? [Yes]

  • Do these changes include sufficient testing updates? [Yes]

  • Will this PR result in changes to the test suite? [Yes]

    If yes, describe the new output and/or changes to the existing output:

The fire use case will contain diffs that will require an update to the truth data

  • Do these changes introduce new SonarQube findings? [No]

    If yes, please describe:

  • Please complete this pull request review by 4/11/2025.

Pull Request Checklist

See the METplus Workflow for details.

  • Add any new Python packages to the METplus Components Python Requirements table.
  • For any new datasets, an entry to the METplus Verification Datasets Guide.
  • Review the source issue metadata (required labels, projects, and milestone).
  • Complete the PR definition above.
  • Ensure the PR title matches the feature or bugfix branch name.
  • Define the PR metadata, as permissions allow.
    Select: Reviewer(s) and Development issue
    Select: Milestone as the version that will include these changes
    Select: Coordinated METplus-X.Y Support project for bugfix releases or METplus-Wrappers-X.Y.Z Development project for official releases
  • After submitting the PR, select the ⚙️ icon in the Development section of the right hand sidebar. Search for the issue that this PR will close and select it, if it is not already selected.
  • After the PR is approved, merge your changes. If permissions do not allow this, request that the reviewer do the merge.
  • Close the linked issue and delete your feature or bugfix branch from GitHub.

@georgemccabe georgemccabe added this to the METplus-6.1.0 milestone Apr 4, 2025
@georgemccabe georgemccabe requested a review from Copilot April 4, 2025 16:33
@github-project-automation github-project-automation bot moved this to 🩺 Needs Triage in METplus-6.1 Development Apr 4, 2025
@georgemccabe georgemccabe moved this from 🩺 Needs Triage to 🔎 In review in METplus-6.1 Development Apr 4, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 8 changed files in this pull request and generated no comments.

Files not reviewed (3)
  • docs/Release_Guide/release_steps/met/update_web_server_data.rst: Language not supported
  • internal/tests/use_cases/all_use_cases.txt: Language not supported
  • parm/use_cases/model_applications/fire/GridStat_fcstWRF_obsMMA_fire_perimeter.conf: Language not supported
Comments suppressed due to low confidence (3)

metplus/wrappers/runtime_freq_wrapper.py:889

  • Consider verifying that the remove_quotes function is idempotent to prevent potential double quoting if the file path is already enclosed in quotation marks.
file_list = [f'"{remove_quotes(item)}"' if ' ' in item else item for item in file_list]

metplus/wrappers/py_embed_ingest_wrapper.py:109

  • Setting RDP_SKIP_RUN_CHECK unconditionally may affect behavior in other wrappers; consider adding a comment that explains this configuration update and its intended scope.
self.config.set('config', 'RDP_SKIP_RUN_CHECK', True)

internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py:911

  • [nitpick] Ensure that the substring check for 'PYTHON' in the OBS_POINT_STAT_INPUT_TEMPLATE reliably distinguishes the Python embedding case from standard file paths; a stricter condition or additional comment could enhance clarity.
if 'OBS_POINT_STAT_INPUT_TEMPLATE' in config_overrides and 'PYTHON' in config_overrides['OBS_POINT_STAT_INPUT_TEMPLATE']:

@georgemccabe georgemccabe changed the title add quotation marks around file path if it includes spaces Feature #2560 Update Fire use case Apr 4, 2025
@georgemccabe
Copy link
Collaborator Author

Addressing feedback from Copilot:

Consider verifying that the remove_quotes function is idempotent to prevent potential double quoting if the file path is already enclosed in quotation marks.

The file_list values are not always surrounded by quotation marks. A "file path" in this list can be a call to a Python script or a string that defines grid information. The logic to handle this already adds quotation marks. However, updates to the use case in this PR uncovered that file paths that include a space character are not properly quoted. This new line ensures that quotation marks are added around paths with spaces. Since the values can potentially already include quotation marks, the remove_quotes function is called to remove any extra quotation marks. If the value does not include quotation marks, the function returns the string as-is.

Setting RDP_SKIP_RUN_CHECK unconditionally may affect behavior in other wrappers; consider adding a comment that explains this configuration update and its intended scope.

I added a comment to explain why this was set. The config variable is meant to be internal and not set by users, so I did not add info about this variable to the documentation. It is only used to prevent an incorrect error from being logged, so there is no harm if a user accidentally creates a config variable with the same name.

[nitpick] Ensure that the substring check for 'PYTHON' in the OBS_POINT_STAT_INPUT_TEMPLATE reliably distinguishes the Python embedding case from standard file paths; a stricter condition or additional comment could enhance clarity.

I agree that the check for the string 'PYTHON' will break down if a file path includes the string. I didn't think it was necessarily to come up with a more robust solution because this is an internally-used test and it is unlikely that any future modifications to the tests will include the string and cause an issue. If a developer does do this, the tests will break and a closer review should uncover the requirements of a new test.

Copy link
Collaborator

@JohnHalleyGotway JohnHalleyGotway left a comment

Choose a reason for hiding this comment

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

George, thanks for pointing out the differences that this PR causes. I definitely do think that we should add set_attr options to eliminate the diffs in the stat files and reduce the ones in the NetCDF files. The "truth" units (%) are better than the new "output" units (1). And if we're updating the units, we may as well update the level string as well. And this will serve as a nice example of the -set_attr options in a METplus Use Case.

I'd recommend adding:

FCST_VAR1_OPTIONS = -set_attr_units % -set_attr_level Z0

I'll just proposed that one line change to the code.

georgemccabe and others added 2 commits April 4, 2025 14:22
Co-authored-by: John Halley Gotway <johnhg@ucar.edu>
Copy link
Collaborator

@JohnHalleyGotway JohnHalleyGotway left a comment

Choose a reason for hiding this comment

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

Thanks @georgemccabe for adding the set_attr_units and set_attr_level options to minimize the diffs. The remaining differences for the WRF-Fire Grid-Stat runs are in the NetCDF matched pairs files:

  • The long_name variable attributes are modified but that's totally fine since the content for that is now being read directly from the input files.
  • The grid definition information listed in the global attributes are modified slightly, generally in the second decimal place, but so too have the x_pin and y_pin locations.
Screenshot 2025-04-05 at 10 03 04 AM

You suggested that these were minor diffs based on rounding, but I think they're actually significant differences. But those differences are actually fine. They are just two different ways of defining the same grid!

The x/y pin locations define the location of the reference lat/lon in the grid. The old x/y of (0,0) means that lat/lon (37.402645, -107.881439) occurs at the lower-left corner of the grid. The new x/y of (235.5, 235.5) means that lat/lon (37.461014, -107.80799) occurs at the center of the grid.

The lat/lon difference from old to new reference location is (-0.058369, 0.073449). Very roughly assuming 110km per degree latitude, with d_km = 0.027542 a shift of 235.5 grid points in the x/y directions = 6.486 km = 0.05896 degrees of latitude... which is very close to the actual latitude difference we're seeing!

So the lat/lon locations have changed very slightly in a way that's consistent with the x/y pin location change... for a very, very tiny grid.

The we're running Grid-Stat with forecast data defined relative to the center of the grid and "observation" data (output from Gen-Vx-Mask) defined relative to the lower-left corner of the grid. Since those grid definitions differ, Grid-Stat needs to put them on a common grid. And in metplus_final.conf I see we're auto-regridding to the forecast grid:

GRID_STAT_REGRID_TO_GRID = FCST

And with nothing overriding the default regridding method in the default Grid-Stat config file, we're regridding using the nearest neighbor method. So the "obs" input data is being regridded with nearest neighbor to forecast grid. But since they're in the same location on earth, we end up getting exactly the same contingency table counts and statistics.

This is a pretty subtle difference. I'd say your options are:

  1. Keep everything as-is and let Grid-Stat keep doing its regridding between two grids that are equivalent but defined with different parameters.
  2. Modify the Python embedding script used when running Gen-Vx-Mask so that the forecast and observation grids are defined the same way for Grid-Stat.

Honestly, either approach is totally fine. And sticking with the existing "auto-regridding" does demonstrate the functionality of grid handling in MET.

@JohnHalleyGotway JohnHalleyGotway self-requested a review April 5, 2025 16:39
Copy link
Collaborator

@JohnHalleyGotway JohnHalleyGotway left a comment

Choose a reason for hiding this comment

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

I approve of these changes, but I added a bunch of details and ended with a question in this PR comment. Feel free to stick with the changes as-is or tweak the observation grid definition to avoid unnecessary regridding. Either way is totally fine.

@georgemccabe
Copy link
Collaborator Author

Hi @JohnHalleyGotway , thank you for the detailed summary of what is going on with the diffs. I'll note that GenVxMask is not using Python Embedding. A script is run to convert the fire boundary data to a poly file, then the grid is defined explicitly:

GEN_VX_MASK_INPUT_TEMPLATE = "lambert 472 472 37.402645 -107.88144 -107.808 0.02754 6371.229 37.461 N"

so I won't be able to change the obs grid to use the same x/y pin. That said, I am OK with leaving the "different but same" grid definition and let MET regrid to the forecast.

@georgemccabe georgemccabe merged commit 2069965 into develop Apr 16, 2025
79 of 80 checks passed
@github-project-automation github-project-automation bot moved this from 🔎 In review to 🏁 Done in METplus-6.1 Development Apr 16, 2025
@georgemccabe georgemccabe deleted the feature_2560_read_wrf_subgrid branch April 16, 2025 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: 🏁 Done
Development

Successfully merging this pull request may close these issues.

2 participants