Position of cell within grid
Added by Ronny Berndt over 12 years ago
Hi,
can i extract the position (lon/lat) of a gridcell with cdo?
Ronny
Replies (15)
RE: Position of cell within grid - Added by Jaison-Thomas Ambadan over 12 years ago
Hi,
can i extract the position (lon/lat) of a gridcell with cdo?
I'm not sure if I understood your question correctly. For all grid/cells (assuming your input file has only one variable and one level; otherwise you have to include -selvar and -sellevel)
cdo -outputcenter input_file.grb > outfile.dat
This will give all lon/lat and corresponding value
"-outputbounds" also can be used instead of -outputcenter
If you are looking for the exact lat/lon (for example nearby 68 lon and -18 lat), you may try:
cdo -outputcenter -remapnn,lon=-68_lat=-18 input_file.grb
Cheers,
Jaison.
RE: Position of cell within grid - Added by Ronny Berndt over 12 years ago
ok, thanks for this hint! ;-)
i have a nc file with monthly-mean-temperature over one year period!
with
cdo outputf,'%10.2f',2700 input > output
i get a list with values
293.42 293.46 293.14 293.69 ... 283.42 294.46 296.14 299.69 ... . . . . ... . . . . ... . . . . ... 243.42 273.46 293.04 283.69 ...
12 rows with 2700 values each.
ist it possible to combine outputcenter with outputf?
i would like to have
293.42(LAT/LON) 293.46(LAT/LON) 293.14(LAT/LON) 293.69(LAT/LON) ...
or
ROW 1 ROW 2 ROW 3 ROW 4 ... LAT LAT LAT LAT ... LON LON LON LON ... 293.42 293.46 293.14 293.69 ...
as an example of formatting.
is it possible with cdo?
RE: Position of cell within grid - Added by Jaison-Thomas Ambadan over 12 years ago
Hi,
I don't think there is an option in CDO to format "outputcenter"; otherwise you could use the shell commands like sed and awk;
for example;
cdo -outputcenter ifile.nc | sed '/^ #/d;s/#.*//' > colums_out.dat
this will remove the header and
awk '{ for (i=1;i<=NF;i++) { arr[i]=arr[i]" "$i; }} END{ for(i=1;i<=NF;i++) print arr[i]; }' colums_out.dat > rows_out.dat
the above will transform the column data to rows.
May be others can help you with more intuitive ways
Cheers,
J.
RE: Position of cell within grid - Added by Ronny Berndt over 12 years ago
Hi,
thanks for your help!
I suspect that it boils down to awk and sed... ;-)
The Regular expression did not remove the header.
Can you explain the regular expression in sed, i'm not very familiar with this at the moment...
Cheers,
Ronny
RE: Position of cell within grid - Added by Uwe Schulzweida over 12 years ago
Try the undocumented operator outputtab to create a user defined table of a dataset:
Each parameter of outputtab is one row in the table. Here is an example to print the Lon, Lat and Value of all fields:
cdo outputtab,lon,lat,value ifileThe following parameter are implemented:
value, code, name, lon, lat, lev, date, time, year, month, day
RE: Position of cell within grid - Added by Jaison-Thomas Ambadan over 12 years ago
The Regular expression did not remove the header.
It will work BUT if you simply copy the expression (using mouse) it may not work since there is NO space between ^ and # in the first part of the sed expression; if there is a space character it won't work. It must be /^#/d
Anyway thanks to Uwe for the "outputtab" info.
Cheers,
J.
RE: Position of cell within grid - Added by Ronny Berndt over 12 years ago
Thanks for your great tips!
That helps me alot and i can mix that with sed and awk!
Cheers,
Ronny
RE: Position of cell within grid - Added by Romulo Oliveira over 12 years ago
Hi,
I have a spatio-temporal dataset. I need the time series of the specific grid point (for example -44 lon and -20 lat, from 01/01/2009 to 31/12/2009).
How can I do this?
I've been tried this functions:
cdo -outputcenter -remapnn,lon=-68_lat=-18 input_file.grb (but just worked with the first hour/day).
and
cdo outputtab,date,lon,lat,value ifile (but extract all grid points and I need only one)
Can anybody help me?
best regards,
Romulo
RE: Position of cell within grid - Added by Jaison-Thomas Ambadan over 12 years ago
Hi,
I've been tried this functions:
cdo -outputcenter -remapnn,lon=-68_lat=-18 input_file.grb (but just worked with the first hour/day).
try "outputtab" along with remapnn (instead of outputcenter"); i.e.
cdo -outputtab,date,lon,lat,value -remapnn,lon=-68_lat=-18 input_file.grb
Cheers,
J.
RE: Position of cell within grid - Added by Romulo Oliveira over 12 years ago
Hi J.,
Thank you very much for the help!
exactly how I wanted.
cheers,
Romulo
How to sum up all the grid values for a region - Added by Ping Yang about 12 years ago
Hi, I am following up this topic, I need to get one value for all the grids (e.g. region), Is that a command to calculate this? I tried cdo zonmean but it generate a value for each longitude? Can someone here help me out?
Regards,
Ping
RE: Position of cell within grid - Added by Uwe Schulzweida about 12 years ago
fldmean computes the mean value over all grid cells.
RE: Position of cell within grid - Added by Phuong Nam Vu about 11 years ago
Hi Jaison,
Could you help me to write as below formatting :
ID 1x1 ID 1x2 ID 1x3 ID 1x4 ...
LAT LAT LAT LAT ...
TIME LON LON LON LON ...
20140101 1.1 4.6 5.2 5.6 ...
20140102 5.8 5.8 9.6 2.5 ...
.
.
.
and I would like to get one value for each grid (computes the annual mean value).
I am looking forward your answering.
Thanks so much.
Jaison-Thomas Ambadan wrote:
Hi,
I don't think there is an option in CDO to format "outputcenter"; otherwise you could use the shell commands like sed and awk;
for example;
cdo -outputcenter ifile.nc | sed '/^ #/d;s/#.*//' > colums_out.dat
this will remove the header and
awk '{ for (i=1;i<=NF;i++) { arr[i]=arr[i]" "$i; }} END{ for(i=1;i<=NF;i++) print arr[i]; }' colums_out.dat > rows_out.dat
the above will transform the column data to rows.
May be others can help you with more intuitive ways
Cheers,
J.
RE: Position of cell within grid - Added by Jaison-Thomas Ambadan about 11 years ago
I would recommend using:
cdo -outputtab,date,time,lon > ifile.dat
then load the ifile.dat to some software like matlab/R and then do a transpose()
if you want to use shell, then use the awk loop mentioned above to transpose into rows
RE: Position of cell within grid - Added by Jaime Eduardo over 10 years ago
Hi all,
I need help with outputtab, I'm using version cdo 1.6 for windows, I have problemos when I want to save the result in a table data.tab and I get this error:
cdo outputtab: Open failed on >> <
Invalid argument
My line of code is:
cdo -outputtab,year,month,lon,lat,value -remapnn,lon=76_lat=3 data.nc > data.tab
Appreciate your help