File: test_python_region.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 (47 lines) | stat: -rw-r--r-- 1,050 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
import cmor

import numpy

cmor.setup("Test", netcdf_file_action=cmor.CMOR_REPLACE)

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

cmor.load_table("Tables/CMIP6_Omon.json")

nlat = 90
dlat = 180 / nlat
lats = numpy.arange(-90 + dlat / 2., 90, dlat)
blats = numpy.arange(-90, 90 + dlat, dlat)

ilat = cmor.axis(
    table_entry='latitude',
    coord_vals=lats,
    cell_bounds=blats,
    units='degrees_north')

myregions = [
    "atlantic_ocean",
    "indian_pacific_ocean",
    "pacific_ocean",
    "atlantic_arctic_ocean",
    "global_ocean"]
nreg = len(myregions)
ireg = cmor.axis(table_entry='basin', units='1', coord_vals=myregions)
ntime = 12

itim = cmor.axis(
    table_entry='time',
    units='months since 2030',
    interval='1 month',
    coord_vals=numpy.arange(ntime),
    cell_bounds=numpy.arange(
        ntime + 1))


var = cmor.variable(table_entry='htovgyre', units='W',
                    axis_ids=numpy.array([itim, ireg, ilat]))

data = numpy.random.random((ntime, nreg, nlat)) * 3.E14

cmor.write(var, data)
cmor.close()