Changeset 923 for trunk/UTIL


Ignore:
Timestamp:
Mar 31, 2013, 10:18:37 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2

PPCLASS AND PPPLOT

  • added global plot settings in pp() objects
  • self is returned for each method to allow e.g. one-line get + attribution
  • added labeling of 1D plots
  • fine-tuning of plot appearance (e.g. vector key)
  • corrected a problem with plotin (same object can be referred to all along)
  • fixed meanarea for 1D requests

PP.PY

  • no more -f for pp.py (files are simply given as arguments!)
  • added missing options to pp.py
  • nice informative header

PP_RELOAD.PY

  • pp_reload.py can now change colorbars and 1D markers

EXAMPLES

  • general update of examples + few additions
  • added a nice example tide with mixed 2D+1D plots
Location:
trunk/UTIL/PYTHON/planetoplot_v2
Files:
3 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot_v2/README.TXT

    r920 r923  
    3030data
    3131----
    32 - demo_data/* --> plot objects for a demonstration tour and customizing tests
     32plot objects for a demonstration tour and customizing tests
     33https://dl.dropbox.com/u/11078310/demo_data.tar.gz
    3334
    3435Requirements
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/aire.py

    r921 r923  
    1111tpond.compute = "meanarea"
    1212tpond.superpose = True
     13tpond.label = "mean with ponderation by mesh area"
    1314tpond.getplot(extraplot=1)
    1415
     
    1718tnormal.compute = "mean"
    1819tnormal.plotin = tpond
     20tnormal.label = "simple mean (kind of wrong)"
     21tnormal.filename = "aire"
    1922tnormal.getplot()
    2023
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/anomaly.py

    r910 r923  
    1717## COMPUTE AND PLOT RELATIVE ANOMALY in %
    1818anomaly = ((simple-mean)/mean)*100.
     19anomaly.filename = "anomaly"
    1920anomaly.defineplot()
    2021anomaly.p[0].title = "surface temperature anomaly in %"
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/chain_pp.sh

    r910 r923  
    11#! /bin/bash
    22
    3 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc
    4 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -v v -t 0.5 -z 10.
    5 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -y 2
    6 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -y 2 -m 1000 -L --
    7 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -C spectral
    8 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P ortho
    9 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P moll
    10 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P npstere
    11 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P spstere
    12 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P cyl -A Tharsis
    13 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P lcc -A Tharsis
    14 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P laea -A Tharsis
    15 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -A Tropics -P merc
    16 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -c phisinit -t 0.5 -z 10. -T Yeah -P laea -A Tharsis
    17 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -P merc -A Whole_No_High
    18 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -P robin
     3./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc
     4./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -v v -t 0.5 -z 10.
     5./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -y 2
     6./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -y 2 -m 1000 -L --
     7./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -C spectral
     8./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P ortho
     9./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P moll
     10./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P npstere
     11./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P spstere
     12./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P cyl -A Tharsis
     13./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P lcc -A Tharsis
     14./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -z 10. -T Yeah -P laea -A Tharsis
     15./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -A Tropics -P merc
     16./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -c phisinit -t 0.5 -z 10. -T Yeah -P laea -A Tharsis
     17./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -P merc -A Whole_No_High
     18./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -P robin
    1919
    20 ./pp.py -f /home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00\:00\:00
    21 ./pp.py -f /home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00\:00\:00 -v HGT -B vishires
    22 ./pp.py -f /home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00\:00\:00 -v HGT -t 1. -B vishires -H 0.5
    23 ./pp.py -f /home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00\:00\:00 -v HGT -t 1. -P ortho -B vishires
     20./pp.py /home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00\:00\:00
     21./pp.py /home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00\:00\:00 -v HGT -B vishires
     22./pp.py /home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00\:00\:00 -v HGT -t 1. -B vishires -H 0.5
     23./pp.py /home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00\:00\:00 -v HGT -t 1. -P ortho -B vishires
    2424
    25 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -P robin
    26 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -x 10 -C jet -P robin
    27 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -P robin -H 0.5 -B vishires
     25./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -P robin
     26./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v u -t 0.5 -x 10 -C jet -P robin
     27./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v ps -t 0.5 -z 10. -C jet -P robin -H 0.5 -B vishires
    2828
    29 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -P robin
    30 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v phisinit -P ortho -I -120.
    31 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v phisinit -P ortho -I -120. -v phisinit -I 120
    32 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v phisinit -P ortho -I -120. -v phisinit
    33 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P robin -I -120. -v icetot -I 120.
     29./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -P robin
     30./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v phisinit -P ortho -I -120.
     31./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v phisinit -P ortho -I -120. -v phisinit -I 120
     32./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v phisinit -P ortho -I -120. -v phisinit
     33./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P robin -I -120. -v icetot -I 120.
    3434
    35 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P moll
    36 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P moll -i u -j v
    37 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P moll -i u -j v -z 10.
    38 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P moll -i u -j v -z 10000.
    39 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P cyl -i u -j v -z 10000. --verbose
    40 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P cyl -i u -j v -z 10000. -c phisinit
    41 ./pp.py -f /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P cyl -z 10000. -c temp
     35./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P moll
     36./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P moll -i u -j v
     37./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P moll -i u -j v -z 10.
     38./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P moll -i u -j v -z 10000.
     39./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P cyl -i u -j v -z 10000. --verbose
     40./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P cyl -i u -j v -z 10000. -c phisinit
     41./pp.py /home/aymeric/Big_Data/DATAPLOT/diagfired.nc -v icetot -t 1. -P cyl -z 10000. -c temp
    4242
    43 ./pp.py -f wrfout_d03_2024-06-09_00\:00\:00_z -v tk -c HGT -t 1 -z 0 -P lcc -i Um -j Vm --verbose
     43./pp.py wrfout_d03_2024-06-09_00\:00\:00_z -v tk -c HGT -t 1 -z 0 -P lcc -i Um -j Vm --verbose
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/hodograph.py

    r910 r923  
    1717# u as a function of v
    1818hodo = u.f(v)
     19hodo.filename = "hodograph"
    1920hodo.makeplot()
    2021
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/les_psfc.py

    r910 r923  
    1414les.y = None
    1515les.t = ["10"]
    16 #les.stridex = 3
    17 #les.stridey = 3
     16les.stridex = 3
     17les.stridey = 3
     18les.filename = "les_psfc"
    1819les.getplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/meso_profile.py

    r910 r923  
    4747S.p[0].ylabel="Geopotential height (km)"
    4848S.p[0].xlabel="Potential temperature (K)"
     49S.filename = "meso_profile"
    4950
    5051# make the plot
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/scatter.py

    r910 r923  
    5050S3.p[0].color="k"
    5151S3.p[0].ylabel="wind speed $\sqrt{u^{2}+v^{2}}$ (m s$^{-1}$)"
     52S3.filename="scatter"
    5253S3.makeplot()
    5354
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/simple.py

    r910 r923  
    2121u.p[0].title = "This is what we name $u$ (m s$^{-1}$)"
    2222u.p[0].proj = "robin"
     23u.filename = "simple"
    2324
    2425# we plot
     
    2829# ... no need to reload data
    2930u.p[0].colorb = "RdBu"
     31u.filename = "myplot"
    3032u.makeplot()
    3133
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/vector.py

    r910 r923  
    88u.t = "0.5,0.8"
    99u.z = "50000"
     10u.filename = "vector"
    1011u.get()
    1112u.defineplot()
     
    1617
    1718u.z = "50"
     19u.filename = "myplot"
    1820u.getplot()
    1921
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/vertpress.py

    r910 r923  
    99prof.x = 30
    1010prof.y = 30
     11prof.filename = "vertpress"
    1112
    1213prof.get()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/windspeed.py

    r910 r923  
    2525wind = wind**0.5
    2626wind.plotin = v
     27wind.filename = "windspeed"
    2728wind.defineplot()
    2829wind.p[2].title = "$\sqrt{u^2+v^2}$ (m s$^{-1}$)"
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/zonalcontour.py

    r910 r923  
    88u.x = "0"
    99u.t = "0.5"
     10u.filename = "zonalcontour"
    1011u.get()
    1112u.defineplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/zonalmean.py

    r910 r923  
    2121u.y = None
    2222u.t = "0.5"
     23u.filename = "zonalmean"
    2324u.get()
    2425u.defineplot()
     
    3031## ZONAL MINIMUM
    3132u.compute = "min"
     33u.filename = "zonalmin"
    3234u.get()
    3335u.defineplot()
     
    3941## ZONAL MAXIMUM
    4042u.compute = "max"
     43u.filename = "myplot"
    4144u.get()
    4245u.defineplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/pp.py

    r921 r923  
    1616#     ... see sample scripts
    1717
    18 #####################################
    19 # get arguments from the command line
    20 #####################################
     18######################################
     19# define parser with version and usage
     20######################################
    2121parser = OptionParser()
     22parser.version = \
     23'''************************************************************************
     24PLANETOPLOT (for help: pp.py -h)
     25--> command line tool to make nice & quick plots from netCDF files
     26--> based on python + numpy + scipy + matplotlib + basemap + netCDF4
     27--> Author: A. Spiga (LMD/UPMC) aymeric.spiga@upmc.fr
     28************************************************************************'''
     29parser.usage = \
     30'''pp.py [options] netCDF file(s)
     31(NB: no options --> simple inspection of variables and dimensions in netCDF files'''
     32parser.print_version()
     33
     34########################################
     35# set options for the pp.py command line
     36########################################
    2237parser.add_option('--verbose',action='store_true',dest='verbose',default=False,help='make the program verbose')
    2338# field --> lower case
    24 parser.add_option('-f','--file',action='append',dest='file',type="string",default=None,help="[NEEDED] 'file' or ['file1','file2',etc]")
    2539parser.add_option('-v','--var',action='append',dest='var',type="string",default=None,help="'variable' or ['var1','var2',etc]")
    26 parser.add_option('-x','--lon',action='append',dest='x',type="string",default=None,help="x axis value. either one value; or val1,val2 (computations)")
    27 parser.add_option('-y','--lat',action='append',dest='y',type="string",default=None,help="y axis value. either one value; or val1,val2 (computations)")
    28 parser.add_option('-z','--vert',action='append',dest='z',type="string",default=None,help="z axis value. either one value; or val1,val2 (computations)")
    29 parser.add_option('-t','--time',action='append',dest='t',type="string",default=None,help="t axis value. either one value; or val1,val2 (computations)")
    30 parser.add_option('-u','--compute',action='store',dest='compute',type="string",default="mean",help="computation: mean, min, max")
     40parser.add_option('-x','--lon',action='append',dest='x',type="string",default=None,help="x axis value. one value; or val1,val2 (computations)")
     41parser.add_option('-y','--lat',action='append',dest='y',type="string",default=None,help="y axis value. one value; or val1,val2 (computations)")
     42parser.add_option('-z','--vert',action='append',dest='z',type="string",default=None,help="z axis value. one value; or val1,val2 (computations)")
     43parser.add_option('-t','--time',action='append',dest='t',type="string",default=None,help="t axis value. one value; or val1,val2 (computations)")
     44parser.add_option('-u','--compute',action='store',dest='compute',type="string",default="mean",help="computation: mean, min, max, meanarea")
    3145parser.add_option('-c','--contour',action='store',dest='contour',type="string",default=None,help="one 'variable' for contour")
    3246parser.add_option('-i','--vecx',action='store',dest='vecx',type="string",default=None,help="one 'variable' for wind vector x component")
     
    3650parser.add_option('-o','--output',action='store',dest='filename',type="string",default="myplot",help="name of output files")
    3751parser.add_option('-d','--directory',action='store',dest='folder',type="string",default="./",help="directory of output files")
    38 parser.add_option('-u','--compute',action='store',dest='compute',type="string",default="mean",help='')
    3952# plot --> upper case
    4053# -- generic
     
    5164parser.add_option('-K','--marker',action='append',dest='marker',type="string",default=None,help="[1D] marker: '' 'x' 'o' etc")
    5265parser.add_option('-S','--superpose',action='store_true',dest='superpose',default=False,help="[1D] use same axis for all plots")
     66parser.add_option('-E','--label',action='append',dest='label',type="string",default=None,help="[1D] label for line")
    5367# -- 2D plot
    5468parser.add_option('-C','--colorb',action='append',dest='colorb',type="string",default=None,help="[2D] colormap: http://micropore.files.wordpress.com/2010/06/colormaps.png")
     
    6276(opt,args) = parser.parse_args()
    6377
    64 ##########################################
    65 # a possibility to simply inspect the file
    66 ##########################################
    67 if opt.file is None:
    68     print "Stop here. I need at least a file: -f FILE" ; exit()
     78######################################
     79# get arguments (one or several files)
     80######################################
     81if args is None:
     82    print "Stop here! I need file(s) as argument(s)!" ; exit()
     83else:
     84    files = args
     85
     86#############################################
     87# a possibility to simply inspect the file(s)
     88#############################################
    6989if opt.var is None:
    70     for filename in opt.file: inspect(filename)
     90    for filename in files: inspect(filename)
    7191    exit()
    7292
     
    83103# set pp object
    84104user = pp()
    85 user.file = opt.file
    86 user.var = var
    87 user.vargoal = vargoal
    88 user.x = opt.x
    89 user.y = opt.y
    90 user.z = opt.z
    91 user.t = opt.t
     105user.file = files
     106user.var = var ; user.vargoal = vargoal
     107user.x = opt.x ; user.y = opt.y
     108user.z = opt.z ; user.t = opt.t
    92109user.verbose = opt.verbose
    93110user.compute = opt.compute
     
    118135try:
    119136    f = open(opt.folder+'/'+opt.filename+'.sh', 'w')
    120     f.write(command)
     137    f.write(command)   
    121138except IOError:
    122139    print "!! WARNING !! pp.py command not saved. Probably do not have permission to write here."
  • trunk/UTIL/PYTHON/planetoplot_v2/pp_reload.py

    r917 r923  
    1010parser = OptionParser()
    1111parser.add_option('-O','--out',action='store',dest='out',type="string",default="gui",help='Specify a new output format')
    12 parser.add_option('-P','--proj',action='store',dest='proj',type="string",default=None,help='Define a new map projection')
     12parser.add_option('-K','--marker',action='store',dest='marker',type="string",default=None,help="[1D] Define a new marker")
     13parser.add_option('-P','--proj',action='store',dest='proj',type="string",default=None,help='[2D] Define a new map projection')
     14parser.add_option('-C','--colorb',action='store',dest='colorb',type="string",default=None,help="[2D] Define a new colormap")
    1315(opt,args) = parser.parse_args()
    1416# -----------------------------------------------------------------------
     
    2022      for plot in yeah.p:
    2123        plot.proj = opt.proj
     24    if opt.colorb is not None:
     25      for plot in yeah.p:
     26        plot.colorb = opt.colorb
     27    if opt.marker is not None:
     28      for plot in yeah.p:
     29        plot.marker = opt.marker
    2230    yeah.makeplot()
    2331
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r921 r923  
    2424#### ... executed when imported  ##
    2525###################################
    26 print "************************************"
    27 print "**** WELCOME TO PLANETOPLOT 2.0 ****"
    28 print "************************************"
    2926# where settings files are located...
    3027whereset = None
     
    143140                      out="gui",\
    144141                      filename="myplot",\
    145                       folder="./"):
     142                      folder="./",\
     143                      xlabel=None,ylabel=None,\
     144                      xcoeff=None,ycoeff=None,\
     145                      proj=None,\
     146                      vmin=None,vmax=None,\
     147                      div=None,\
     148                      colorb=None,\
     149                      lstyle=None,\
     150                      marker=None,\
     151                      color=None,\
     152                      label=None,\
     153                      title=None):
    146154        self.request = None
    147155        self.nfin = 0 ; self.nvin = 0
     
    172180        self.filename = filename
    173181        self.folder = folder
     182        ## here are user-defined plot settings
     183        ## -- if not None, valid on all plots in the pp() objects
     184        self.xlabel = xlabel ; self.xcoeff = xcoeff
     185        self.ylabel = ylabel ; self.ycoeff = ycoeff
     186        self.proj = proj
     187        self.vmin = vmin ; self.vmax = vmax
     188        self.div = div
     189        self.colorb = colorb
     190        self.lstyle = lstyle
     191        self.marker = marker
     192        self.color = color
     193        self.label = label
     194        self.title = title
    174195
    175196    # print status
     
    178199            pass
    179200        else:
    180             print "**** Done step: " + self.status
     201            print "**** PPCLASS. Done step: " + self.status
    181202
    182203    #####################################################
    183204    # EMULATE OPERATORS + - * / ** << FOR PP() OBJECTS  #
    184205    #####################################################
     206
     207    # define the operation <<
     208    # ... e.g. obj2 << obj1
     209    # ... means: get init for pp object obj2 from another pp object obj1
     210    # ... (this should solve the affectation trap obj2 = obj1)
     211    def __lshift__(self,other):
     212        if other.__class__.__name__ == "pp":
     213            self.file = other.file
     214            self.var = other.var
     215            self.filegoal = other.filegoal
     216            self.vargoal = other.vargoal
     217            self.x = other.x ; self.y = other.y   ## if None, free dimension
     218            self.z = other.z ; self.t = other.t   ## if None, free dimension
     219            self.stridex = other.stridex ; self.stridey = other.stridey
     220            self.stridez = other.stridez ; self.stridet = other.stridet
     221            self.verbose = other.verbose
     222            self.noproj = other.noproj
     223            self.plotin = other.plotin
     224            self.superpose = other.superpose
     225            self.forcedimplot = other.forcedimplot
     226            self.out = other.out
     227            self.filename = other.filename
     228            self.folder = other.folder
     229            self.xlabel = other.xlabel ; self.xcoeff = other.xcoeff
     230            self.ylabel = other.ylabel ; self.ycoeff = other.ycoeff
     231            self.proj = other.proj
     232            self.vmin = other.vmin ; self.vmax = other.vmax
     233            self.div = other.div
     234            self.colorb = other.colorb
     235            self.lstyle = other.lstyle
     236            self.marker = other.marker
     237            self.color = other.color
     238            self.label = other.label
     239            self.title = other.title
     240        else:
     241            print "!! ERROR !! argument must be a pp object." ; exit()
    185242
    186243    # check the compatibility of two objects for operations
     
    236293                setattr(obj,k,v)
    237294        the_clone.status = "retrieved"
     295        the_clone.filename = self.filename
    238296        return the_clone
    239297
     
    258316              else:           
    259317                  ope = other
    260               if "vector" in self.vargoal[j] + self.filegoal[i]:
    261                   print "!! ERROR !! we do not operate on vectors yet."
    262                   exit()
     318              goal = self.vargoal[j] + self.filegoal[i]
     319              if ("vector" in goal) or ("contour" in goal):
     320                  if self.verbose: print "!! WARNING !! No operation was made on contours and vectors. This can be debatted actually."
     321                  obj.field = obj_ref.field
    263322              else:
    264323                  obj.field = obj_ref.field + ope
     
    285344              else:
    286345                  ope = other
    287               if "vector" in self.vargoal[j] + self.filegoal[i]:
    288                   print "!! ERROR !! we do not operate on vectors yet."
    289                   exit()
     346              goal = self.vargoal[j] + self.filegoal[i]
     347              if ("vector" in goal) or ("contour" in goal):
     348                  if self.verbose: print "!! WARNING !! No operation was made on contours and vectors. This can be debatted actually."
     349                  obj.field = obj_ref.field
    290350              else:
    291351                  obj.field = obj_ref.field - ope
     
    312372              else:
    313373                  ope = other
    314               if "vector" in self.vargoal[j] + self.filegoal[i]:
    315                   print "!! ERROR !! we do not operate on vectors yet."
    316                   exit()
     374              goal = self.vargoal[j] + self.filegoal[i]
     375              if ("vector" in goal) or ("contour" in goal):
     376                  if self.verbose: print "!! WARNING !! No operation was made on contours and vectors. This can be debatted actually."
     377                  obj.field = obj_ref.field
    317378              else:
    318379                  obj.field = obj_ref.field * ope
     
    339400              else:
    340401                  ope = other
    341               if "vector" in self.vargoal[j] + self.filegoal[i]:
    342                   print "!! ERROR !! we do not operate on vectors yet."
    343                   exit()
     402              goal = self.vargoal[j] + self.filegoal[i]
     403              if ("vector" in goal) or ("contour" in goal):
     404                  if self.verbose: print "!! WARNING !! No operation was made on contours and vectors. This can be debatted actually."
     405                  obj.field = obj_ref.field
    344406              else:
    345407                  obj.field = obj_ref.field / ope
     
    383445                  obj  = the_clone.request[i][j][t][z][y][x]
    384446                  obj_ref = self.request[i][j][t][z][y][x]
    385                   if "vector" in self.vargoal[j] + self.filegoal[i]:
    386                       print "!! ERROR !! we do not operate on vectors yet."
    387                       exit()
     447                  goal = self.vargoal[j] + self.filegoal[i]
     448                  if ("vector" in goal) or ("contour" in goal):
     449                      if self.verbose: print "!! WARNING !! No operation was made on contours and vectors. This can be debatted actually."
     450                      obj.field = obj_ref.field
    388451                  else:
    389452                      obj.field = obj_ref.field ** num
     
    392455        return the_clone
    393456
    394     # define the operation <<
    395     # ... e.g. obj2 << obj1
    396     # ... means: get init for pp object obj2 from another pp object obj1
    397     # ... (this should solve the affectation trap obj2 = obj1)
    398     def __lshift__(self,other):
    399         if other.__class__.__name__ == "pp":
    400             self.file = other.file
    401             self.var = other.var
    402             self.filegoal = other.filegoal
    403             self.vargoal = other.vargoal
    404             self.x = other.x ; self.y = other.y   ## if None, free dimension
    405             self.z = other.z ; self.t = other.t   ## if None, free dimension
    406             self.stridex = other.stridex ; self.stridey = other.stridey
    407             self.stridez = other.stridez ; self.stridet = other.stridet
    408             self.verbose = other.verbose
    409             self.noproj = other.noproj
    410             self.plotin = other.plotin
    411             self.superpose = other.superpose
    412             self.forcedimplot = other.forcedimplot
    413             self.out = other.out
    414             self.filename = other.filename
    415             self.folder = other.folder
    416         else:
    417             print "!! ERROR !! argument must be a pp object." ; exit()
     457    ### TBD: reverse power? for exponentials?
    418458
    419459    ##############################################################################################
     
    505545        # change status
    506546        self.status = "defined"
     547        return self
    507548
    508549    ##############################################################################################
     
    533574        # change status
    534575        self.status = "retrieved"
     576        return self
    535577
    536578    ##########################################################
     
    540582        self.define()
    541583        self.retrieve()
     584        return self 
    542585
    543586    ########################################
     
    643686                    plobj.ordi = obj.ordi      # ordinate (or latitude)
    644687                                               # -- useless in 1D but not used anyway
     688                    # specific 1D plot stuff
     689                    if dp == 1:
     690                        # -- a default label
     691                        plobj.label = ""
     692                        if self.nfin > 1: plobj.label = plobj.label + " file #"+str(i+1)
     693                        if self.nvin > 1: plobj.label = plobj.label + " var #"+str(j+1)
     694                        if self.nplott > 1: plobj.label = plobj.label + " t #"+str(t+1)
     695                        if self.nplotz > 1: plobj.label = plobj.label + " z #"+str(z+1)
     696                        if self.nploty > 1: plobj.label = plobj.label + " y #"+str(y+1)
     697                        if self.nplotx > 1: plobj.label = plobj.label + " x #"+str(x+1)
     698                    # specific 2d plot stuff
    645699                    if dp == 2:
    646                     # specific 2d plot stuff
    647700                        # -- light grey background for missing values
    648701                        if type(plobj.field).__name__ in 'MaskedArray': plobj.axisbg = '0.75'
     
    651704                                       and "grid points" not in obj.name_x \
    652705                                       and not self.noproj )
    653                     # finally append
     706                    # possible user-defined plot settings shared by all plots
     707                    if self.div is not None: plobj.div = self.div
     708                    if self.xlabel is not None: plobj.xlabel = self.xlabel
     709                    if self.xcoeff is not None: plobj.xcoeff = self.xcoeff
     710                    if self.ylabel is not None: plobj.ylabel = self.ylabel
     711                    if self.ycoeff is not None: plobj.ycoeff = self.ycoeff
     712                    if self.title is not None: plobj.title = self.title
     713                    # -- 1D specific
     714                    if dp == 1:
     715                        if self.lstyle is not None: plobj.lstyle = self.lstyle
     716                        if self.marker is not None: plobj.marker = self.marker
     717                        if self.color is not None: plobj.color = self.color
     718                        if self.label is not None: plobj.label = self.label
     719                    # -- 2D specific
     720                    elif dp == 2:
     721                        if self.proj is not None and not self.noproj: plobj.proj = self.proj
     722                        if self.vmin is not None: plobj.vmin = self.vmin
     723                        if self.vmax is not None: plobj.vmax = self.vmax
     724                        if self.colorb is not None: plobj.colorb = self.colorb
     725                    # finally append plot object
    654726                    self.p.append(plobj)
    655727                    count = count + 1
     
    711783        # final status
    712784        self.status = "definedplot"
     785        return self
    713786
    714787    ##############################################################################################
     
    780853            # finally make the plot
    781854            pl.make()
    782             self.n = self.n+1
     855            # increment plot count (and propagate this in plotin)
     856            self.n = self.n+1
     857            if self.plotin is not None: self.plotin.n = self.n
    783858        # once completed show the plot (cannot show intermediate plotin)
    784859        # ... added a fix (customplot=True) for the label problem in basemap
    785         print "**** Done step: makeplot"
    786         if (self.n == self.howmanyplots): 
     860        print "**** PPCLASS. Done step: makeplot"
     861        if (self.n == self.howmanyplots):
    787862            ppplot.save(mode=self.out,filename=self.filename,folder=self.folder,custom=self.customplot)
    788863            mpl.close()
     
    795870        except IOError:
    796871            print "!! WARNING !! Saved object file not written. Probably do not have permission to write here."
     872        return self
    797873
    798874    ###########################################################
     
    802878        self.defineplot(extraplot=extraplot)
    803879        self.makeplot()
     880        return self
    804881
    805882    #######################################################
     
    809886        self.get()
    810887        self.plot(extraplot=extraplot)
     888        return self
    811889
    812890    ###################################################################
     
    816894        self.get()
    817895        self.defineplot(extraplot=extraplot)
     896        return self
    818897
    819898    ##############################################################
     
    907986            except: 
    908987                try: self.p[iii].marker = opt.marker[0]
     988                except: pass
     989            ###
     990            try: self.p[iii].label = opt.label[iii]
     991            except:
     992                try: self.p[iii].label = opt.label[0]
    909993                except: pass
    910994            ###
     
    10451129          if "grid points" not in self.name_x:
    10461130            if self.field_x.all() == self.field_x[0,0]:
    1047                print "!! WARNING !! xy axis look undefined. creating a non-dummy ones."
     1131               print "!! WARNING !! xy axis look undefined. creating non-dummy ones."
    10481132               self.field_x = np.array(range(self.dim_x)) ; self.name_x = "x grid points"
    10491133               self.field_y = np.array(range(self.dim_y)) ; self.name_y = "y grid points"
     
    13301414        # ... this is done in the .area() method.
    13311415        # after that self.field contains field*area/totarea
    1332         if "area" in self.compute: self.area()
     1416        if "area" in self.compute:
     1417            if "comp" in self.method_x+self.method_y:
     1418                self.area()
     1419            else:
     1420                if self.verbose: print "!! WARNING !! No area accounted for (computing on t and/or z axis)."
    13331421        # now ready to compute [TBD: we would like to have e.g. mean over x,y and min over t ??]
    13341422        if self.method_t == "comp":
     
    13711459            print "**** OK. Final shape for "+self.var+" after averaging and squeezing",self.field.shape
    13721460   
    1373     # get areas for computations and ponderate field by those areas
    1374     # -------------------------------------------------------------
     1461    # get areas for computations and ponderate self.field by area/totarea
     1462    # -------------------------------------------------------------------
    13751463    def area(self):
    13761464        if self.verbose: print "**** OK. Get area array for computations."
     
    13981486        # read the 2D area array in netCDF file
    13991487        aire.getfield()
    1400         # normalize by total area
    14011488        aire.field = np.squeeze(aire.field)
    1402         totarea = ppcompute.sum(ppcompute.sum(aire.field,axis=1),axis=0)
    1403         if self.verbose: print "**** OK. Total area is: ",totarea
    1404         aire.field = aire.field / totarea
    14051489        # reduce with self horizontal indexes
    14061490        if "fixed" in self.method_x+self.method_y:
    14071491            aire.field = aire.field[self.index_y,self.index_x]
     1492        # calculate total area
     1493        # ... 2D comp is easy. 1D comp is a bit less easy but simple array manipulation.
     1494        if "free" in self.method_x+self.method_y:
     1495            if self.method_x == "free":
     1496                totarea = ppcompute.sum(aire.field,axis=0)
     1497                totarea = np.reshape(totarea,(1,totarea.size))
     1498                totarea = np.tile(totarea,(1,self.index_x))
     1499            elif self.method_y == "free":
     1500                totarea = ppcompute.sum(aire.field,axis=1)
     1501                totarea = np.reshape(totarea,(totarea.size,1))
     1502                totarea = np.tile(totarea,(1,self.index_x.size))
     1503        elif self.method_x == "comp" and self.method_y == "comp":
     1504            totarea = ppcompute.sum(ppcompute.sum(aire.field,axis=1),axis=0)
     1505        else:
     1506            if self.verbose: print "!! WARNING !! Not account for areas. Only averaging over z and/or t axis."
     1507        # normalize by total area
     1508        print "**** OK. I can now normalize field by areas."
     1509        aire.field = aire.field / totarea
    14081510        # tile area array over self t and z axis so that area field could be multiplied with self.field
    14091511        aire.field = np.tile(aire.field,(self.index_t.size,self.index_z.size,1,1))
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r920 r923  
    349349                 lstyle='-',\
    350350                 color='b',\
    351                  marker='x'):
     351                 marker='x',\
     352                 label=None):
    352353        ## get initialization from parent class
    353354        plot.__init__(self)
     
    356357        self.color = color
    357358        self.marker = marker
     359        self.label = label
    358360
    359361    # define_from_var
     
    389391        # either request linestyle or let matplotlib decide
    390392        if self.lstyle is not None and self.color is not None:
    391             mpl.plot(x,y,self.color+self.lstyle,marker=self.marker)
     393            mpl.plot(x,y,self.color+self.lstyle,marker=self.marker,label=self.label)
    392394        else:
    393             mpl.plot(x,y,marker=self.marker)
     395            mpl.plot(x,y,marker=self.marker,label=self.label)
    394396        # make log axes and/or invert ordinate
    395397        # ... this must be after plot so that axis bounds are well-defined
     
    398400        if self.logy: mpl.semilogy()
    399401        if self.invert: ax = mpl.gca() ; ax.set_ylim(ax.get_ylim()[::-1])
     402        # add a label for line(s)
     403        if self.label is not None:
     404            if self.label != "":
     405                mpl.legend(loc="best",fancybox=True)
    400406        ## TBD: set with .div the number of ticks
    401407        ## TBD: be able to control plot limits
     
    556562                wlat[0] = None ; wlat[1] = None ; wlon[0] = None ; wlon[1] = None
    557563                steplon = 30. ; steplat = 30.
    558                 if self.proj == "robin": steplon = 60.
     564                if self.proj in ["robin","moll"]: steplon = 60.
    559565                mertab = np.r_[-360.:360.:steplon]
    560566                partab = np.r_[-90.:90.:steplat]
     
    642648                              scale=zescale*reducevec,width=widthvec )
    643649                # make vector key. default is on upper left corner.
    644                 p = mpl.quiverkey(q,-0.03,1.08,\
     650                keyh = 1.025 ; keyv = 1.05
     651                #keyh = -0.03 ; keyv = 1.08
     652                p = mpl.quiverkey(q,keyh,keyv,\
    645653                                  zescale,str(int(zescale)),\
    646654                                  color='black',labelpos='S',labelsep = 0.07)
    647         #### streamplot!!! avec basemap
  • trunk/UTIL/PYTHON/planetoplot_v2/set_multiplot.txt

    r917 r923  
    44############################################
    551 ; 1 ; 1 ; 0.0 ; 0.0 ; 22
    6 2 ; 1 ; 2 ; 0.35 ; 0.0 ; 20
     62 ; 1 ; 2 ; 0.5 ; 0.0 ; 20
    77#3 ; 3 ; 1 ; 0.0 ; 1.0 ; 18
    883 ; 1 ; 3 ; 0.35 ; 0.0 ; 18
    9 4 ; 2 ; 2 ; 0.8 ; 0.6 ; 18
     94 ; 2 ; 2 ; 0.35 ; 0.6 ; 18
    10106 ; 3 ; 2 ; 0.6 ; 1.0 ; 18
    11118 ; 2 ; 4 ; 0.6 ; 0.6 ; 18
Note: See TracChangeset for help on using the changeset viewer.