Difference between revisions of "Using Python with Climate Data"

(Imported from Wikispaces)
 
 
Line 1: Line 1:
 +
{{Needs Update}}
 +
 
At the Melbourne Uni follow-up meeting for the 2013 Software Carpentry workshop Damien Irving showed off several Python libraries for working with climate data. Damien's notes are given below, he also has material available on [http://drclimate.wordpress.com/2013/02/18/python-and-software-carpentry-a-3-year-journey |  his blog].
 
At the Melbourne Uni follow-up meeting for the 2013 Software Carpentry workshop Damien Irving showed off several Python libraries for working with climate data. Damien's notes are given below, he also has material available on [http://drclimate.wordpress.com/2013/02/18/python-and-software-carpentry-a-3-year-journey |  his blog].
  
Line 66: Line 68:
 
* use docstrings as your primary documentation method
 
* use docstrings as your primary documentation method
 
* use pylint to test the quality of your code
 
* use pylint to test the quality of your code
 +
 +
[[Category: Python]]

Latest revision as of 01:33, 18 March 2019

Template:Needs Update This page needs updating

At the Melbourne Uni follow-up meeting for the 2013 Software Carpentry workshop Damien Irving showed off several Python libraries for working with climate data. Damien's notes are given below, he also has material available on | his blog.


Hi all,

Thanks for coming to the Software Carpentry boot camp follow up session this afternoon. Below is a summary of the text that I showed at the end, including the various links that I promised. If you're struggling with Python at all, feel free to look through my bitbucket repository for useful examples (https://bitbucket.org/DBrent/phd/src). At the 'cdat_tutorial' directory in that repository, you'll see the example code that I used today.

netCDF

ipython

  • excellent interactive development environment (IDE)
  • use dir() and ? to explore objects
  • use pdb for debugging
  • use ! to run any command at the system shell
  • on abyss: /usr/local/uvcdat/1.2.0rc1/bin/ipython

uvcdat

import cdms2

import cdutil

import genutil

import regrid2

  • for regirdding

import MV2

  • for masked arrays
  • it's a copy of numpy.ma, but the data keep their attributes

import matplotlib

  • for all plotting (timeseries, spatial maps, etc)
  • from mpl_toolkits.basemap import Basemap, for spatial maps
  • from mpl_toolkits.basemap import shiftgrid, for longitude axis fiddling
  • documentation: http://matplotlib.org/

programming tips

  • use the argparse module for parsing the command line
  • create your own modules to avoid duplication of code
  • use docstrings as your primary documentation method
  • use pylint to test the quality of your code