File: test_python_jamie_6.py

package info (click to toggle)
cmor 3.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,960 kB
  • sloc: ansic: 28,094; f90: 13,872; python: 12,423; sh: 3,738; makefile: 111
file content (155 lines) | stat: -rw-r--r-- 3,868 bytes parent folder | download | duplicates (5)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from __future__ import print_function
import cmor
import numpy

error_flag = cmor.setup(inpath='Test', netcdf_file_action=cmor.CMOR_REPLACE)

error_flag = cmor.dataset_json("Test/CMOR_input_example.json")


# creates 1 degree grid
nlat = 180
nlon = 360
alats = numpy.arange(180) - 89.5
bnds_lat = numpy.arange(181) - 90
alons = numpy.arange(360) + .5
bnds_lon = numpy.arange(361)
cmor.load_table("Tables/CMIP6_Amon.json")
ilat = cmor.axis(
    table_entry='latitude',
    units='degrees_north',
    length=nlat,
    coord_vals=alats,
    cell_bounds=bnds_lat)

ilon = cmor.axis(
    table_entry='longitude',
    length=nlon,
    units='degrees_east',
    coord_vals=alons,
    cell_bounds=bnds_lon)

lev = 5
ntimes = 12
plevs = (numpy.arange(lev) + 1) * 1.E4


itim = cmor.axis(
    table_entry='time',
    units='months since 2030-1-1',
    length=ntimes,
    interval='1 month')

zlevs = numpy.array((0.1, 0.3, 0.55, 0.7, 0.9))
zlev_bnds = numpy.array((0., .2, .42, .62, .8, 1.))
table_entry = 'hybrid_height'
if table_entry == 'hybrid_height':
    ilev = cmor.axis(
        table_entry='hybrid_height',
        # table_entry='standard_sigma',
        # table_entry='standard_hybrid_sigma',
        units='m',
        length=lev,
        coord_vals=zlevs,
        cell_bounds=zlev_bnds)

    p0 = 0.5e4
##   p0 = 1.e5
# a_coeff = (/ 0.1, 0.2, 0.3, 0.2, 0.1 /)
    a_coeff = numpy.array((0.2, 0.4, 0.6, 0.8, 0.95))
    b_coeff = numpy.array((0.0, 0.1, 0.2, 0.5, 0.8))

# a_coeff_bnds=(/0.,.15, .25, .25, .15, 0./)
    a_coeff_bnds = numpy.array((0., .3, .5, .7, .9, 1.))
    b_coeff_bnds = numpy.array((0., .05, .15, .35, .65, 1.))

# error_flag = cmor.zfactor(
# zaxis_id=ilev,
# zfactor_name='ptop',
# units='Pa',
# zfactor_values = p0)

    error_flag = cmor.zfactor(
        zaxis_id=ilev,
        zfactor_name='b',
        axis_ids=numpy.array((ilev, )),
        zfactor_values=b_coeff,
        zfactor_bounds=b_coeff_bnds)

# error_flag = cmor.zfactor(
# zaxis_id=ilev,
# zfactor_name='lev',
##         axis_ids= numpy.array(( ilev, )),
# units='m',
##         zfactor_values = a_coeff,
# zfactor_bounds = a_coeff_bnds )

    data2d = numpy.random.random((180, 360)).astype('f') * 8000

    zfactor_id = cmor.zfactor(
        zaxis_id=ilev,
        zfactor_name='orog',
        axis_ids=numpy.array((ilon, ilat)),
        units='m',
        zfactor_values=data2d)
else:
    print('yep working case')
    ilev = cmor.axis(
        table_entry='standard_sigma',
        units='1',
        length=lev,
        coord_vals=zlevs,
        cell_bounds=zlev_bnds)

    p0 = 0.5E4
    a_coeff = numpy.array((0.2, 0.4, 0.6, 0.8, 0.95))
    b_coeff = numpy.array((0.0, 0.1, 0.2, 0.5, 0.8))

    a_coeff_bnds = numpy.array((0., .3, .5, .7, .9, 1.))
    b_coeff_bnds = numpy.array((0., .05, .15, .35, .65, 1.))

    error_flag = cmor.zfactor(
        zaxis_id=ilev,
        zfactor_name='ptop',
        units='Pa',
        zfactor_values=p0)

    error_flag = cmor.zfactor(
        zaxis_id=ilev,
        zfactor_name='sigma',
        axis_ids=numpy.array((ilev, )),
        zfactor_values=a_coeff,
        zfactor_bounds=a_coeff_bnds)

    data2d = numpy.random.random((180, 360)).astype('f') - 97000.

    zfactor_id = cmor.zfactor(
        zaxis_id=ilev,
        zfactor_name='ps',
        axis_ids=numpy.array((ilon, ilat, itim)),
        units='Pa')


var3d_ids = cmor.variable(
    table_entry='cl',
    units='%',
    axis_ids=numpy.array((ilev, ilon, ilat, itim)),
    missing_value=1.0e28,
    original_name='cloud')


for it in range(ntimes):

    time = numpy.array((it))
    bnds_time = numpy.array((it, it + 1))
    data3d = numpy.random.random((5, 360, 180)).astype('f') * 40.

    error_flag = cmor.write(
        var_id=var3d_ids,
        data=data3d,
        ntimes_passed=1,
        time_vals=time,
        time_bnds=bnds_time)


error_flag = cmor.close()