Changeset 4059


Ignore:
Timestamp:
Dec 6, 2006, 12:30:54 PM (18 years ago)
Author:
duncan
Message:

checking in, so I can checkout in another repository...

Location:
anuga_core/source/anuga
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/geospatial_data/geospatial_data.py

    r4035 r4059  
    1515from anuga.coordinate_transforms.geo_reference import Geo_reference, TitleError
    1616from anuga.coordinate_transforms.redfearn import convert_from_latlon_to_utm
     17from anuga.shallow_water.data_manager import Exposure_csv
    1718
    1819       
     
    521522            except IOError, e:   
    522523                msg = 'Could not open file %s ' %file_name
     524                raise IOError, msg 
     525       
     526        elif file_name[-4:]== ".xxx":
     527            #let's do ticket#116 stuff
     528            #
     529            try:
     530                data_points, attributes, geo_reference = _read_csv_file(file_name, verbose)
     531            except IOError, e:   
     532                msg = 'Could not open file %s ' %file_name
    523533                raise IOError, msg       
    524534        else:     
    525535            msg = 'Extension %s is unknown' %file_name[-4:]
    526536            raise IOError, msg
    527        
    528537#        print'in import data_points', data_points
    529538#        print'in import attributes', attributes
     
    704713
    705714
     715def _read_csv_file(file_name, verbose = False):
     716    """Read .csv file
     717   
     718    Return a dic of array of points, and dic of array of attribute
     719    eg
     720    dic['points'] = [[1.0,2.0],[3.0,5.0]]
     721    dic['attributelist']['elevation'] = [[7.0,5.0]
     722    """   
     723
     724    return pointlist, attributes, geo_reference
     725
    706726def _read_xya_file( fd, delimiter):
    707727    points = []
  • anuga_core/source/anuga/geospatial_data/test_geospatial_data.py

    r4035 r4059  
    643643        os.remove(FN)
    644644       
    645     def test_loadxya(self):
     645    def test_loadcsv(self):
    646646        """
    647647        comma delimited
    648648        """
    649         fileName = tempfile.mktemp(".xya")
     649        fileName = tempfile.mktemp(".csv")
    650650        file = open(fileName,"w")
    651651        file.write("elevation  , speed \n\
     
    6536530.0, 1.0, 0.0, 10.0\n\
    6546541.0, 0.0, 10.4, 40.0\n")
     655        file.close()
     656        results = Geospatial_data(fileName, delimiter=',')
     657        os.remove(fileName)
     658#        print 'data', results.get_data_points()
     659        assert allclose(results.get_data_points(), [[1.0, 0.0],[0.0, 1.0],[1.0, 0.0]])
     660        assert allclose(results.get_attributes(attribute_name='elevation'), [10.0, 0.0, 10.4])
     661        assert allclose(results.get_attributes(attribute_name='speed'), [0.0, 10.0, 40.0])
     662
     663    def test_loadxya(self):
     664        """
     665        comma delimited
     666        """
     667        fileName = tempfile.mktemp(".xya")
     668        file = open(fileName,"w")
     669        file.write("longitude,latitude,z \n\
     670-35.3149601,150.9198238,452.688000\n\
     671-35.3149791,150.9209232,459.126000\n\
     672-35.3149980,150.9220226,465.613000\n")
    655673        file.close()
    656674        results = Geospatial_data(fileName, delimiter=',')
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r4050 r4059  
    794794        self._load_exposure_csv(self._file_name)
    795795        try:
     796            #Have code here that handles caps or lower
    796797            lats = self._attribute_dic[latitude_title]
    797798            longs = self._attribute_dic[longitude_title]
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r4052 r4059  
    43984398########## testing nbed class ##################
    43994399    def test_exposure_csv_loading(self):
    4400        
    4401 
    44024400        file_name = tempfile.mktemp(".xya")
    44034401        file = open(file_name,"w")
     
    44174415        os.remove(file_name)
    44184416       
    4419     def test_exposure_csv_loading(self):
     4417    def test_exposure_csv_loadingII(self):
    44204418       
    44214419
Note: See TracChangeset for help on using the changeset viewer.