I have temperature data w/ 3 dimensions (lat, lon, time). I want to create a grid that contains the value of the time dimension when max temperature occurs. I'm guessing I'll have to use ncap2 and write a script. Is there a simpler way?
Thanks.
I have temperature data w/ 3 dimensions (lat, lon, time). I want to create a grid that contains the value of the time dimension when max temperature occurs. I'm guessing I'll have to use ncap2 and write a script. Is there a simpler way?
Thanks.
John,
When you extract the max of your variable using 'ncwa' it gives you the corresponding coordinates and time step, I use:
ncwa -y max -v temp in.nc out.nc
Hope it helps,
Augusto
There is no simpler way that I can think of.
This would be a great feature to have in ncap2, and has been suggested before,
I don't think we ever implemented a simpler way than writing a script.
Henry will correct me if I am wrong.
cz
Augusto,
ncwa -y max returns the maximum value in each variable independently.
John wants to know the value of a second variable (time) corresponding to the maximum values of the first variable (temperature). The two are linked, and NCO/ncap2 does not have a simple, elegant way of getting that linked information.
cz
Henry pointed out that NCO supports what you want to do through
ncap2/GSL functions. Specifically, gsl_stats_min_index() and gsl_stats_max_index(). Please see http://nco.sf.net/nco.html#gsl
for more info on calling them from ncap2.
cz
Thanks all for your ideas. I wrote a script for ncap2 and it wasn't too bad. About 15 lines of code, and it runs pretty fast too. The trick was to always use 'where' rather than iterating over the lat, lon dimensions.
Could you provide this script?
I had trouble finding that script, so I just kind of typed it out. I hope it works! Or gets you close to it.
// Assume temperature data is stored in a 3-dimensional variable called 'temperature', // and the 3 dimensions are time, lat, lon. // Create 2-dim variables using 'temperature' as a template. *max_value = array(0, 1, temperature(0,:,:)); *max_time = array(0, 1, temperature(0,:,:)); // Set max time to the first time step. max_value = temperature(0,:,:); max_time = 0; // Iterate over time. for(*i = 1; i < $time.size; i++) { // If the i'th value is greater than max time found so far, update max_time. where (temperature(i,:,:) > max_value) { max_time = i; max_value = temperature(i,:,:); } } max_time.ram_write();
Log in to post a comment.