User1503
User1503

Reputation: 1

cfgrib: Incorrect Handling of Zero Values in GRIB File Data

I have a GRIB file generated from local WRF calculation based on GFS file from NOAA/NCEP. I am using the cfgrib library to load the forecast data from this GRIB file. However, when I attempt to access the DSWRF (Downward Short-Wave Radiation Flux) or TCC (Total Cloud Cover) variables, I encounter abnormally high and low values, such as 2147466880.0 and -2147331584.0, but only for the values that should be zero (for example night hours for DSWRF).

I ran the following code and observed abnormal DSWRF values specifically during the night hours.

import numpy as np
import pandas as pd
import cfgrib

ds=cfgrib.open_datasets('wrfprs_d02_05_09.grib2')
grid_df = pd.DataFrame({'latitude':ds[0].latitude.to_numpy().flatten(), 'longitude':ds[0].longitude.to_numpy().flatten(), 'dswrf':ds[22].dswrf[0].to_numpy().flatten()})

I also attempted to read the GRIB file using the xarray and pygrib libraries, but encountered the same issue with abnormal DSWRF and TCC values.

ds = xr.open_dataset('wrfprs_d02_05_09.grib2', engine='cfgrib')
grbs = pygrib.open('wrfprs_d02_05_09.grib2')

Additionally, I verified the data encoding using the wgrib2 tool, which correctly reads zero values from the GRIB file. This suggests that the issue is likely related to how the cfgrib library decodes the data, rather than a problem with the file's encoding.

The first graph is notable because it illustrates that the DSWRF values consistently increase until reaching 2147466880.0, at which point they reset and start again from -2147331584.0.

DSWRF values on graph DSWRF values in dataframe

Upvotes: 0

Views: 40

Answers (0)

Related Questions