Skip to content

Commit 38dcb54

Browse files
committed
add exposure.read_csv() in Exposures/base.py
1 parent 3df607b commit 38dcb54

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

climada/entity/exposures/base.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,32 @@ def read_mat(self, file_name, var_names=DEF_VAR_MAT):
381381
Exposures.__init__(self, data=exposures)
382382
_read_mat_metadata(self, data, file_name, var_names)
383383

384+
def read_csv(self, file_name):
385+
"""Read MATLAB file and store variables in exposures.
386+
387+
Parameters:
388+
file_name (str): absolute path file
389+
Note:
390+
The input CSV-file needs to consist of at least these columns:
391+
- value
392+
- latitude
393+
- longitude
394+
"""
395+
# load CSV to pandas data frame:
396+
data = pd.read_csv(file_name)
397+
# check for missing variables:
398+
if not ('value' and 'latitude' and 'longitude') in data.columns:
399+
raise ValueError('Required column(s) missing: value, latitude, or longitude.')
400+
if 'Unnamed: 0' in data.columns:
401+
data.index = data['Unnamed: 0']
402+
data = data.drop(columns='Unnamed: 0')
403+
if not 'if_TC' in data.columns:
404+
data['if_TC'] = np.ones(data.shape[0], int)
405+
# Init Exposures from data frame:
406+
Exposures.__init__(self, data=data)
407+
self.tag = Tag(file_name)
408+
self.check()
409+
384410
#
385411
# Implement geopandas methods
386412
#

0 commit comments

Comments
 (0)