source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/tests/make_data.py @ 2596

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/tests/make_data.py@2596
Revision 2596, 2.1 KB checked in by spascoe, 13 years ago (diff)

Improved tests.

Line 
1"""
2Create test data on several different grids.
3
4"""
5
6import cdms
7import Numeric as N
8import os
9import random
10from csml import csmlscan
11
12
13
14def make_var(grid):
15    """
16    Make a variable on a given grid with an X in it.
17    The first column and row are filled with their respective axis values.
18
19    """
20    i = N.indices(grid.shape)
21    a = N.where(i[0] == i[1], 1000., 1.)
22    a = N.where(i[0][-1::-1,:] == i[1], 1000., a)
23
24    a[0] = grid.getLatitude().getValue()
25    a[:,0] = grid.getLongitude().getValue()
26
27    a = N.array([a])
28
29    t = cdms.createAxis(N.array([0]))
30    t.id = 'time'
31    t.units = 'days since 2000-01-01'
32    t.designateTime()
33
34    return cdms.createVariable(a, axes=[t, grid.getLatitude(),
35                                        grid.getLongitude()])
36
37
38def make_grids(here):
39    # 4 common lat/lon orderings
40    grids = {}
41    grids['0_360p'] = cdms.createUniformGrid(-87.5, 36, 5, 5, 36, 10)
42    grids['0_360m'] = cdms.createUniformGrid(87.5, 36, -5, 5, 36, 10)
43    grids['m180_180m'] = cdms.createUniformGrid(87.5, 36, -5, -185, 36, 10)
44    grids['m180_180p'] = cdms.createUniformGrid(-87.5, 36, 5, -185, 36, 10)
45
46    for gname in grids:
47        f = cdms.open('%s/data/cross_%s.nc' % (here, gname), 'w')
48        f.write(make_var(grids[gname]), id='cross_%s' % gname,
49                #axes=[grids[gname].getLatitude(), grids[gname].getLongitude()],
50                )
51        f.close()
52
53    return grids
54
55def make_csml(here):
56    config = '''
57[features]
58type: GridSeries
59number: many
60
61[files]
62root: %(here)s/data
63mapping: onetoseveral
64output: %(here)s/data/test.csml
65printscreen:0
66
67[spatialaxes]
68spatialstorage:fileextract
69
70[values]
71valuestorage:fileextract
72
73[SpatialReference]
74srs: EPSG 4326
75
76[time]
77timedimension: time
78timestorage:inline
79''' % dict(here=here)
80    open('%s/data/csmlscan.cfg' % here, 'w').write(config)
81
82    csmlscan.main(['csmlscan', '-c', '%s/data/csmlscan.cfg' % here])
83
84
85
86def main(args=None):
87    # This trick ensures we always get the same CSML id's
88    random.seed(42)
89
90    here = os.path.abspath(os.path.dirname(__file__))
91    grids = make_grids(here)
92    make_csml(here)
93
94
95
96
97if __name__ == '__main__':
98    import sys
99    main(sys.argv[1:])
Note: See TracBrowser for help on using the repository browser.