Project

General

Profile

Convert COSMO REA 6 to a normal geographical projection

Added by Zhongyang Hu about 6 years ago

Hi there,

I am currently using the REA 6 data, how ever I found the data is of a rotated longitude-latitude grid with a shifted pole.

I tried cdo remapbil function, with the parameters provided by the:

COSMO-REA6 Starting Example, ftp://ftp-cdc.dwd.de/pub/REA/COSMO_REA6/help_COSMO_REA6/COSMO_REA6_Starting_example.pdf

However, once I display the results in arcgis/qgis the results are still in Africa, could somebody help me.

I also displayed COSMO_REA6_CONST_withOUTsponge.nc file, it is also shifted to Africa.

Thanks in advance,
Young


Replies (31)

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer about 6 years ago

Hi Zhongyang,

please upload a test file containing one time step.

-Karin

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Zhongyang Hu about 6 years ago

Hi Karin,

I used $ cdo seltimestep,1/1 T.2M.200701.nc T.2M.200701_step1.nc to get one step netCDF image, I hope it is fine.

Could you please help me to convert it to a normal lat/lon geographical coordinate image.

Thanks in advance,
Zhongyang

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Uwe Schulzweida about 6 years ago

You can generate the geographical lon/lat coordinates from a rotated grid with:

cdo setgridtype,curvilinear infile outfile

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer about 6 years ago

By the way if you want the output to be lonlat instead of curvilinear you can use a grid file to remap the data.

Grid file grid.txt:

gridtype = lonlat
xsize    = 724
ysize    = 780
xfirst   = -4.0
xinc     = 0.034
yfirst   = 43.0
yinc     = 0.020
Remap:
cdo -remapbil,grid.txt T.2M.200701_step1.nc remap_T.2M.200701_step1.nc
Plot: cdo shaded,device="png",lon_min=-6.0,lon_max=22.0,lat_min=42.0,lat_max=59.0 remap_T.2M.200701_step1.nc plot1_remapped_COSMO_REA6

-Karin

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Zhongyang Hu about 6 years ago

Hi Karin,

it works perfectly thank you very much.

If I may, I just have one last question. Could you make it in a loop (.NC files and time steps)

In a folder I have 10 .nc files, and each one has 31 time steps. It would be nice to have a loop to extract all time steps and remap them into latlon.

Thanks a lot,
Zhongyang

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer about 6 years ago

That's simple. You have to write a shell script which loops through the list of your input files. You don't have to loop through time.

Lets assume the grid files name is grid.txt and the input files are called file1.nc, file2.nc, file3.nc, ...
Here is a KSH example script:

#!/bin/ksh

files=$(ls file*.nc)

for f in $files
do
   ofile=remap_${f}
   echo "cdo -remapbil,grid.txt $f $ofile" 
   cdo -remapbil,grid.txt $f $ofile
done

exit

Or you can enter the following command in your terminal:

files=$(ls file*.nc); for f in ${files}; do ofile=remap2_${f}; cdo -remapbil,grid.txt $f $ofile ; done

-Karin

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Jonathan Tinsley over 1 year ago

Hi Karin,

I have a similar issue. I need to convert the coordinates for my .nc files from rotated pole to lon/lat. My region is CORDEX Africa, with raster resolution for the climate data set at 0.44 x 0.44, lat = 201, lon = 194. Does the grd.text file need to be changed so it works for my data?

Best regards

Jonathan

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer over 1 year ago

Hi Jonathan,

you can remap the AFR-44 to lonlat using a gridfile:

gridfile.txt:

gridtype  = lonlat
gridsize  = 38994
xsize     = 194
ysize     = 201
xname     = lon
xlongname = "longitude" 
xunits    = "degrees_east" 
yname     = lat
ylongname = "latitude" 
yunits    = "degrees_north" 
xfirst    = -24.6399993896484
xinc      = 0.43999999051267
yfirst    = -45.7599983215332
yinc      = 0.44

cdo -remapbil,gridfile.txt infile outfile

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Jonathan Tinsley over 1 year ago

Hi Karin,

Thank you for getting back to me so quickly, this is incredibly useful. Thank you very much!

Best regards,

Jonathan

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Jonathan Tinsley over 1 year ago

Hi Karin,

Apologies for yet another request. But I was wondering if you have the same information for the AFR-22 dataset? Also, is it possible to work this information out for myself, so I do not have to pester you again?

With thanks,

Jonathan

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer over 1 year ago

Certainly the CORDEX domain information can be found on its web pages but I used the table of https://py-cordex.readthedocs.io/en/stable/domains.html to get the values for the gridfile.

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Denis Bzowy over 1 year ago

Hi Karin, folks,
how can I map RLAT / RLON in COSMO_REA6_CONST_withOUTsponge.nc from / to latlon (4326) with pyproj --
that is, which of the many https://proj.org/operations/projections describes unrotated COSMO_REA6 ?

from pyproj import Transformer
trans = Transformer.from_crs( fromcrs="+proj=???", tocrs=4326 )

Thanks,
cheers
-- denis

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer over 1 year ago

You can use cartopy to get the proj4 string:

import cartopy.crs as ccrs

grid_north_pole_latitude = 39.25
grid_north_pole_longitude = -162.

crs = ccrs.RotatedPole(pole_longitude=grid_north_pole_longitude, 
                       pole_latitude=grid_north_pole_latitude)

proj_string = crs.proj4_init

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Denis Bzowy over 1 year ago

Thank you Karin,
but I don't have cartopy
and its build process https://scitools.org.uk/cartopy/docs/latest/installing.html looks painful.
Could you possibly put up the string ?

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer over 1 year ago

Installing cartopy is really easy when you use conda from miniconda.

The proj string is

'+ellps=WGS84 +a=6378137.0 +proj=ob_tran +o_proj=latlon +o_lon_p=0.0 +o_lat_p=39.25 +lon_0=18.0 +to_meter=111319.4907932736 +no_defs'

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Denis Bzowy over 1 year ago

Karin,
does it work in pyproj for you ? I get

pyproj.CRS.from_user_input( proj )
CRSError: Invalid projection: +proj=ob_tran +ellps=wgs84 +a=6378137.0 +o_proj=latlon +o_lon_p=0.0 +o_lat_p=39.25 +lon_0=18.0 +to_meter=111319.4907932736 +no_defs +type=crs:
(Internal Proj Error: proj_create: Error 1027 (Invalid value for an argument): pj_init_ctx: Must specify ellipsoid or sphere

pyproj.show_versions()
pyproj info:
pyproj: 3.5.0
PROJ: 9.2.0
data dir: /opt/local/py/site/geo/pyproj/proj_dir/share/proj
user_data_dir: /Users/bz/Library/Application Support/proj
PROJ DATA (recommended version): 1.13
PROJ Database: 1.2
EPSG Database: v10.082 [2023-02-06]
ESRI Database: ArcGIS Pro 3.1 [2023-19-01]
IGNF Database: 3.1.0 [2019-05-24]
System:
python: 3.9.13

I could ask gis.stack, but I'm no expert
and https://gis.stackexchange.com/questions/tagged/pyproj 284 questions ! looks daunting, no fun

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer over 1 year ago

Sorry, I'm not an expert of pyproj. Maybe you can use CRS.from_crs(source_crs, target_crs) instead of CRS.from_user_input(proj).

RE: Convert COSMO REA 6 to a normal geographical projection - Added by JUHI DHURIYA over 1 year ago

Hi Karin,

I am working with Cordex was-44 NetCDF data. I need to convert the coordinates from the rotated pole to the lon/lat geographical grid system. The resolution of my data is 0.44x0.44 and the region is CORDEX South Asia.
I've attached ncdump and sinfo results of my pr_WAS-44_NOAA-GFDL-GFDL-ESM2M_historical_r1i1p1_SMHI-RCA4_v2_day_19510101-19551231.nc file.

Can you please help me how to convert the data?

Regards,
Juhi

ncdump.png (105 KB) ncdump.png ncdump
sinfo.png (86.8 KB) sinfo.png cdo_sinfo

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer over 1 year ago

Hi Juhi,

without the data file I'm not able to check the steps from below!

You can get the needed information from the 'cdo griddes pr_WAS-44_NOAA-GFDL-GFDL-ESM2M_historical_r1i1p1_SMHI-RCA4_v2_day_19510101-19551231.nc' output or you can get more information from the CORDEX web site https://cordex.org/domains/region-6-south-asia-2/ to create the grid description file.

gridfile-CORDEX_WAS-44.txt:

gridtype  = lonlat
gridsize  = 25090
xsize     = 193
ysize     = 130
xname     = lon
xlongname = "longitude" 
xunits    = "degrees_east" 
yname     = lat
ylongname = "latitude" 
yunits    = "degrees_north" 
xfirst    = -32.12
xinc      = 0.44
yfirst    = -21.56
yinc      = 0.44
grid_mapping = rotated_pole
grid_mapping_name = rotated_latitude_longitude
grid_north_pole_latitude = 79.95
grid_north_pole_longitude = 236.66

Remap to lonlat regular grid:

cdo -remapnn,gridfile_CORDEX_WAS-44.txt infile outfile

RE: Convert COSMO REA 6 to a normal geographical projection - Added by JUHI DHURIYA over 1 year ago

Thank you for your reply, I've attached the cdo griddes pr_WAS-44_NOAA-GFDL-GFDL-ESM2M_historical_r1i1p1_SMHI-RCA4_v2_day_19510101-19551231.nc output
.
Can I make the text file from the above given data?

RE: Convert COSMO REA 6 to a normal geographical projection - Added by JUHI DHURIYA over 1 year ago

I've got a doubt here as I want to convert the file from rotated to the regular grid, so the text file for the -remapnn command should contain the details of the regular grid, aka geographical grid data rotated grid data.

RE: Convert COSMO REA 6 to a normal geographical projection - Added by JUHI DHURIYA over 1 year ago

JUHI DHURIYA wrote in RE: Convert COSMO REA 6 to a normal geographical projection:

I've got a doubt here as I want to convert the file from rotated to the regular grid, so the text file for the -remapnn command should contain the details of the regular grid, aka geographical grid data or the rotated grid data.

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer over 1 year ago

When you compare the send griddes information you'll see that the grid description file gridfile-CORDEX_WAS-44.txt from me contains the information, or better it contains only what is needed for the remapping with CDO for this case. Just do the remapping as explained above ;) .

RE: Convert COSMO REA 6 to a normal geographical projection - Added by JUHI DHURIYA over 1 year ago


The above image is the griddes output for the NC file ta200_WAS-44i_MPI-M-MPI-ESM-LR_historical_r1i1p1_MPI-CSC-REMO2009_v1_day_19610101-19651231.nc which is in the regular coordinate system of WAS-44i cordex, can the above details be used for making the textfile for the conversion of rotated grid coordinate?

RE: Convert COSMO REA 6 to a normal geographical projection - Added by Karin Meier-Fleischer over 1 year ago

That is the WAS-44i domain.

short name   region     long_name     nlon     nlat     ll_lon        ur_lon     ll_lat         ur_lat     dlon     dlat     pollon     pollat

WAS-44i      6         South Asia     195     124     19.25000   116.25000     -15.75000   45.75000     0.5000     0.5000     NaN     NaN

Maybe you have to delete the 'scanningMode = 64' line in your grid description file. It should work.

(1-25/31)