Project

General

Profile

Converting Regular TO Polar Stereographic Grids

Added by Simon Driscoll over 1 year ago

Hi! I have seen a few messages about using CDO to convert polar stereographic to regular, but I have not seen much about if the reverse is possible (apologies if I have missed anything).

If I have e.g. an ERA5 netCDF that is on a regular grid, how would I use cdo to regrid it to a polar stereographic grid (attached an example, being a netCDF of melt pond fraction)? (I believe the e.g. 'r144x144' type commands are redundant as they're meant for regridding to regular - any help would be most appreciated)


Replies (9)

RE: Converting Regular TO Polar Stereographic Grids - Added by Estanislao Gavilan over 1 year ago

Hi Simon,

I have never done it, but it should not be that difficult. Have you tried to make an gridfile.txt and use the command remap? I found a polar stereographic grid specification on this forum. Try to fill the values according to your grid paramters and then type

cdo remapbil, gridfile.txt infile.nc outfile.nc

gridfile.txt

gridtype  = projection
gridsize = 152830986 (xsize*ysize)
xsize = 14762
ysize = 10353
xname = x
xlongname = "x coordinate of projection"
xunits = "m"
yname = y
ylongname = "y coordinate of projection"
yunits = "m"
xfirst = -6111475.22239475
xinc = 926.625433138333
yfirst = 4114895.09469662
yinc = -926.625433138333
grid_mapping = polar_stereographic
grid_mapping_name = polar_stereographic
straight_vertical_longitude_from_pole = 0.
false_easting = 0.
false_northing = 0.
latitude_of_projection_origin = 90.
standard_parallel = 71.
longitude_of_prime_meridian = 0.
semi_major_axis = 6378137.
inverse_flattening = 298.257223563
proj_params = "+proj=stere +lat_0=90 +lat_ts=71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"

RE: Converting Regular TO Polar Stereographic Grids - Added by Simon Driscoll over 1 year ago

Hi,

I tried this with the .txt file as you gave it, and I get:

tests_regrid_data % cdo remapbil, gridfile.txt infile.nc outfile.nc
cdo (Abort): remapbil, gridfile.txt infile.nc outfile.nc
^ To many inputs

So I removed the space between the remapbil, and gridfile.txt:

_tests_regrid_data % cdo remapbil,gridfile.txt infile.nc outfile.nc
Warning (cdf_set_dim): Inconsistent dimension definition for lat! dimid = 0; type = 3; newtype = 2
Warning (cdf_set_dim): Inconsistent dimension definition for lon! dimid = 0; type = 3; newtype = 1
Warning (cdfInqContents): Coordinates variable realization can't be assigned!

cdo remapbil (Abort): proj library support not compiled in!
_

I apologise about my possibly incredibly simple question, as I can't find in e.g. the text file any reference to 'new type' and so on, but do you have any idea what's going on/how I can get past the error?

Thank you!

RE: Converting Regular TO Polar Stereographic Grids - Added by Estanislao Gavilan over 1 year ago

Hi Simon,

those are warnings, so do not get too bother about that. The problem is

cdo remapbil (Abort): proj library support not compiled in!

it means that your cdo is not built with proj support. That library is a total deal. I recommend you to install cdo via anaconda -never let you down. Now moving to your case. I have set this grid using the data from the NISC.

gridtype  = projection
gridsize = 544768
xsize = 608
ysize = 896
xname = x
xlongname = "x coordinate of projection"
xunits = "m"
yname = y
ylongname = "y coordinate of projection"
yunits = "m"
xfirst = -3843750
xinc = 12500
yfirst = -5343750
yinc = 12500
grid_mapping = Polar_stereographic
grid_mapping_name = polar_stereographic
proj_params = "+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs"

Then press the command

cdo remapbil,grid.txt input.nc output.nc

this is the result

simonremap.png (552 KB) simonremap.png remap to ps grid

RE: Converting Regular TO Polar Stereographic Grids - Added by Simon Driscoll over 1 year ago

Hi Estanislao,

thank you so much!! This is incredibly useful. One further thing, I have two different 'satellite sources' of the same product. (e.g. satellite1 monitors Year1-Year10, satellite2 monitors Year11-Year20 as such). They are both on polar stereographic grids. How can I be sure that they are on the same grid? This would seem easy on regular, but having the same numbers of data points on ps grids to me (and a few other usual things) doesn't seem to be enough of a guarantee that they are on the same grid/resolution/starting points etc.

I attach two small netCDF files of a day of observations each, one of MERIS ('satellite' 1 as such) and OLCI ('satellite' 2 as such), both on polar stereographic grids.

Any help would be incredible.

RE: Converting Regular TO Polar Stereographic Grids - Added by Estanislao Gavilan over 1 year ago

Hi,

The only way to check that both grids have the same coordinates is to compare the attributes of your files. In this case, both files have the same grid info, Coordinate Reference Systems (crs) and dimensions. In addition, you could even compare the variables y and x to make sure they have the same values.

Kind regards,

Estanislao

RE: Converting Regular TO Polar Stereographic Grids - Added by Simon Driscoll over 1 year ago

Hi Estanislao,

ok thanks! I figured this is a possible way, but wondered if CDO had a built in command, say that could easily evaluate two grids/see if they're identical. I'll do as you say otherwise to check these. One final question (and thank you so much for all the help! It is so useful), in your first reply there are a few minor details in your .txt file I do not quite understand, for example:

xfirst = -3843750
xinc = 12500
yfirst = -5343750
yinc = 12500

also

+lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449

I don't know how to 'make the text file' like this or if I were to do one on my own, what I would set a or b, first, +lat_ts, +k and so on as. How do I understand what these should be so I can build a text file to regrid a regular file to any polar stereographic file (or even just understand what these values are in relation to the polar stereographic file provided at the top).

Thank you so much once again!

RE: Converting Regular TO Polar Stereographic Grids - Added by Simon Driscoll over 1 year ago

Hi Estanislao,

one quick question, you provide the gridfile.txt to remap the one regular gridded ERA5 netCDF to polar stereographic, I assume that this gridfile.txt you provide:

gridtype = projection
gridsize = 544768
xsize = 608
ysize = 896
xname = x
xlongname = "x coordinate of projection"
xunits = "m"
yname = y
ylongname = "y coordinate of projection"
yunits = "m"
xfirst = -3843750
xinc = 12500
yfirst = -5343750
yinc = 12500
grid_mapping = Polar_stereographic
grid_mapping_name = polar_stereographic
proj_params = "+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs"

can be used to do: "cdo remapbil,grid.txt input.nc output.nc" For all other identically gridded ERA5 data (e.g. if it is precipitation, or temperature, this is irrespective).

i.e. I assume this is the correct gridfile.txt that can then be used to regrid not just this ERA5 temperature netCDF but all ERA5 data on this grid.

Thanks,

Simon

RE: Converting Regular TO Polar Stereographic Grids - Added by Estanislao Gavilan over 1 year ago

Hi Simon,

The gridfile only holds information about the grid that you are going to interpolate to. Therefore, you can use it is with any file that follows the netcdf cf convention (e.g ERA, JRA, NCAR..)

Kind regards,

Estanislao

RE: Converting Regular TO Polar Stereographic Grids - Added by Simon Driscoll over 1 year ago

Hi Estanislao,

thanks! Ok, so the gridfile contains the important information about the file desired to be interpolated to. In that case can I clarify which one of the two is correct. I provided a likely incorrect guess for a gridfile (I copied an example from elsewhere not necessarily relevant, and I. also have no idea what I'm doing on these bits :)).

Gridfile 1 =========
gridtype = projection
gridsize = 152830986 (xsize*ysize)
xsize = 14762
ysize = 10353
xname = x
xlongname = "x coordinate of projection"
xunits = "m"
yname = y
ylongname = "y coordinate of projection"
yunits = "m"
xfirst = -6111475.22239475
xinc = 926.625433138333
yfirst = 4114895.09469662
yinc = -926.625433138333
grid_mapping = polar_stereographic
grid_mapping_name = polar_stereographic
straight_vertical_longitude_from_pole = 0.
false_easting = 0.
false_northing = 0.
latitude_of_projection_origin = 90.
standard_parallel = 71.
longitude_of_prime_meridian = 0.
semi_major_axis = 6378137.
inverse_flattening = 298.257223563
proj_params = "+proj=stere +lat_0=90 +lat_ts=71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"

This seemed to be the wrong file, as when you looked at the netCDF files you chose the following gridfile "Gridfile 2":

Gridfile 2 =========
gridtype = projection
gridsize = 544768
xsize = 608
ysize = 896
xname = x
xlongname = "x coordinate of projection"
xunits = "m"
yname = y
ylongname = "y coordinate of projection"
yunits = "m"
xfirst = -3843750
xinc = 12500
yfirst = -5343750
yinc = 12500
grid_mapping = Polar_stereographic
grid_mapping_name = polar_stereographic
proj_params = "+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs"

===========

Notably the second that works appears to not have information on any " semi_major_axis = 6378137" say. But there is a number quite similar in gridfile 2 which is part of "proj_params": "+a=6378273 " My assumption is they refer to the same thing under different names, and indeed that a difference of 6378137 and 6378273 is important.

Therefore can I be clear that either I can use "Gridfile 2" to create a regridded data of the netCDF to the desired/second netCDF's grid 'blindly' and if not, is/was there an importance in choice of these "proj_params"? All other data in the gridfile 2 seems easily verifiable. I'm unsure on meanings/values of "lat_0, lat_ts, lon_0, +k, y_o, a, b".

I assume you've checked these against the netCDF file to be regridded to, then, as you say, and you've obtained these values from somewhere in the netCDF?

Thanks!

Simon

    (1-9/9)