/[escript]/trunk/downunder/test/python/run_datasources.py
ViewVC logotype

Contents of /trunk/downunder/test/python/run_datasources.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4005 - (show annotations)
Fri Sep 28 06:09:03 2012 UTC (8 years, 8 months ago) by caltinay
File MIME type: text/x-python
File size: 3511 byte(s)
test fixes, doco updates, annoyance removals.

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2012 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 import logging
24 import numpy as np
25 import os
26 import sys
27 import unittest
28 from esys.escript import inf,sup,saveDataCSV
29 from esys import ripley, finley, dudley
30 from esys.downunder.datasources import *
31
32 # this is mainly to avoid warning messages
33 logger=logging.getLogger('inv')
34 logger.setLevel(logging.INFO)
35 handler=logging.StreamHandler()
36 handler.setLevel(logging.INFO)
37 logger.addHandler(handler)
38
39 try:
40 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
41 except KeyError:
42 TEST_DATA_ROOT='.'
43
44 try:
45 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
46 except KeyError:
47 WORKDIR='.'
48
49
50 ERS_DATA = os.path.join(TEST_DATA_ROOT, 'ermapper_test.ers')
51 ERS_REF = os.path.join(TEST_DATA_ROOT, 'ermapper_test.csv')
52 ERS_NULL = -99999 * 1e-6
53 ERS_SIZE = [10,10]
54 ERS_ORIGIN = [309097.0, 6321502.0]
55 VMIN=-10000.
56 VMAX=10000
57 NE_V=15
58 ALT=0.
59 PAD_X=7
60 PAD_Y=7
61
62 class TestERSDataSource(unittest.TestCase):
63 def test_ers_with_padding(self):
64 source = ERSDataSource(headerfile=ERS_DATA, vertical_extents=(VMIN,VMAX,NE_V), alt_of_data=ALT)
65 source.setPadding(PAD_X,PAD_Y)
66 dom=source.getDomain()
67 g,s=source.getGravityAndStdDev()
68
69 outfn=os.path.join(WORKDIR, '_ersdata.csv')
70 saveDataCSV(outfn, g=g[2], s=s)
71
72 X0,NP,DX=source.getDataExtents()
73 V0,NV,DV=source.getVerticalExtents()
74
75 # check metadata
76 self.assertEqual(NP, ERS_SIZE, msg="Wrong number of data points")
77 # this only works if gdal is available
78 #self.assertAlmostEqual(X0, ERS_ORIGIN, msg="Data origin wrong")
79
80 # check data
81 nx=NP[0]+2*PAD_X
82 ny=NP[1]+2*PAD_Y
83 nz=NE_V
84 z_data=int(np.round((ALT-V0)/DV)-1)
85
86 ref=np.genfromtxt(ERS_REF, delimiter=',', dtype=float)
87 g_ref=ref[:,0].reshape(NP)
88 s_ref=ref[:,1].reshape(NP)
89
90 out=np.genfromtxt(outfn, delimiter=',', skip_header=1, dtype=float)
91 # recompute nz since ripley might have adjusted number of elements
92 nz=len(out)/(nx*ny)
93 g_out=out[:,0].reshape(nz,ny,nx)
94 s_out=out[:,1].reshape(nz,ny,nx)
95
96 self.assertAlmostEqual(np.abs(
97 g_out[z_data,PAD_Y:PAD_Y+NP[1],PAD_X:PAD_X+NP[0]]-g_ref).max(),
98 0., msg="Difference in data area")
99
100 # overwrite data -> should only be padding value left
101 g_out[z_data, PAD_Y:PAD_Y+NP[1], PAD_X:PAD_X+NP[0]]=ERS_NULL
102 self.assertAlmostEqual(np.abs(g_out-ERS_NULL).max(), 0.,
103 msg="Wrong values in padding area")
104
105 if __name__ == "__main__":
106 suite = unittest.TestSuite()
107 suite.addTest(unittest.makeSuite(TestERSDataSource))
108 s=unittest.TextTestRunner(verbosity=2).run(suite)
109 if not s.wasSuccessful(): sys.exit(1)
110

  ViewVC Help
Powered by ViewVC 1.1.26