- Timestamp:
- May 20, 2009, 2:45:15 PM (16 years ago)
- Location:
- branches/numpy/anuga/coordinate_transforms
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/numpy/anuga/coordinate_transforms/geo_reference.py
r7035 r7061 87 87 if zone is None: 88 88 zone = DEFAULT_ZONE 89 self.false_easting = false_easting90 self.false_northing = false_northing89 self.false_easting = int(false_easting) 90 self.false_northing = int(false_northing) 91 91 self.datum = datum 92 92 self.projection = projection 93 self.zone = zone93 self.zone = int(zone) 94 94 self.units = units 95 self.xllcorner = xllcorner96 self.yllcorner = yllcorner95 self.xllcorner = float(xllcorner) 96 self.yllcorner = float(yllcorner) 97 97 98 98 if NetCDFObject is not None: … … 101 101 if ASCIIFile is not None: 102 102 self.read_ASCII(ASCIIFile, read_title=read_title) 103 104 103 105 104 # Set flag for absolute points (used by get_absolute) … … 139 138 # @param infile Handle to open NetCDF file. 140 139 def read_NetCDF(self, infile): 141 self.xllcorner = infile.xllcorner[0]142 self.yllcorner = infile.yllcorner[0]143 self.zone = in file.zone[0]144 145 # Fix some assertion failures146 if isinstance(self.zone, num.ndarray) and self.zone.shape == ():147 self.zone = self.zone[0]148 if (isinstance(self.xllcorner, num.ndarray) and149 self.xllcorner.shape == ()):150 self.xllcorner = self.xllcorner[0]151 if (isinstance(self.yllcorner, num.ndarray) and152 self.yllcorner.shape == ()):153 self.yllcorner = self.yllcorner[0]154 155 assert (self.xllcorner.dtype.kind in num.typecodes['Float'] or156 self.xllcorner.dtype.kind in num.typecodes['Integer'])157 assert (self.yllcorner.dtype.kind in num.typecodes['Float'] or158 self.yllcorner.dtype.kind in num.typecodes['Integer'])159 assert (self.zone.dtype.kind in num.typecodes['Integer'])140 self.xllcorner = float(infile.xllcorner[0]) 141 self.yllcorner = float(infile.yllcorner[0]) 142 self.zone = int(infile.zone[0]) 143 144 ## # Fix some assertion failures 145 ## if isinstance(self.zone, num.ndarray) and self.zone.shape == (): 146 ## self.zone = self.zone[0] 147 ## if (isinstance(self.xllcorner, num.ndarray) and 148 ## self.xllcorner.shape == ()): 149 ## self.xllcorner = self.xllcorner[0] 150 ## if (isinstance(self.yllcorner, num.ndarray) and 151 ## self.yllcorner.shape == ()): 152 ## self.yllcorner = self.yllcorner[0] 153 ## 154 ## assert (self.xllcorner.dtype.kind in num.typecodes['Float'] or 155 ## self.xllcorner.dtype.kind in num.typecodes['Integer']) 156 ## assert (self.yllcorner.dtype.kind in num.typecodes['Float'] or 157 ## self.yllcorner.dtype.kind in num.typecodes['Integer']) 158 ## assert (self.zone.dtype.kind in num.typecodes['Integer']) 160 159 161 160 try: 162 self.false_easting = in file.false_easting[0]163 self.false_northing = in file.false_northing[0]161 self.false_easting = int(infile.false_easting[0]) 162 self.false_northing = int(infile.false_northing[0]) 164 163 165 164 self.datum = infile.datum -
branches/numpy/anuga/coordinate_transforms/test_geo_reference.py
r6533 r7061 637 637 self.failUnless(num.alltrue(new_points == points)) 638 638 639 def test_georef_types(self): 640 '''Ensure that attributes of a georeference are of correct type. 641 642 zone int 643 false_easting int 644 false_northing int 645 xllcorner float 646 yllcorner float 647 ''' 648 649 from Scientific.IO.NetCDF import NetCDFFile 650 651 # ensure that basic instance attributes are correct 652 g = Geo_reference(56, 1.8, 1.8) 653 self.failUnless(isinstance(g.zone, int), 654 "geo_ref .zone should be 'int' type, " 655 "was '%s' type" % type(g.zone)) 656 self.failUnless(isinstance(g.false_easting, int), 657 "geo_ref .false_easting should be int type, " 658 "was '%s' type" % type(g.false_easting)) 659 self.failUnless(isinstance(g.false_northing, int), 660 "geo_ref .false_northing should be int type, " 661 "was '%s' type" % type(g.false_northing)) 662 self.failUnless(isinstance(g.xllcorner, float), 663 "geo_ref .xllcorner should be float type, " 664 "was '%s' type" % type(g.xllcorner)) 665 self.failUnless(isinstance(g.yllcorner, float), 666 "geo_ref .yllcorner should be float type, " 667 "was '%s' type" % type(g.yllcorner)) 668 669 # now write fikle, read back and check types again 670 file_name = tempfile.mktemp(".geo_referenceTest") 671 672 out_file = NetCDFFile(file_name, netcdf_mode_w) 673 g.write_NetCDF(out_file) 674 out_file.close() 675 676 in_file = NetCDFFile(file_name, netcdf_mode_r) 677 new_g = Geo_reference(NetCDFObject=in_file) 678 in_file.close() 679 os.remove(file_name) 680 681 self.failUnless(isinstance(new_g.zone, int), 682 "geo_ref .zone should be 'int' type, " 683 "was '%s' type" % type(new_g.zone)) 684 self.failUnless(isinstance(new_g.false_easting, int), 685 "geo_ref .false_easting should be int type, " 686 "was '%s' type" % type(new_g.false_easting)) 687 self.failUnless(isinstance(new_g.false_northing, int), 688 "geo_ref .false_northing should be int type, " 689 "was '%s' type" % type(new_g.false_northing)) 690 self.failUnless(isinstance(new_g.xllcorner, float), 691 "geo_ref .xllcorner should be float type, " 692 "was '%s' type" % type(new_g.xllcorner)) 693 self.failUnless(isinstance(new_g.yllcorner, float), 694 "geo_ref .yllcorner should be float type, " 695 "was '%s' type" % type(new_g.yllcorner)) 696 697 def test_georef_types_coerceable(self): 698 '''Ensure that attributes of a georeference are of correct type. 699 700 zone int 701 false_easting int 702 false_northing int 703 xllcorner float 704 yllcorner float 705 ''' 706 707 # now provide wrong types but coerceable 708 g = Geo_reference(56.0, '1.8', '1.8') 709 self.failUnless(isinstance(g.zone, int), 710 "geo_ref .zone should be 'int' type, " 711 "was '%s' type" % type(g.zone)) 712 self.failUnless(isinstance(g.false_easting, int), 713 "geo_ref .false_easting should be int type, " 714 "was '%s' type" % type(g.false_easting)) 715 self.failUnless(isinstance(g.false_northing, int), 716 "geo_ref .false_northing should be int type, " 717 "was '%s' type" % type(g.false_northing)) 718 self.failUnless(isinstance(g.xllcorner, float), 719 "geo_ref .xllcorner should be float type, " 720 "was '%s' type" % type(g.xllcorner)) 721 self.failUnless(isinstance(g.yllcorner, float), 722 "geo_ref .yllcorner should be float type, " 723 "was '%s' type" % type(g.yllcorner)) 724 639 725 640 726 #-------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.