Skip to content
Advertisement

Calculate yearly anomalies for several years on netcdf files in python

I need to calculate monthly, seasonal and annualy anomalies of air temperature of netcdf monthly files of 44 years with some function that allows me to obtain anomalies in the period on a monthly, seasonal and annualy automatically and save the results in a folder. I only know how to do It for one year and not for several years with a function.

JavaScript

Advertisement

Answer

I know you are looking for a python answer, but this is bread and butter of CDO (climate data operators), that allows you to do these sort of calculations in one or two commands from the terminal window.

For example, to get the annual means of your Era Interim data you can do

JavaScript

and then to calculate the annual anomaly you need to do the long term average and subtract it

JavaScript

You can combine all these above 3 commands using “piping”, but I keep them separate here as it is easier to see what is going on.

you can get the mean monthly seasonal cycle with:

JavaScript

this gives you a file with the average of all the januarys, Feb etc (12 time slices). And then you can calculate the monthly anomaly, each with respect to its own monthly mean with

JavaScript

There are also functions for seasonal averages.

See the online documentation for further details: https://code.mpimet.mpg.de/projects/cdo/

Lastly, msi_gerva is correct in the comment, it is not clear in the question what the anomalies are with respect to, as you could also calculate monthly anomalies with respect to the annual or long term mean. Moreover, you ask for annual anomalies and say you only know how to do it for one year, but I don’t think that makes much sense, as the anomalies would be zero. It may be helpful to clarify the question more precisely.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement