Project

General

Profile

How to cut a netcdf file

Added by pooran khedri over 6 years ago

Hi everybody,
I have a bathymetry all aver the word, I need to cut the specified region in this file.
could you please explain to me how to do it with cdo?

Thank you in advance?

Best regards,
Pooran


Replies (15)

RE: How to cut a netcdf file - Added by Karin Meier-Fleischer over 6 years ago

Hi Pooran,

have a look at the CDO documentation and FAQ

[[https://code.mpimet.mpg.de/projects/cdo/embedded/cdo.pdf]]
[[https://code.mpimet.mpg.de/projects/cdo/wiki/FAQ]]

cdo -sellonlatbox,lonmin,lonmax,latmin,latmax infile outfile

-Karin

RE: How to cut a netcdf file - Added by Muhammad Ramzan almost 2 years ago

Hi Karin is it possible to crop the NetCDF file using a country or any other shape file.

Thanks

RE: How to cut a netcdf file - Added by Karin Meier-Fleischer almost 2 years ago

Hi Muhammad,

a few days ago, we had a similar question, see issue https://code.mpimet.mpg.de/boards/1/topics/13551.

RE: How to cut a netcdf file - Added by Muhammad Ramzan almost 2 years ago

Thanks

I have gone through this post https://code.mpimet.mpg.de/boards/1/topics/13551.

will the final output be in NetCDF form or in raster image. I want the croped image to be in NetCDF form.

mkdir -p $HOME/data/DCW
cd $HOME/data/DCW
wget ftp://ftp.soest.hawaii.edu/dcw/dcw-gmt-2.1.1.tar.gz
export DIR_DCW=$HOME/data/DCW/dcw-gmt-2.1.1
For this example create a file with global topography data used as input file and in the second step mask India using the maskregion operator:

cdo -f nc -topo topo.nc
cdo -sellonlatbox,67,98.5,7.5,36.5 -maskregion,dcw:IN topo.nc o.nc

Where do I run these commands. I am new to this as I am Economics student, my appologies for this basic question.

Thanks

RE: How to cut a netcdf file - Added by Karin Meier-Fleischer almost 2 years ago

It depends on your input data file format, if it is netCDF the output file will also be netCDF. If it is GRIB than you have to use the option e.g. '-f nc' as in the given example above to generate a netCDF output file.

RE: How to cut a netcdf file - Added by Muhammad Ramzan almost 2 years ago

Thanks

where I can input the commands please which software I have to install and can these commands works a large number of files or I have to do one by one please

RE: How to cut a netcdf file - Added by Karin Meier-Fleischer almost 2 years ago

First, the command have to be run in a terminal. The commands are explained in the mentioned example. You have to download the DCW dataset and then use CDO with it in a terminal. If you have to install CDO too then see https://code.mpimet.mpg.de/projects/cdo/wiki#Installation-and-Supported-Platforms.

RE: How to cut a netcdf file - Added by Muhammad Ramzan almost 2 years ago

Thanks I have downloaded the CDO but there is no installation file, is there any video on this , which I can follow please.

RE: How to cut a netcdf file - Added by Muhammad Ramzan almost 2 years ago

Hi

I am able to install the CDO

but when I run the command

wget ftp://ftp.soest.hawaii.edu/dcw/dcw-gmt-2.1.1.tar.gz

I am getting the error message, please

1.png (36.8 KB) 1.png wget error

RE: How to cut a netcdf file - Added by Karin Meier-Fleischer almost 2 years ago

Maybe you can use a browser that is able to ftp the file.

RE: How to cut a netcdf file - Added by Muhammad Ramzan almost 2 years ago

thanks

what is not working as well.
I am able to run these commands that is I am able to crop the NetCDF file based on the min and max lat & longi values.

cdo -sellonlatbox,60,78,22,37 air.2021.nc Ct_2021.nc
cdo -sellonlatbox,60,78,22,37 air.2020.nc Ct_2020.nc
cdo -sellonlatbox,60,78,22,37 air.2019.nc Ct_2019.nc

I have attached the share file , how I can crop the netcdf file using the attached shape file.

Thanks

b75.zip (1.75 MB) b75.zip

RE: How to cut a netcdf file - Added by Muhammad Ramzan almost 2 years ago

Hi I am unable to download the file directly please help

RE: How to cut a netcdf file - Added by Karin Meier-Fleischer almost 2 years ago

There are many examples 'how to use shapefile for masking' in the CDO forums - just google your question.

    (1-15/15)