Project

General

Profile

Extract the Lat/Lon information from a Polar Stereographic projection

Added by Jia Wang 3 months ago

The file I have is on a Polar Stereographic projection and in the grib2 format.

When I converted it to the netCDF format,
cdo -f nc copy st4_conus.2023121800.06h.grb2 1.nc

"1.nc" does not contain the Lat/Lon information, and only has the x/y information.

How could it have the Lat/Lon information?


Replies (11)

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Karin Meier-Fleischer 3 months ago

The GRIB file contains:

cdo sinfon st4_conus.2023121800.06h.grb2

   File format : GRIB2
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter name
     1 : unknown  unknown  v accum         1   1    987601   1  P21  : tp            
   Grid coordinates :
     1 : projection               : points=987601 (1121x881)
                          mapping : polar_stereographic
                                x : 0 to 5334000 by 4762.5 m
                                y : 0 to 4191000 by 4762.5 m
   Vertical coordinates :
     1 : surface                  : levels=1
   Time coordinate :
                             time : 1 step
     RefTime =  2023-12-17 18:00:00  Units = hours  Calendar = proleptic_gregorian
  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
  2023-12-18 00:00:00

When you convert the data from GRIB to netCDF the coordinates will be kept, not remapped to a lonlat grid. This can be done with one of the remap operators, e.g.

gridfile.txt

gridtype  = lonlat
gridsize  = 987601
xsize     = 1121
ysize     = 881
xname     = lon
xunits    = "degrees_east" 
yname     = lat
yunits    = "degrees_north" 
xfirst    = -130.
xinc      = 0.06
yfirst    = 20.
yinc      = 0.06

cdo -f nc -remapbil,grid_deg.txt st4_conus.2023121800.06h.grb2 outfile.nc

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Jia Wang 3 months ago

But I want the Lat / Lon of the original grid in Polar Stereographic projection, which would be 2-dimensional for either Lat or Lon. Is there a way to get it?

Another issue I have is that, I realize the grid information in some of my grib2 files are "wrong".

For the file "ST4.2009113018.06h.grb2", the grid information using "cdo griddes" is:
gridtype = projection
gridsize = 987601
xsize = 1121
ysize = 881
xname = x
xunits = "m"
yname = y
yunits = "m"
xfirst = 0
xinc = 4763
yfirst = 0
yinc = 4763
grid_mapping = Polar_Stereographic
grid_mapping_name = polar_stereographic
standard_parallel = 60.
straight_vertical_longitude_from_pole = -105.
latitude_of_projection_origin = 90.
earth_radius = 6367470.
false_easting = 1901416.77987822
false_northing = 7613145.49149694
longitudeOfFirstGridPointInDegrees = 240.977
latitudeOfFirstGridPointInDegrees = 23.117

For the file "st4_conus.2023121800.06h.grb2", the grid information using "cdo griddes" is:
gridtype = projection
gridsize = 987601
xsize = 1121
ysize = 881
xname = x
xunits = "m"
yname = y
yunits = "m"
xfirst = 0
xinc = 4762.5
yfirst = 0
yinc = 4762.5
grid_mapping = Polar_Stereographic
grid_mapping_name = polar_stereographic
standard_parallel = 60.
straight_vertical_longitude_from_pole = 255.
latitude_of_projection_origin = 90.
earth_radius = 6371200.
false_easting = 1902531.67435698
false_northing = 7617604.93005048
longitudeOfFirstGridPointInDegrees = 240.976992
latitudeOfFirstGridPointInDegrees = 23.117

Based on my knowledge, the "xinc"/"yinc"/"earth_radius" in "ST4.2009113018.06h.grb2" is wrong, and they should be the same as those in "st4_conus.2023121800.06h.grb2".

I think this error in its grid description will cause problems when I either interpolate other data into the grid represented by "ST4.2009113018.06h.grb2" or interpolate data in "ST4.2009113018.06h.grb2" to other grids.

How could I make corrections to the grid description in "ST4.2009113018.06h.grb2".

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Karin Meier-Fleischer 3 months ago

Use the correct grid description file with one of the remap operators to fix this issue.

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Jia Wang 3 months ago

Could you give an example of the command line?

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Karin Meier-Fleischer 3 months ago

The command is similar to the command obove, but instead of using the grid description file you can use the file with the correct grid directly.

cdo -remapbil,st4_conus.2023121800.06h.grb2 ST4.2009113018.06h.grb2 outfile.grb2

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Jia Wang 3 months ago

In this way, the CDO will ignore the grid description of "ST4.2009113018.06h.grb2", but only use its data?

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Karin Meier-Fleischer 3 months ago

If you want to exchange the grid description you can set the correct grid before you copy the data.

cdo -copy -setgrid,st4_conus.2023121800.06h.grb2 ST4.2009113018.06h.grb2 outfile.grb2

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Jia Wang 3 months ago

I think I did not explain my issue clear.

"ST4.2009113018.06h.grb2"'s grid description is wrong.

"st4_conus.2023121800.06h.grb2"'s grid description is right.

These two files should be on the same grid, and should have the same grid description when I use "cdo griddes". But in reality, "ST4.2009113018.06h.grb2"'s grid description is wrong.

If I use the command "cdo -remapbil,st4_conus.2023121800.06h.grb2 ST4.2009113018.06h.grb2 outfile.grb2", it will interpolate data from "ST4.2009113018.06h.grb2"'s grid, which has a wrong grid description, to the "st4_conus.2023121800.06h.grb2"'s grid, then "outfile.grb2" will be wrong, because NO interpolation is actually needed since the data in reality is on the same grid.

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Karin Meier-Fleischer 3 months ago

You were too fast or I was too slow. See my last answer that only exchange the grid description. ;)

RE: Extract the Lat/Lon information from a Polar Stereographic projection - Added by Jia Wang 3 months ago

Just saw you post after I did my last post. I think your suggestion "setgrid" is what I need. Thanks.

    (1-11/11)