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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5288 - (show annotations)
Tue Dec 2 23:18:40 2014 UTC (4 years, 9 months ago) by sshaw
File MIME type: text/x-python
File size: 4556 byte(s)
fixing tests for cases where required domains not built
1 from __future__ import print_function
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 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 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import logging
25 import numpy as np
26 import os
27 import sys
28 import esys.escriptcore.utestselect as unittest
29 from esys.escriptcore.testing import *
30 from esys.escript import inf,sup,saveDataCSV,getMPISizeWorld
31 from esys.downunder.datasources import *
32 from esys.downunder.domainbuilder import DomainBuilder
33 from esys.downunder import WGS84ReferenceSystem
34
35
36 # this is mainly to avoid warning messages
37 logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
38
39 try:
40 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
41 except KeyError:
42 TEST_DATA_ROOT='ref_data'
43
44 try:
45 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
46 except KeyError:
47 WORKDIR='.'
48
49 try:
50 import esys.ripley
51 HAVE_RIPLEY = True
52 except ImportError:
53 HAVE_RIPLEY = False
54
55 try:
56 import pyproj
57 haveProj=True
58 except ImportError:
59 haveProj=False
60
61 NC_DATA1 = os.path.join(TEST_DATA_ROOT, 'zone51.nc')
62 NC_DATA2 = os.path.join(TEST_DATA_ROOT, 'zone52.nc')
63
64 @unittest.skipIf('NetCdfData' not in dir(), 'netCDF not available')
65 @unittest.skipIf(not HAVE_RIPLEY, "Ripley module not available")
66 class TestDomainBuilderWithNetCdf(unittest.TestCase):
67
68 # append custom messages instead of overwriting originals
69 longMessage = True
70
71 def test_add_garbage(self):
72 db=DomainBuilder()
73 self.assertRaises(TypeError, db.addSource, 42)
74
75 @unittest.skipIf(not haveProj, 'pyproj not available')
76 def test_mixing_utm_zones(self):
77 source1 = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
78 source2 = NetCdfData(DataSource.GRAVITY, NC_DATA2, scale_factor=1.)
79 domainbuilder=DomainBuilder()
80 domainbuilder.addSource(source1)
81 self.assertRaises(ValueError, domainbuilder.addSource, source2)
82
83 @unittest.skipIf(not haveProj, 'pyproj not available')
84 def test_add_source_after_domain_built(self):
85 db=DomainBuilder()
86 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
87 db.addSource(source1a)
88 _=db.getDomain()
89 source1b = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=2.)
90 self.assertRaises(Exception, db.addSource, source1b)
91
92 @unittest.skipIf(not haveProj, 'pyproj not available')
93 def test_cartesian_domain(self):
94 db=DomainBuilder()
95 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
96 db.addSource(source1a)
97 db.setVerticalExtents(depth=20000., air_layer=30000., num_cells=10)
98 dom=db.getDomain()
99
100 def test_geodetic_domain(self):
101 COORDINATES=WGS84ReferenceSystem()
102 db=DomainBuilder(reference_system=COORDINATES)
103 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1., reference_system=COORDINATES)
104 db.addSource(source1a)
105 db.setVerticalExtents(depth=20000., air_layer=30000., num_cells=10)
106 dom=db.getDomain()
107 x=dom.getX()
108 self.assertAlmostEqual(inf(x[0]), 120.2, delta=0.001, msg="phi range wrong")
109 self.assertAlmostEqual(inf(x[1]), -29.2 , delta=0.0001, msg="lambda range wrong")
110 self.assertAlmostEqual(inf(x[2]), -0.2, msg="h range wrong"+str(x[2]))
111 # Cannot check upper bounds of coordinates with more than 1 rank
112 # because ripley may adjust internally.
113 if getMPISizeWorld()==1:
114 self.assertAlmostEqual(sup(x[0]), 120.3, delta=0.001, msg="phi range wrong")
115 self.assertAlmostEqual(sup(x[1]), -29.1, delta=0.0001, msg="lambda range wrong")
116 self.assertAlmostEqual(sup(x[2]), 0.3, msg="h range wrong: "+str(x[2]))
117
118
119 if __name__ == '__main__':
120 run_tests(__name__, exit_on_failure=True)
121

  ViewVC Help
Powered by ViewVC 1.1.26