File: test_compression.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 (68 lines) | stat: -rw-r--r-- 1,457 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
from __future__ import print_function
import sys
import os
try:
    import cdms2
except BaseException:
    print('This test requires cdms2 for I/O')
    sys.exit()

import cmor
import numpy

f = cdms2.open(os.path.join('data/clt.nc'))


pth = os.path.split(os.path.realpath(os.curdir))
if pth[-1] == 'Test':
    ipth = opth = '.'
else:
    ipth = opth = 'Test'
cmor.setup(inpath=ipth,
           set_verbosity=cmor.CMOR_NORMAL,
           netcdf_file_action=cmor.CMOR_REPLACE)

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

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

s = f("clt", slice(14))
Saxes = s.getAxisList()

axes = []
for ax in Saxes[1:]:
    tmp = cmor.axis(
        ax.id,
        coord_vals=ax[:],
        cell_bounds=ax.getBounds(),
        units=ax.units)
    axes.append(tmp)

# Now creates a dummy HUGE axis for resizing s as really big
factor = 100
nt = s.shape[0] * factor
print('nt is:', nt)
t = numpy.arange(nt)

tmp = cmor.axis(
    'time',
    coord_vals=t,
    units=Saxes[0].units,
    cell_bounds=numpy.arange(
        nt + 1))
axes.insert(0, tmp)
print(axes)
var_id1 = cmor.variable(s.id, s.units, axes)
# the one with 2 at the end is compressed
var_id2 = cmor.variable(s.id, s.units, axes)
sh = list(s.shape)
sh[0] = nt
s = numpy.resize(s, sh)
# s=numpy.where(numpy.greater(s,100.),100,s)
s = numpy.random.random(s.shape) * 10000.
print(s.shape)
cmor.write(var_id1, s)
cmor.close(var_id1)
cmor.write(var_id2, s)

cmor.close()