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

Bug fixes associated with having adapted the code to run with the config file

parent 070c171c
......@@ -95,13 +95,15 @@ def run_this_file(config_dict):
# Define part of the output name based on the list of cells processed:
if grid_cells_def_method=='country_in_DB':
#TO DO: WRITE FUNCTION THAT RETRIEVES CELLS IDs FOR AN ADMIN BOUNDARY GIVEN AS A SHAPEFILE, SO AS TO NOT NEED TO LINK TO THE DATABASE
out_name= sera_disaggregation_to_consider + '_' + config_dict['GDE_gather_SERA_and_OBM']['country_name']
out_name= sera_disaggregation_to_consider + '_' + config_dict['Cells to Process']['country_name']
elif grid_cells_def_method=='admin_ID_in_country':
out_name= 'exposure_grid_'+sera_disaggregation_to_consider+'_'+config_dict['Cells to Process']['country_name']+'_'+str(config_dict['Cells to Process']['admin_id_in_country'])
elif grid_cells_def_method=='bbox':
out_name= sera_disaggregation_to_consider + '_bbox_' +str(grid_cells_list[0])+'_'+str(grid_cells_list[-1])
elif grid_cells_def_method=='arbitrary':
out_name= sera_disaggregation_to_consider + '_arbitrary_' +str(grid_cells_list[0])+'_'+str(grid_cells_list[-1])
elif grid_cells_def_method== 'random_from_country':
out_name= sera_disaggregation_to_consider + '_' + config_dict['GDE_gather_SERA_and_OBM']['country_name'] + '_random'
out_name= sera_disaggregation_to_consider + '_' + config_dict['Cells to Process']['country_name'] + '_random'
else:
print('ERROR!!! METHOD FOR DEFINING LIST OF CELL IDs UNKNOWN. ERROR!!!')
print('Retrieving completeness information for grid cells...')
......
......@@ -165,12 +165,12 @@ def run_this_file(config_dict):
print('Summary:')
out_csv= open(os.path.join(out_path, 'export_grids_QGIS', out_name+'_summary.txt'), "w")
if grid_cells_def_method=='country_in_DB':
out_csv.write('Country: '+country_name+'\n')
out_csv.write('Country: '+config_dict['Cells to Process']['country_name']+'\n')
elif grid_cells_def_method=='admin_ID_in_country':
out_csv.write('Country: '+country_name+'\n')
out_csv.write('Admin ID in country: '+str(admin_id_in_country)+'\n')
out_csv.write('Country: '+config_dict['Cells to Process']['country_name']+'\n')
out_csv.write('Admin ID in country: '+config_dict['Cells to Process']['admin_id_in_country']+'\n')
elif grid_cells_def_method=='random_from_country':
out_csv.write(config_dict['Cells to Process']['num_random_cells']+' random cells selected from country: '+country_name+'\n')
out_csv.write(config_dict['Cells to Process']['num_random_cells']+' random cells selected from country: '+config_dict['Cells to Process']['country_name']+'\n')
elif grid_cells_def_method=='bbox':
out_csv.write('Bounding box used:\n')
out_csv.write('South-West Longitude: '+'{:.5f}'.format(bb_sw_lon)+'\n')
......@@ -180,7 +180,7 @@ def run_this_file(config_dict):
elif grid_cells_def_method=='arbitrary':
out_csv.write('Arbitrary list of cells used:\n')
out_str= []
for cell_id in arbitr_list:
for cell_id in grid_cells_list:
out_str.append(str(cell_id))
out_csv.write(','.join(out_str))
out_csv.write('\n')
......@@ -205,7 +205,7 @@ def run_this_file(config_dict):
print(string)
out_csv.write(string+'\n')
out_csv.close()
print('Done!')
if __name__=='__main__':
......
......@@ -89,8 +89,12 @@ def run_this_file(config_dict):
log= [] # list that I fill in for logging purposes and then dump to a txt file
if grid_cells_def_method=='country_in_DB':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name'])
elif grid_cells_def_method=='admin_ID_in_country':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name']+'... Admin ID: '+config_dict['Cells to Process']['admin_id_in_country'])
elif grid_cells_def_method== 'random_from_country':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name']+'... Number of random cells: '+config_dict['Cells to Process']['num_random_cells'])
else:
print('Defining grid cells list using method '+grid_cells_def_method+'...')
print('Defining grid cells list using method '+grid_cells_def_method+'...')
# Load GHS grid:
# The GHS value is a percentage between 0 and 100%.
fle= h5py.File(os.path.join(ghs_path, ghs_filename))
......
......@@ -81,8 +81,12 @@ def run_this_file(config_dict):
log= [] # list that I fill in for logging purposes and then dump to a txt file
if grid_cells_def_method=='country_in_DB':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name'])
elif grid_cells_def_method=='admin_ID_in_country':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name']+'... Admin ID: '+config_dict['Cells to Process']['admin_id_in_country'])
elif grid_cells_def_method== 'random_from_country':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name']+'... Number of random cells: '+config_dict['Cells to Process']['num_random_cells'])
else:
print('Defining grid cells list using method '+grid_cells_def_method+'...')
print('Defining grid cells list using method '+grid_cells_def_method+'...')
# Load GPW grid:
print('Loading GPW grid...')
population_values, _, gpw_pop_x_coord_edges, gpw_pop_y_coord_edges, _, _, _, _, _, _= gdet_gpw.get_gpw_grids(gpw_path)
......
......@@ -76,11 +76,15 @@ def run_this_file(config_dict):
####################################################
# START
####################################################
log= [] # list that I fill in for logging purposes and then dump to a txt file
log= [] # list that I fill in for logging purposes and then dump to a txt file
if grid_cells_def_method=='country_in_DB':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name'])
elif grid_cells_def_method=='admin_ID_in_country':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name']+'... Admin ID: '+config_dict['Cells to Process']['admin_id_in_country'])
elif grid_cells_def_method== 'random_from_country':
print('Defining grid cells list using method '+grid_cells_def_method+'... Country: '+config_dict['Cells to Process']['country_name']+'... Number of random cells: '+config_dict['Cells to Process']['num_random_cells'])
else:
print('Defining grid cells list using method '+grid_cells_def_method+'...')
print('Defining grid cells list using method '+grid_cells_def_method+'...')
# The built-up area from Nicolas' satellite imagery is in m2:
sat_df= pd.read_csv(os.path.join(sat_path, 'SAR_F_Grid_with_cell_IDs.csv'), sep=';')
for i, grid_cell_id in enumerate(grid_cells_list):
......
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