File: test_cmor_python_not_enough_data.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 (65 lines) | stat: -rw-r--r-- 2,272 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
import cmor
import numpy
import unittest
import sys
import os
import tempfile


class TestCase(unittest.TestCase):

    # This test demonstrates an exception that gets thrown when
    # ntimes_passed is greater than the number of times passed in data
    def testNotEnoughData(self):

        cmor.setup(inpath='Tables',
                netcdf_file_action=cmor.CMOR_REPLACE)
        cmor.dataset_json("Test/CMOR_input_example.json")

        table = 'CMIP6_Omon.json'
        cmor.load_table(table)
        axes = [{'table_entry': 'time',
                'units': 'days since 1850-01-01 00:00:00',
                'coord_vals': [15.5, 45, ],
                'cell_bounds':[[0, 31], [31, 62]]
                },
                {'table_entry': 'depth_coord_half',
                'units': 'm',
                'coord_vals': [5000., 3000., 2000., 1000.],
                'cell_bounds': [5000., 3000., 2000., 1000., 0]},
                {'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]},
                ]

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

        for var, units, value in (('zhalfo', 'm', 274.),):
            values = numpy.ones([len(x['coord_vals']) for x in axes]) * value
            values = values.astype("f")
            varid = cmor.variable(var,
                                units,
                                axis_ids,
                                history='variable history',
                                missing_value=-99
                                )
            try:
                cmor.write(varid, values, ntimes_passed=3)
            except Exception as inst:
                self.assertEqual(str(inst), "not enough data is being passed "
                                            "for the number of times passed")
            else:
                raise Exception("cmor.write did not throw expected exception")

        cmor.close()

if __name__ == '__main__':
    unittest.main()