Project

General

Profile

Data extraction for multiple locations from Cordex NETCDF

Added by ibomcha meitei over 4 years ago

Hello everyone,
I have a codex netCDF file for precipitation.
I am able to get precipitation data for a single location.
However, I am unable to get for multiple locations(>500) in CSV format.

Thanks


Replies (7)

RE: Data extraction for multiple locations from Cordex NETCDF - Added by Ralf Mueller over 4 years ago

hi!

it's hard to comment without more information. please upload some sample data, some info about which locations you want to extract and how exactly the CSV file should look like.

cheers
ralf

RE: Data extraction for multiple locations from Cordex NETCDF - Added by ibomcha meitei over 4 years ago

Thanks for reply Ralf,
suppose I have 6 locations as provided below.
lat lon
31.57 -85.25
34.26 -87.18
31.31 -86.52
33.29 -85.78
31.18 -87.44
31.02 -87.52

I would like to extract precipitation for each location separately from pr.box.SE.nc in CSV format i.e. I want to have 6 csv files.

RE: Data extraction for multiple locations from Cordex NETCDF - Added by Ralf Mueller over 4 years ago

hi!

I am sure, there are examples for those operations in forum. you can use a for-loop over your locations.

please use the search field in the forum.

cheers
ralf

RE: Data extraction for multiple locations from Cordex NETCDF - Added by Tufan Turp over 4 years ago

Hi,

First prepare a csv file (locations.csv) for your locations like:

1 31.57 -85.25
2 34.26 -87.18
3 31.31 -86.52

Then prepare a mini-script like:

#!/bin/bash
IFS=","
while read f1 f2 f3
do
echo "cdo remapdis,lon=$f3-lat=$f2 input.nc input_$f1.nc"
echo "cdo outputtab,nohead,value input$f1.nc > input$f1.csv"
done < locations.csv > output.sh

That script will create another script called output.sh, and you have to add #!/bin/bash onto the first line in output.sh.

Finally, if you can execute the output.sh script, you will get csv files for each location. For example, input_1.csv will be the data of location 1 (31.57 -85.25) so on...

This is just a sample for idea, you need to modify your script depending on you needs. I hope it is clear.

Good luck,

Tufan

RE: Data extraction for multiple locations from Cordex NETCDF - Added by Tufan Turp over 4 years ago

A correction:

#!/bin/bash
IFS=","
while read f1 f2 f3
do
echo "cdo remapdis,lon=$f3-lat=$f2 input.nc input$f1.nc"
echo "cdo outputtab,nohead,value input$f1.nc > input$f1.csv"
done < locations.csv > output.sh

RE: Data extraction for multiple locations from Cordex NETCDF - Added by Ralf Mueller over 4 years ago

you can do this without an intermediate file by just calling CDO instead of echoing commands

while read lon lat; do 
  cdo -f nc -remapnn,lon=${lon}_lat=${lat} -topo t_lon${lon}_lat${lat}.nc; 
done <locations.txt

I use this as input

cat locations.txt 
100 50
-100 0
-32.9 -77.2

hth
ralf

    (1-7/7)