Sorting by variable value
Added by Ciara O'Hara over 10 years ago
Hi all,
I want to be able to sort my netCDF files by variable values, rather than by date and time. I want to do this to produce a graph of the frequency of occurance of particular values against those values, therefore I think the best way would be to sort by variable value and plot against time (can anyone think of a better way?).
Does anyone know how I could sort in this way?
Thanks in advance,
Ciara
Replies (7)
RE: Sorting by variable value - Added by Jaison-Thomas Ambadan over 10 years ago
I'm not sure if I understood your question correctly. You may be able to use the histogram operators for your purpose. 2.15.12 HISTOGRAM - Histogram
https://code.zmaw.de/projects/cdo/embedded/1.6.3/cdo.html#x1-6670002.15.12
RE: Sorting by variable value - Added by Ciara O'Hara over 10 years ago
Thanks for your response Jaiso-Thomas,
I don't think I explained it very well. I want to be able to plot the normalised values I actually have, against their frequency of occurance. The histfreq function will tell me how many appear between a particular range, but I'd have to do this many times, and then create a plot manually for each one, I guess? I have many of these data sets and I want to do it with a number of different time series so that would be impractical.
histfreq returns a float value of how many are between a certain interval. Even If I did do this manually, I wouldn't know how to apply the relevant data range to it to plot it. I don't know if I'm making any sense!
Thanks again,
Ciara
RE: Sorting by variable value - Added by Jaison-Thomas Ambadan over 10 years ago
Hi,
Other than histogram operators, you could use the comparison/relational operators in CDO for your purpose. These operators actually create mask (zeros and ones) as output. For example, you could create an AND operator by multiplying the output [masks] of ge and lt operators, and then a timsum will give you the frequency over time, and if you want the same over a field just do fldsum You could actually manipulate these comparison/relational operators in CDO to get the number of grid-points/fields [basically the frequency] satisfying a certain condition.
For more info see CDO doc section 2.5: https://code.zmaw.de/projects/cdo/embedded/1.6.3/cdo.html#x1-1450002.5
Cheers,
J
RE: Sorting by variable value - Added by Ciara O'Hara over 10 years ago
Thanks J,
I need to reshuffle them though, to order them in terms of variable value, to produce a graph that looks like those on p.5 of this report (the temperature anomaly ones): http://www.bom.gov.au/state-of-the-climate/documents/state-of-the-climate-2014_low-res.pdf?ref=button.
Maybe it can't be done with cdo. I'll just save the files in .csv format and reshuffle them manually.
Thanks for your help,
Ciara
RE: Sorting by variable value - Added by Jaison-Thomas Ambadan over 10 years ago
Hi,
I think it can be done with histfreq. Attached is a test plot using CRU temp over North-America:
cdo -histfreq,$(echo $(seq -4 0.5 4) |sed 's/ /,/g' ) ifile.nc ofile.nc $(echo $(seq -4 0.5 4) produce a simple-silly bins for testing (although it is not the right way to generate proper bins)
Then you just need to dump all the fields over all bins (or reshape into a vector or use outputtab) and plot. Anyway you may want try other tools like Matlab if you are not comfortable using CDO for this purpose.
Cheers,
J
histfreq.png (20 KB) histfreq.png |
RE: Sorting by variable value - Added by Ciara O'Hara over 10 years ago
THanks, I'll have a look at that, and yes I think you're right.
Thanks very much for your help.
Ciara
RE: Sorting by variable value - Added by Miles Sowden almost 4 years ago
Thanks Jaison for the hint on seq. I used
cdo -fldmean -histfreq,$(seq -s, -50 1 50) t2.nc t3.nc
no need for the replace space with coma just use '-s,'
Can also dump to asci by
cdo infov -fldmean -histfreq,$(seq -s, -50 1 50) t2.nc > t3.txt
Cheers
Miles