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

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

Various changes. Some test data is generated with make_data.py and this
is used to test the csml_wms controller. These tests pass.

Also there are some subsetToGridSeries tests. These fail at the moment. They need refining to check they are valid 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
18    """
19    i = N.indices(grid.shape)
20    a = N.where(i[0] == i[1], 10, 1)
21    a = N.where(i[0][-1::-1,:] == i[1], 10, a)
22    a = N.array([a])
23
24    t = cdms.createAxis(N.array([0]))
25    t.id = 'time'
26    t.units = 'days since 2000-01-01'
27    t.designateTime()
28
29    return cdms.createVariable(a, axes=[t, grid.getLatitude(),
30                                        grid.getLongitude()])
31
32
33def make_grids(here):
34    # 4 common lat/lon orderings
35    grids = {}
36    grids['0_360p'] = cdms.createUniformGrid(-87.5, 36, 5, 5, 36, 10)
37    grids['0_360m'] = cdms.createUniformGrid(87.5, 36, -5, 5, 36, 10)
38    grids['m180_180m'] = cdms.createUniformGrid(87.5, 36, -5, -185, 36, 10)
39    grids['m180_180p'] = cdms.createUniformGrid(-87.5, 36, 5, -185, 36, 10)
40
41    for gname in grids:
42        f = cdms.open('%s/data/cross_%s.nc' % (here, gname), 'w')
43        f.write(make_var(grids[gname]), id='cross_%s' % gname,
44                #axes=[grids[gname].getLatitude(), grids[gname].getLongitude()],
45                )
46        f.close()
47
48    return grids
49
50def make_csml(here):
51    config = '''
52[features]
53type: GridSeries
54number: many
55
56[files]
57root: %(here)s/data
58mapping: onetoseveral
59output: %(here)s/data/test.csml
60printscreen:0
61
62[spatialaxes]
63spatialstorage:fileextract
64
65[values]
66valuestorage:fileextract
67
68[SpatialReference]
69srs: EPSG 4326
70
71[time]
72timedimension: time
73timestorage:inline
74''' % dict(here=here)
75    open('%s/data/csmlscan.cfg' % here, 'w').write(config)
76
77    csmlscan.main(['csmlscan', '-c', '%s/data/csmlscan.cfg' % here])
78
79
80
81def main(args=None):
82    # This trick ensures we always get the same CSML id's
83    random.seed(42)
84
85    here = os.path.abspath(os.path.dirname(__file__))
86    grids = make_grids(here)
87    make_csml(here)
88
89
90
91
92if __name__ == '__main__':
93    import sys
94    main(sys.argv[1:])
Note: See TracBrowser for help on using the repository browser.