Commit df71ff91 authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Added alternative ESRM20 file naming

parent a6aef4c8
...@@ -66,7 +66,15 @@ def get_admin_level_definition(country_name, path, output_dfs=False, full_files= ...@@ -66,7 +66,15 @@ def get_admin_level_definition(country_name, path, output_dfs=False, full_files=
actual_levels_list= [0,0,0] actual_levels_list= [0,0,0]
out_dataframes= {} out_dataframes= {}
for k,case in enumerate(exposure_cases): for k,case in enumerate(exposure_cases):
aux_df= pd.read_csv(os.path.join(path, 'Exposure_'+case+'_'+country_name+'.csv'), sep=',') try:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_%s_%s.csv' % (case, country_name)),
sep=',')
except:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_Model_%s_%s.csv'
% (country_name, case)),
sep=',')
if full_files: if full_files:
for col in aux_df.columns: for col in aux_df.columns:
aux_df= aux_df.rename(columns={col: col.lower()}) aux_df= aux_df.rename(columns={col: col.lower()})
...@@ -142,7 +150,15 @@ def check_admin_levels_unequivocally_defined(country_name, path, full_files=Fals ...@@ -142,7 +150,15 @@ def check_admin_levels_unequivocally_defined(country_name, path, full_files=Fals
is_unequivocally_defined= [True, True, True] is_unequivocally_defined= [True, True, True]
other_levels_checked= [] other_levels_checked= []
for k,case in enumerate(exposure_cases): for k,case in enumerate(exposure_cases):
aux_df= pd.read_csv(os.path.join(path, 'Exposure_'+case+'_'+country_name+'.csv'), sep=',') try:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_%s_%s.csv' % (case, country_name)),
sep=',')
except:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_Model_%s_%s.csv'
% (country_name, case)),
sep=',')
if full_files: if full_files:
for col in aux_df.columns: for col in aux_df.columns:
aux_df= aux_df.rename(columns={col: col.lower()}) aux_df= aux_df.rename(columns={col: col.lower()})
...@@ -155,7 +171,15 @@ def check_admin_levels_unequivocally_defined(country_name, path, full_files=Fals ...@@ -155,7 +171,15 @@ def check_admin_levels_unequivocally_defined(country_name, path, full_files=Fals
available_levels_list.append(aux_list_levels) available_levels_list.append(aux_list_levels)
for k,case in enumerate(exposure_cases): for k,case in enumerate(exposure_cases):
print(' Checking '+case) print(' Checking '+case)
aux_df= pd.read_csv(os.path.join(path, 'Exposure_'+case+'_'+country_name+'.csv'), sep=',') try:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_%s_%s.csv' % (case, country_name)),
sep=',')
except:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_Model_%s_%s.csv'
% (country_name, case)),
sep=',')
if full_files: if full_files:
for col in aux_df.columns: for col in aux_df.columns:
aux_df= aux_df.rename(columns={col: col.lower()}) aux_df= aux_df.rename(columns={col: col.lower()})
...@@ -199,14 +223,30 @@ def check_number_points_per_admin_level(country_name, path): ...@@ -199,14 +223,30 @@ def check_number_points_per_admin_level(country_name, path):
actual_levels_list= [0,0,0] actual_levels_list= [0,0,0]
have_one_point_per_ID= [True, True, True] have_one_point_per_ID= [True, True, True]
for k,case in enumerate(exposure_cases): for k,case in enumerate(exposure_cases):
aux_df= pd.read_csv(os.path.join(path, 'Exposure_'+case+'_'+country_name+'.csv'), sep=',') try:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_%s_%s.csv' % (case, country_name)),
sep=',')
except:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_Model_%s_%s.csv'
% (country_name, case)),
sep=',')
for i in range(0,max_possible_level+1): for i in range(0,max_possible_level+1):
if 'id_'+str(i) in aux_df.columns: if 'id_'+str(i) in aux_df.columns:
if np.all(aux_df['id_'+str(i)].values!='No_tag'): # if not('No_tag' in aux_df['id_'+str(i)].values): if np.all(aux_df['id_'+str(i)].values!='No_tag'): # if not('No_tag' in aux_df['id_'+str(i)].values):
actual_levels_list[k]= i actual_levels_list[k]= i
for k,case in enumerate(exposure_cases): for k,case in enumerate(exposure_cases):
print(' Checking '+case) print(' Checking '+case)
aux_df= pd.read_csv(os.path.join(path, 'Exposure_'+case+'_'+country_name+'.csv'), sep=',') try:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_%s_%s.csv' % (case, country_name)),
sep=',')
except:
aux_df= pd.read_csv(os.path.join(path,
'Exposure_Model_%s_%s.csv'
% (country_name, case)),
sep=',')
try: try:
mixcase= False mixcase= False
unique_ids_actual= np.unique(aux_df['id_'+str(actual_levels_list[k])].values) # unique admin unit IDs of the level that defines the exposure unique_ids_actual= np.unique(aux_df['id_'+str(actual_levels_list[k])].values) # unique admin unit IDs of the level that defines the exposure
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment