Project

General

Profile

How to merge a different grids of different variables into a single file?

Added by jyoti lodha over 6 years ago

Hi
I have a issue when mergeing differnt grids of data to single a file.like
cdo sinfon /ankit/mrsl.grb has : lonlat : points=27840 (192x145)
lon : 0 to 358.125 by 1.875 degrees_east circular
lat : -90 to 90 by 1.25 degrees_north

cdo sinfon /ankit/hus.grb 1 : lonlat : points=27648 (192x144)
lon : 0.938 to 359.063 by 1.875 degrees_east circular
lat : -89.375 to 89.375 by 1.25 degrees_north

cdo is merging the files into single file, but when I am seeing it in panoply, it is showing me different field as I want to view it in one file? How it is possible. How can I re-grid it so proper merging can be done ? I have attached my print screen for clear view. How I can merge them together and can also visible in same file.

mrsl.grb (654 KB) mrsl.grb (192x145) grid
hus.grb (19 MB) hus.grb (192x144) grid
test.grb (19.7 MB) test.grb merge file
Screenshot from 2018-07-26 14-34-10.png (131 KB) Screenshot from 2018-07-26 14-34-10.png screen short

Replies (7)

RE: How to merge a different grids of different variables into a single file? - Added by Karin Meier-Fleischer over 6 years ago

Hi Jyoti,

merging two files does not mean the data will be automatically on the same grid. If you want to do that you have to regrid the data first.
See https://code.mpimet.mpg.de/projects/cdo/wiki/Tutorial#Interpolation

For example, regrid the data of mrsl.grb to the same grid as hus.grb using interpolation method bilinear and do the merge:

cdo remapbil,hus.grb mrsl.grb tmp.nc

cdo -O merge tmp.nc hus.grb outfile.nc

-Karin

RE: How to merge a different grids of different variables into a single file? - Added by jyoti lodha over 6 years ago

Hi
Thanks for the reply.It solved my problem ,But if I want to apply rempabil for multiple files , how to put loop. As I tried using this

for i in *.nc;
do echo $i
cdo remapbil,target.nc "$i" > "convert_$i_bil.nc";

done
How to run a cdo script in a text file? It is not working,as I have little knowledge about it.Please guide me where I have made mistake.:)

RE: How to merge a different grids of different variables into a single file? - Added by Karin Meier-Fleischer over 6 years ago

For more information about the use of shell scripts search the internet there are lots of docus.

Without knowing which shell you want to use I can give you just an example for KSH which I prefer.

Lets say you have lots of netCDF files named infile*.nc and you want to remap them to the grid of target.nc.

The script script.ksh would look like

#!/bin/ksh

for f in infile*.nc; do cdo remapbil,target.nc ${f} ${f%.*}_remap.nc; done

You can run it in a terminal with the command

ksh script.ksh

The output files are named infile*_remap.nc.

-Karin

RE: How to merge a different grids of different variables into a single file? - Added by Anna marra over 5 years ago

Dear Karin,
I found this discussion, that is similar to what I am looking for. I have many files, which represent a small portion of a full satellite orbit. The grid is on the original irregular satellite swath. I would like to use some (if any) CDO operator to join all these granules together in order to create one netcdf file recontructing the full satellite orbit. I also need to preserve the original irregular grid. You already know that cdo copy, or merge or cat does not work for me. Do you there is some way to get what I need? To be clearer, I attache two of my files to be concatenated.
Thank you in advance.
Anna

RE: How to merge a different grids of different variables into a single file? - Added by Karin Meier-Fleischer over 5 years ago

Hi Anna,

because your data has a 2D time (int time(xc,t)) in my opinion CDO is not able to handle those files.

But maybe NCL is able to do that. I'll see if I can do it with NCL.

-Karin

RE: How to merge a different grids of different variables into a single file? - Added by Karin Meier-Fleischer over 5 years ago

I've found a way to merge the data with CDO. You have to remap the files to a common grid e.g. 720x360 and add a time axis.

For the variable rr:

cdo -r -settaxis,1970-01-01,00:00:00,1sec -selname,rr h02_20180101_000121_METOPA_58125.nc rr1.nc
cdo -r -settaxis,1970-01-01,00:00:00,1sec -selname,rr h02_20180101_000425_METOPA_58125.nc rr2.nc

cdo remapbil,r720x360 rr1.nc rr1_remap.nc
cdo remapbil,r720x360 rr2.nc rr2_remap.nc

cdo -O mergegrid rr*_remap.nc  mergegrid_rr.nc

plot of variable rr

-Karin

plot_rr.png (30.5 KB) plot_rr.png plot of variable rr

RE: How to merge a different grids of different variables into a single file? - Added by Anna marra over 5 years ago

Thank you very much, Karin. Actually I need to preserve the original irregular grid before merging the files. In fact I use those files in a procedure that includes the remapping over a regular grid (I use remapbil). But I need to do the remapping after reconstructing the orbit, in order to avoid the holes (the empty lines) due to bilinear interpolation applied to the first and last line of the files.
I hope I was clear.
If I merge the files by using other tools (e.g. matlab), and then I remap them, I do not have the empty lines.
Do you have other suggestions to do that by CDO or NCO? I would really prefer it.
Thank you very much.
Anna

    (1-7/7)