Commit 37ff08b2 authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Merge branch 'feature/narrowcom' into 'master'

Adjust occupancy sub-types classification and narrow down commercial building classes based on occupancy type

See merge request !19
parents 9b2bf257 c40293cf
""" """
Copyright (C) 2020 Copyright (C) 2020-2021
Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ Helmholtz-Zentrum Potsdam Deutsches GeoForschungsZentrum GFZ
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
...@@ -320,10 +320,10 @@ def write_sera_to_bdg(in_osm_id, open_fle_part, sera_dict, adm_level_from_OBM): ...@@ -320,10 +320,10 @@ def write_sera_to_bdg(in_osm_id, open_fle_part, sera_dict, adm_level_from_OBM):
Otherwise, he attribute "'Sto_SERA_inconsist_'+disag_case" is set to False. TO DO: IN THE FUTURE WE MIGHT Otherwise, he attribute "'Sto_SERA_inconsist_'+disag_case" is set to False. TO DO: IN THE FUTURE WE MIGHT
WANT TO DO SOMETHING DIFFERENT WITH CASES LIKE THIS. NEED TO DISCUSS. WANT TO DO SOMETHING DIFFERENT WITH CASES LIKE THIS. NEED TO DISCUSS.
""" """
err_str= '' err_str = ''
for disag_case in sera_dict.keys(): for disag_case in sera_dict.keys():
if len(sera_dict[disag_case].keys())!=0: # SERA HDF5 contains info for this cell and admin unit if len(sera_dict[disag_case].keys()) != 0: # SERA HDF5 contains info for this cell and admin unit
if sera_dict[disag_case]['Adm_Level']!=adm_level_from_OBM: if sera_dict[disag_case]['Adm_Level'] != adm_level_from_OBM:
err_str= 'ERROR IN ADM LEVEL OF SERA HDF5 FILES VS OBM DATABASE FOR '+disag_case+'.' err_str= 'ERROR IN ADM LEVEL OF SERA HDF5 FILES VS OBM DATABASE FOR '+disag_case+'.'
else: else:
if 'SERA_classes'+'_'+disag_case in list(open_fle_part[str(in_osm_id)]): if 'SERA_classes'+'_'+disag_case in list(open_fle_part[str(in_osm_id)]):
...@@ -331,14 +331,33 @@ def write_sera_to_bdg(in_osm_id, open_fle_part, sera_dict, adm_level_from_OBM): ...@@ -331,14 +331,33 @@ def write_sera_to_bdg(in_osm_id, open_fle_part, sera_dict, adm_level_from_OBM):
if 'SERA_vals'+'_'+disag_case in list(open_fle_part[str(in_osm_id)]): if 'SERA_vals'+'_'+disag_case in list(open_fle_part[str(in_osm_id)]):
del open_fle_part[str(in_osm_id)]['SERA_vals'+'_'+disag_case] del open_fle_part[str(in_osm_id)]['SERA_vals'+'_'+disag_case]
# Narrowing down the distribution based on the number of storeys, only if available: # Narrowing down the distribution based on the number of storeys, only if available:
num_sto= open_fle_part[str(in_osm_id)].attrs['Storeys'] num_sto = open_fle_part[str(in_osm_id)].attrs['Storeys']
keep_class= np.array([True for i in range(0, len(sera_dict[disag_case]['SERA_classes']))]) # keep all classes unles removed keep_class_sto = np.array([True for i in range(0, len(sera_dict[disag_case]['SERA_classes']))]) # keep all classes unless removed
if num_sto!='UNK': if num_sto != 'UNK':
if float(num_sto)>0.1: if float(num_sto) > 0.1:
num_sto_lower, num_sto_upper= gdet_sera.interpret_num_storeys_from_building_class(sera_dict[disag_case]['SERA_classes']) num_sto_lower, num_sto_upper = gdet_sera.interpret_num_storeys_from_building_class(sera_dict[disag_case]['SERA_classes'])
for k, theo_class in enumerate(sera_dict[disag_case]['SERA_classes']): for k, theo_class in enumerate(sera_dict[disag_case]['SERA_classes']):
if not np.logical_and(np.ceil(float(num_sto))>=num_sto_lower[k], np.ceil(float(num_sto))<=num_sto_upper[k]): # np.ceil(float), not int, because there are OSM buildings with non-integer number of storeys (ceiling needed bec if e.g. num_sto='4.5' and the bdg classes I am comparing against have H:4 and H:5, the code would not assign it to any of the two classes otherwise) if not np.logical_and(np.ceil(float(num_sto)) >= num_sto_lower[k], np.ceil(float(num_sto)) <= num_sto_upper[k]): # np.ceil(float), not int, because there are OSM buildings with non-integer number of storeys (ceiling needed bec if e.g. num_sto='4.5' and the bdg classes I am comparing against have H:4 and H:5, the code would not assign it to any of the two classes otherwise)
keep_class[k]= False # remove class keep_class_sto[k] = False # remove class
# Narrowing down the distribution based on commercial occupancies:
occupancy = open_fle_part[str(in_osm_id)].attrs["Occup"]
keep_class_com = np.array([True for i in range(0, len(sera_dict[disag_case]['SERA_classes']))]) # keep all classes unless removed
if (occupancy == "RES3" # Hotels
or occupancy == "COM5"): # Restaurants
for k, theo_class in enumerate(sera_dict[disag_case]['SERA_classes']):
if "Hotels" not in theo_class: # In SERA, "Hotels" includes hotels and restaurants
keep_class_com[k] = False # remove class
elif occupancy == "COM3": # Offices
for k, theo_class in enumerate(sera_dict[disag_case]['SERA_classes']):
if "Offices" not in theo_class:
keep_class_com[k] = False # remove class
elif (occupancy == "COM1" # Retail trade
or occupancy == "COM2"): # Wholesale trade and storage (warehouse)
for k, theo_class in enumerate(sera_dict[disag_case]['SERA_classes']):
if "Trade" not in theo_class: # In SERA, "Trade" includes wholesale and retail trade
keep_class_com[k] = False # remove class
# Combine results from both types of narrowing down cases:
keep_class = np.logical_and(keep_class_sto, keep_class_com)
if keep_class.sum()>0.1: # i.e. if there is at least one class left as "to keep", i.e. at least one "True" in keep_class if keep_class.sum()>0.1: # i.e. if there is at least one class left as "to keep", i.e. at least one "True" in keep_class
# Write the classes and values to keep (it is all of them if num_sto is unknown): # Write the classes and values to keep (it is all of them if num_sto is unknown):
dt=h5py.special_dtype(vlen=str) # examples on using special_dtype: https://www.programcreek.com/python/example/105243/h5py.special_dtype dt=h5py.special_dtype(vlen=str) # examples on using special_dtype: https://www.programcreek.com/python/example/105243/h5py.special_dtype
......
...@@ -102,7 +102,7 @@ min_grid_cell_id = 0 ...@@ -102,7 +102,7 @@ min_grid_cell_id = 0
# Occupancy cases in which the OBM buildings will be classified ('Oth' is implicit in the method when needed): # Occupancy cases in which the OBM buildings will be classified ('Oth' is implicit in the method when needed):
occupancy_cases = Res, Com, Ind occupancy_cases = Res, Com, Ind
# Occupancy strings associated with each value of occupancy_cases # Occupancy strings associated with each value of occupancy_cases
occupancy_classifications = [RES; RES1; RES2; RES3; RES4; RES5; RES99; MIX1], [COM; COM1; COM10; COM11; COM12; COM13; COM14; COM15; COM16; COM17; COM18; COM2; COM3; COM5; COM6; COM7; COM8; COM9; COM99], [IND; IND1; IND2; IND3; IND4; IND5; IND6; IND7; IND8; IND9; IND99] occupancy_classifications = [RES; RES99; RES1; RES2; RES2A; RES4; MIX1; MIX4], [COM; COM99; COM1; COM2; COM3; COM5; RES3], [IND; IND99; IND1; IND2; MIX3]
[GDE_gather_SERA_and_OBM] [GDE_gather_SERA_and_OBM]
# This code will go cell by cell. There are many ways in which one can define the list # This code will go cell by cell. There are many ways in which one can define the list
......
Markdown is supported
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