/[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 4895 - (show annotations)
Tue Apr 29 00:21:43 2014 UTC (4 years, 11 months ago) by sshaw
File MIME type: text/x-python
File size: 4437 byte(s)
affected tests now skipped if pyproj not installed
1
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 unittest
29 from esys.escript import inf,sup,saveDataCSV,getMPISizeWorld
30 from esys.downunder.datasources import *
31 from esys.downunder.domainbuilder import DomainBuilder
32 from esys.downunder import WGS84ReferenceSystem
33
34
35 # this is mainly to avoid warning messages
36 logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
37
38 try:
39 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
40 except KeyError:
41 TEST_DATA_ROOT='ref_data'
42
43 try:
44 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
45 except KeyError:
46 WORKDIR='.'
47
48 try:
49 import pyproj
50 haveProj=True
51 except ImportError:
52 haveProj=False
53
54 NC_DATA1 = os.path.join(TEST_DATA_ROOT, 'zone51.nc')
55 NC_DATA2 = os.path.join(TEST_DATA_ROOT, 'zone52.nc')
56
57 @unittest.skipIf('NetCdfData' not in dir(), 'netCDF not available')
58 class TestDomainBuilderWithNetCdf(unittest.TestCase):
59
60 # append custom messages instead of overwriting originals
61 longMessage = True
62
63 def test_add_garbage(self):
64 db=DomainBuilder()
65 self.assertRaises(TypeError, db.addSource, 42)
66
67 @unittest.skipIf(not haveProj, 'pyproj not available')
68 def test_mixing_utm_zones(self):
69 source1 = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
70 source2 = NetCdfData(DataSource.GRAVITY, NC_DATA2, scale_factor=1.)
71 domainbuilder=DomainBuilder()
72 domainbuilder.addSource(source1)
73 self.assertRaises(ValueError, domainbuilder.addSource, source2)
74
75 @unittest.skipIf(not haveProj, 'pyproj not available')
76 def test_add_source_after_domain_built(self):
77 db=DomainBuilder()
78 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
79 db.addSource(source1a)
80 _=db.getDomain()
81 source1b = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=2.)
82 self.assertRaises(Exception, db.addSource, source1b)
83
84 @unittest.skipIf(not haveProj, 'pyproj not available')
85 def test_cartesian_domain(self):
86 db=DomainBuilder()
87 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
88 db.addSource(source1a)
89 db.setVerticalExtents(depth=20000., air_layer=30000., num_cells=10)
90 dom=db.getDomain()
91
92 def test_geodetic_domain(self):
93 COORDINATES=WGS84ReferenceSystem()
94 db=DomainBuilder(reference_system=COORDINATES)
95 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1., reference_system=COORDINATES)
96 db.addSource(source1a)
97 db.setVerticalExtents(depth=20000., air_layer=30000., num_cells=10)
98 dom=db.getDomain()
99 x=dom.getX()
100 self.assertAlmostEqual(inf(x[0]), 120.2, delta=0.001, msg="phi range wrong")
101 self.assertAlmostEqual(inf(x[1]), -29.2 , delta=0.0001, msg="lambda range wrong")
102 self.assertAlmostEqual(inf(x[2]), -0.2, msg="h range wrong"+str(x[2]))
103 # Cannot check upper bounds of coordinates with more than 1 rank
104 # because ripley may adjust internally.
105 if getMPISizeWorld()==1:
106 self.assertAlmostEqual(sup(x[0]), 120.3, delta=0.001, msg="phi range wrong")
107 self.assertAlmostEqual(sup(x[1]), -29.1, delta=0.0001, msg="lambda range wrong")
108 self.assertAlmostEqual(sup(x[2]), 0.3, msg="h range wrong: "+str(x[2]))
109
110
111 if __name__ == "__main__":
112 suite = unittest.TestSuite()
113 suite.addTest(unittest.makeSuite(TestDomainBuilderWithNetCdf))
114 s=unittest.TextTestRunner(verbosity=2).run(suite)
115 if not s.wasSuccessful(): sys.exit(1)
116

  ViewVC Help
Powered by ViewVC 1.1.26