Project

General

Profile

cdo sellonlatbox error

Added by sylvain pierre 2 months ago

Hi ,
I get an error when trying to shift netcdf file from [[https://springernature.figshare.com/articles/dataset/Significantly_wetter_or_drier_future_conditions_for_one_to_two_thirds_of_the_world_s_population/24711969]].
Data are in range 0-360° and I want to shift on -180 + 180 to display in GIS software

cdo sellonlatbox,-180,180,-90,90 -selname,"Multi-model\ convergence" CMIP5_agreement_RCP85.nc res/CMIP5_agreement_RCP85.nc
cdo sellonlatbox: Started child process "selname,Multi-model\ convergence CMIP5_agreement_RCP85.nc (pipe1.1)".
Warning (cdf_read_mapping_atts): Text attribute crs:grid_mapping_name missing!
setBaseTime       : Unsupported TIMEUNIT: unknown!
cdo sellonlatbox: Unsupported grid type: projection

cdo sellonlatbox (Abort): Unsupported grid type!


I've found almost similar issue on this forum , but not exctly , so what-s the way to solve

Thanks


Replies (7)

RE: cdo sellonlatbox error - Added by Estanislao Gavilan 2 months ago

Hi Sylvain,

sellonlatbox is not used for that. That command is used to select a region in a regular lanlon grid. Said that, your file is a bit weird. First, your file does not have time variable (aka setBaseTime : Unsupported TIMEUNIT: unknown!). Second, it seems the data is in a regular lanlon grid, but cdo thinks it is a projection. I think it is because your file has variables such as crs with the projection parameters. If your file is indeed in a regular lanlon grid, you can easily fix that. You only need to use the griddes and setgrid command. griddes will give you a description of your grid

cdo griddes CMIP5_agreement_RCP85.nc > sylgrid.txt

that will give you this output

#
  1. gridID 1 #
    gridtype = projection
    gridsize = 28800
    xsize = 240
    ysize = 120
    xname = X
    xlongname = "X"
    xunits = "degrees_east"
    yname = Y
    ylongname = "Y"
    yunits = "degrees_north"
    xfirst = 0
    xinc = 1.5
    yfirst = 89.25
    yinc = -1.5
    grid_mapping = crs
    proj4 = "+proj=longlat +datum=WGS84 +no_defs"

From here you remove grid_mapping, proj4 and you change gridtype = lonlat. Then you type

cdo -setgrid,sylgrid.txt CMIP5_agreement_RCP85.nc output.nc

If the remaining files use the same grid, you can use the same txt file. Finally, your description file says yfirst =89.25 and yinc = -1.5. I suspect this is another error because you nc file is not well formatted. You need to check that your grid does not end flipped upside-down. If that were to happen, you only need to change the signs to yfirst =-89.25 and yinc = 1.5.

Best regards,

Estanislao

RE: cdo sellonlatbox error - Added by sylvain pierre 2 months ago

Thanks Estanislao,

Im not very familiar with netcdf files, but this format seems to be very permissive. In this case, files have been processed by R software I think.
I'm going to try your solution. I've tried sellonlatbox according this post:
[[https://stackoverflow.com/questions/57682977/converting-longitude-in-netcdf-from-0360-to-180180-using-nco]]
Sylvain

RE: cdo sellonlatbox error - Added by sylvain pierre 2 months ago

Hi,
After some test (-setgrid + sellonlatbox) it's almost done. But first command (setgrid ) change grid scalar value...

RE: cdo sellonlatbox error - Added by Estanislao Gavilan 2 months ago

Hi Sylvain,

if you subtract the old and the new file, you will see that they are the same. If they look different is because one is a projection and the other is a lon-lat grid. At the first, I thought that a projection longlat is the same than a lonlat grid, but it seems they are not. The reason is projection and latlon grid use different ellipsoids (I think..I am not an expert on this). Therefore, if you use a software which reads the grids parameters, the plot will look different.

RE: cdo sellonlatbox error - Added by Karin Meier-Fleischer 2 months ago

Maybe this is another way to get the wanted result:

ncatted -O -a grid_mapping,Multi-model\ convergence,d,, \
           -a proj4,Multi-model\ convergence,d,, \
           CMIP5_agreement_RCP85.nc tmp.nc

cdo -sellonlatbox,-180,180,-90,90 -invertlat tmp.nc outfile.nc

The coordinate variable Y refuses to be inverted only with sellonlatbox, which is why invertlat is also used here.

RE: cdo sellonlatbox error - Added by sylvain pierre 2 months ago

Estanislao Gavilan wrote in RE: cdo sellonlatbox error:

Hi Sylvain,

if you subtract the old and the new file, you will see that they are the same. If they look different is because one is a projection and the other is a lon-lat grid. At the first, I thought that a projection longlat is the same than a lonlat grid, but it seems they are not. The reason is projection and latlon grid use different ellipsoids (I think..I am not an expert on this). Therefore, if you use a software which reads the grids parameters, the plot will look different.

You are right. I'm using QGIS GIS software.

    (1-7/7)