2

I have downloaded climate model output in the form of netcdf files with one variable (pr) for the whole world with a daily time-step. My final goal is to have monthly data for Europe.

I have never used netcdf files before and all the specific software for netcdf I could find doesn't seems to work in windows. Since I programme in R, I tried using the ncdf4 package but run into memory size problems (my files are around 2Gb)... I am now trying the netCDF4 module in python (first time I am using python - so go easy on me).

I have managed to install everything and found some code online to import the dataset:

nc_fid = Dataset(nc_f, 'r')  
# Extract data from NetCDF file
lats = nc_fid.variables['lat'][:]
lons = nc_fid.variables['lon'][:]
time = nc_fid.variables['time'][:]
pp  = nc_fid.variables['pr'][:]  

However all the tutorials I found are on how to make a netcdf file... I have no idea how to aggregate this daily rainfall (variable pr) into monthly. Also, I have different types of calender in different files, but I don't even know how to access that information:

time.calendar
AttributeError: 'numpy.ndarray' object has no attribute 'calendar'

Please help, I don't want to have to learn Linux just so I can sort-out some data :(

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
sbg
  • 1,772
  • 8
  • 27
  • 45
  • 1
    Tell more about the input netCDF daily data. Is it one file per day? Or all in one file? What do you mean by different calendars? – Spencer Hill Oct 07 '14 at 19:31
  • There are several years in each file and the whole time-series for each climate model is in a handful of files (but if you can tell me how to do it for each file that would be already very helpful). I need to take the calendar type in consideration because once I know how to do it I will be running the code for outputs of different climate models, and they have different calendars (standard, 360 days...) – sbg Oct 07 '14 at 21:36

2 Answers2

3

Why not avoid programming entirely and use NCO which supplies the ncrcat command that aggregates data thusly:

ncrcat day*.nc month.nc

Voilà. See more ncrcat examples here.

Added 20160628: If instead of a month-long timeseries you want a monthly average then use the same command only with ncra instead of ncrcat. The manual explains things like this.

Charlie Zender
  • 5,929
  • 14
  • 19
  • A little question for you, I did what you posted but it just merged my daily NetCDF but did not do the monthly average... can you suggest something? – Erincon Jun 27 '16 at 20:30
2

If you have a daily timestep and you want to calculate the monthly mean then you can do

cdo monmean input_yyyy.nc output_yyyy.nc

It sounds as if you have several of these files, so you will need to merge them with

cdo mergetime file_*.nc timeseries.nc 

where the * is a wildcard for the years.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86