File: test_python_jamie_12.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 (71 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/env python
from __future__ import print_function
import cmor
import numpy


def define_axes(axes):
    axis_ids = list()
    for axis in axes:
        axis_id = cmor.axis(**axis)
        axis_ids.append(axis_id)

    print('MY:cmor.axis calls complete')
    return axis_ids


def define_write_var(axis_ids, entry, unit, values):
    varid = cmor.variable(entry,
                          unit,
                          axis_ids,
                          missing_value=-99
                          )

    cmor.write(varid, values, time_vals=[15.0], time_bnds=[0., 30.0])
    cmor.close(varid, preserve=True)
    cmor.write(varid, values, time_vals=[45.0], time_bnds=[30., 60.0])
    cmor.close()


def cmor_ini():
    cmor.setup(inpath='/git/cmip5-cmor-tables/Tables',
               netcdf_file_action=cmor.CMOR_REPLACE)
    cmor.dataset_json("Test/CMOR_input_example.json")


def define_write_landcoverfrac():
    cmor.load_table('Tables/CMIP6_Lmon.json')
    axes = [{'table_entry': 'time',
             'units': 'days since 2000-01-01 00:00:00',
             },
            {'table_entry': 'latitude',
             'units': 'degrees_north',
             'coord_vals': [0],
             'cell_bounds': [-1, 1]},
            {'table_entry': 'longitude',
             'units': 'degrees_east',
             'coord_vals': [90],
             'cell_bounds': [89, 91]},
            {'table_entry': 'vegtype',
             'coord_vals': ['landcover'],
             'units': '1',
             },
            ]

    axis_ids = define_axes(axes)

    values = numpy.array([2.], numpy.float32)
    values = numpy.reshape(values, (1, 1, 1, 1))

    define_write_var(axis_ids, 'landCoverFrac', '1', values)


def main():

    cmor_ini()
    define_write_landcoverfrac()


if __name__ == '__main__':

    main()