Project

General

Profile

replacing a subset of orginal data

Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

Hi,

I want to reduce the emissions from a particular city and the rest of the emissions as original. So I selected the representative gridbox(rectangle) in the dataset and manipulated it with the reduction we want. Now I want to put back this gridbox into the original dataset, ie., replace/overwrite the data of this gridbox in the original data with this new data. Is it possible to do this in CDO?

Thank you very much for any help.

Semeena


Replies (19)

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

Have you tried the "replace" operator?

https://code.zmaw.de/embedded/cdo/1.5.5/cdo.html#x1-680002.2.2

Cheers,
J.

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

Hi Jaison,

Yes I have! But I understand that this is replacing the variable/field. In my case, what I want is to dump all variables of first file to the second file. The grid sizes of these two files are different, but they have same timesteps.

Cheers,
Semeena

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

Okay, would you mind uploading your data (both files, may be not the original but a tweaked version) - that may help to solve the problem

Cheers,
J.

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

Oh yes, Here they are!

Emis_TNO7.nc is the original file which is for whole Europe and
Paris_cdo.nc is the data for Paris area.

I want to dump Paris into Emis_TNO7, that means replace the 'Paris' area in 'Emis_TNO'.

Cheers,
Semeena

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

I see that the original file did not go through. I'm making a copy with a small domain and will upload you soon..

S.

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

try the "replace" operator along with "enlarge" operator; something like:

cdo -replace Emis_TNO7_box.nc -enlarge,Emis_TNO7_box.nc Paris_cdo.nc new_file.nc

Please let me know if this works.

Cheers,
J

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

I guess I replaced the wrong data (wrong order)? Anyway in principle you could use the "enlarge" operator (to make both files on same grid size), then make it zero outside Paris, and then add to your [masked paris] input file - may be not possible in one step as I said before.

Anyway hope this helps!

Cheers,
J.

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

Hi Jaison,

This actually created a new file with the dimensions of Emis_TNO7_box.nc. But the resulting data is written as the first grids have the values from Paris_cdo.nc and then the whole domain is replaced with the last grid point value of Paris_cdo.nc, which makes sense according to the command says 'enlarge'! Of course what it had done was enlarging 'Paris_cdo.nc' for the entire domain of 'Emis_TNO7'. Did you get what I meant? Here are portion of the ncdumps from both files:

Paris_cdo.nc:

NH3_sec09 =
190920, 65506, 21258, 4405, 2322.8,
137110, 59227, 10741, 6358.9, 5970.3,
59922, 31235, 4497.9, 3135.3, 11039,
18020, 3976.5, 3857.6, 2056, 1266.5,
4438.9, 4826.8, 3524.8, 2269.9, 585.74 ;

Emis_TNO7_box.nc:
NH3_sec09 =
190920, 65506, 21258, 4405, 2322.8, 137110, 59227, 10741, 6358.9, 5970.3,
59922, 31235, 4497.9, 3135.3, 11039, 18020, 3976.5, 3857.6, 2056, 1266.5,
4438.9, 4826.8, 3524.8, 2269.9, 585.74, 585.74, 585.74, 585.74, 585.74,
585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74,
585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74,
585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74,
585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74,
585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74, 585.74,
..........................
...........................

Cheers,
Semeena

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

Sorry, I messed-up :(

I'm running out of ideas - means, getting old ;) But if there is a way with cdo, I'll let you know

Cheers,
J.

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

;) Thanks Jaison. It will be great, if you let me know when you have some new ideas.

Cheers,
Semeena

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

It seems there is an undocumented operator "enlargegrid" (+ other operators) which could be used to get the desired result.

try this:

cdo -add -setclonlatbox,0,2.4375,2.9375,48.84375,49.09375 ifile1.nc -setmisstoc,0 -enlargegrid,ifile1.nc ifile2.nc new_file.nc

where ifile1.nc is Emis_TNO7_box.nc and ifile2.nc is Paris_cdo.nc

CDO is showing some problems with your input NetCDF file formats, so I first convert/copy to NetCDF-2 format ("-f nc2" option)

Please let me know if this works.

Cheers,
Jaison.

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

Hi Jaison,

It seems like this time it is appending the datas. I got exactly same results when I have tried to do the whole thing with NCO. Here is the ncdump of the resulting file.

data:

lon = 2.4375, 2.5625, 2.6875, 2.8125, 2.9375, -44.3125, -44.1875, -44.0625,
-43.9375, -43.8125, -43.6875, -43.5625, -43.4375, -43.3125, -43.1875,
-43.0625, -42.9375, -42.8125, -42.6875, -42.5625, -42.4375, -42.3125,
-42.1875, -42.0625, -41.9375, -41.8125, -41.6875, -41.5625, -41.4375,......
..............................................

lat = 48.84375, 48.90625, 48.96875, 49.03125, 49.09375, 27.34375, 27.40625,
27.46875, 27.53125, 27.59375, 27.65625, 27.71875, 27.78125, 27.84375,
27.90625, 27.96875, 28.03125, 28.09375, 28.15625, 28.21875, 28.28125,
28.34375, 28.40625, 28.46875, 28.53125, 28.59375, 28.65625, 28.71875,
................................................................

Do you see what I mean? The Paris data is written in the beginning followed by the big data.

Cheers,
Semeena

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

I'm a bit confused here :( For example, if you look at the variable CO_sec04:

cdo -outputcenter -selvar,CO_sec04 ifile.nc > data1.dat

cdo -outputcenter -selvar,CO_sec04 new_file.nc > data2.dat

and now take look at the difference:

diff data1.dat data2.dat

It looks fine to me. Now you see the difference only in the required region! I think it doesn't matter how the data is stored (I mean, the order) in the NetCDF. It also look fine when I compare with ncview. Am I missing something? (it was wrong when I use "enlarge" instead of "enlargegrid")

Cheers,
J

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

Hi Jaison,

I have many problems now. I thought, since there is some problem with the data format I also decided to convert it into nc2 as you have done. Now I get the following error when I try to copy, but it creates a new file all variables as the input file.

cdf_get_vara_double : ncid = 65536 varid = 83

Error (cdf_get_vara_double) : HDF error

Still, I started working with this file to extract and then modify Paris, and finally put it back to Emis_TNO as you have suggested. Everything works without any error msg. But when I try to output the new_file only for the replaced region, it still outputs for the whole domain!! It should output the values only for the lonlatbox2.4375,2.9375,48.84375,49.09375. Does it work well with your file? Is it possible for you to upload ur final data file, just to have a look at it? May be there is something wrong with the cdo we have here, it is version 1.5.4.

Cheers,
Semeena

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi,

It looks like the NetCDF-4 (HDF) library issues with your cdo (If you look at "cdo -V", you will see NC4 if it is compiled-in. I'm also using 1.5.4). Anyway, please find the attached files (Due to the large size (nc2), I bzipped the files).

Cheers,
J.

RE: replacing a subset of orginal data - Added by Jaison-Thomas Ambadan over 11 years ago

Hi again,

In my previous post there was a mistake in the command sequence that I used (I used "setclonlat" instead of "sellonlat" , so i deleted the second part!) - sorry for that!

Cheers,
J.

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

Hi Jaison,

Thanks a lot. I had a look into your files and they look perfect!

I did check our cdo -V and it seems like compiled with NC4. Anyway, I'll have a look and let you know when I also get the same results as you did!

cheers,
Semeena

RE: replacing a subset of orginal data - Added by Valiyaveetil Shamsudheen Semeena over 11 years ago

Hi Jaison,

I think the problem is solved now! I just cleaned up my directory and started doing everything from scratch and apparently gave me better results than earlier.

I also checked with the "-output sellonlatbox" option now, apart from my usual 'ncview' and double confirmed that only Paris grids are different.

Thanks a lot.

Cheers,
Semeena

    (1-19/19)