Changeset 7062


Ignore:
Timestamp:
May 20, 2009, 3:45:43 PM (11 years ago)
Author:
rwilson
Message:

Back-merge of changes to fix validation.

Location:
anuga_core/source/anuga/coordinate_transforms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/coordinate_transforms/geo_reference.py

    r6546 r7062  
    5858        if zone is None:
    5959            zone = DEFAULT_ZONE
    60         self.false_easting = false_easting
    61         self.false_northing = false_northing       
     60        self.false_easting = int(false_easting)
     61        self.false_northing = int(false_northing)
    6262        self.datum = datum
    6363        self.projection = projection
    64         self.zone = zone       
     64        self.zone = int(zone)
    6565        self.units = units
    66         self.xllcorner = xllcorner
    67         self.yllcorner = yllcorner       
     66        self.xllcorner = float(xllcorner)
     67        self.yllcorner = float(yllcorner)
    6868           
    6969        if NetCDFObject is not None:
     
    9999
    100100    def read_NetCDF(self, infile):
    101         self.xllcorner = infile.xllcorner[0]
    102         self.yllcorner = infile.yllcorner[0]
    103         self.zone = infile.zone[0]
    104 
    105        
    106         # Fix some assertion failures
    107         if type(self.zone) == num.ArrayType and self.zone.shape == ():
    108             self.zone = self.zone[0]
    109         if type(self.xllcorner) == num.ArrayType and self.xllcorner.shape == ():
    110             self.xllcorner = self.xllcorner[0]
    111         if type(self.yllcorner) == num.ArrayType and self.yllcorner.shape == ():
    112             self.yllcorner = self.yllcorner[0]
    113 
    114         assert (type(self.xllcorner) == types.FloatType or\
    115                 type(self.xllcorner) == types.IntType)
    116         assert (type(self.yllcorner) == types.FloatType or\
    117                 type(self.yllcorner) == types.IntType)
    118         assert (type(self.zone) == types.IntType)
    119        
     101        self.xllcorner = float(infile.xllcorner[0])
     102        self.yllcorner = float(infile.yllcorner[0])
     103        self.zone = int(infile.zone[0])
     104
    120105        try:
    121             self.false_easting = infile.false_easting[0]
    122             self.false_northing = infile.false_northing[0]
    123        
    124             self.datum = infile.datum       
     106            self.false_easting = int(infile.false_easting[0])
     107            self.false_northing = int(infile.false_northing[0])
     108
     109            self.datum = infile.datum
    125110            self.projection = infile.projection
    126111            self.units = infile.units
    127112        except:
    128113            pass
     114
    129115        if (self.false_easting != DEFAULT_FALSE_EASTING):
    130116            print "WARNING: False easting of %f specified." %self.false_easting
  • anuga_core/source/anuga/coordinate_transforms/test_geo_reference.py

    r6149 r7062  
    423423                        'bad shape did not raise error!')
    424424            os.remove(point_file)
     425
     426    def test_functionality_get_absolute(self):
     427        x0 = 1000.0
     428        y0 = 2000.0
     429        geo = Geo_reference(56, x0, y0)
     430
     431        # iterable points (*not* num.array())
     432        points = ((2,3), (3,1), (5,2))
     433        abs_points = geo.get_absolute(points)
     434        # check we haven't changed 'points' itself
     435        self.failIf(num.alltrue(abs_points == points))
     436        new_points = abs_points.copy()
     437        new_points[:,0] -= x0
     438        new_points[:,1] -= y0
     439        self.failUnless(num.alltrue(new_points == points))
     440
     441        # points in num.array()
     442        points = num.array(((2,3), (3,1), (5,2)), num.float)
     443        abs_points = geo.get_absolute(points)
     444        # check we haven't changed 'points' itself
     445        self.failIf(num.alltrue(abs_points == points))
     446        new_points = abs_points.copy()
     447        new_points[:,0] -= x0
     448        new_points[:,1] -= y0
     449        self.failUnless(num.alltrue(new_points == points))
     450
     451    def test_georef_types(self):
     452        '''Ensure that attributes of a georeference are of correct type.
     453       
     454        zone            int
     455        false_easting   int
     456        false_northing  int
     457        xllcorner       float
     458        yllcorner       float
     459        '''
     460
     461        from Scientific.IO.NetCDF import NetCDFFile
     462
     463        # ensure that basic instance attributes are correct
     464        g = Geo_reference(56, 1.8, 1.8)
     465        self.failUnless(isinstance(g.zone, int),
     466                        "geo_ref .zone should be 'int' type, "
     467                        "was '%s' type" % type(g.zone)) 
     468        self.failUnless(isinstance(g.false_easting, int),
     469                        "geo_ref .false_easting should be int type, "
     470                        "was '%s' type" % type(g.false_easting)) 
     471        self.failUnless(isinstance(g.false_northing, int),
     472                        "geo_ref .false_northing should be int type, "
     473                        "was '%s' type" % type(g.false_northing))
     474        self.failUnless(isinstance(g.xllcorner, float),
     475                        "geo_ref .xllcorner should be float type, "
     476                        "was '%s' type" % type(g.xllcorner))
     477        self.failUnless(isinstance(g.yllcorner, float),
     478                        "geo_ref .yllcorner should be float type, "
     479                        "was '%s' type" % type(g.yllcorner))
     480
     481        # now write fikle, read back and check types again
     482        file_name = tempfile.mktemp(".geo_referenceTest")
     483       
     484        out_file = NetCDFFile(file_name, 'w')
     485        g.write_NetCDF(out_file)
     486        out_file.close()
     487       
     488        in_file = NetCDFFile(file_name, 'r')
     489        new_g = Geo_reference(NetCDFObject=in_file)
     490        in_file.close()
     491        os.remove(file_name)
     492
     493        self.failUnless(isinstance(new_g.zone, int),
     494                        "geo_ref .zone should be 'int' type, "
     495                        "was '%s' type" % type(new_g.zone)) 
     496        self.failUnless(isinstance(new_g.false_easting, int),
     497                        "geo_ref .false_easting should be int type, "
     498                        "was '%s' type" % type(new_g.false_easting)) 
     499        self.failUnless(isinstance(new_g.false_northing, int),
     500                        "geo_ref .false_northing should be int type, "
     501                        "was '%s' type" % type(new_g.false_northing))
     502        self.failUnless(isinstance(new_g.xllcorner, float),
     503                        "geo_ref .xllcorner should be float type, "
     504                        "was '%s' type" % type(new_g.xllcorner))
     505        self.failUnless(isinstance(new_g.yllcorner, float),
     506                        "geo_ref .yllcorner should be float type, "
     507                        "was '%s' type" % type(new_g.yllcorner))
     508       
     509    def test_georef_types_coerceable(self):
     510        '''Ensure that attributes of a georeference are of correct type.
     511       
     512        zone            int
     513        false_easting   int
     514        false_northing  int
     515        xllcorner       float
     516        yllcorner       float
     517        '''
     518
     519        # now provide wrong types but coerceable
     520        g = Geo_reference(56.0, '1.8', '1.8')
     521        self.failUnless(isinstance(g.zone, int),
     522                        "geo_ref .zone should be 'int' type, "
     523                        "was '%s' type" % type(g.zone)) 
     524        self.failUnless(isinstance(g.false_easting, int),
     525                        "geo_ref .false_easting should be int type, "
     526                        "was '%s' type" % type(g.false_easting)) 
     527        self.failUnless(isinstance(g.false_northing, int),
     528                        "geo_ref .false_northing should be int type, "
     529                        "was '%s' type" % type(g.false_northing))
     530        self.failUnless(isinstance(g.xllcorner, float),
     531                        "geo_ref .xllcorner should be float type, "
     532                        "was '%s' type" % type(g.xllcorner))
     533        self.failUnless(isinstance(g.yllcorner, float),
     534                        "geo_ref .yllcorner should be float type, "
     535                        "was '%s' type" % type(g.yllcorner))
     536
    425537       
    426538#-------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.