Changeset 2941


Ignore:
Timestamp:
May 23, 2006, 9:11:57 AM (18 years ago)
Author:
duncan
Message:

added more tests to geo_ref. It throws a different error as well now. Updated cornell room

Location:
inundation
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • inundation/coordinate_transforms/geo_reference.py

    r2608 r2941  
    1010from utilities.numerical_tools import ensure_numeric
    1111from utilities.anuga_exceptions import ANUGAError
     12
     13import exceptions
     14class TitleError(exceptions.IOError): pass
    1215
    1316DEFAULT_ZONE = -1
     
    3437        ASCIIFile - a handle to the text file
    3538        read_title - the title of the georeference text, if it was read in.
     39         If the function that calls this has already read the title line,
     40         it can't unread it, so this info has to be passed.
     41         If you know of a way to unread this info, then tell us.
    3642        """
    3743
     
    106112        #print "gr TITLE[0:2].upper()",TITLE[0:2].upper()
    107113        if read_title[0:2].upper() != TITLE[0:2].upper():
    108             raise SyntaxError
     114            msg = 'File error.  Expecting line: %s.  Got this line: %s' \
     115                  %(TITLE, read_title)
     116            raise TitleError, msg
    109117        self.zone = int(fd.readline())
    110118        self.xllcorner = float(fd.readline())
  • inundation/coordinate_transforms/test_geo_reference.py

    r2594 r2941  
    7272        self.failUnless(g == new_g, 'test_read_write_ASCII failed')
    7373       
    74     def test_read_write_ASCII2(self):
     74    def test_read_write_ASCII3(self):
    7575        from Scientific.IO.NetCDF import NetCDFFile
    7676        g = Geo_reference(56,1.9,1.9)
     
    8686            fd.close()
    8787            os.remove(file_name)
    88         except SyntaxError:
     88        except TitleError:
    8989            fd.close()
    9090            os.remove(file_name)
     
    254254            msg = 'Should have raised an exception'
    255255            raise msg
    256        
    257        
    258        
    259        
    260        
    261        
     256 
     257    def test_bad_ASCII_title(self):     
     258 # create an .xya file
     259        point_file = tempfile.mktemp(".xya")
     260        fd = open(point_file,'w')
     261        fd.write("# hey! \n")
     262        fd.close()
     263       
     264        fd = open(point_file,'r')
     265        #
     266        #new_g = Geo_reference(ASCIIFile=fd)
     267        try:
     268            new_g = Geo_reference(ASCIIFile=fd)
     269            fd.close()
     270            os.remove(point_file)
     271        except TitleError:
     272            fd.close()
     273            os.remove(point_file)
     274        else:
     275            self.failUnless(0 ==1,
     276                        'bad text file did not raise error!')
     277            os.remove(point_file)
     278
     279    def test_read_write_ASCII_test_and_fail(self):
     280        from Scientific.IO.NetCDF import NetCDFFile
     281
     282        # This is to test a fail
     283        g = Geo_reference(56,1.9,1.9)
     284        file_name = tempfile.mktemp(".geo_referenceTest")
     285        fd = open(file_name,'w')
     286        g.write_ASCII(fd)
     287        fd.close()       
     288        fd = open(file_name,'r')
     289        line = fd.readline()
     290        line = " #Geo"
     291        try:
     292            new_g = Geo_reference(ASCIIFile=fd, read_title=line)
     293            fd.close()
     294            os.remove(file_name)
     295        except TitleError:
     296            fd.close()
     297            os.remove(file_name)
     298        else:
     299            self.failUnless(0 ==1,
     300                        'bad text file did not raise error!')
     301
     302        # this tests a pass
     303        g = Geo_reference(56,1.9,1.9)
     304        file_name = tempfile.mktemp(".geo_referenceTest")
     305        fd = open(file_name,'w')
     306        g.write_ASCII(fd)
     307        fd.close()
     308       
     309        fd = open(file_name,'r')
     310        line = fd.readline()
     311        line = "#geo_yeah"
     312        new_g = Geo_reference(ASCIIFile=fd, read_title=line)
     313        fd.close()
     314        os.remove(file_name)
     315
     316        self.failUnless(g == new_g, 'test_read_write_ASCII failed')
     317       
     318        # this tests a pass
     319        g = Geo_reference(56,1.9,1.9)
     320        file_name = tempfile.mktemp(".geo_referenceTest")
     321        fd = open(file_name,'w')
     322        g.write_ASCII(fd)
     323        fd.close()
     324       
     325        fd = open(file_name,'r')
     326        line = fd.readline()
     327        line = "#geo crap"
     328        new_g = Geo_reference(ASCIIFile=fd, read_title=line)
     329        fd.close()
     330        os.remove(file_name)
     331
     332        self.failUnless(g == new_g, 'test_read_write_ASCII failed')
     333       
     334    def xxtest_good_title(self):     
     335 # create an .xya file
     336        point_file = tempfile.mktemp(".xya")
     337        fd = open(point_file,'w')
     338        fd.write("#Geo crap \n 56\n ")
     339        fd.close()
     340       
     341        fd = open(point_file,'r')
     342        #
     343        #new_g = Geo_reference(ASCIIFile=fd)
     344        try:
     345            new_g = Geo_reference(ASCIIFile=fd)
     346            fd.close()
     347            os.remove(point_file)
     348        except TitleError:
     349            fd.close()
     350            os.remove(point_file)
     351        else:
     352            self.failUnless(0 ==1,
     353                        'bad text file did not raise error!')
     354            os.remove(point_file)
     355         
    262356#-------------------------------------------------------------
    263357if __name__ == "__main__":
  • inundation/geospatial_data/geospatial_data.py

    r2940 r2941  
    99from Numeric import concatenate, array, Float, shape
    1010
    11 from coordinate_transforms.geo_reference import Geo_reference
     11from coordinate_transforms.geo_reference import Geo_reference, TitleError
    1212
    1313from os import access, F_OK, R_OK
     
    320320                        fd = open(file_name)
    321321                        data_points, attributes, geo_reference = _read_xya_file(fd, ',')
    322                     except SyntaxError:
     322                    except TitleError:
    323323                        fd.close()
    324324                        fd = open(file_name)
     
    333333                raise IOError, msg
    334334            except IOError, e:
     335                fd.close()   
    335336                # Catch this to add an error message
    336337                msg = 'Could not open file or incorrect file format %s:%s' %(file_name, e)
  • inundation/load_mesh/loadASCII.py

    r2888 r2941  
    8282from os.path import splitext
    8383
    84 from coordinate_transforms.geo_reference import Geo_reference,TITLE
     84from coordinate_transforms.geo_reference import Geo_reference,TITLE, TitleError
    8585
    8686import exceptions
     
    105105            msg = 'Extension %s is unknown' %ofile[-4:]
    106106            raise IOError, msg
    107     except (SyntaxError,IndexError, ValueError): #FIXME No test for ValueError
     107    except (TitleError,SyntaxError,IndexError, ValueError): #FIXME No test for ValueError
    108108            msg = 'File could not be opened'
    109109            raise IOError, msg 
     
    993993
    994994    #FIXME (Ole): This function should really return a Geospatial_data object.      #FIXME (DSG): Do you know it does, in the points dic?
     995    #No.  Where this function is used, geospatial objects should be used.
    995996   
    996997    if ofile[-4:]== ".xya":
     
    10001001                    fd = open(ofile)
    10011002                    points_dict = _read_xya_file(fd, ',')
    1002                 except SyntaxError:
     1003                except TitleError: # this is catching the error thrown by geo_ref
    10031004                    fd.close()
    10041005                    fd = open(ofile)
     
    10091010            fd.close()
    10101011        except (IndexError,ValueError,SyntaxError):
    1011             fd.close()   
     1012            fd.close()
     1013            msg = 'Could not open file %s ' %ofile
     1014            raise IOError, msg
     1015        except TitleError:
     1016            print "reclassifying title error"
     1017            fd.close()
    10121018            msg = 'Could not open file %s ' %ofile
    10131019            raise IOError, msg
  • inundation/pyvolution/cornell_room.py

    r773 r2941  
    1515from Numeric import array
    1616from math import sqrt
    17 from least_squares import Interpolation
     17#from least_squares import Interpolation
     18from fit_interpolate.interpolate import Interpolate
    1819   
    1920
     
    4546#Compute smooth surface on new mesh based on values from old (regrid)
    4647print 'Interp'
    47 interp = Interpolation(mesh_points, vertices, data_points, alpha=10)
    48 mesh_values = interp.fit(data_values)
     48interp = Interpolate(mesh_points, vertices, alpha=10)
     49mesh_values = interp.fit( data_points, data_values) # this has not been tested
    4950print 'Len mesh values', len(mesh_values)
    5051print 'Len mesh points', len(mesh_points)
Note: See TracChangeset for help on using the changeset viewer.