carpentries-lab / python-aos-lesson

Python for Atmosphere and Ocean Scientists
https://carpentries-lab.github.io/python-aos-lesson/
Other
88 stars 50 forks source link

Add content on wrangling netCDF files? #7

Open DamienIrving opened 6 years ago

DamienIrving commented 6 years ago

It would be nice to add a lesson on wrangling netCDF files.

The premise for the lesson could be that we want to download some ERA-Interim precipitation data (total precipitation, synoptic monthly mean) to compare to our models. Wrangling that data would involve something like the following (from here) to have the ERA-Interim data dimensions and attributes match the CMIP5 data files:

ncpdq -P upk ${infile} {infile}
cdo invertlat -sellonlatbox,0,359.9,-90,90 -mulc,33 -monsum ${infile} ${outfile}
ncrename -O -v tp,pr ${outfile}
ncatted -O -a calendar,global,d,, ${outfile}
ncatted -O -a standard_name,pr,o,c,"precipitation_flux" ${outfile}
ncatted -O -a long_name,pr,o,c,"precipitation flux" ${outfile}
ncatted -O -a units,pr,o,c,"mm/day" ${outfile}

(The -mulc,33 covers mutliplying by 1000 to convert the units from m/month to mm/month and then dividing by 30 to crudely convert to mm/day.)

The main barrier to this lesson is that cdo isn't available on windows and the conda-forge recipe for Mac is broken: https://github.com/conda-forge/cdo-feedstock/issues/15

I love the convenience of cdo, but the fact that it essentially only works on Linux machines is very problematic. To get around this, I could do the cdo parts of the wrangling on a Linux machine in advance and provide the final file for download - the participants could then do the nco parts?

Other useful links:

MathewBiddle commented 3 years ago

It would be nice to do something a little higher level wrt netCDF. How to work with netCDF in Python is a question I get quite frequently. Most of the examples are using gridded model (or satellite) output. However, netCDF has various other featureTypes (like profile, timeseries, etc) that are a little easier to understand from the get-go. A lesson giving the background on netCDF and the various conventions which can be applied would be helpful. Then, showing how to not only open and investigate data, but how to create and manage netCDF would be helpful.

We have a couple examples in the IOOS code gallery which could be expanded upon into a lesson here.