Changeset 4326


Ignore:
Timestamp:
Mar 26, 2007, 3:55:11 PM (17 years ago)
Author:
duncan
Message:

damage modelling change. Get a message quickly if the csv label is not present.

Location:
anuga_core/source/anuga
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/damage_modelling/inundation_damage.py

    r4324 r4326  
    3434from anuga_config import epsilon
    3535depth_epsilon = epsilon
     36
     37# Change these if the ouput from nexix changes
    3638SHORE_DIST_LABEL = 'SHORE_DIST'
    3739WALL_TYPE_LABEL = 'WALL_TYPE'
     
    5658    """
    5759
    58     csv = Exposure_csv(exposure_file_in)
     60    csv = Exposure_csv(exposure_file_in,
     61                       title_check_list=[SHORE_DIST_LABEL,WALL_TYPE_LABEL,
     62                                         STR_VALUE_LABEL,CONT_VALUE_LABEL])
    5963    geospatial = csv.get_location()
    6064    geospatial = ensure_absolute(geospatial)
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r4318 r4326  
    750750
    751751
    752 #### NED is national exposure database
     752#### NED is national exposure database (name changed to NEXIS)
    753753   
    754754LAT_TITLE = 'LATITUDE'
     
    760760                 longitude_title=LONG_TITLE, is_x_y_locations=None,
    761761                 x_title=X_TITLE, y_title=Y_TITLE,
    762                  refine_polygon=None):
     762                 refine_polygon=None, title_check_list=None):
    763763        """
    764764        This class is for handling the exposure csv file.
     
    799799        #The values are the index positions of file columns.
    800800        self._attribute_dic, self._title_index_dic = \
    801         self._load_exposure_csv(self._file_name)
     801        self._load_exposure_csv(self._file_name,
     802                                title_check_list=title_check_list)
    802803        try:
    803804            #Have code here that handles caps or lower
     
    857858            return 1
    858859   
    859     def _load_exposure_csv(self, file_name):
     860    def _load_exposure_csv(self, file_name, title_check_list=None):
    860861        """
    861862        Load in the csv as a dic, title as key and column info as value, .
     
    867868        title_index_dic = {}
    868869        titles_stripped = [] # list of titles
    869        
    870870        reader = csv.reader(file(file_name))
    871871
     
    877877        title_count = len(titles_stripped)       
    878878        #print "title_index_dic",title_index_dic
    879 
     879        if title_check_list is not None:
     880            for title_check in title_check_list:
     881                #msg = "Reading error.  This row is not present ", title_check
     882                #assert title_index_dic.has_key(title_check), msg
     883                if not title_index_dic.has_key(title_check):
     884                    #reader.close()
     885                    msg = "Reading error.  This row is not present ", \
     886                          title_check                     
     887                    raise IOError, msg
     888                   
     889       
    880890       
    881891        #create a dic of colum values, indexed by column title
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r4318 r4326  
    44074407114.5, -21.4, bang, 40.0\n")
    44084408        file.close()
    4409         exposure = Exposure_csv(file_name)
     4409        exposure = Exposure_csv(file_name, title_check_list = ['speed','sound'])
    44104410        exposure.get_column("sound")
    44114411       
     
    44364436       
    44374437        os.remove(file_name)
    4438 
     4438       
     4439    def test_exposure_csv_loading_title_check_list(self):
     4440
     4441        # I can't get cvs.reader to close the exposure file
     4442        # The hacks below are to get around this.       
     4443        if sys.platform == 'win32':
     4444            file_name = tempfile.gettempdir() + \
     4445                    "test_exposure_csv_loading_title_check_list.xya"
     4446        else:
     4447            file_name = tempfile.mktemp(".xya")
     4448        file = open(file_name,"w")
     4449        file.write("LATITUDE, LONGITUDE ,sound  , speed \n\
     4450115.0, -21.0, splat, 0.0\n\
     4451114.0, -21.7, pow, 10.0\n\
     4452114.5, -21.4, bang, 40.0\n")
     4453        file.close()
     4454        try:
     4455            exposure = Exposure_csv(file_name, title_check_list = ['SOUND'])
     4456        except IOError:
     4457            pass
     4458        else:
     4459            self.failUnless(0 ==1,  'Assertion not thrown error!')
     4460           
     4461        if not sys.platform == 'win32':
     4462            os.remove(file_name)
     4463       
    44394464    def test_exposure_csv_cmp(self):
    44404465        file_name = tempfile.mktemp(".xya")
Note: See TracChangeset for help on using the changeset viewer.