-
Notifications
You must be signed in to change notification settings - Fork 50
Add Python Script to Translate Increments #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
70f6c40
Save commit of partial work
CoryMartin-NOAA a768067
Working converter
CoryMartin-NOAA c75d50d
Coding norms
CoryMartin-NOAA ed3f13e
Attempt at gathering test data and new unit test
CoryMartin-NOAA 313eb87
Working ctest
CoryMartin-NOAA 13528e0
Add pycodestyle install
CoryMartin-NOAA 69dda87
Make ctest verbose in CI
CoryMartin-NOAA 91e9879
Add netCDF4 to CI
CoryMartin-NOAA 5498453
No need to run pynorms so many times
CoryMartin-NOAA a8699d2
update min cmake version
CoryMartin-NOAA 46acaa6
remove assert, wrap everything in a try
CoryMartin-NOAA 3d0fdb7
Merge branch 'develop' into feature/translate_inc
CoryMartin-NOAA 4283ca1
Fix funky indentation
CoryMartin-NOAA a382ac4
Merge branch 'feature/translate_inc' of https://github.com/NOAA-EMC/G…
CoryMartin-NOAA faa972f
Update CMakeLists.txt
CoryMartin-NOAA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| name: Check Python Coding Norms | ||
| on: [push, pull_request] | ||
| on: [push] | ||
|
|
||
| jobs: | ||
| check_pynorms: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,41 @@ | ||
| add_test(NAME test_check_yaml_keys | ||
| ##### get test data from EMC FTP server | ||
| # set URL and hash | ||
| set(URL "https://ftp.emc.ncep.noaa.gov/static_files/public/GDASApp") | ||
| set(SHA "75c4ce84028956c1ce050e07f70abc25c540492c3e1a40f6fa56d35182322e8e") | ||
| string(SUBSTRING ${SHA} 0 6 SHORTSHA) | ||
| set(TAR "gdasapp-fix-${SHORTSHA}.tgz") | ||
| # download test files | ||
| file(DOWNLOAD | ||
| ${URL}/${TAR} | ||
| ${CMAKE_CURRENT_BINARY_DIR}/${TAR} | ||
| INACTIVITY_TIMEOUT 30 | ||
| TIMEOUT 90 | ||
| SHOW_PROGRESS | ||
| STATUS status | ||
| EXPECTED_HASH SHA256=${SHA} | ||
| ) | ||
| # Extract downloaded tarball. | ||
| file(ARCHIVE_EXTRACT INPUT ${TAR}) | ||
|
|
||
| # list of test files to install | ||
| list(APPEND test_data | ||
| ${CMAKE_CURRENT_BINARY_DIR}/testdata/atminc_compress.nc4 | ||
| ) | ||
|
|
||
| # install | ||
| install(FILES ${test_data} | ||
| DESTINATION "test/testdata") | ||
|
|
||
| ##### unit tests | ||
| # test for python coding norms | ||
| add_test(NAME GDASApp_check_python_norms | ||
| COMMAND pycodestyle -v --config ./.pycodestyle . | ||
| WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) | ||
| # test for ush/check_yaml_keys.py | ||
| add_test(NAME GDASApp_check_yaml_keys | ||
| COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/ush/check_yaml_keys.py ${PROJECT_SOURCE_DIR}/test/testinput/check_yaml_keys_ref.yaml ${PROJECT_SOURCE_DIR}/test/testinput/check_yaml_keys_test.yaml | ||
| WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/) | ||
| # test for ush/jediinc2fv3.py | ||
| add_test(NAME GDASApp_jedi_increment_to_fv3 | ||
| COMMAND ${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/ush/jediinc2fv3.py ${PROJECT_BINARY_DIR}/test/testdata/atminc_compress.nc4 ${PROJECT_BINARY_DIR}/test/testdata/fv_increment.nc | ||
| WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/test/) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/usr/bin/env python3 | ||
| # translate FV3-JEDI increment to FV3 readable format | ||
| import argparse | ||
| import netCDF4 as nc | ||
| import numpy as np | ||
| import os | ||
|
|
||
| vardict = { | ||
| 'ua': 'u_inc', | ||
| 'va': 'v_inc', | ||
| 'delp': 'delp_inc', | ||
| 'DELP': 'delp_inc', | ||
| 'delz': 'delz_inc', | ||
| 'T': 'T_inc', | ||
| 'sphum': 'sphum_inc', | ||
| 'liq_wat': 'liq_wat_inc', | ||
| 'o3mr': 'o3mr_inc', | ||
| 'ice_wat': 'icmr_inc', | ||
| 'lat': 'lat', | ||
| 'lon': 'lon', | ||
| } | ||
|
|
||
|
|
||
| def jedi_inc_to_fv3(FV3JEDIinc, FV3inc): | ||
| # open netCDF files | ||
| try: | ||
| with nc.Dataset(FV3JEDIinc) as ncin, nc.Dataset(FV3inc, "w", format="NETCDF4") as ncout: | ||
| # copy over dimensions | ||
| for name, dimension in ncin.dimensions.items(): | ||
| if name == 'time': | ||
| continue | ||
| elif name == 'edge': | ||
| nameout = 'ilev' | ||
| else: | ||
| nameout = name | ||
| ncout.createDimension(nameout, | ||
| (len(dimension) if not dimension.isunlimited() else None)) | ||
| # some global attributes | ||
| ncout.source = 'jediinc2fv3.py' | ||
| ncout.comment = 'Increment produced by FV3-JEDI and modified for use by FV3 read' | ||
| # create all the dummy vertical coordinate variables | ||
| nlevs = len(ncin.dimensions['lev']) | ||
| pfull = range(1, nlevs+1) | ||
| phalf = range(1, nlevs+2) | ||
| levvar = ncout.createVariable('lev', 'f4', ('lev')) | ||
| levvar[:] = pfull | ||
| pfullvar = ncout.createVariable('pfull', 'f4', ('lev')) | ||
| pfullvar[:] = pfull | ||
| ilevvar = ncout.createVariable('ilev', 'f4', ('ilev')) | ||
| ilevvar[:] = phalf | ||
| hyaivar = ncout.createVariable('hyai', 'f4', ('ilev')) | ||
| hyaivar[:] = phalf | ||
| hybivar = ncout.createVariable('hybi', 'f4', ('ilev')) | ||
| hybivar[:] = phalf | ||
| # rename and change dimensionality of fields | ||
| for name, variable in ncin.variables.items(): | ||
| if len(variable.dimensions) == 4: | ||
| dimsout = variable.dimensions[1:] | ||
| else: | ||
| dimsout = variable.dimensions | ||
| if name in vardict: | ||
| x = ncout.createVariable(vardict[name], 'f4', dimsout) | ||
| if len(variable.dimensions) == 4: | ||
| ncout[vardict[name]][:] = ncin[name][0, ...] | ||
| else: | ||
| ncout[vardict[name]][:] = ncin[name][:] | ||
| except FileNotFoundError as e: | ||
| print(e) | ||
| raise | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('FV3JEDIincrement', type=str, help='Input FV3-JEDI LatLon Increment File') | ||
| parser.add_argument('FV3increment', type=str, help='Output FV3 Increment File') | ||
| args = parser.parse_args() | ||
| jedi_inc_to_fv3(args.FV3JEDIincrement, args.FV3increment) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Need to change the cmake min version to something more recent. 3.16.3 is too old for the option above, 3.20.0 seems fine.