Skip to content
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

Add a grib to netcdf conversion scirpt #40

Closed
alexamici opened this issue Dec 19, 2018 · 3 comments
Closed

Add a grib to netcdf conversion scirpt #40

alexamici opened this issue Dec 19, 2018 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@alexamici
Copy link
Contributor

This can be done easily with xarray and netcdf4.

@alexamici alexamici added the enhancement New feature or request label Dec 19, 2018
@alexamici alexamici self-assigned this Dec 19, 2018
@alexamici
Copy link
Contributor Author

A simple conversion script has been added in 80ade61

@alexamici
Copy link
Contributor Author

The usage is:

$ cfgrib to_netcdf --help
Usage: cfgrib to_netcdf [OPTIONS] [INPATHS]...

Options:
  -o, --outpath TEXT
  -c, --cdm TEXT
  -e, --engine TEXT
  --help              Show this message and exit.

For example:

$ cfgrib to_netcdf -c CDS tests/sample-data/era5-levels-members.grib
$ ncdump -h tests/sample-data/era5-levels-members.nc 
netcdf era5-levels-members {
dimensions:
	realization = 10 ;
	forecast_reference_time = 4 ;
	plev = 2 ;
	lat = 61 ;
	lon = 120 ;
variables:
	double lon(lon) ;
		lon:units = "degrees_east" ;
		lon:standard_name = "longitude" ;
		lon:long_name = "longitude" ;
		lon:_FillValue = NaN ;
	double lat(lat) ;
		lat:units = "degrees_north" ;
		lat:standard_name = "latitude" ;
		lat:long_name = "latitude" ;
		lat:stored_direction = "decreasing" ;
		lat:_FillValue = NaN ;
	float z(realization, forecast_reference_time, plev, lat, lon) ;
		z:GRIB_paramId = 129 ;
		z:GRIB_shortName = "z" ;
		z:GRIB_units = "m**2 s**-2" ;
		z:GRIB_name = "Geopotential" ;
		z:GRIB_cfName = "geopotential" ;
		z:GRIB_cfVarName = "z" ;
		z:GRIB_dataType = "an" ;
		z:GRIB_missingValue = 9999 ;
		z:GRIB_numberOfPoints = 7320 ;
		z:GRIB_totalNumber = 10 ;
		z:GRIB_typeOfLevel = "isobaricInhPa" ;
		z:GRIB_NV = 0 ;
		z:GRIB_stepUnits = 1 ;
		z:GRIB_stepType = "instant" ;
		z:GRIB_gridType = "regular_ll" ;
		z:GRIB_gridDefinitionDescription = "Latitude/Longitude Grid" ;
		z:GRIB_Nx = 120 ;
		z:GRIB_iDirectionIncrementInDegrees = 3. ;
		z:GRIB_iScansNegatively = 0 ;
		z:GRIB_longitudeOfFirstGridPointInDegrees = 0. ;
		z:GRIB_longitudeOfLastGridPointInDegrees = 357. ;
		z:GRIB_Ny = 61 ;
		z:GRIB_jDirectionIncrementInDegrees = 3. ;
		z:GRIB_jPointsAreConsecutive = 0 ;
		z:GRIB_jScansPositively = 0 ;
		z:GRIB_latitudeOfFirstGridPointInDegrees = 90. ;
		z:GRIB_latitudeOfLastGridPointInDegrees = -90. ;
		z:long_name = "Geopotential" ;
		z:units = "m**2 s**-2" ;
		z:standard_name = "geopotential" ;
		z:coordinates = "leadtime time" ;
		z:_FillValue = NaNf ;
	float t(realization, forecast_reference_time, plev, lat, lon) ;
		t:GRIB_paramId = 130 ;
		t:GRIB_shortName = "t" ;
		t:GRIB_units = "K" ;
		t:GRIB_name = "Temperature" ;
		t:GRIB_cfName = "air_temperature" ;
		t:GRIB_cfVarName = "t" ;
		t:GRIB_dataType = "an" ;
		t:GRIB_missingValue = 9999 ;
		t:GRIB_numberOfPoints = 7320 ;
		t:GRIB_totalNumber = 10 ;
		t:GRIB_typeOfLevel = "isobaricInhPa" ;
		t:GRIB_NV = 0 ;
		t:GRIB_stepUnits = 1 ;
		t:GRIB_stepType = "instant" ;
		t:GRIB_gridType = "regular_ll" ;
		t:GRIB_gridDefinitionDescription = "Latitude/Longitude Grid" ;
		t:GRIB_Nx = 120 ;
		t:GRIB_iDirectionIncrementInDegrees = 3. ;
		t:GRIB_iScansNegatively = 0 ;
		t:GRIB_longitudeOfFirstGridPointInDegrees = 0. ;
		t:GRIB_longitudeOfLastGridPointInDegrees = 357. ;
		t:GRIB_Ny = 61 ;
		t:GRIB_jDirectionIncrementInDegrees = 3. ;
		t:GRIB_jPointsAreConsecutive = 0 ;
		t:GRIB_jScansPositively = 0 ;
		t:GRIB_latitudeOfFirstGridPointInDegrees = 90. ;
		t:GRIB_latitudeOfLastGridPointInDegrees = -90. ;
		t:long_name = "Temperature" ;
		t:units = "K" ;
		t:standard_name = "air_temperature" ;
		t:coordinates = "leadtime time" ;
		t:_FillValue = NaNf ;
	int realization(realization) ;
		realization:long_name = "ensemble member numerical id" ;
		realization:units = "1" ;
		realization:standard_name = "realization" ;
	int forecast_reference_time(forecast_reference_time) ;
		forecast_reference_time:long_name = "initial time of forecast" ;
		forecast_reference_time:standard_name = "forecast_reference_time" ;
		forecast_reference_time:units = "seconds since 1970-01-01T00:00:00+00:00" ;
		forecast_reference_time:calendar = "proleptic_gregorian" ;
	double time(forecast_reference_time) ;
		time:standard_name = "time" ;
		time:long_name = "time" ;
		time:units = "seconds since 1970-01-01T00:00:00+00:00" ;
		time:calendar = "proleptic_gregorian" ;
		time:_FillValue = NaN ;
	double plev(plev) ;
		plev:long_name = "pressure" ;
		plev:units = "Pa" ;
		plev:positive = "down" ;
		plev:stored_direction = "decreasing" ;
		plev:standard_name = "air_pressure" ;
		plev:_FillValue = NaN ;
	double leadtime ;
		leadtime:long_name = "time since forecast_reference_time" ;
		leadtime:standard_name = "forecast_period" ;
		leadtime:units = "hours" ;
		leadtime:_FillValue = NaN ;

// global attributes:
		:GRIB_edition = 1 ;
		:GRIB_centre = "ecmf" ;
		:GRIB_centreDescription = "European Centre for Medium-Range Weather Forecasts" ;
		:GRIB_subCentre = 0 ;
		:Conventions = "CF-1.7" ;
		:institution = "European Centre for Medium-Range Weather Forecasts" ;
		:history = "GRIB to CDM+CF via cfgrib-0.9.5.1.dev0/ecCodes-2.8.2 with source=\'/Users/amici/devel/MPY/cfgrib/tests/sample-data/era5-levels-members.grib\', filter_by_keys={}, encode_cf=(\'parameter\', \'time\', \'geography\', \'vertical\')" ;
}

@mstrahl
Copy link

mstrahl commented Dec 28, 2019

I tested this cfgrib to_netcdf with C3S seasonal forecast data and it required dask and scipy to function. so the cfgrib install with conda would need some fixes in the requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants