Changeset 2942


Ignore:
Timestamp:
May 23, 2006, 10:50:19 AM (18 years ago)
Author:
duncan
Message:

changing errors thrown by geo_ref. adding tests to geospatial

Location:
inundation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/coordinate_transforms/geo_reference.py

    r2941 r2942  
    99from Numeric import array, Float, ArrayType, reshape
    1010from utilities.numerical_tools import ensure_numeric
    11 from utilities.anuga_exceptions import ANUGAError
    12 
    13 import exceptions
    14 class TitleError(exceptions.IOError): pass
     11from utilities.anuga_exceptions import ANUGAError, TitleError, ParsingError
     12
     13
     14#import exceptions
     15#class TitleError(exceptions.IOError): pass
     16#class ParsingError(exceptions.IOError): pass
    1517
    1618DEFAULT_ZONE = -1
     
    107109
    108110    def read_ASCII(self, fd,read_title=None):
    109         if read_title == None:
    110             read_title = fd.readline() # remove the title line
    111         #print "gr read_title[0:2].upper()",read_title[0:2].upper()
    112         #print "gr TITLE[0:2].upper()",TITLE[0:2].upper()
    113         if read_title[0:2].upper() != TITLE[0:2].upper():
    114             msg = 'File error.  Expecting line: %s.  Got this line: %s' \
    115                   %(TITLE, read_title)
    116             raise TitleError, msg
    117         self.zone = int(fd.readline())
    118         self.xllcorner = float(fd.readline())
    119         self.yllcorner = float(fd.readline())
     111        try:
     112            if read_title == None:
     113                read_title = fd.readline() # remove the title line
     114            if read_title[0:2].upper() != TITLE[0:2].upper():
     115                msg = 'File error.  Expecting line: %s.  Got this line: %s' \
     116                      %(TITLE, read_title)
     117                raise TitleError, msg
     118            self.zone = int(fd.readline())
     119            self.xllcorner = float(fd.readline())
     120            self.yllcorner = float(fd.readline())
     121        except SyntaxError:
     122                msg = 'File error.  Got syntax error while parsing geo reference'
     123                raise ParsingError, msg
    120124           
    121125        # Fix some assertion failures
  • inundation/geospatial_data/geospatial_data.py

    r2941 r2942  
    458458    line = fd.readline()
    459459    numbers = clean_line(line,delimiter)
    460     #print 'read xya numbers', numbers
    461     while len(numbers) > 1:
     460   
     461    while len(numbers) > 1 and line[0] <> '#':
    462462        if numbers != []:
    463463            try:
     
    481481        line = fd.readline()
    482482        numbers = clean_line(line,delimiter)
     483   
    483484    if line == '':
    484             # end of file
    485485        geo_reference = None
    486        
    487486    else:
    488487        geo_reference = Geo_reference(ASCIIFile=fd,read_title=line)
  • inundation/geospatial_data/test_geospatial_data.py

    r2940 r2942  
    1010from geospatial_data import *
    1111
    12 from coordinate_transforms.geo_reference import Geo_reference
     12from coordinate_transforms.geo_reference import Geo_reference, TitleError
    1313
    1414class Test_Geospatial_data(unittest.TestCase):
     
    10401040            raise msg       
    10411041
    1042     def xxx_test_check_geo_reference(self):
     1042    def test_check_geo_reference(self):
    10431043        """
    10441044        checks geo reference details are OK. eg can be called '#geo reference'
     
    105210520.0 1.0 0.0\n\
    105310531.0 0.0 10.4\n\
    1054 #geo reference\n\
     1054#ge oreference\n\
    1055105556\n\
    105610561.1\n\
     
    10621062        assert allclose(results.get_geo_reference().get_yllcorner(), 1.0)
    10631063
    1064     def xxx_test_check_geo_reference1(self):
     1064        fileName = tempfile.mktemp(".xya")
     1065        file = open(fileName,"w")
     1066        file.write("  elevation  \n\
     10671.0 0.0 10.0\n\
     10680.0 1.0 0.0\n\
     10691.0 0.0 10.4\n")
     1070
     1071        file.close()
     1072        results = Geospatial_data(fileName)
     1073       
     1074    def test_check_geo_reference1(self):
    10651075        """
    10661076        checks geo reference details are OK. eg can be called '#geo reference'
     
    107410840.0 1.0 0.0\n\
    107510851.0 0.0 10.4\n\
    1076 #geo reference\n\
     1086#geo t t\n\
    1077108756\n\
    107810881.1\n"
     
    10801090        file.close()
    10811091
    1082 #        try:
    1083         results = Geospatial_data(fileName)
    1084 #        except ValueError or SyntaxError:
    1085 #            pass
    1086 #        else:
    1087 #            msg = 'Geo reference data format is incorrect'
    1088 #            raise msg       
    1089 
    1090 
    1091 
    1092         assert allclose(results.get_geo_reference().get_xllcorner(), 1.1)
    1093         assert allclose(results.get_geo_reference().get_yllcorner(), 1.0)
    1094        
     1092        try:
     1093            results = Geospatial_data(fileName, delimiter = " ")
     1094        except IOError:
     1095            pass
     1096        else:
     1097            msg = 'Geo reference data format is incorrect'
     1098            raise msg       
     1099
     1100
    10951101
    10961102
    10971103if __name__ == "__main__":
    1098     #suite = unittest.makeSuite(Test_Geospatial_data, 'test_ensure_absolute')
     1104    #suite = unittest.makeSuite(Test_Geospatial_data, 'test_check_geo_reference1')
    10991105    suite = unittest.makeSuite(Test_Geospatial_data, 'test')
    11001106    runner = unittest.TextTestRunner()
  • inundation/utilities/anuga_exceptions.py

    r2617 r2942  
    11"""Exceptions used by ANUGA
    22"""
     3
     4import exceptions
     5class TitleError(exceptions.IOError): pass
     6class ParsingError(exceptions.IOError): pass
    37
    48
Note: See TracChangeset for help on using the changeset viewer.