-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Per #2781, added function to convert MET NetCDF point observation data to pandas so it can be read and modified in a python embedding script. Added example python embedding script * ignore python cache files * fixed function call * reduce cognitive complexity to satisfy SonarQube and add boolean return value to catch if function fails to read data * clean up script and add comments * replace call to object function that doesn't exist, handle exception when file passed to script cannot be read by the NetCDF library * rename example script * add new example script to makefiles * fix logic to build pandas DataFrame to properly get header information from observation header IDs * Per #2781, add unit test to demonstrate python embedding script that reads MET NetCDF point observation file and converts it to a pandas DataFrame * Per #2781, added init function for nc_point_obs to take an input filename. Also raise TypeError exception from nc_point_obs.read_data() if input file cannot be read * call parent class init function to properly initialize nc_point_obs
- Loading branch information
1 parent
542b4ba
commit 79ac568
Showing
7 changed files
with
154 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -19,3 +19,5 @@ make.log | |
make_install.log | ||
.idea | ||
cmake-build-debug | ||
|
||
__pycache__ |
This file contains 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 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 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 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,52 @@ | ||
import os | ||
import sys | ||
|
||
from met.point_nc import nc_point_obs | ||
|
||
# Description: Reads a point observation NetCDF file created by MET and passes | ||
# the data to another MET tool via Python Embedding. This script can be copied | ||
# to perform modifications to the data before it is passed to MET. | ||
# Example: plot_point_obs "PYTHON_NUMPY=pyembed_met_point_nc.py in.nc" out.ps | ||
# Contact: George McCabe <[email protected]> | ||
|
||
# Read and format the input 11-column observations: | ||
# (1) string: Message_Type | ||
# (2) string: Station_ID | ||
# (3) string: Valid_Time(YYYYMMDD_HHMMSS) | ||
# (4) numeric: Lat(Deg North) | ||
# (5) numeric: Lon(Deg East) | ||
# (6) numeric: Elevation(msl) | ||
# (7) string: Var_Name(or GRIB_Code) | ||
# (8) numeric: Level | ||
# (9) numeric: Height(msl or agl) | ||
# (10) string: QC_String | ||
# (11) numeric: Observation_Value | ||
|
||
print(f"Python Script:\t{sys.argv[0]}") | ||
|
||
if len(sys.argv) != 2: | ||
print("ERROR: pyembed_met_point_nc.py -> Specify only 1 input file") | ||
sys.exit(1) | ||
|
||
# Read the input file as the first argument | ||
input_file = os.path.expandvars(sys.argv[1]) | ||
print("Input File:\t" + repr(input_file)) | ||
|
||
# Read MET point observation NetCDF file | ||
try: | ||
point_obs = nc_point_obs(input_file) | ||
except TypeError: | ||
print(f"ERROR: Could not read MET point data file {input_file}") | ||
sys.exit(1) | ||
|
||
# convert point observation data to a pandas DataFrame | ||
df = point_obs.to_pandas() | ||
|
||
################################################## | ||
# perform any modifications to the data here # | ||
################################################## | ||
|
||
# convert pandas DataFrame to list format that is expected by MET | ||
point_data = df.values.tolist() | ||
print(f" point_data: Data Length:\t{len(point_data)}") | ||
print(f" point_data: Data Type:\t{type(point_data)}") |
This file contains 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 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