ecmwf / cfgrib

A Python interface to map GRIB files to the NetCDF Common Data Model following the CF Convention using ecCodes
Apache License 2.0
410 stars 77 forks source link

Radar-derived precipitation rates unrecognized (NEXRAD data, MRMS reanalysis dataset) #230

Closed lassiterdc closed 1 year ago

lassiterdc commented 3 years ago

Disclaimer: I'm a beginner to python and wrangling climate datasets in general. I did my best to scour the web and the issues page to find a solution with no luck. I hope I've provided enough information!

Data source: http://edc.occ-data.org/nexrad/mosaic/#data-updates

Problem: The 'PrecipRate' attribute I know to be in the grib is unrecognized resulting in na data values. I confirmed that these data are there using the pygrib library, but I need this to work with cgrib so I can use the 'open_mfdataset' function.

Code:

ds = xr.open_dataset('MRMS_PrecipRate_00.00_20010101-120000.grib2', engine = 'cfgrib')

print(ds)

<xarray.Dataset>
Dimensions:     (latitude: 3500, longitude: 7000)
Coordinates:
    time        datetime64[ns] 2001-01-01T12:00:00
    step        timedelta64[ns] 00:00:00
    surface     float64 0.0
  * latitude    (latitude) float64 54.99 54.98 54.98 54.97 ... 20.03 20.02 20.01
  * longitude   (longitude) float64 230.0 230.0 230.0 ... 300.0 300.0 300.0
    valid_time  datetime64[ns] 2001-01-01T12:00:00
Data variables:
    unknown     (latitude, longitude) float32 ...
Attributes:
    GRIB_edition:            2
    GRIB_centre:             161
    GRIB_centreDescription:  161
    GRIB_subCentre:          0
    Conventions:             CF-1.7
    institution:             161
    history:                 2021-05-04T13:11 GRIB to CDM+CF via cfgrib-0.9.9...

print(ds['unknown'].values)

[[nan nan nan ... nan nan nan]
 [nan nan nan ... nan nan nan]
 [nan nan nan ... nan nan nan]
 ...
 [nan nan nan ... nan nan nan]
 [nan nan nan ... nan nan nan]
 [nan nan nan ... nan nan nan]]
shahramn commented 3 years ago

The fields in these files use a non-standard (i.e., local) encoding. For example the discipline is 209 which is not a WMO standard value

lassiterdc commented 3 years ago

Thank you. I found the local encodings here (https://www.nssl.noaa.gov/projects/mrms/operational/tables.php) where I'm able to download them as a .csv. How do I pass this as an argument to cfgrib?

YasharGIS commented 2 years ago

did you figure out the problem? I am trying to use the data and I have the same issue.

shahramn commented 2 years ago

First of all see this FAQ https://confluence.ecmwf.int/display/UDOC/Creating+your+own+local+definitions+-+ecCodes+GRIB+FAQ

shahramn commented 2 years ago

Steps: Check centre code; here it is 161

% mkdir -p mydefs/grib2/localConcepts/161

In this new directory, create these 4 files: name.def, shortName.def, paramId.def and units.def

We have to assign a parameter ID (paramId) to each of the local NOAA parameters. It is customary to start with the centre code, so I have chosen paramId=161001001 for 'Radar Precipitation Rate'.

% cat mydefs/grib2/localConcepts/161/paramId.def
#Radar Precipitation Rate
'161001001' = {
 discipline = 209 ;
 parameterCategory = 6 ;
 parameterNumber = 1 ;
}

% cat mydefs/grib2/localConcepts/161/shortName.def
#Radar Precipitation Rate
'PrecipRate' = {
 discipline = 209 ;
 parameterCategory = 6 ;
 parameterNumber = 1 ;
}

Create name.def and units.def using this same model.

Now point ecCodes to this directory by setting the environment variable ECCODES_DEFINITION_PATH

% export ECCODES_DEFINITION_PATH=$PWD/mydefs

Now run cfgrib and the shortName should be 'PrecipRate'.

YasharGIS commented 2 years ago

I followed the instruction and I had success at some level. still didn't work. I use Windows and I think that was the reason. I am trying to use this rainfall data in hydrologic modeling. The model requires the daily rainfall value. Any suggestion is appreciated.

shahramn commented 2 years ago

Everything I said was related to UNIX! I don't even know if the PWD environment variable is defined on Windows

shahramn commented 2 years ago

On Windows the equivalent of "export" is "SET". Also to get the working directory, you type "CHDIR". Now take the output of CHDIR and use it to set the env. var e.g. set ECCODES_DEFINITION_PATH=C:/users/john/mydefs

YasharGIS commented 2 years ago

thank you Shahram! it worked.