Project

General

Profile

clipping the netcdf file with a mask in meters and NOT lat/lon

Added by Marko Miki almost 5 years ago

Hi there,

I have a netcdf file that is saved in x y coordinates in meters (in :grid_mapping = lambert_azimuthal_equal_area ETRS_1989_LAEA).

I also have the mask.nc that I want to apply to a original netcdf file.

I have tried several commands (see below pls) and read several contributions in the forum:
sellonlatbox
remapycon
reducegrid
selindexbox

but they all seem to be based only on lat/lon. Is there a way to extract the wanted area and wanted points/locations when having netcdf expressed in meters of a certain projection?

my error is: Unsupported grid type: projection

Attached is just the print of my original netcdf file.

Thank you a lot

Marc


Replies (18)

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Ralf Mueller almost 5 years ago

hi Marc!

is the mask on the same grid as your data? if possible consider uploading both, please

cheers
ralf

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Marko Miki almost 5 years ago

Hi Ralf,

the original file is way too big. I uploaded the mask that has the same coordinates as the original file. Somehow, all abovementioned commands do not let me do operations without lat/lon.

Thanks for any tip

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Ralf Mueller almost 5 years ago

hi!

there are some issues with this file

  • how cdo see this contents
    % cdo infov Iberiajoint.nc 
        -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter name
         1 : 0000-00-00 00:00:00       0   950000       0 :      1.0000         nan      1.0000 : area          
    cdo    infon: Processed 1 variable over 1 timestep [0.12s 56MB].
  • you have used nan's but CDO does not recognize them as missing values
  • ncdump -h:
        float area(y, x) ;
            area:_FillValue = -9999.f ;
            area:standard_name = "area_cells" ;
            area:long_name = "area_cells" ;
            area:units = "-" ;
  • here we are: you use a special numeric value instead of nan - so CDO cannot figure out that this field really has missing values.

you can try

cdo -setmissval,nan Iberiajoint.nc newMask.nc
and then apply it by multiplication. But be aware the missval*0=0 by convention.

hth
ralf

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Marko Miki almost 5 years ago

Thanks Raph for this advice!

I created the maskmap but cant cut it when I have a coordinate system in meters rather than in lat/lon.

I also attached the example file where I want to apply my mask and get values only for that region.

Thanks for any further advice,

Mark

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Ralf Mueller almost 5 years ago

I am not sure I understood your problem, so I post what I can do

  1. create the mask
    cdo -setmissval,nan Iberiajoint.nc IberiajointMASK.nc
  2. apply the mask by division:
    % cdo div Wind_season_207099.nc IberiajointMASK.nc Wind_season_207099_MASKED.nc
    cdo    div: Filling up stream2 >IberiajointMASK.nc< by copying the first timestep.
    cdo    div: Processed 2 variables over 5 timesteps [0.09s 87MB].
    Note that you could also use mul but this can lead to issues because of 0*miss=0

hth
ralf

PS: I use the latest CDO release

t.png (39.6 KB) t.png

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Marko Miki almost 5 years ago

Hi Raph,

Thanks a lot for this. It is mainly what I wanted, only instead of having the big window do you know if it is possible to clip it somehow and
get the only window of Iberia (meaning where data are).

And four different frames that correspond to different seasons?

Cheers

Mark

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Ralf Mueller almost 5 years ago

Marko Miki wrote:

Hi Raph,

Thanks a lot for this. It is mainly what I wanted, only instead of having the big window do you know if it is possible to clip it somehow and
get the only window of Iberia (meaning where data are).

try

cdo -selindexbox,0,300,600,800 Wind_season_207099_MASKED.nc out.nc

And four different frames that correspond to different seasons?

Good question - sounds reasonable, but I cannot say for sure because I did not create the data. BUT: check the history attribute. The last operations mentioned there is

cdo yseasmean
So seasonal data is very likely

hth
ralf

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Marko Miki almost 5 years ago

Hi Raph,

was trying it before but I always get the same message: Unsupported grid type when using -selindexbox

Is it because my coordinate system is in meters and not in lat/lot?

Thanks!

mark

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Marko Miki almost 5 years ago

Climate Data Operators version 1.9.5 (http://mpimet.mpg.de/cdo)
System: x86_64-pc-linux-gnu
CXX Compiler: g++ -g -O2 -fopenmp
CXX version : g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
C Compiler: gcc -g -O2 -fopenmp
C version : gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
F77 Compiler:
Features: 125GB 28threads C++14 DATA PTHREADS OpenMP45 NC4/HDF5 OPeNDAP SSE2
Libraries:
Filetypes: srv ext ieg grb1 nc1 nc2 nc4 nc4c nc5
CDI library version : 1.9.5
CGRIBEX library version : 1.9.1
NetCDF library version : 4.6.0 of Feb 9 2018 19:21:24 $
HDF5 library version : library undefined
EXSE library version : 1.4.0
FILE library version : 1.8.3

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Ralf Mueller almost 5 years ago

you need at least cdo-1.9.6 for this to work, sry. If you don't want to compile CDO yourself, I recommend Anaconda or docker

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Marko Miki almost 5 years ago

Hm thanks Ralf,

do you know if reducegrid command could do a work?

Thanks

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Ralf Mueller almost 5 years ago

reducegrid can create unstructured grids, this will not ease your workflow I think. Tools to plot data on these grids are very rare IMO: NCL, ParaView as far as I know. But most tools can handle missing values - so if you declare them correctly (_FillValue attribute) everything should be fine

cheers
ralf

is updating a problem? the Conda-workflow is really easy IMO

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Marko Miki almost 5 years ago

Hi Ralf,

yes, I am already using a docker on the server where I dont have rights to install any updates so I am afraid I have to stick with version 1.9.5.

So there is no way to reduce the above picture that you put, on only regions with data?

Thanks a lot for your time!

Mark

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Ralf Mueller almost 5 years ago

Mark,
conda does not need such admin rights, everything can be installed in your home-directory. it's a brilliant solution for such setups.

reducegrid does not work with projections,yet.

sry - u need to update I guess
ralf

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Marko Miki almost 5 years ago

Here are the files Ralf,

in the meanwhile I will try to install conda.

Thanks a lot for any tip!

RE: clipping the netcdf file with a mask in meters and NOT lat/lon - Added by Ralf Mueller almost 5 years ago

here is the result of selindexbox: BOX_Wind_BCed_207099DJFchangeIB.nc

now that you have it, you should be able to use is for nearest neighbor interpolation for other files. this emulates the selindexbox command. - in case you want to reduce other data to the spain region

hth
ralf

    (1-18/18)