1 | #! /usr/bin/env python |
---|
2 | from ppclass import pp |
---|
3 | |
---|
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 | ############################################## |
---|
14 | icetot = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc",var="icetot",t=0.5).getf() |
---|
15 | print "icetot", icetot[10,10] |
---|
16 | |
---|
17 | ## 2 --> simple multiple request, no labelling |
---|
18 | ############################################## |
---|
19 | test = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc",t=0.5) |
---|
20 | test.var = ["mtot","icetot"] |
---|
21 | allf = test.getf() # or allf = test.get().f |
---|
22 | ## |
---|
23 | mtot = allf[0] |
---|
24 | icetot = allf[1] |
---|
25 | print "mtot", mtot[10,10] |
---|
26 | print "icetot", icetot[10,10] |
---|
27 | |
---|
28 | ## 3 --> complex multiple requests and labelling |
---|
29 | ################################################ |
---|
30 | test = pp(file="/home/aymeric/Big_Data/DATAPLOT/diagfired.nc") |
---|
31 | test.var = ["mtot","icetot"] |
---|
32 | test.t = [0.4,0.5] |
---|
33 | allf,lab = test.getfl() |
---|
34 | ## |
---|
35 | icetot04 = allf[lab.index("_v=icetot_t=0.4_")] |
---|
36 | mtot04 = allf[lab.index("_v=mtot_t=0.4_")] |
---|
37 | icetot05 = allf[lab.index("_v=icetot_t=0.5_")] |
---|
38 | mtot05 = allf[lab.index("_v=mtot_t=0.5_")] |
---|
39 | print "mtot04", mtot04[10,10] |
---|
40 | print "icetot04", icetot04[10,10] |
---|
41 | print "mtot05", mtot05[10,10] |
---|
42 | print "icetot05", icetot05[10,10] |
---|
43 | |
---|
44 | ## 4 --> an example of complete labelling |
---|
45 | ## .... a rather unlikely example .... |
---|
46 | ## .... but shows label ordering .... |
---|
47 | ######################################### |
---|
48 | test = pp() |
---|
49 | test.file = ["/home/aymeric/Big_Data/DATAPLOT/diagfired.nc","/home/aymeric/Big_Data/DATAPLOT/diagfired.nc"] |
---|
50 | test.var = ["u","v"] |
---|
51 | test.x = [10.,20.] |
---|
52 | test.y = [10.,20.] |
---|
53 | test.z = [10.,20.] |
---|
54 | test.t = [0.4,0.5] |
---|
55 | print "... please wait. this one is a bit stupid..." |
---|
56 | allf,lab = test.getfl() |
---|
57 | ## note label ordering: file -- var -- x -- y -- z -- t |
---|
58 | l1 = "_f=#2_v=u_x=10.0_y=10.0_z=20.0_t=0.4_" |
---|
59 | l2 = "_f=#2_v=v_x=10.0_y=10.0_z=20.0_t=0.4_" |
---|
60 | u_example = allf[lab.index(l1)] |
---|
61 | v_example = allf[lab.index(l2)] |
---|
62 | print l1, u_example |
---|
63 | print l2, v_example |
---|