Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetCDF spatially merging to global data

Currently I use global precipitation (ppt) and potential evapotranspiration (pet) data to calculate SPEI. As I have limited hardware resources, I divided global ppt and ppt data into 32 parts, each file covering 45x45deg and contains 756 data - monthly from 1958-2020 (tile01.nc, tile02.nc, ... tile32.nc)

  • For example to do this, I use cdo sellonlatbox,-180,-135,45,90 in.nc out.nc or ncks -d lat,45.,90. -d lon,-180.,-135. in.nc -O out.nc
  • As required by SPEI script, I reorder and fixed the dimension from time,lat,lon to lat,lon,time using ncpdq and ncks.
  • From the SPEI output, I got the output in lat,lon,time. So I did reorder the dimension so that it becomes time,lat,lon using ncpdq.
  • Each tile SPEI output covering 45x45deg and contains 756 SPEI data - monthly from 1958-2020

Finally I need to merge all the output together (32 files) into one, so I will get the global SPEI output. I have try to use cdo mergegrid but the result is not what I expected. Is there any command from cdo or nco to solve this problem that has function similar to gdal_merge if we are dealing with geoTIFF format?

Below is the example of the SPEI output

panoply

UPDATE

I managed to merge all the data using cdo collgrid as suggested by Robert below. And here's the result:

spei

like image 929
user97103 Avatar asked Oct 25 '25 04:10

user97103


1 Answers

I believe you want to use CDO's distgrid and collgrid methods for this.

First, run this:

cdo distgrid,4,8 in.nc obase

That will split the files up the way you want them.

Then do the post-processing necessary on the files.

Then use collgrid to merge the files:

cdo collgrid obase* out.nc

Potentially you can just use collgrid in place of mergegrid in your present work flow, depending on how you have split the files up.

like image 174
Robert Wilson Avatar answered Oct 26 '25 23:10

Robert Wilson