/[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 4433 - (show annotations)
Fri May 31 12:09:58 2013 UTC (5 years, 10 months ago) by gross
File MIME type: text/x-python
File size: 3879 byte(s)
some clarifications on geodetic coordinates. 
order of background magnetic flux density component has been corrected: input is now B_east, B_north, B_vertical.


1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2013 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-2013 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,getMPISizeWorld
29 from esys.downunder.datasources import *
30 from esys.downunder.domainbuilder import DomainBuilder
31 from esys.downunder import WGS84ReferenceSystem
32
33
34 # this is mainly to avoid warning messages
35 logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
36
37 try:
38 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
39 except KeyError:
40 TEST_DATA_ROOT='ref_data'
41
42 try:
43 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
44 except KeyError:
45 WORKDIR='.'
46
47
48 NC_DATA1 = os.path.join(TEST_DATA_ROOT, 'zone51.nc')
49 NC_DATA2 = os.path.join(TEST_DATA_ROOT, 'zone52.nc')
50
51 class TestDomainBuilderWithNetCdf(unittest.TestCase):
52 def test_add_garbage(self):
53 db=DomainBuilder()
54 self.assertRaises(TypeError, db.addSource, 42)
55
56 def test_mixing_utm_zones(self):
57 source1 = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
58 source2 = NetCdfData(DataSource.GRAVITY, NC_DATA2, scale_factor=1.)
59 domainbuilder=DomainBuilder()
60 domainbuilder.addSource(source1)
61 self.assertRaises(ValueError, domainbuilder.addSource, source2)
62
63 def test_add_source_after_domain_built(self):
64 db=DomainBuilder()
65 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
66 db.addSource(source1a)
67 _=db.getDomain()
68 source1b = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=2.)
69 self.assertRaises(Exception, db.addSource, source1b)
70
71 def test_cartesian_domain(self):
72 db=DomainBuilder()
73 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1.)
74 db.addSource(source1a)
75 db.setVerticalExtents(depth=20000., air_layer=30000., num_cells=10)
76 dom=db.getDomain()
77
78 def test_geodetic_domain(self):
79 COORDINATES=WGS84ReferenceSystem()
80 db=DomainBuilder(reference_system=COORDINATES)
81 source1a = NetCdfData(DataSource.GRAVITY, NC_DATA1, scale_factor=1., reference_system=COORDINATES)
82 db.addSource(source1a)
83 db.setVerticalExtents(depth=20000., air_layer=30000., num_cells=10)
84 dom=db.getDomain()
85 x=dom.getX()
86 self.assertAlmostEqual(inf(x[0]), 120.2, delta=0.001, msg="phi range wrong")
87 self.assertAlmostEqual(sup(x[0]), 120.3, delta=0.001, msg="phi range wrong")
88 self.assertAlmostEqual(inf(x[1]), -29.2 , delta=0.0001, msg="lambda range wrong")
89 self.assertAlmostEqual(sup(x[1]), -29.13333333333333, delta=0.0001, msg="lambda range wrong")
90 self.assertAlmostEqual(inf(x[2]), -20., msg="h range wrong")
91 self.assertAlmostEqual(sup(x[2]), 30., msg="h range wrong")
92
93
94 if __name__ == "__main__":
95 suite = unittest.TestSuite()
96 if 'NetCdfData' in dir():
97 suite.addTest(unittest.makeSuite(TestDomainBuilderWithNetCdf))
98 else:
99 print("Skipping tests that require netCDF.")
100 s=unittest.TextTestRunner(verbosity=2).run(suite)
101 if not s.wasSuccessful(): sys.exit(1)
102

  ViewVC Help
Powered by ViewVC 1.1.26