Project

General

Profile

extract daily mean values from a series point locations (lat/lon)

Added by Vicki Lindsay almost 6 years ago

The NetCDF data I have to contain hourly values of NO2 concentrations. I am trying to extract daily mean values for a series of locations, saved in a .txt file in the following format:

ID, lon, lat
UKA00137, -3.034178, 52.50385
UKA00353, -1.510436, 53.56292
UKA00306, -2.354155, 51.391127
UKA00479, -1.830583, 52.511722
UKA00543, -1.830861, 52.512194
......

I can only extract single location using cdo daymean -remapnn,lon=-3.034178_lat=52.50385, input.nc output.nc

How can I extract the values in a loop and export the values in a .txt file? Many thanks!


Replies (2)

RE: extract daily mean values from a series point locations (lat/lon) - Added by Ralf Mueller almost 6 years ago

hi Vicky!

a for loop in the shell should provide that you want, although I'd rather use a better programming language for this like Ruby or Python. you can use the cdo-bindings for them. Here is my (guessed) ruby-solution:

locations = [
  [-3.034178, 52.50385],
  [-1.510436, 53.56292],
  [ -2.354155, 51.391127],
   ....
]

require 'cdo'
cdo = Cdo.new()

locations.each {|location|
  lon,lat = location
  ofile  = "NCO_atLON#{lon}_LAT#{lat}.txt" 
  File.open(ofile,'w') {|f|
    f << cdo.outputkey("value",input: "-daymean -remapnn,lon=#{lon}_lat=#{lat} input.nc")
  }
}

you might upload the input file for a more precise help, though.

hth
ralf

RE: extract daily mean values from a series point locations (lat/lon) - Added by Vicki Lindsay almost 6 years ago

Thanks very much ralf. The input hourly file is 9GB, so I can't upload here... I'll try using other languages as you suggested

    (1-2/2)