#acl AdminGroup:read,write,delete,revert EditorGroup:read,write,delete,revert All:read #format wiki #language en #pragma section-numbers off <> = Visualisation = Python does not rely on one standard library for plotting and visualization, you have the choice to from several alternatives: * [[http://matplotlib.sourceforge.net/|matplotlib]] is becoming a quasi standard for plotting within the numpy/scipy/ipython environment and easy to use. * [[http://www.pyngl.ucar.edu/|PyNGL and PyNIO]] provide interfaces to the functionality existing in the NCAR Command Language (NCL). * [[http://code.enthought.com/projects/mayavi/|Mayavi Project - 3D Scientific Data Visualization and Plotting]] * [[http://www.pythonware.com/products/pil/|The Python Imaging Library (PIL) supports many file formats, and provides powerful image processing and graphics capabilities.]] * Interaction with other (non-Python) tools, e.g. [[http://www.soest.hawaii.edu/GMT/|The Generic Mapping Tools]], Google Earth == 2 D Plots with Pylab == {{attachment:density.png}} {{{#!python from pylab import * # The seawater module is installed only for Python2.6.2: # module load Python/2.6.2 import seawater S=linspace(0,35) T=linspace(-2,35.0) rho=zeros((S.size,T.size)) for i,t in enumerate(T): rho[i,:]=seawater.dens(S,t) figure() CS = contour(S,T,rho,15,colors='k') clabel(CS, fontsize=8, inline=1) ylabel('Temperature [$^\circ$C]') xlabel('Salinity') title('Sea water density [kg/m$^3$]') show() savefig('density.png',dpi=75) }}} == Basemap == The [[http://matplotlib.sourceforge.net/basemap/doc/html/| matplotlib basemap toolkit]] is a library for plotting 2D data on maps in Python. {{attachment:Map1.png}} {{{#!python from pylab import * from mpl_toolkits.basemap import Basemap m = Basemap(projection='ortho',lon_0=10.0,lat_0=45.0,resolution='l') m.bluemarble() lon,lat=10.0,53.5 # Hamburg x,y=m(lon,lat) m.plot([x],[y],'r.') show() savefig('Map1.png',dpi=75) }}} Don't forget to set the correct path for using Basemap on ZMAW systems {{{ module load Python }}} == GMT == {{attachment:map.png}} [[http://gmt.soest.hawaii.edu/|GMT]] is an open source collection of ~60 tools for manipulating geographic and Cartesian data sets (including filtering, trend fitting, gridding, projecting, etc.) and producing publication quality scientific plots. In particular useful are the [[http://gmt.soest.hawaii.edu/gmt/examples/ex14/gmt_example_14.html|gridding routines]] which can be used for irregular sampled oceanographic as well as for satellite data. GMT can be easily applied together with Python using the [[http://docs.python.org/library/os.html|os module]]. {{{#!python import os os.system('pscoast -R4/12/52/57 -JM6i -P -B1g1 -Ggray -Df > map.ps') os.system('gv map.ps') }}} == Google Earth == {{attachment:600px-Google_earth_chlorophyll.png}} Documentation: http://code.google.com/apis/kml/documentation/ Chlorophyll data: http://oceancolor.gsfc.nasa.gov/cgi/climatologies.pl Download png and make black transparent {{{ convert -transparent black A20020012007273.L3m_CU_CHLO_4.png A20020012007273.L3m_CU_CHLO_4_trans.png }}} Create ''.kml'' file {{{ Chlorophyll Climatology MODIS UHH Logo ffffffff 1 http://www.ifm.uni-hamburg.de/logo_uhh_neu.gif 8 53 2000000 0 Chlorophyll 2002-2007 1ffffffff A20020012007273.L3m_CU_CHLO_4_trans.png 90-90180-180 }}} == Grads == http://opengrads.org/wiki/index.php?title=PyGrADS_Interactive_Shell = Exercise = Add to the above Basemap the air temperature from NCEP reanalyis as isolines: {{{#!python fid=io.netcdf_file('air.mon.mean.nc','r') lat=array(fid.variables['lat']) lon=array(fid.variables['lon']) air=array(fid.variables['air']) LON,LAT=meshgrid(lon,lat) x,y=m(LON,LAT) m.contour(x,y,air[753,:,:]) }}}