Ignore:
Timestamp:
May 15, 2013, 8:29:27 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. MAJOR: created an easy way to load a variable from a netcdf file, see easy_get_field.py [note: now to avoid confusion with .f attributes containing field, .f() method is named .func()] ; MINOR: generic units keyword, quiet mode, dummy xy axis when not given in ppplot, bug fixes for one-value 0D requests.

Location:
trunk/UTIL/PYTHON/planetoplot_v2/examples
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/easy_get_field.py

    r931 r960  
    11#! /usr/bin/env python
    22from ppclass import pp
    3 import numpy as np
    4 import matplotlib.pyplot as mpl
    53
     4########
     5## ppclass allows for getting fields very easily from a netcdf file
     6## ... this is contained in the "f" attributes of the pp object
     7## ... and the "l" attributes of the pp object contains useful information
     8## ... two methods getf() and getfl() are helpful shortcuts
     9###########################################
     10
     11## 1 --> an unique and straightforward request
     12##   --> very easy ! see also minimal_field.py
     13##############################################
     14icetot = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc",var="icetot",t=0.5).getf()
     15print "icetot", icetot[10,10]
     16
     17## 2 --> simple multiple request, no labelling
     18##############################################
     19test = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc",t=0.5)
     20test.var = ["mtot","icetot"]
     21allf = test.getf() # or allf = test.get().f
     22##
     23mtot = allf[0]
     24icetot = allf[1]
     25print "mtot", mtot[10,10]
     26print "icetot", icetot[10,10]
     27
     28## 3 --> complex multiple requests and labelling
     29################################################
     30test = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc")
     31test.var = ["mtot","icetot"]
     32test.t = [0.4,0.5]
     33allf,lab = test.getfl()
     34##
     35icetot04 = allf[lab.index("_v=icetot_t=0.4_")]
     36mtot04 = allf[lab.index("_v=mtot_t=0.4_")]
     37icetot05 = allf[lab.index("_v=icetot_t=0.5_")]
     38mtot05 = allf[lab.index("_v=mtot_t=0.5_")]
     39print "mtot04", mtot04[10,10]
     40print "icetot04", icetot04[10,10]
     41print "mtot05", mtot05[10,10]
     42print "icetot05", icetot05[10,10]
     43
     44## 4 --> an example of complete labelling
     45## .... a rather unlikely example ....
     46## .... but shows label ordering ....
     47#########################################
    648test = pp()
    7 test.file = [ \
    8   "/planeto/jllmd/Earth/Nmix/F1525/output/diagfi4.nc", \
    9   "/planeto/jllmd/Earth/Nmix/F1550/output/diagfi4.nc", \
    10   "/planeto/jllmd/Earth/Nmix/F1500/output/diagfi4.nc" ]
    11 test.var = ["tsurf","ASR"]
    12 test.x = "-180.,175."
    13 test.y = "-90.,90."
    14 test.t = "0,1000"
    15 #test.verbose = True
    16 test.compute = "meanarea"
    17 test.get()
    18 
    19 # -----------------------------
    20 # self.allfield contains data !
    21 # -----------------------------
    22 # index ordering:
    23 # - file
    24 # - var
    25 # - request t
    26 # - request z
    27 # - request y
    28 # - request x
    29 # - field dimensions
    30 # -----------------------------
    31 
    32 
    33 for ii in range(test.nfin):
    34     print "tsurf",test.allfield[ii][0][0][0][0][0]
    35     print "asr",test.allfield[ii][1][0][0][0][0]
    36 
    37 #mpl.plot(tsurf,asr)
    38 #mpl.show()
     49test.file = ["/home/aymeric/Big_Data/DATAPLOT/diagfired.nc","/home/aymeric/Big_Data/DATAPLOT/diagfired.nc"]
     50test.var = ["u","v"]
     51test.x = [10.,20.]
     52test.y = [10.,20.]
     53test.z = [10.,20.]
     54test.t = [0.4,0.5]
     55print "... please wait. this one is a bit stupid..."
     56allf,lab = test.getfl()
     57## note label ordering: file -- var -- x -- y -- z -- t
     58l1 = "_f=#2_v=u_x=10.0_y=10.0_z=20.0_t=0.4_"
     59l2 = "_f=#2_v=v_x=10.0_y=10.0_z=20.0_t=0.4_"
     60u_example = allf[lab.index(l1)]
     61v_example = allf[lab.index(l2)]
     62print l1, u_example
     63print l2, v_example
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/function.py

    r933 r960  
    1919var2 = var2 / 3.72
    2020
    21 S = var2.f(var1)
     21S = var2.func(var1)
    2222
    2323S.p[0].marker = 'o'
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/hodograph.py

    r923 r960  
    1616
    1717# u as a function of v
    18 hodo = u.f(v)
     18hodo = u.func(v)
    1919hodo.filename = "hodograph"
    2020hodo.makeplot()
    2121
    2222# v as a function of u
    23 hodo2 = v.f(u)
     23hodo2 = v.func(u)
    2424hodo2.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/meso_profile.py

    r923 r960  
    3838
    3939# define potential temperature as a function of height
    40 S = tpot.f(z)
     40S = tpot.func(z)
    4141
    4242# change a few plot settings
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/scatter.py

    r923 r960  
    1515ps.getdefineplot()
    1616
    17 S = ps.f(tsurf)
     17S = ps.func(tsurf)
    1818S.p[0].lstyle=""
    1919S.p[0].marker="h"
     
    2626icetot.getdefineplot()
    2727
    28 S2 = icetot.f(tsurf)
     28S2 = icetot.func(tsurf)
    2929S2.p[0].lstyle=""
    3030S2.p[0].marker="D"
     
    4545wind = u**2 + v**2
    4646wind = wind**0.5
    47 S3 = wind.f(ps)
     47S3 = wind.func(ps)
    4848S3.p[0].lstyle=""
    4949S3.p[0].marker="o"
     
    7070ps.getdefineplot()
    7171
    72 S = ps.f(tsurf)
     72S = ps.func(tsurf)
    7373S.p[0].lstyle=""
    7474S.p[0].marker="h"
Note: See TracChangeset for help on using the changeset viewer.