Changeset 3336


Ignore:
Timestamp:
Jul 14, 2006, 4:47:35 PM (18 years ago)
Author:
duncan
Message:

exposure csv class can now have x, y location info

Location:
inundation/pyvolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/pyvolution/data_manager.py

    r3312 r3336  
    725725LAT_TITLE = 'LATITUDE'
    726726LONG_TITLE = 'LONGITUDE'
     727X_TITLE = 'x'
     728Y_TITLE = 'y'
    727729class Exposure_csv:
    728730    def __init__(self,file_name, latitude_title=LAT_TITLE,
    729                  longitude_title=LONG_TITLE, refine_polygon=None):
     731                 longitude_title=LONG_TITLE, is_x_y_locations=False,
     732                 x_title=X_TITLE, y_title=Y_TITLE,
     733                 refine_polygon=None):
    730734        """
    731735        This class is for handling the exposure csv file.
     
    777781            self._geospatial = Geospatial_data(latitudes = lats,
    778782                 longitudes = longs)
     783
     784        if is_x_y_locations:
     785            if self._geospatial is not None:
     786                pass #fixme throw an error
     787            try:
     788                xs = self._attribute_dic[x_title]
     789                ys = self._attribute_dic[y_title]
     790                points = [[float(i),float(j)] for i,j in map(None,xs,ys)]
     791            except KeyError:
     792                # maybe a warning..
     793                raise TitleValueError, msg
     794            else:
     795                self._geospatial = Geospatial_data(data_points=points)
    779796           
    780797        # create a list of points that are in the refining_polygon
  • inundation/pyvolution/test_data_manager.py

    r3308 r3336  
    46594659
    46604660
    4661 
     4661########## testing nbed class ##################
    46624662    def test_exposure_csv_loading(self):
    46634663       
     
    48874887        else:
    48884888            self.failUnless(0 ==1,  'Error not thrown error!')
     4889           
     4890    def test_exposure_csv_loading_x_y(self):
    48894891       
     4892
     4893        file_name = tempfile.mktemp(".xya")
     4894        file = open(file_name,"w")
     4895        file.write("x, y ,sound  , speed \n\
     4896115.0, 7, splat, 0.0\n\
     4897114.0, 8.0, pow, 10.0\n\
     4898114.5, 9., bang, 40.0\n")
     4899        file.close()
     4900        e1 = Exposure_csv(file_name, is_x_y_locations=True)
     4901        gsd = e1.get_location()
     4902       
     4903        points = gsd.get_data_points(absolute=True)
     4904       
     4905        assert allclose(points[0][0], 115)
     4906        assert allclose(points[0][1], 7)
     4907        assert allclose(points[1][0], 114)
     4908        assert allclose(points[1][1], 8)
     4909        assert allclose(points[2][0], 114.5)
     4910        assert allclose(points[2][1], 9)
     4911        self.failUnless(gsd.get_geo_reference().get_zone() == -1,
     4912                        'Bad zone error!')
     4913
     4914        os.remove(file_name)
    48904915       
    48914916#-------------------------------------------------------------
    48924917if __name__ == "__main__":
    4893     #suite = unittest.makeSuite(Test_Data_Manager,'test_exposure_csv')
     4918    #suite = unittest.makeSuite(Test_Data_Manager,'test_exposure_csv_loadiny')
    48944919    suite = unittest.makeSuite(Test_Data_Manager,'test')
    48954920    runner = unittest.TextTestRunner()
Note: See TracChangeset for help on using the changeset viewer.