File: test_python_singleton_anywhere_in_table_def.py

package info (click to toggle)
cmor 2.9.1-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,332 kB
  • ctags: 9,614
  • sloc: f90: 22,548; ansic: 19,102; python: 7,693; sh: 3,041; makefile: 113; xml: 4
file content (114 lines) | stat: -rw-r--r-- 3,695 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python

from test_python_common import * # common subroutines

import cmor._cmor
import os

pth = os.path.split(os.path.realpath(os.curdir))
if pth[-1]=='Test':
    ipth = opth = '.'
else:
    ipth = opth = 'Test'


myaxes=numpy.zeros(9,dtype='i')
myaxes2=numpy.zeros(9,dtype='i')
myvars=numpy.zeros(9,dtype='i')


cmor.setup(inpath=ipth,set_verbosity=cmor.CMOR_NORMAL, netcdf_file_action = cmor.CMOR_REPLACE, exit_control = cmor.CMOR_EXIT_ON_MAJOR);
cmor.dataset(
    outpath = opth,
    experiment_id = "historical",
    institution = "GICC (Generic International Climate Center, Geneva, Switzerland)",
    source = "GICCM1 2002: atmosphere:  GICAM3 (gicam_0_brnchT_itea_2, T63L32); ocean: MOM (mom3_ver_3.5.2, 2x3L15); sea ice: GISIM4; land: GILSM2.5",
    calendar = "standard",
    realization = 1,
    contact = "Rusty Koder (koder@middle_earth.net)",
    history = "Output from archive/giccm_03_std_2xCO2_2256.",
    comment = "Equilibrium reached after 30-year spin-up after which data were output starting with nominal date of January 2030",
    references = "Model described by Koder and Tolkien (J. Geophys. Res., 2001, 576-591).  Also see http://www.GICC.su/giccm/doc/index.html  2XCO2 simulation described in Dorkey et al. '(Clim. Dyn., 2003, 323-357.)",
    leap_year=0,
    leap_month=0,
    month_lengths=None,
    model_id="GICCM1",
    forcing="Ant, Nat",
    institute_id="pcmdi",
    parent_experiment_id="piControl",branch_time=18336.33)

tables=[]
a = cmor.load_table("/git/cmip5-cmor-tables/Tables/CMIP5_grids")
tables.append(a)

t='CMIP5_Omon'
te = 'dissic'
u='mol m-3'
time='time'
ts='month'
tscl=1.

t='CMIP5_cfSites'
te = 'pr'
u= 'kg m-2 s-1'
time='time1'
ts='days'
tscl=2.e-2

tables.append(cmor.load_table("/git/cmip5-cmor-tables/Tables/%s" % t))
print 'Tables ids:',tables

cmor.set_table(tables[0])

x,y,lon_coords,lat_coords,lon_vertices,lat_vertices = gen_irreg_grid(lon,lat)



myaxes[0] = cmor.axis(table_entry = 'y', 
                      units = 'm', 
                      coord_vals = y)
myaxes[1] = cmor.axis(table_entry = 'x', 
                      units = 'm', 
                      coord_vals = x)

grid_id = cmor.grid(axis_ids = myaxes[:2], 
                    latitude = lat_coords, 
                    longitude = lon_coords, 
                    latitude_vertices = lat_vertices, 
                    longitude_vertices = lon_vertices)
print 'got grid_id:',grid_id
myaxes[2] = grid_id

mapnm = 'lambert_conformal_conic'
params = [ "standard_parallel1",
           "longitude_of_central_meridian","latitude_of_projection_origin",
           "false_easting","false_northing","standard_parallel2" ]
punits = ["","","","","","" ]
pvalues = [-20.,175.,13.,8.,0.,20. ]
cmor.set_grid_mapping(grid_id=myaxes[2],
                      mapping_name = mapnm,
                      parameter_names = params,
                      parameter_values = pvalues,
                      parameter_units = punits)

cmor.set_table(tables[1])
myaxes[3] = cmor.axis(table_entry = time,
                      units = '%s since 1980' % ts)

pass_axes = [myaxes[3],myaxes[2]]

myvars[0] = cmor.variable( table_entry = te,
                           units = u,
                           axis_ids = pass_axes,
                           history = 'no history',
                           comment = 'no future'
                           )

ntimes=2
for i in range(ntimes):
    data2d = read_2d_input_files(i, varin2d[0], lat,lon)*1.E-6
    print 'writing time: ',i,data2d.shape#,data2d
    #print Time[i],bnds_time[2*i:2*i+2]    
    cmor.write(myvars[0],data2d,1,time_vals=Time[i]*tscl,time_bnds=tscl*bnds_time[2*i:2*i+2])
    print 'wrote'
cmor.close()