Commit 5bf0113d authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Made currency and cost fields configurable parameters

parent 36253626
......@@ -77,7 +77,7 @@ def make_list_country_admin_units_to_retrieve(admin_unit_type, list_subgroups, w
def retrieve_OBM_buildings_in_cell_from_hdf5(obm_hdf5_filename, bdg_classes_hdf5_filename, countries_shp_path, sera_meta_path, gral_output_path, gde_tile_filename, occu_case, admin_unit_type= 'all', disagg_method= 'area', which_country= '', which_admin_ID= ''):
def retrieve_OBM_buildings_in_cell_from_hdf5(obm_hdf5_filename, bdg_classes_hdf5_filename, countries_shp_path, sera_meta_path, gral_output_path, gde_tile_filename, occu_case, cost_per_area_field, currency, admin_unit_type= 'all', disagg_method= 'area', which_country= '', which_admin_ID= ''):
"""
obm_hdf5_filename: full file path to the OBM HDF5 file for a particular cell and occupancy case
bdg_classes_hdf5_filename: full file path to the HDF5 file of the SERA building classes for a particular occupancy case
......@@ -88,6 +88,8 @@ def retrieve_OBM_buildings_in_cell_from_hdf5(obm_hdf5_filename, bdg_classes_hdf5
gde_tile_filename will only be created/written to if obm_hdf5_filename exists, i.e. if there exist OBM buildings
in this cell
occu_case: Res, Com, Ind, Oth
cost_per_area_field: name of the field that contains the cost per area (e.g., 'cost_per_area_eur', 'cost_per_area_usd')
currency: string indicating the currency of the replacement costs (e.g. 'EUR', 'USD')
admin_unit_type:
"all" = all admin units within the cell
"country" = all admin units of a certain country (defined by setting which_country)
......@@ -182,7 +184,7 @@ def retrieve_OBM_buildings_in_cell_from_hdf5(obm_hdf5_filename, bdg_classes_hdf5
all_sera_proportions= fle[country_adminID][osm_id]['SERA_vals'+'_'+disagg_method][:]
dwell_per_bdg= np.zeros([len(all_sera_classes)])
area_per_dwelling_sqm= np.zeros([len(all_sera_classes)])
cost_per_area_usd= np.zeros([len(all_sera_classes)])
cost_per_area= np.zeros([len(all_sera_classes)])
ppl_per_dwell= np.zeros([len(all_sera_classes)])
for k, bdg_class in enumerate(all_sera_classes):
osm_ids.append('OSM_'+str(osm_id))
......@@ -196,21 +198,21 @@ def retrieve_OBM_buildings_in_cell_from_hdf5(obm_hdf5_filename, bdg_classes_hdf5
which_row_admin_id= np.where(country_adminid_locs==country_adminID)[0][0]
dwell_per_bdg[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='dwell_per_bdg')[0][0]].split('_')[-1])]
area_per_dwelling_sqm[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='area_per_dwelling_sqm')[0][0]].split('_')[-1])]
cost_per_area_usd[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='cost_per_area_usd')[0][0]].split('_')[-1])]
cost_per_area[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)==cost_per_area_field)[0][0]].split('_')[-1])]
ppl_per_dwell[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='ppl_per_dwell')[0][0]].split('_')[-1])]
# For adding values of people and cost per building to the GDE tile HDF5 file:
ppl_per_bdg= dwell_per_bdg * ppl_per_dwell # 1D array of len(all_sera_classes)
cost_per_bdg_usd= dwell_per_bdg * area_per_dwelling_sqm * cost_per_area_usd # 1D array of len(all_sera_classes)
cost_per_bdg= dwell_per_bdg * area_per_dwelling_sqm * cost_per_area # 1D array of len(all_sera_classes)
weighted_av_ppl= (ppl_per_bdg * all_sera_proportions[:,0]).sum()
weighted_av_cost= (cost_per_bdg_usd * all_sera_proportions[:,0]).sum()
error_writing_gde_tile= gdet_gral.write_OBM_to_GDE_tiles_add_params(gral_output_path, gde_tile_filename, occu_case, disagg_method, osm_id, country_adminID, all_sera_classes, ppl_per_bdg, cost_per_bdg_usd, weighted_av_ppl, weighted_av_cost, 'USD')
weighted_av_cost= (cost_per_bdg * all_sera_proportions[:,0]).sum()
error_writing_gde_tile= gdet_gral.write_OBM_to_GDE_tiles_add_params(gral_output_path, gde_tile_filename, occu_case, disagg_method, osm_id, country_adminID, all_sera_classes, ppl_per_bdg, cost_per_bdg, weighted_av_ppl, weighted_av_cost, currency)
if error_writing_gde_tile!='':
error_messages= error_messages+' '+error_writing_gde_tile
# For building the DataFrame to output:
num_bdgs= np.hstack([num_bdgs, all_sera_proportions[:,0]])
num_dwells_local= all_sera_proportions[:,0] * dwell_per_bdg
num_dwells= np.hstack([num_dwells, num_dwells_local])
cost_local= num_dwells_local * area_per_dwelling_sqm * cost_per_area_usd
cost_local= num_dwells_local * area_per_dwelling_sqm * cost_per_area
cost= np.hstack([cost, cost_local])
ppl_local= num_dwells_local * ppl_per_dwell
ppl= np.hstack([ppl, ppl_local])
......
......@@ -564,11 +564,13 @@ def get_down_to_one_building_DEPRECATED(sera_for_cell_and_admin_unit_dict, disag
return aux_sera_vals / sum_all_bdgs_sera
def compute_bdgs_dwells_ppl_cost_for_cell_total(cell_attrs_tot_num_bdgs, bdg_classes_names, bdg_classes_proportions, bdg_classes_proportions_per_admin, list_of_cols_of_country_adminIDs, list_of_country_adminIDs, list_of_country_adminIDs_levels, sera_bdg_classes_full_path, output_by_admin_unit=False):
def compute_bdgs_dwells_ppl_cost_for_cell_total(cell_attrs_tot_num_bdgs, bdg_classes_names, bdg_classes_proportions, bdg_classes_proportions_per_admin, list_of_cols_of_country_adminIDs, list_of_country_adminIDs, list_of_country_adminIDs_levels, sera_bdg_classes_full_path, cost_per_area_field, output_by_admin_unit=False):
"""
cell_attrs_tot_num_bdgs, bdg_classes_names, bdg_classes_proportions, bdg_classes_proportions_per_admin, list_of_cols_of_country_adminIDs, list_of_country_adminIDs: all retrieved using the
function "retrieve_sera_hdf5_classes_and_vals" for the total of a cell (i.e. in_admin_id='Total').
cost_per_area_field: name of the field that contains the cost per area (e.g., 'cost_per_area_eur', 'cost_per_area_usd')
No assessment of the admin units and/or countries involved in the cell is made.
Output:
......@@ -610,12 +612,12 @@ def compute_bdgs_dwells_ppl_cost_for_cell_total(cell_attrs_tot_num_bdgs, bdg_cla
if country_adminid in country_adminid_locs:
dwell_per_bdg= parameter_vals[np.where(country_adminid_locs==country_adminid)[0][0], int(col_names[np.where(np.array(col_contents)=='dwell_per_bdg')[0][0]].split('_')[-1])]
area_per_dwelling_sqm= parameter_vals[np.where(country_adminid_locs==country_adminid)[0][0], int(col_names[np.where(np.array(col_contents)=='area_per_dwelling_sqm')[0][0]].split('_')[-1])]
cost_per_area_usd= parameter_vals[np.where(country_adminid_locs==country_adminid)[0][0], int(col_names[np.where(np.array(col_contents)=='cost_per_area_usd')[0][0]].split('_')[-1])]
cost_per_area= parameter_vals[np.where(country_adminid_locs==country_adminid)[0][0], int(col_names[np.where(np.array(col_contents)==cost_per_area_field)[0][0]].split('_')[-1])]
ppl_per_dwell= parameter_vals[np.where(country_adminid_locs==country_adminid)[0][0], int(col_names[np.where(np.array(col_contents)=='ppl_per_dwell')[0][0]].split('_')[-1])]
# Calculate dwellings, people and cost for this building class in this country_admin_ID:
num_dwells_per_class_and_admin_unit[k,j]= num_bdgs_per_class_and_admin_unit[k,j] * dwell_per_bdg
num_ppl_per_class_and_admin_unit[k,j]= num_dwells_per_class_and_admin_unit[k,j] * ppl_per_dwell
repl_cost_per_class_and_admin_unit[k,j]= num_dwells_per_class_and_admin_unit[k,j] * area_per_dwelling_sqm * cost_per_area_usd
repl_cost_per_class_and_admin_unit[k,j]= num_dwells_per_class_and_admin_unit[k,j] * area_per_dwelling_sqm * cost_per_area
if output_by_admin_unit: # the output arrays are two-dimensional, with one row per bdg class and one column per country_adminID
out_num_bdgs= num_bdgs_per_class_and_admin_unit
out_num_dwells= num_dwells_per_class_and_admin_unit
......
......@@ -1178,7 +1178,7 @@ def disaggregate_OBM_by_class_and_adm_unit(in_obm_DF, in_list_country_adminIDs,
return out_obm_num_bdgs_per_class_and_adm_unit, out_obm_num_dwells_per_class_and_adm_unit, out_obm_num_ppl_per_class_and_adm_unit, out_obm_cost_per_class_and_adm_unit
def calculate_leftover_per_class_and_admin_unit(sera_num_bdgs_per_class_and_adm_unit, sera_list_country_adminIDs, sera_classes, obm_with_classes_num_bdgs_per_class_and_adm_unit, obm_list_country_adminIDs_of_arrays, obm_list_bdg_classes_of_arrays, bdg_classes_hdf5_filename):
def calculate_leftover_per_class_and_admin_unit(sera_num_bdgs_per_class_and_adm_unit, sera_list_country_adminIDs, sera_classes, obm_with_classes_num_bdgs_per_class_and_adm_unit, obm_list_country_adminIDs_of_arrays, obm_list_bdg_classes_of_arrays, cost_per_area_field, bdg_classes_hdf5_filename):
"""
This function calculates the number of "leftover" buildings and their associated number of dwellings, people and costs.
The premise is N_leftover= MAX[0, N_sera - N_obm]. This calculation is carried out for a particular cell and adm unit,
......@@ -1192,6 +1192,7 @@ def calculate_leftover_per_class_and_admin_unit(sera_num_bdgs_per_class_and_adm_
and columns are country_adminIDs (as per obm_list_country_adminIDs_of_arrays)
obm_list_country_adminIDs_of_arrays: list of country_adminIDs associated with each column of obm_with_classes_num_bdgs_per_class_and_adm_unit
obm_list_bdg_classes_of_arrays: list of bdg classes associated with each row of obm_with_classes_num_bdgs_per_class_and_adm_unit
cost_per_area_field: name of the field that contains the cost per area (e.g., 'cost_per_area_eur', 'cost_per_area_usd')
In the most general case, the dimensions of sera_num_bdgs_per_class_and_adm_unit and
obm_with_classes_num_bdgs_per_class_and_adm_unit may or may not match. While SERA is the only source of building classes
......@@ -1219,7 +1220,7 @@ def calculate_leftover_per_class_and_admin_unit(sera_num_bdgs_per_class_and_adm_
# arrays to collect values for all bdg classes:
dwell_per_bdg= np.zeros([len(sera_classes)])
area_per_dwelling_sqm= np.zeros([len(sera_classes)])
cost_per_area_usd= np.zeros([len(sera_classes)])
cost_per_area= np.zeros([len(sera_classes)])
ppl_per_dwell= np.zeros([len(sera_classes)])
for k, bdg_class in enumerate(sera_classes):
country_adminid_locs, parameter_vals, col_names, col_contents= gdet_serah.retrieve_parameters_for_taxonomy(bdg_class, bdg_classes_hdf5_filename)
......@@ -1228,13 +1229,13 @@ def calculate_leftover_per_class_and_admin_unit(sera_num_bdgs_per_class_and_adm_
if len(which_row_admin_id)==1:
dwell_per_bdg[k]= parameter_vals[which_row_admin_id[0], int(col_names[np.where(np.array(col_contents)=='dwell_per_bdg')[0][0]].split('_')[-1])]
area_per_dwelling_sqm[k]= parameter_vals[which_row_admin_id[0], int(col_names[np.where(np.array(col_contents)=='area_per_dwelling_sqm')[0][0]].split('_')[-1])]
cost_per_area_usd[k]= parameter_vals[which_row_admin_id[0], int(col_names[np.where(np.array(col_contents)=='cost_per_area_usd')[0][0]].split('_')[-1])]
cost_per_area[k]= parameter_vals[which_row_admin_id[0], int(col_names[np.where(np.array(col_contents)==cost_per_area_field)[0][0]].split('_')[-1])]
ppl_per_dwell[k]= parameter_vals[which_row_admin_id[0], int(col_names[np.where(np.array(col_contents)=='ppl_per_dwell')[0][0]].split('_')[-1])]
else: # this can happen because the SERA array might contain bdg classes that are only in one of the adm units it has, and in this case the function retrieve_parameters_for_taxonomy will not be able to provide values for classes in adm units that do not occur together
pass
LO_num_dwells_per_class_and_adm_unit[:,j]= LO_num_bdgs_per_class_and_adm_unit[:,j] * dwell_per_bdg
LO_num_ppl_per_class_and_adm_unit[:,j]= LO_num_dwells_per_class_and_adm_unit[:,j] * ppl_per_dwell
LO_cost_per_class_and_adm_unit[:,j]= LO_num_dwells_per_class_and_adm_unit[:,j] * area_per_dwelling_sqm * cost_per_area_usd
LO_cost_per_class_and_adm_unit[:,j]= LO_num_dwells_per_class_and_adm_unit[:,j] * area_per_dwelling_sqm * cost_per_area
return LO_num_bdgs_per_class_and_adm_unit, LO_num_dwells_per_class_and_adm_unit, LO_num_ppl_per_class_and_adm_unit, LO_cost_per_class_and_adm_unit
......@@ -1441,7 +1442,7 @@ def write_OBM_to_GDE_tiles_add_params(gral_output_path, gde_tile_filename, occu_
building belonging to that class ('SERA_vals' proportions)
weighted_average_cost: float; the weighted average cost of this building, obtained as in the case of
weighted_average_ppl
cost_currency: string, e.g. "USD" or "EURO"
cost_currency: string, e.g. "USD" or "EUR"
"""
error_str= ''
gde_fle = h5py.File(os.path.join(gral_output_path, 'GDE_tiles', disagg_method, gde_tile_filename), "a")
......@@ -1493,7 +1494,7 @@ def write_LeftOver_to_GDE_tiles(gral_output_path, gde_tile_filename, occu_case,
just 1D because there is just one admin unit involved, hence the reshaping step
arr_costs: same dimensions as arr_num_bdgs, content is total cost for the total number of buildings in arr_num_bdgs
arr_ppl: same dimensions as arr_num_bdgs, content is total number of people for the total number of buildings in arr_num_bdgs
cost_currency: string, e.g. "USD" or "EURO"
cost_currency: string, e.g. "USD" or "EUR"
"""
gde_fle = h5py.File(os.path.join(gral_output_path, 'GDE_tiles', disagg_method, gde_tile_filename), "a")
if occu_case not in list(gde_fle):
......
......@@ -356,7 +356,7 @@ def write_hdf5_of_building_classes_parameters(in_case, in_country_admID, in_df,
in_case= Res, Com, Ind
in_country_admID= e.g. 'BE_12', 'GB_32', etc (i.e. ISO2 of country with admin ID
in_df= Pandas DataFrame containing only the columns of interest, i.e. taxonomy (which is taxonomy*),
dwell_per_bdg, area_per_dwelling_sqm, cost_per_area_usd, ppl_per_dwell, for in_country_admID.
dwell_per_bdg, area_per_dwelling_sqm, cost_per_area, ppl_per_dwell, for in_country_admID.
Each value of taxonomy appears only once (i.e. group_same_taxonomies has already been run).
Structure of the HDF5 file:
......@@ -573,6 +573,8 @@ def get_rounding_type(param):
rounding_str= 'normal_2'
elif param=='cost_per_area_usd':
rounding_str= 'cost_100'
elif param=='cost_per_area_eur':
rounding_str= 'cost_100'
elif param=='ppl_per_dwell':
rounding_str= 'normal_2'
else:
......@@ -695,9 +697,9 @@ def group_same_taxonomies(in_df, in_array_unique_combis, in_position_of_unique,
aux_num_bdgs_list= []
for j in range(0,len(which_t)):
aux_country_admin_ID.append(in_country_adm_ids[which_t[j]])
aux_num_bdgs_list.append(in_df['buildings'].values[which_t[j]])
aux_num_bdgs_list.append(in_df['buildings'].values[which_t[j]])
for k, col in enumerate(cols_to_distribute_effective):
if (col!='buildings') and (col!='occupants_per_asset') and (col!='dwellings') and (col!='total_repl_cost_usd'): # col=='occupants_per_asset' and col=='dwellings' should not happen, written this way just in case we change our minds later
if (col!='buildings') and (col!='occupants_per_asset') and (col!='dwellings') and (col!='total_repl_cost_usd') and (col!='total_repl_cost_eur'): # col=='occupants_per_asset' and col=='dwellings' should not happen, written this way just in case we change our minds later
arr_floats[t,k]= in_df[col].values[which_t[j]] # values will be overwritten but they should be the same
else:
arr_floats[t,k]= arr_floats[t,k] + in_df[col].values[which_t[j]]
......
......@@ -162,6 +162,19 @@ def check_parameters(config, section_name):
config["GDE_gather_SERA_and_OBM"]["print_screen_during_run"],
"print_screen_during_run",
)
if not config.has_option("GDE_gather_SERA_and_OBM", "currency"):
raise IOError(
"ERROR!! currency PARAMETER MISSING FROM CONFIG FILE!!"
)
else:
if config["GDE_gather_SERA_and_OBM"]["currency"] != "EUR" and config["GDE_gather_SERA_and_OBM"]["currency"] != "USD":
raise IOError(
"ERROR!! currency PARAMETER PROVIDED IN CONFIG FILE COULD NOT BE RECOGNISED!! VALID OPTIONS ARE 'EUR' AND 'USD'."
)
if not config.has_option("GDE_gather_SERA_and_OBM", "cost_per_area_field"):
raise IOError(
"ERROR!! cost_per_area_field PARAMETER MISSING FROM CONFIG FILE!!"
)
elif section_name == "GDE_plot_maps":
_ = check_of_occupancy_cases_parameter(config, section_name)
if not config.has_option("GDE_plot_maps", "location_var"):
......@@ -173,6 +186,8 @@ def check_parameters(config, section_name):
elif section_name == "GDE_check_consistency":
if not config.has_option("GDE_check_consistency", "location_var"):
raise IOError("ERROR!! location_var PARAMETER MISSING FROM CONFIG FILE!!")
if not config.has_option("GDE_check_consistency", "total_repl_cost_field"):
raise IOError("ERROR!! total_repl_cost_field PARAMETER MISSING FROM CONFIG FILE!!")
elif section_name == "OBM_assign_cell_ids_and_adm_ids_to_footprints":
if not config.has_option(
"OBM_assign_cell_ids_and_adm_ids_to_footprints", "method_to_use"
......@@ -231,6 +246,10 @@ def check_parameters(config, section_name):
_ = check_of_occupancy_cases_parameter(config, section_name)
if not config.has_option("SERA_create_OQ_input_files", "countries"):
raise IOError("ERROR!! countries PARAMETER MISSING FROM CONFIG FILE!!")
if not config.has_option("SERA_create_OQ_input_files", "cost_per_area_field"):
raise IOError(
"ERROR!! cost_per_area_field PARAMETER MISSING FROM CONFIG FILE!!"
)
elif section_name == "SERA_create_outputs_QGIS_for_checking":
if not config.has_option("SERA_create_outputs_QGIS_for_checking", "country"):
raise IOError("ERROR!! country PARAMETER MISSING FROM CONFIG FILE!!")
......@@ -248,6 +267,10 @@ def check_parameters(config, section_name):
raise IOError(
"ERROR!! max_num_cells_per_stage NEEDS TO BE A POSITIVE INTEGER!!"
)
if not config.has_option("SERA_create_visual_output_of_grid_model_full_files", "cost_per_area_field"):
raise IOError(
"ERROR!! cost_per_area_field PARAMETER MISSING FROM CONFIG FILE!!"
)
elif section_name == "SERA_distributing_exposure_to_cells":
check_of_sera_disaggregation_to_consider_parameter(config, section_name)
if not config.has_option("SERA_distributing_exposure_to_cells", "countries"):
......@@ -286,6 +309,26 @@ def check_parameters(config, section_name):
float(config[section_name]["tolerance_diff"])
except:
raise IOError("ERROR!! tolerance_diff PARAMETER NEEDS TO BE A REAL NUMBER")
if not config.has_option("SERA_exploration_investigate_full_CSV_files", "cost_per_area_field"):
raise IOError(
"ERROR!! cost_per_area_field PARAMETER MISSING FROM CONFIG FILE!!"
)
if not config.has_option("SERA_exploration_investigate_full_CSV_files", "total_repl_cost_field"):
raise IOError(
"ERROR!! total_repl_cost_field PARAMETER MISSING FROM CONFIG FILE!!"
)
if not config.has_option("SERA_exploration_investigate_full_CSV_files", "cost_structural_field"):
raise IOError(
"ERROR!! cost_structural_field PARAMETER MISSING FROM CONFIG FILE!!"
)
if not config.has_option("SERA_exploration_investigate_full_CSV_files", "cost_nonstructural_field"):
raise IOError(
"ERROR!! cost_nonstructural_field PARAMETER MISSING FROM CONFIG FILE!!"
)
if not config.has_option("SERA_exploration_investigate_full_CSV_files", "cost_contents_field"):
raise IOError(
"ERROR!! cost_contents_field PARAMETER MISSING FROM CONFIG FILE!!"
)
elif section_name == "SERA_exploration_investigate_macro_taxonomies":
if not config.has_option("SERA_exploration_investigate_macro_taxonomies", "country"):
raise IOError("ERROR!! country PARAMETER MISSING FROM CONFIG FILE!!")
......@@ -374,11 +417,19 @@ def check_parameters(config, section_name):
or section_name == "SERA_testing_rebuilding_exposure_from_cells_alternative_03"
):
if not config.has_option(
"SERA_testing_rebuilding_exposure_from_cells_alternative_01", "countries"
section_name, "countries"
):
raise IOError("ERROR!! countries PARAMETER MISSING FROM CONFIG FILE!!")
check_of_sera_disaggregation_to_consider_parameter(config, section_name)
_ = check_of_occupancy_cases_parameter(config, section_name)
_ = check_of_occupancy_cases_parameter(config, section_name)
if not config.has_option(section_name, "cost_per_area_field"):
raise IOError(
"ERROR!! cost_per_area_field PARAMETER MISSING FROM CONFIG FILE!!"
)
if not config.has_option(section_name, "total_repl_cost_field"):
raise IOError(
"ERROR!! total_repl_cost_field PARAMETER MISSING FROM CONFIG FILE!!"
)
elif section_name == "GDE_check_tiles_vs_visual_CSVs":
_ = check_of_occupancy_cases_parameter(config, section_name)
if not config.has_option("GDE_check_tiles_vs_visual_CSVs", "path_GDE_tiles"):
......
......@@ -50,6 +50,8 @@ def run_this_file(config_dict):
sera_models_path= config_dict['File Paths']['sera_models_path']
# The visual output files have names such as GDE_visual_'+crit+'_'+location_var+'.csv'
location_var= config_dict['GDE_check_consistency']['location_var']
# Total-replacement-cost field (e.g. 'total_repl_cost_eur', 'total_repl_cost_usd'):
total_repl_cost_field = config_dict['GDE_check_consistency']['total_repl_cost_field']
# Load dictionary of result paths to be used within the code:
results_available_for= config_dict['Available Results']['results_available_for'].split(', ') # eg: area, gpw_2015_pop, ghs, sat_27f, sat_27f_model
result_paths= config_dict['Available Results']['result_paths'].split(', ') # each associated with each element of results_available_for
......@@ -134,7 +136,7 @@ def run_this_file(config_dict):
sera_num_bdgs_j= dfs_dict[occu]['buildings'].values[which].sum()
sera_num_dwells_j= dfs_dict[occu]['dwellings'].values[which].sum()
sera_num_ppl_j= dfs_dict[occu]['occupants_per_asset'].values[which].sum()
sera_repl_cost_j= dfs_dict[occu]['total_repl_cost_usd'].values[which].sum()
sera_repl_cost_j= dfs_dict[occu][total_repl_cost_field].values[which].sum()
gde_num_bdgs_sera_j= dict_by_crit[crit]['visual_by_admin']['number_'+occu+'_SERA'].values[j]
gde_num_dwells_sera_j= dict_by_crit[crit]['visual_by_admin']['num_dwells_'+occu+'_SERA'].values[j]
gde_num_ppl_sera_j= dict_by_crit[crit]['visual_by_admin']['night_'+occu+'_SERA'].values[j]
......@@ -208,7 +210,7 @@ def run_this_file(config_dict):
out_list.append('{:.2f}'.format(dfs_dict[occu]['buildings'].values[which_attica].sum()))
out_list.append('{:.2f}'.format(dfs_dict[occu]['dwellings'].values[which_attica].sum()))
out_list.append('{:.2f}'.format(dfs_dict[occu]['occupants_per_asset'].values[which_attica].sum()))
out_list.append('{:.2f}'.format(dfs_dict[occu]['total_repl_cost_usd'].values[which_attica].sum()))
out_list.append('{:.2f}'.format(dfs_dict[occu][total_repl_cost_field].values[which_attica].sum()))
out_list.append(sera_models_path)
out_csv.write(','.join(out_list)+'\n')
for crit in list(dict_by_crit.keys()):
......
......@@ -118,6 +118,10 @@ read_completeness = obm_tiles
print_screen_during_run = False
# Occupancy cases in which the OBM buildings will be classified ('Oth' is implicit in the method):
occupancy_cases = Res, Com, Ind
# Currency (options: EUR, USD):
currency = EUR
# Cost-per-area field (options: cost_per_area_eur, cost_per_area_usd):
cost_per_area_field = cost_per_area_eur
[GDE_plot_maps]
# The visual output files have names such as GDE_visual_'+crit+'_'+location_var+'.csv'
......@@ -133,6 +137,8 @@ sera_disaggregation_to_consider = sat_27f
[GDE_check_consistency]
# The visual output files have names such as GDE_visual_'+crit+'_'+location_var+'.csv'
location_var = Greece
# Total-replacement-cost field (options: total_repl_cost_eur, total_repl_cost_usd):
total_repl_cost_field = total_repl_cost_eur
[OBM_assign_cell_ids_and_adm_ids_to_footprints]
# Method to use to assign a building footprint to a cell or admin unit.
......@@ -165,6 +171,8 @@ countries = Greece
# Within those countries, do not process admin units with the following IDs
# (useful for running parts of countries only, it can be empty or ignored too):
admin_ids_to_ignore = 9999999
# Cost-per-area field (options: cost_per_area_eur, cost_per_area_usd):
cost_per_area_field = cost_per_area_eur
[SERA_create_outputs_QGIS_for_checking]
country = Greece
......@@ -177,6 +185,8 @@ sera_disaggregation_to_consider = sat_27f
occupancy_cases = Res, Com, Ind
# Maximum number of cells per calculation stage (the code processes and appends output by blocks):
max_num_cells_per_stage = 1000
# Cost-per-area field (options: cost_per_area_eur, cost_per_area_usd):
cost_per_area_field = cost_per_area_eur
[SERA_distributing_exposure_to_cells]
# SELECT CASE OF SERA DISAGGREGATION TO CARRY OUT:
......@@ -190,7 +200,7 @@ countries = Greece
# (useful for running parts of countries only, it can be empty or ignored too):
admin_ids_to_ignore = 9999999
# Columns to distribute (TO DO: provide better description of this parameter):
columns_to_distribute = buildings, dwell_per_bdg, area_per_dwelling_sqm, cost_per_area_usd, ppl_per_dwell
columns_to_distribute = buildings, dwell_per_bdg, area_per_dwelling_sqm, cost_per_area_eur, ppl_per_dwell
# Write the HDF5 file of building classes parameters or not.
# (write_hdf5_bdg_classes parameter for gdet_sera.distribute_SERA_to_cells() function):
write_hdf5_bdg_classes_param = True
......@@ -200,6 +210,16 @@ write_hdf5_bdg_classes_param = True
tolerance_ratio = 1E-3
# Tolerance for the difference of parameters (e.g. X-Y):
tolerance_diff = 10.0
# Cost-per-area field (options: cost_per_area_eur, cost_per_area_usd):
cost_per_area_field = cost_per_area_eur
# Total-replacement-cost field (options: total_repl_cost_eur, total_repl_cost_usd):
total_repl_cost_field = total_repl_cost_eur
# Structural-replacement-cost field (options: cost_structural_eur, cost_structural_usd):
cost_structural_field = cost_structural_eur
# Non-structural-replacement-cost field (options: cost_nonstructural_eur, cost_nonstructural_usd):
cost_nonstructural_field = cost_nonstructural_eur
# Contents-replacement-cost field (options: cost_contents_eur, cost_contents_usd):
cost_contents_field = cost_contents_eur
[SERA_exploration_investigate_macro_taxonomies]
country = Greece
......@@ -253,6 +273,10 @@ admin_ids_to_ignore = 9999999
sera_disaggregation_to_consider = sat_27f
# Occupancy cases to consider:
occupancy_cases = Res, Com, Ind
# Cost-per-area field (options: cost_per_area_eur, cost_per_area_usd):
cost_per_area_field = cost_per_area_eur
# Total-replacement-cost field (options: total_repl_cost_eur, total_repl_cost_usd):
total_repl_cost_field = total_repl_cost_eur
[SERA_testing_rebuilding_exposure_from_cells_alternative_02]
# Countries to process (if many, separate with comma and space):
......@@ -264,6 +288,10 @@ min_grid_cell_id = 0
sera_disaggregation_to_consider = sat_27f
# Occupancy cases to consider:
occupancy_cases = Res, Com, Ind
# Cost-per-area field (options: cost_per_area_eur, cost_per_area_usd):
cost_per_area_field = cost_per_area_eur
# Total-replacement-cost field (options: total_repl_cost_eur, total_repl_cost_usd):
total_repl_cost_field = total_repl_cost_eur
[SERA_testing_rebuilding_exposure_from_cells_alternative_03]
# Countries to process (if many, separate with comma and space):
......@@ -276,6 +304,10 @@ admin_ids_to_ignore = 9999999
sera_disaggregation_to_consider = sat_27f
# Occupancy cases to consider:
occupancy_cases = Res, Com, Ind
# Cost-per-area field (options: cost_per_area_eur, cost_per_area_usd):
cost_per_area_field = cost_per_area_eur
# Total-replacement-cost field (options: total_repl_cost_eur, total_repl_cost_usd):
total_repl_cost_field = total_repl_cost_eur
[GDE_check_tiles_vs_visual_CSVs]
# Path to the GDE tiles HDF5 files to consider (directory):
......
......@@ -84,6 +84,10 @@ def run_this_file(config_dict):
occupancy_cases= config_dict['GDE_gather_SERA_and_OBM']['occupancy_cases'].split(', ')
if 'Oth' not in occupancy_cases: # i.e. all other cases (e.g. neither Res nor Com nor Ind)
occupancy_cases.append('Oth')
# Currency:
currency = config_dict['GDE_gather_SERA_and_OBM']['currency']
# Cost-per-area field:
cost_per_area_field = config_dict['GDE_gather_SERA_and_OBM']['cost_per_area_field']
# This code will go cell by cell. Define the list of cells from the config file:
grid_cells_list, grid_cells_def_method= gdet_gral.define_grid_cell_list_to_process(config_dict, 'Cells to Process')
# Cell IDs with numbers below this one will be ignored (useful while running pieces of regions):
......@@ -139,7 +143,7 @@ def run_this_file(config_dict):
bdg_classes_hdf5_filename= os.path.join(out_path,'Europe_SERA_bdg_classes_'+case+'.hdf5')
else:
bdg_classes_hdf5_filename= ''
obm_dict, obm_country_adminIDs, obm_without_classes_num_bdgs_per_adm_unit, obm_country_adminIDs_levels, error_message= gdet_obmh.retrieve_OBM_buildings_in_cell_from_hdf5(obm_hdf5_filename, bdg_classes_hdf5_filename, sera_shp_path, os.path.join(out_path, 'Europe_SERA_metadata_v_'+version_of_SERA_metadata+'.hdf5'), out_path, 'GDE_cell_'+str(grid_cell_id).zfill(10)+'.hdf5', case, admin_unit_type= 'all', disagg_method= sera_disaggregation_to_consider)
obm_dict, obm_country_adminIDs, obm_without_classes_num_bdgs_per_adm_unit, obm_country_adminIDs_levels, error_message= gdet_obmh.retrieve_OBM_buildings_in_cell_from_hdf5(obm_hdf5_filename, bdg_classes_hdf5_filename, sera_shp_path, os.path.join(out_path, 'Europe_SERA_metadata_v_'+version_of_SERA_metadata+'.hdf5'), out_path, 'GDE_cell_'+str(grid_cell_id).zfill(10)+'.hdf5', case, cost_per_area_field, currency, admin_unit_type= 'all', disagg_method= sera_disaggregation_to_consider)
if error_message!='':
print(error_message)
log.append(error_message)
......@@ -169,7 +173,7 @@ def run_this_file(config_dict):
print(' No OBM buildings')
# Retrieve SERA data:
_, _, sera_num_bdgs, sera_num_dwells, sera_num_ppl, sera_defined, sera_classes, sera_proportion_per_class, sera_proportions_subclasses_per_admin, _, _, sera_list_country_adminIDs_columns, sera_list_country_adminIDs, sera_list_country_adminIDs_levels= gdet_serah.retrieve_sera_hdf5_classes_and_vals(grid_cell_id, 'Total', 'Total', os.path.join(out_path, 'Europe_SERA_cells_'+sera_disaggregation_to_consider+'_'+case+'.hdf5'))
sera_num_bdgs_per_class_and_adm_unit, sera_num_dwells_per_class_and_adm_unit, sera_num_ppl_per_class_and_adm_unit, sera_cost_per_class_and_adm_unit, sera_country_adminIDs, sera_country_adminIDs_levels, error_string = gdet_serah.compute_bdgs_dwells_ppl_cost_for_cell_total(sera_num_bdgs, sera_classes, sera_proportion_per_class, sera_proportions_subclasses_per_admin, sera_list_country_adminIDs_columns, sera_list_country_adminIDs, sera_list_country_adminIDs_levels, os.path.join(out_path,'Europe_SERA_bdg_classes_'+case+'.hdf5'), output_by_admin_unit=True)
sera_num_bdgs_per_class_and_adm_unit, sera_num_dwells_per_class_and_adm_unit, sera_num_ppl_per_class_and_adm_unit, sera_cost_per_class_and_adm_unit, sera_country_adminIDs, sera_country_adminIDs_levels, error_string = gdet_serah.compute_bdgs_dwells_ppl_cost_for_cell_total(sera_num_bdgs, sera_classes, sera_proportion_per_class, sera_proportions_subclasses_per_admin, sera_list_country_adminIDs_columns, sera_list_country_adminIDs, sera_list_country_adminIDs_levels, os.path.join(out_path,'Europe_SERA_bdg_classes_'+case+'.hdf5'), cost_per_area_field, output_by_admin_unit=True)
if error_string=='ERROR' or len(sera_proportion_per_class)==0:
log.append(' NO SERA BUILDINGS FOUND FOR CELL ID '+str(grid_cell_id)+' FROM '+os.path.join(out_path, 'Europe_SERA_cells_'+sera_disaggregation_to_consider+'_'+case+'.hdf5'))
sera_cost= 0.0
......@@ -207,7 +211,7 @@ def run_this_file(config_dict):
else: # cell is incomplete
if error_string!='ERROR':
if case!='Oth':
leftover_num_bdgs_per_class_and_adm_unit, leftover_num_dwells_per_class_and_adm_unit, leftover_num_ppl_per_class_and_adm_unit, leftover_cost_per_class_and_adm_unit= gdet_gral.calculate_leftover_per_class_and_admin_unit(sera_num_bdgs_per_class_and_adm_unit, sera_country_adminIDs, sera_classes, obm_with_classes_num_bdgs_per_class_and_adm_unit, obm_list_country_adminIDs_of_arrays, obm_list_bdg_classes_of_arrays, bdg_classes_hdf5_filename)
leftover_num_bdgs_per_class_and_adm_unit, leftover_num_dwells_per_class_and_adm_unit, leftover_num_ppl_per_class_and_adm_unit, leftover_cost_per_class_and_adm_unit= gdet_gral.calculate_leftover_per_class_and_admin_unit(sera_num_bdgs_per_class_and_adm_unit, sera_country_adminIDs, sera_classes, obm_with_classes_num_bdgs_per_class_and_adm_unit, obm_list_country_adminIDs_of_arrays, obm_list_bdg_classes_of_arrays, cost_per_area_field, bdg_classes_hdf5_filename)
else: # SERA is not defined for "Other"
leftover_num_bdgs_per_class_and_adm_unit= np.zeros_like(sera_num_bdgs_per_class_and_adm_unit)
leftover_num_dwells_per_class_and_adm_unit= np.zeros_like(sera_num_dwells_per_class_and_adm_unit)
......@@ -270,7 +274,7 @@ def run_this_file(config_dict):
cell_summary_dict= gdet_gral.fill_in_cell_summary_dictionary_with_SERA_LeftOver_or_Total_bdgs_dwells_ppl(cell_summary_dict, case, 'Total', total_num_bdgs, total_num_dwells, total_num_ppl, total_cost)
admin_summary_dict= gdet_gral.fill_in_admin_summary_dictionary_with_SERA_LeftOver_or_Total_bdgs_dwells_ppl(admin_summary_dict, case, 'LeftOver', sera_country_adminIDs, sera_country_adminIDs_levels, leftover_num_bdgs_per_class_and_adm_unit, leftover_num_dwells_per_class_and_adm_unit, leftover_num_ppl_per_class_and_adm_unit, leftover_cost_per_class_and_adm_unit, sera_shp_path, os.path.join(out_path, 'Europe_SERA_metadata_v_'+version_of_SERA_metadata+'.hdf5'), input_kind='per_class_and_adm_unit')
admin_summary_dict= gdet_gral.fill_in_admin_summary_dictionary_with_SERA_LeftOver_or_Total_bdgs_dwells_ppl(admin_summary_dict, case, 'Total', total_list_country_adminIDs, total_list_country_adminIDs_levels, total_num_bdgs_all_per_adm_unit, total_num_dwells_per_adm_unit, total_num_ppl_per_adm_unit, total_cost_per_adm_unit, sera_shp_path, os.path.join(out_path, 'Europe_SERA_metadata_v_'+version_of_SERA_metadata+'.hdf5'), input_kind='per_adm_unit')
gdet_gral.write_LeftOver_to_GDE_tiles(out_path, 'GDE_cell_'+str(grid_cell_id).zfill(10)+'.hdf5', case, sera_disaggregation_to_consider, sera_classes, sera_country_adminIDs, leftover_num_bdgs_per_class_and_adm_unit, leftover_cost_per_class_and_adm_unit, leftover_num_ppl_per_class_and_adm_unit, 'USD')
gdet_gral.write_LeftOver_to_GDE_tiles(out_path, 'GDE_cell_'+str(grid_cell_id).zfill(10)+'.hdf5', case, sera_disaggregation_to_consider, sera_classes, sera_country_adminIDs, leftover_num_bdgs_per_class_and_adm_unit, leftover_cost_per_class_and_adm_unit, leftover_num_ppl_per_class_and_adm_unit, currency)
gdet_gral.wrap_up_totals_in_GDE_tiles(out_path, 'GDE_cell_'+str(grid_cell_id).zfill(10)+'.hdf5', sera_disaggregation_to_consider)
# Generate visual output:
gdet_gral.write_visual_output_GDE_by_cell(grid_cell_id, cell_summary_dict, os.path.join(out_path, 'export_grids_QGIS', 'GDE_visual_'+out_name+'.csv'))
......
......@@ -66,6 +66,8 @@ def run_this_file(config_dict):
occupancies= config_dict['SERA_create_OQ_input_files']['occupancy_cases'].split(', ') # Res, Com, Ind
# Countries to process:
countries= config_dict['SERA_create_OQ_input_files']['countries'].split(', ')
# Cost-per-area field:
cost_per_area_field = config_dict['SERA_create_OQ_input_files']['cost_per_area_field']
# Ignore (i.e. do not process) the following administrative unit IDs:
if 'admin_ids_to_ignore' in config_dict['SERA_create_OQ_input_files'].keys():
admin_ids_to_ignore= config_dict['SERA_create_OQ_input_files']['admin_ids_to_ignore'].split(', ')
......@@ -132,7 +134,7 @@ def run_this_file(config_dict):
if cell_attrs_defined=='True': # SERA model defined for this country_adminid
dwell_per_bdg= np.zeros([len(bdg_classes_names)])
area_per_dwelling_sqm= np.zeros([len(bdg_classes_names)])
cost_per_area_usd= np.zeros([len(bdg_classes_names)])
cost_per_area= np.zeros([len(bdg_classes_names)])
ppl_per_dwell= np.zeros([len(bdg_classes_names)])
for k, bdg_class in enumerate(bdg_classes_names):
# Write values:
......@@ -144,12 +146,12 @@ def run_this_file(config_dict):
which_row_admin_id= np.where(country_adminid_locs==country_adminid)[0][0]
dwell_per_bdg[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='dwell_per_bdg')[0][0]].split('_')[-1])]
area_per_dwelling_sqm[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='area_per_dwelling_sqm')[0][0]].split('_')[-1])]
cost_per_area_usd[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='cost_per_area_usd')[0][0]].split('_')[-1])]
cost_per_area[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)==cost_per_area_field)[0][0]].split('_')[-1])]
ppl_per_dwell[k]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='ppl_per_dwell')[0][0]].split('_')[-1])]
lon= np.hstack([lon, np.array([centroid_lon for i in range(0,len(bdg_classes_names))])])
lat= np.hstack([lat, np.array([centroid_lat for i in range(0,len(bdg_classes_names))])])
num_bdgs= np.hstack([num_bdgs, cell_attrs_tot_num_bdgs * bdg_classes_proportions[:,0]])
cost= np.hstack([cost, cell_attrs_tot_num_bdgs * bdg_classes_proportions[:,0] * dwell_per_bdg * area_per_dwelling_sqm * cost_per_area_usd])
cost= np.hstack([cost, cell_attrs_tot_num_bdgs * bdg_classes_proportions[:,0] * dwell_per_bdg * area_per_dwelling_sqm * cost_per_area])
ppl= np.hstack([ppl, cell_attrs_tot_num_bdgs * bdg_classes_proportions[:,0] * dwell_per_bdg * ppl_per_dwell])
else: # SERA model is NOT defined for this country_adminid --> we can just skip this whole j, admin_id loop
break
......
......@@ -66,6 +66,8 @@ def run_this_file(config_dict):
max_num_cells_per_stage = int(config_dict['SERA_create_visual_output_of_grid_model_full_files']['max_num_cells_per_stage']) # 1000 is a reasonable number
# SERA disaggregation case to consider:
param_for_weighting = config_dict['SERA_create_visual_output_of_grid_model_full_files']['sera_disaggregation_to_consider'] # 'area', 'gpw_2015_pop', 'ghs', 'sat_27f', 'sat_27f_model'
# Cost-per-area field:
cost_per_area_field = config_dict['SERA_create_visual_output_of_grid_model_full_files']['cost_per_area_field']
# This code will go cell by cell. Define the list of cells from the config file:
print('Defining grid cells list...')
grid_cells_list, grid_cells_def_method= gdet_gral.define_grid_cell_list_to_process(config_dict, 'Cells to Process')
......@@ -143,7 +145,7 @@ def run_this_file(config_dict):
repl_cost_per_class_and_admin_unit= np.zeros_like(subclasses_array) # each row is a bdg class, each column is a country_admin_ID
dwell_per_bdg= np.zeros_like(subclasses_array) # each row is a bdg class, each column is a country_admin_ID
area_per_dwelling_sqm= np.zeros_like(subclasses_array) # each row is a bdg class, each column is a country_admin_ID
cost_per_area_usd= np.zeros_like(subclasses_array) # each row is a bdg class, each column is a country_admin_ID
cost_per_area= np.zeros_like(subclasses_array) # each row is a bdg class, each column is a country_admin_ID
for k, bdg_class in enumerate(bdg_classes_names):
num_bdgs_per_class_and_admin_unit[k,:]= num_bdgs_per_class[k] * subclasses_array[k,:]
for j in range(0,subclasses_array.shape[1]): # go one by one the country_admin_IDs
......@@ -154,8 +156,8 @@ def run_this_file(config_dict):
which_row_admin_id= np.where(country_adminid_locs==country_adminid)[0][0]
dwell_per_bdg[k,j]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='dwell_per_bdg')[0][0]].split('_')[-1])]
area_per_dwelling_sqm[k,j]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='area_per_dwelling_sqm')[0][0]].split('_')[-1])]
cost_per_area_usd[k,j]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)=='cost_per_area_usd')[0][0]].split('_')[-1])]
repl_cost_per_class_and_admin_unit= num_bdgs_per_class_and_admin_unit * dwell_per_bdg * area_per_dwelling_sqm * cost_per_area_usd
cost_per_area[k,j]= parameter_vals[which_row_admin_id, int(col_names[np.where(np.array(col_contents)==cost_per_area_field)[0][0]].split('_')[-1])]
repl_cost_per_class_and_admin_unit= num_bdgs_per_class_and_admin_unit * dwell_per_bdg * area_per_dwelling_sqm * cost_per_area
cost[i]= repl_cost_per_class_and_admin_unit.sum()
fle.close()
fle_bdgs.close()
......
......@@ -64,7 +64,7 @@ def run_this_file(config_dict):
else:
admin_ids_to_ignore= []
# Columns to distribute (TO DO: provide better description of this parameter):
columns_to_distribute= config_dict['SERA_distributing_exposure_to_cells']['columns_to_distribute'].split(', ') # ['buildings','dwell_per_bdg','area_per_dwelling_sqm','cost_per_area_usd','ppl_per_dwell'] # OLD VERSION (OQ files): columns_to_distribute=['number','structural','night']
columns_to_distribute= config_dict['SERA_distributing_exposure_to_cells']['columns_to_distribute'].split(', ')
# Write the HDF5 file of building classes parameters or not:
write_hdf5_bdg_classes_str= config_dict['SERA_distributing_exposure_to_cells']['write_hdf5_bdg_classes_param']
if write_hdf5_bdg_classes_str.lower()=='true':
......
......@@ -25,15 +25,15 @@ SERA_exploration_investigate_full_CSV_files
===========================================
This code carries out the following checks on the costs reported in the SERA model (full files):
CHECK 01
Is the “structural” column of the OpenQuake CSV the same as the “total_repl_cost_usd” column of the full CSV?
Is the “structural” column of the OpenQuake CSV the same as the “total_repl_cost” column of the full CSV?
CHECK 02
Is the “total_repl_cost_usd” column of the full CSV the same as the product of the columns “area_per_dwelling_sqm” by “cost_per_area_usd” by (“buildings” for Com/Ind or “dwellings” for Res)?
Is the “total_repl_cost” column of the full CSV the same as the product of the columns “area_per_dwelling_sqm” by “cost_per_area” by (“buildings” for Com/Ind or “dwellings” for Res)?
CHECK 03
Same as CHECK 02 but in Euros instead of USD.
Deprecated.
CHECK 04
Is the “total_repl_cost_usd” column of the full CSV the same as the sum of the columns “cost_structural_usd” plus “cost_nonstructural_usd” plus “cost_contents_usd”?
Is the “total_repl_cost” column of the full CSV the same as the sum of the columns “cost_structural” plus “cost_nonstructural” plus “cost_contents”?
CHECK 05
Same as CHECK 04 but in Euros instead of USD.
Deprecated.
"""
import sys
......@@ -69,6 +69,16 @@ def run_this_file(config_dict):
# Read tolerance values:
tolerance_ratio= float(config_dict['SERA_exploration_investigate_full_CSV_files']['tolerance_ratio']) # 1E-3
tolerance_diff= float(config_dict['SERA_exploration_investigate_full_CSV_files']['tolerance_diff']) # 10.0
# Cost-per-area field:
cost_per_area_field = config_dict['SERA_exploration_investigate_full_CSV_files']['cost_per_area_field']
# Total-replacement-cost field:
total_repl_cost_field = config_dict['SERA_exploration_investigate_full_CSV_files']['total_repl_cost_field']
# Structural-replacement-cost field:
cost_structural_field = config_dict['SERA_exploration_investigate_full_CSV_files']['cost_structural_field']
# Non-structural-replacement-cost field:
cost_nonstructural_field = config_dict['SERA_exploration_investigate_full_CSV_files']['cost_nonstructural_field']
# Contents-replacement-cost field:
cost_contents_field = config_dict['SERA_exploration_investigate_full_CSV_files']['cost_contents_field']
####################################################
# START
####################################################
......@@ -94,44 +104,37 @@ def run_this_file(config_dict):
ratio_01= np.array([-999.9])
else:
check_00= 'OK'
# Check 01: 'structural' from OQ vs 'total_repl_cost_usd' from full CSV files
vals_full=dfs_dict_full[case]['total_repl_cost_usd'].values
# Check 01: 'structural' from OQ vs 'total_repl_cost' from full CSV files
vals_full=dfs_dict_full[case][total_repl_cost_field].values
vals_oq= dfs_dict_OQ[case]['structural'].values
diff_01= np.abs(dfs_dict_full[case]['total_repl_cost_usd'].values - dfs_dict_OQ[case]['structural'].values)
ratio_01= diff_01 / dfs_dict_full[case]['total_repl_cost_usd'].values
diff_01= np.abs(dfs_dict_full[case][total_repl_cost_field].values - dfs_dict_OQ[case]['structural'].values)
ratio_01= diff_01 / dfs_dict_full[case][total_repl_cost_field].values
# FUNDAMENTAL ASSUMPTION: nans ARISE DUE TO THERE BEING SOME ENTRIES IN A FEW COUNTRIES WITH ZERO BUILDINGS
ratio_01= ratio_01[np.logical_not(np.isnan(ratio_01))]
check_01= do_check_tolerance(ratio_01, diff_01, tolerance_ratio, tolerance_diff)
# Check 02: area/dwelling * USD/area * dwellings/bdg * buildings = total cost ? in USD
# Check 02: area/dwelling * cost/area * dwellings/bdg * buildings = total cost ?
if case=='Res':
calculated= dfs_dict_full[case]['area_per_dwelling_sqm'].values * dfs_dict_full[case]['cost_per_area_usd'].values * dfs_dict_full[case]['dwellings'].values