source: trunk/UTIL/PYTHON/planetoplot_v2/pp.py @ 911

Last change on this file since 911 was 910, checked in by aslmd, 12 years ago

PLANETOPLOT v2


  1. Spiga LMD/UPMC 24/03/2013

Contents


core


  • ppclass.py --> main class with pp() objects (need ppplot and ppcompute)
  • ppplot.py --> plot class (can be used independently, need ppcompute)
  • ppcompute.py --> computation class (can be used independently)

scripts


  • pp.py --> command line utility to use ppclass
  • pp_reload.py --> command line utility to load saved plot objects *.ppobj
  • example/* --> example scripts using ppclass

settings files


  • set_area.txt --> setting file: predefined areas for plotting (can be omitted)
  • set_back.txt --> setting file: predefined backgrounds for plotting (can be omitted)
  • set_multiplot.txt --> setting file: predefined coefficients for multiplots (can be omitted)
  • set_ppclass.txt --> setting file: predefined variables for x,y,z,t (can be omitted)
  • set_var.txt --> setting file: predefined colorbars, format, labels, etc... for variables (can be omitted)

documentation


  • README.TXT --> this README file

data


  • demo_data/* --> plot objects for a demonstration tour and customizing tests

Requirements


python + numpy + matplotlib + netCDF4

  • for mapping --> Basemap
  • for scientific computations --> scipy

[recommended: Enthought Python Distribution (free for academics)]

Installation


  • install required softwares and librairies in requirements
  • add planetoplot_v2 in your PYTHONPATH environment variable (and in your PATH to use pp.py)

Take a demo tour


pp_reload.py demo_data/*

Improvements compared to v1


  • code readability and structuration for future improvements
  • modularity (class formulation) + easy definition/addition of attributes
  • separation between data retrieval and plotting
  • versatility + command line (pp.py)

--> for quick inspection

+ interactive session (ipython)

--> for testing and exploring

+ scripts

--> for powerful and fully customized results

  • performance (overall and on large files) + memory consumption (only retrieve what is needed)
  • saving/loading plot objects in/from *.ppobj
  • plot aesthetics and customizing (see header in ppplot)
  • multiplot flexibility with .plotin attribute
  • easy definition of presets with set_*.txt files
  • function: one field vs. another one
  • emulation of + - / * operations on fields (between two fields or between a field and a int/float)
  • computations of min/max in addition to mean
  • simple inspection of dimensions+variables in a file (pp.py -f file)
  • verbose / non verbose mode

Acknowledgements


Thanks to A. Colaitis, T. Navarro, J. Leconte
for feedbacks and contributions on version 1

  • Property svn:executable set to *
File size: 4.6 KB
Line 
1#! /usr/bin/env python
2##############################################
3##  A MINIMAL PP.PY SCRIPT USING PPCLASS.PY ##
4##  Author: A. Spiga 03/2013                ##
5##############################################
6from optparse import OptionParser ### TBR by argparse
7from ppclass import pp, inspect
8##############################################
9
10# NB: this is a convenient command-line script
11#     ... but ppclass is more versatile
12#     ... than what is proposed here
13#     ... e.g. differences between files,
14#     ... complex operations,
15#     ... see sample scripts
16
17#####################################
18# get arguments from the command line
19#####################################
20parser = OptionParser()
21parser.add_option('--verbose',action='store_true',dest='verbose',default=False,help='')
22# field --> lower case
23parser.add_option('-f','--file',action='append',dest='file',type="string",default=None,help='')
24parser.add_option('-v','--var',action='append',dest='var',type="string",default=None,help='')
25parser.add_option('-x','--lat',action='append',dest='x',type="string",default=None,help='')
26parser.add_option('-y','--lon',action='append',dest='y',type="string",default=None,help='')
27parser.add_option('-z','--vert',action='append',dest='z',type="string",default=None,help='')
28parser.add_option('-t','--time',action='append',dest='t',type="string",default=None,help='')
29parser.add_option('-c','--contour',action='store',dest='contour',type="string",default=None,help='')
30parser.add_option('-i','--vecx',action='store',dest='vecx',type="string",default=None,help='')
31parser.add_option('-j','--vecy',action='store',dest='vecy',type="string",default=None,help='')
32parser.add_option('-m','--mult',action='store',dest='mult',type="float",default=None,help='')
33parser.add_option('-a','--add',action='store',dest='add',type="float",default=None,help='')
34# plot --> upper case
35# -- generic
36parser.add_option('-T','--title',action='append',dest='title',type="string",default=None,help='')
37parser.add_option('-X','--xlabel',action='append',dest='xlabel',type="string",default=None,help='')
38parser.add_option('-Y','--ylabel',action='append',dest='ylabel',type="string",default=None,help='')
39parser.add_option('-D','--div',action='store',dest='div',type="int",default=20,help='')
40parser.add_option('-H','--trans',action='store',dest='trans',type="float",default=1.0,help='')
41parser.add_option('-O','--logy',action='store_true',dest='logy',default=False,help='')
42# -- 1D plot
43parser.add_option('-L','--lstyle',action='append',dest='lstyle',type="string",default=None,help='')
44parser.add_option('-S','--superpose',action='store_true',dest='superpose',default=False,help='')
45# -- 2D plot
46parser.add_option('-C','--colorb',action='append',dest='colorb',type="string",default=None,help='')
47parser.add_option('-P','--proj',action='append',dest='proj',type="string",default=None,help='')
48parser.add_option('-B','--back',action='append',dest='back',type="string",default=None,help='')
49parser.add_option('-A','--area',action='append',dest='area',type="string",default=None,help='')
50parser.add_option('-I','--blon',action='append',dest='blon',type="float",default=None,help='')
51parser.add_option('-J','--blat',action='append',dest='blat',type="float",default=None,help='')
52parser.add_option('-N','--vmin',action='append',dest='vmin',type="float",default=None,help='')
53parser.add_option('-M','--vmax',action='append',dest='vmax',type="float",default=None,help='')
54(opt,args) = parser.parse_args()
55
56##########################################
57# a possibility to simply inspect the file
58##########################################
59if opt.file is None:
60    print "Stop here. I need at least a file: -f FILE" ; exit()
61if opt.var is None:
62    for filename in opt.file: inspect(filename)
63    exit()
64
65######################################
66# use ppclass to get field and plot it
67######################################
68# treat the case of additional vectors or contours (contours must be before vectors)
69var = [] ; vargoal = []
70for element in opt.var:
71    var.append(element) ; vargoal.append("main")
72    if opt.contour is not None: var.append(opt.contour) ; vargoal.append("contour")
73    if opt.vecx is not None: var.append(opt.vecx) ; vargoal.append("vector")
74    if opt.vecy is not None: var.append(opt.vecy) ; vargoal.append("vector")
75# set pp object
76user = pp(file=opt.file, var=var, vargoal=vargoal, \
77          x=opt.x, y=opt.y, z=opt.z, t=opt.t,\
78          verbose=opt.verbose)
79# define field
80user.define()
81# retrieve field
82user.retrieve()
83# some possible operations
84if opt.add is not None: user = user + opt.add
85if opt.mult is not None: user = user * opt.mult
86# define plot
87user.defineplot()
88# user-defined plot settings
89user.getopt(opt)
90# make plot
91user.makeplot()
Note: See TracBrowser for help on using the repository browser.