@@ -84,8 +84,9 @@ class Exposures(GeoDataFrame):
8484 latitude (pd.Series): latitude
8585 longitude (pd.Series): longitude
8686 value (pd.Series): a value for each exposure
87- if_ (pd.Series): e.g. if_TC. impact functions id for hazard TC. There
88- might be different hazards defined: if_TC, if_FL, ...
87+ if_ (pd.Series, optional): e.g. if_TC. impact functions id for hazard TC.
88+ There might be different hazards defined: if_TC, if_FL, ...
89+ If not provided, set to default 'if_' with ids 1 in check().
8990 geometry (pd.Series, optional): geometry of type Point of each instance.
9091 Computed in method set_geometry_points().
9192 deductible (pd.Series, optional): deductible value for each exposure
@@ -98,13 +99,14 @@ class Exposures(GeoDataFrame):
9899 """
99100 _metadata = GeoDataFrame ._metadata + ['tag' , 'ref_year' , 'value_unit' ]
100101
101- vars_oblig = ['value' , 'latitude' , 'longitude' , INDICATOR_IF ]
102+ vars_oblig = ['value' , 'latitude' , 'longitude' ]
102103 """Name of the variables needed to compute the impact."""
103104
104- vars_def = [INDICATOR_CENTR , 'geometry' ]
105+ vars_def = [INDICATOR_IF ]
105106 """Name of variables that can be computed."""
106107
107- vars_opt = ['deductible' , 'cover' , 'category_id' , 'region_id' ]
108+ vars_opt = [INDICATOR_CENTR , 'deductible' , 'cover' , 'category_id' ,
109+ 'region_id' , 'geometry' ]
108110 """Name of the variables that aren't need to compute the impact."""
109111
110112 @property
@@ -131,21 +133,28 @@ def check(self):
131133 LOGGER .info ('%s metadata set to default value: %s' , var , self .__dict__ [var ])
132134
133135 for var in self .vars_oblig :
136+ if not var in self .columns :
137+ LOGGER .error ("%s missing." , var )
138+ raise ValueError
139+
140+ for var in self .vars_def :
134141 if var == INDICATOR_IF :
135142 found = np .array ([var in var_col for var_col in self .columns ]).any ()
136143 if INDICATOR_IF in self .columns :
137- LOGGER .warning ("Hazard type not set in %s" , var )
144+ LOGGER .info ("Hazard type not set in %s" , var )
138145 else :
139146 found = var in self .columns
140- if not found :
141- LOGGER .error ("%s missing." , var )
142- raise ValueError
147+ if not found and var == INDICATOR_IF :
148+ LOGGER .info ("Setting %s to default impact functions ids 1." , var )
149+ self [INDICATOR_IF ] = np .ones (self .shape [0 ], dtype = int )
150+ elif not found :
151+ LOGGER .info ("%s not set." , var )
143152
144- for var in self .vars_def :
153+ for var in self .vars_opt :
145154 if var == INDICATOR_CENTR :
146155 found = np .array ([var in var_col for var_col in self .columns ]).any ()
147156 if INDICATOR_CENTR in self .columns :
148- LOGGER .warning ("Hazard type not set in %s" , var )
157+ LOGGER .info ("Hazard type not set in %s" , var )
149158 else :
150159 found = var in self .columns
151160 if not found :
@@ -157,10 +166,6 @@ def check(self):
157166 'and longitude. Use set_geometry_points() or set_lat_lon().' )
158167 raise ValueError
159168
160- for var in self .vars_opt :
161- if var not in self .columns :
162- LOGGER .info ("%s not set." , var )
163-
164169 def assign_centroids (self , hazard , method = 'NN' , distance = 'haversine' ,
165170 threshold = 100 ):
166171 """ Assign for each exposure coordinate closest hazard coordinate
@@ -414,7 +419,7 @@ def copy(self, deep=True):
414419 return Exposures (data ).__finalize__ (self )
415420
416421 def _get_transformation (self ):
417- """ Get projection and its units to use in cartopy transforamtions from
422+ """ Get projection and its units to use in cartopy transforamtions from
418423 current crs
419424
420425 Returns:
0 commit comments