From 129c79c93adc6545e308b664b43a7f4b2177f520 Mon Sep 17 00:00:00 2001 From: shinde Date: Wed, 17 Aug 2022 15:00:13 +0200 Subject: [PATCH] Imported building numbers for industrial data --- exposurejapan/baseaggregatedexposure.py | 48 +- exposurejapan/constants.py | 3 + exposurejapan/exposurejapan.py | 11 + exposurejapan/industrial.py | 576 ++++++++++++++++++++++++ exposurejapan/residential.py | 6 +- setup.py | 2 +- 6 files changed, 638 insertions(+), 8 deletions(-) diff --git a/exposurejapan/baseaggregatedexposure.py b/exposurejapan/baseaggregatedexposure.py index 624abd9..cd6c42e 100644 --- a/exposurejapan/baseaggregatedexposure.py +++ b/exposurejapan/baseaggregatedexposure.py @@ -17,18 +17,18 @@ # along with this program. If not, see http://www.gnu.org/licenses/. import logging -from exposurelib.database import SpatialiteDatabase +from databaselib.database import SpatiaLiteDatabase import shapely.wkt import shapely.wkb import pyproj from shapely.ops import transform -from exposurejapan import constants +import constants # Initialize log logger = logging.getLogger(__name__) -class BaseAggregatedExposure(SpatialiteDatabase): +class BaseAggregatedExposure(SpatiaLiteDatabase): """ The BaseAggregatedExposure class represents a Spatialite database for the aggregated exposure model for Japan. It is derived from the generic Database class. @@ -47,7 +47,7 @@ class BaseAggregatedExposure(SpatialiteDatabase): """ def __init__(self, database_filepath, spatialite_filepath="mod_spatialite"): - SpatialiteDatabase.__init__(self, database_filepath, spatialite_filepath) + SpatiaLiteDatabase.__init__(self, database_filepath, spatialite_filepath) def create_district_table(self): """ @@ -65,6 +65,29 @@ class BaseAggregatedExposure(SpatialiteDatabase): self.connection.execute(sql_statement) logger.debug("Table District created") + # Create table `ConstructionMaterial` + sql_statement = "CREATE TABLE ConstructionMaterial (" + sql_statement += "id INTEGER PRIMARY KEY, " + sql_statement += "description TEXT)" + self.connection.execute(sql_statement) + logger.debug("Table ConstructionMaterial created") + + def insert_construction_material(self, construction_material_id, description): + """ + Inserts a construction-material description to the `ConstructionMaterial` table. + + Args: + construction_material_id (int): + ID of the construction material + description (str): + Description of the construction material + """ + + sql_statement = "INSERT INTO ConstructionMaterial " + sql_statement += "(id, description) " + sql_statement += "VALUES (%d, '%s')" % (construction_material_id, description) + self.cursor.execute(sql_statement) + @staticmethod def reproject_polygon(input_polygon, input_crs, target_crs): """ @@ -175,3 +198,20 @@ class BaseAggregatedExposure(SpatialiteDatabase): logger.debug(sql_statement) self.connection.execute(sql_statement) logger.info("Districts and boundaries added") + + def get_district_id(self, district_id): + """ + Gets the ID of the district in the `District` table corresponding + to the ID of the administrative district specified. + + Args: + district_id (int): + ID of the administrative district + """ + + # Identify district_id based on admin_id from the `District` table + sql_statement = "SELECT id FROM District " + sql_statement += "WHERE id = %d" % district_id + self.cursor.execute(sql_statement) + result = self.cursor.fetchone() + return result diff --git a/exposurejapan/constants.py b/exposurejapan/constants.py index e1e6b86..bba41bc 100644 --- a/exposurejapan/constants.py +++ b/exposurejapan/constants.py @@ -108,3 +108,6 @@ NUMBER_DWELLING_SIZES = 6 # Constant numbers for import of dwelling-size data to DwellingFloorspace table FLOORSPACE_PER_DWELLING_DWELLING_SIZES = 13 + +# Constant number for Unidentified values while importing commercial building numbers data +UNIDENTIFIED = -1 diff --git a/exposurejapan/exposurejapan.py b/exposurejapan/exposurejapan.py index 12bbdf5..267f23f 100644 --- a/exposurejapan/exposurejapan.py +++ b/exposurejapan/exposurejapan.py @@ -66,6 +66,17 @@ def main(): exit() ind_db.create_district_table() ind_db.import_districts_and_boundaries("data/Boundary.gpkg") + ind_db.create_tables() + ind_db.import_exposure_data( + "data/Number_of_factories_owned_by_corporations_by_industry_and_structure_158_city_translated.csv", # noqa: E501 + "data/Number_of_factories_owned_by_corporate_industry_and_structure_158_pref_translated.csv", # noqa: E501 + "data/Number_of_factories_owned_by_corporate_industry_and_new_seismic_standards_170_city_translated.csv", # noqa: E501 + "data/Number_of_factories_owned_by_corporate_industry_and_new_earthquake_resistance_standards_170_pref_translated.csv", # noqa: E501 + "data/Number_of_factories_owned_by_corporations_by_industry_and_total_floor_space_134_city_translated.csv", # noqa: E501 + "data/Number_of_factories_owned_by_corporate_industry_and_total_floor_area_134_pref_translated.csv", # noqa: E501 + "data/Number of regular employees, number of factories owned by total floor area_138_city_translated.csv", # noqa: E501 + "data/Number_of_regular_employees_number_of_factories_owned_by_total_floor_space_138_pref_translated.csv", # noqa: E501 + ) # Leave the program sys.exit() diff --git a/exposurejapan/industrial.py b/exposurejapan/industrial.py index 4c1a6ca..ab9a0d1 100644 --- a/exposurejapan/industrial.py +++ b/exposurejapan/industrial.py @@ -17,12 +17,35 @@ # along with this program. If not, see http://www.gnu.org/licenses/. import logging +import pandas +import numpy +from exposurejapan import constants from exposurejapan.baseaggregatedexposure import BaseAggregatedExposure # Initialize log logger = logging.getLogger(__name__) +def add_element_and_get_index(element, element_list): + """ + Checks if an element is in a list and adds it to the list if not. + Returns the index of the element in the list. + + Args: + element (str): + Element to be added to the list + element_list (list): + List to add the element to + + Returns: + Index of inserted element in the list + """ + + if element not in element_list: + element_list.append(element) + return element_list.index(element) + + class IndustrialAggregatedExposure(BaseAggregatedExposure): """ The IndustrialDatabase class represents a Spatialite database for the industrial @@ -44,3 +67,556 @@ class IndustrialAggregatedExposure(BaseAggregatedExposure): def __init__(self, database_filepath, spatialite_filepath="mod_spatialite"): BaseAggregatedExposure.__init__(self, database_filepath, spatialite_filepath) + + def create_tables(self): + """ + Creates all necessary tables in the database. These are: + BuildingNumber : Stores the number of buildings depending on corporate industry, + construction material, earthquake resistance code presence + and total floor area (in square meters) range and number of regular employees range + for each district. + """ + + # Create table `BuildingNumber` + sql_statement = "CREATE TABLE BuildingNumber (" + sql_statement += "id INTEGER PRIMARY KEY AUTOINCREMENT, " + sql_statement += "district_id INTEGER, " + sql_statement += "corporate_industry_id INTEGER, " + sql_statement += "construction_material_id INTEGER, " + sql_statement += "eq_resistance_code_presence_id INTEGER, " + sql_statement += "total_floor_area_id INTEGER, " + sql_statement += "number_of_regular_employees_id INTEGER, " + sql_statement += "number_building REAL);" + self.connection.execute(sql_statement) + logger.debug("Table BuildingNumber created") + + # Create table `CorporateIndustryType` + sql_statement = "CREATE TABLE CorporateIndustryType (" + sql_statement += "id INTEGER PRIMARY KEY, " + sql_statement += "description TEXT)" + self.connection.execute(sql_statement) + logger.debug("Table CorporateIndustryType created") + + # Create table `EarthquakeResistanceCodePresenceType` + sql_statement = "CREATE TABLE EarthquakeResistanceCodePresenceType (" + sql_statement += "id INTEGER PRIMARY KEY, " + sql_statement += "description TEXT)" + self.connection.execute(sql_statement) + logger.debug("Table EarthquakeResistanceCodePresenceType created") + + # Create table `TotalFloorAreaRange` + sql_statement = "CREATE TABLE TotalFloorAreaRange (" + sql_statement += "id INTEGER PRIMARY KEY, " + sql_statement += "description TEXT)" + self.connection.execute(sql_statement) + logger.debug("Table TotalFloorAreaRange created") + + # Create table `NumberOfRegularEmployeesRange` + sql_statement = "CREATE TABLE NumberOfRegularEmployeesRange (" + sql_statement += "id INTEGER PRIMARY KEY, " + sql_statement += "description TEXT)" + self.connection.execute(sql_statement) + logger.debug("Table NumberOfRegularEmployeesRange created") + + def insert_corporate_industry(self, corporate_industry_id, description): + """ + Inserts a main usage description to the `CorporateIndustryType` table. + + Args: + corporate_industry_id (int): + ID of the corporate industry associated to the building + description (str): + Description of the corporate industry associated + to the building + """ + + sql_statement = "INSERT INTO CorporateIndustryType " + sql_statement += "(id, description) " + sql_statement += "VALUES (%d, '%s')" % (corporate_industry_id, description) + self.cursor.execute(sql_statement) + + def insert_earthquake_resistance_code_presence( + self, eq_resistance_code_presence_id, description + ): + """ + Inserts a presence of earthquake resistance code description to the + `EarthquakeResistanceCodePresenceType` table. + + Args: + eq_resistance_code_presence_id (int): + ID of the presence of earthquake resistance code during design + and construction of the building + description (str): + Description of the presence of earthquake resistance code during designing + and construction of the building + """ + + sql_statement = "INSERT INTO EarthquakeResistanceCodePresenceType " + sql_statement += "(id, description) " + sql_statement += "VALUES (%d, '%s')" % ( + eq_resistance_code_presence_id, + description, + ) + self.cursor.execute(sql_statement) + + def insert_total_floor_area(self, total_floor_area_id, description): + """ + Inserts a total floor area (in square meters) range description to the + `TotalFloorAreaRange` + table. + + Args: + total_floor_area_id (int): + ID of the total floor area (in square meters) range of a building + description (str): + Description of the total floor area (in square meters) range of the building + """ + + sql_statement = "INSERT INTO TotalFloorAreaRange " + sql_statement += "(id, description) " + sql_statement += "VALUES (%d, '%s')" % (total_floor_area_id, description) + self.cursor.execute(sql_statement) + + def insert_number_of_regular_employees(self, number_of_regular_employees_id, description): + """ + Inserts number of regular employees range description to the + `NumberOfRegularEmployeesRange` table. + + Args: + number_of_regular_employees_id (int): + ID of the number of regular employees range for a building + description (str): + Description of the number of regular employees range of the building + """ + + sql_statement = "INSERT INTO NumberOfRegularEmployeesRange " + sql_statement += "(id, description) " + sql_statement += "VALUES (%d, '%s')" % (number_of_regular_employees_id, description) + self.cursor.execute(sql_statement) + + def import_building_numbers( + self, + building_numbers_corporate_industry_construction_material_city_filepath, + building_numbers_corporate_industry_construction_material_pref_filepath, + building_numbers_corporate_industry_eq_resistance_code_presence_city_filepath, + building_numbers_corporate_industry_eq_resistance_code_presence_pref_filepath, + building_numbers_corporate_industry_total_floor_area_city_filepath, + building_numbers_corporate_industry_total_floor_area_pref_filepath, + building_numbers_total_floor_area_number_of_regular_employees_city_filepath, + building_numbers_total_floor_area_number_of_regular_employees_pref_filepath, + corporate_industry_list, + construction_material_list, + eq_resistance_code_presence_list, + total_floor_area_list, + number_of_regular_employees_list, + ): + """ + Imports all commercial building data from the 2013 industrial building statistics + files provided by E-Stat, Japan. + + The following files are needed: + - List of number of buildings by their corporate industry and construction material + for each designated city + (building_numbers_corporate_industry_construction_material_city_filepath) + - List of number of buildings by their corporate industry and construction material + for each prefecture + (building_numbers_corporate_industry_construction_material_pref_filepath) + - List of the number of buildings by their corporate industry and earthquake resistance + code presence during design and construction of buildings for each designated city + (building_numbers_corporate_industry_eq_resistance_code_presence_city_filepath) + - List of the number of buildings by their corporate industry and earthquake resistance + code presence during design and construction of buildings for each prefecture + (building_numbers_corporate_industry_eq_resistance_code_presence_pref_filepath) + - List of the number of buildings by their corporate industry and total floor area + (in square meters) range of the building for each designated city + (building_numbers_corporate_industry_total_floor_area_city_filepath) + - List of the number of buildings by their corporate industry and total floor area + (in square meters) range of the building for each prefecture + (building_numbers_corporate_industry_total_floor_area_pref_filepath) + - List of the number of buildings by their total floor area (in square meters) + and number of regular employees range of the building for each city + (building_numbers_total_floor_area_number_of_regular_employees_city_filepath) + - List of the number of buildings by their total floor area (in square meters) + and number of regular employees range of the building for each prefecture + (building_numbers_total_floor_area_number_of_regular_employees_pref_filepath) + + The building data provides the building numbers for a combination of different building + attributes: + - corporate industry associated to the building type (total, agriculture, forestry + and fishing, mining, quarrying and gravel mining, construction industry, electricity, + gas, heat supply, and water services, information and communication industry, + transportation and postal industry, wholesale and retail industry, finance and + insurance industry, real estate business and goods leasing business, academic research + professional technical service industry, accommodation business and food service + business, life related service industry, education and learning support business, + medical and welfare industry, complex service business, service industry not + classified elsewhere, unknown) + - construction material type (total, wooden, steel frame reinforced concrete structure, + reinforced concrete construction, steel frame, concrete block construction and others) + - earthquake resistance code presence (total, do not meet new seismic standards, + meet new seismic standards, unconfirmed) + - total floor area range (total, 200_to_less_than_500_m2, 500_to_less_than_1000_m2, + 1000_to_less_than_2000_m2, 2000_to_less_than_5000_m2, 5000_to_less_than_10000_m2, + 10000_to_less_than_20000_m2, 20000_to_less_than_50000_m2, 50000_m2_or_more) + - number of regular employees range (4 people and less, 5 to 9 people, 10 to 19 people, + 20 to 29 people, 30 to 49 people, 50 to 99 people, 100 to 299 people, 300 to + 999 people, 1000 to 1999 people, 2000 to 4999 people, over 5000 people and unknown + + Args: + building_numbers_corporate_industry_construction_material_city_filepath (str): + Filepath of the file containing building numbers for corporate industry + and construction material for designated cities. + building_numbers_corporate_industry_construction_material_pref_filepath (str): + Filepath of the file containing building numbers for corporate industry + and construction material for prefectures. + building_numbers_corporate_industry_eq_resistance_code_presence_city_filepath (str): + Filepath of the file containing the building numbers for corporate industry + and earthquake resistance code presence for designated cities. + building_numbers_corporate_industry_eq_resistance_code_presence_pref_filepath (str): + Filepath of the file containing the building numbers for corporate industry + and earthquake resistance code presence for prefecture. + building_numbers_corporate_industry_total_floor_area_city_filepath (str): + Filepath of the file containing the building numbers for corporate industry + and total floor area (in square meters) range for designated cities. + building_numbers_corporate_industry_total_floor_area_pref_filepath (str): + Filepath of the file containing the building numbers for corporate industry + and total floor area (in square meters) range for prefecture. + building_numbers_total_floor_area_number_of_regular_employees_city_filepath (str): + Filepath of the file containing the building numbers for total floor + area (in square meters) and number of employees range for designated cities. + building_numbers_total_floor_area_number_of_regular_employees_pref_filepath (str: + Filepath of the file containing the building numbers for total floor + area (in square meters) and number of employees range for prefecture. + corporate_industry_list (list): + Collection of types of corporate industry type associated to the buildings. + construction_material_list (list): + Collection of types of construction materials. + eq_resistance_code_presence_list (list): + Collection of types of earthquake resistance code presence + during design and construction of buildings + total_floor_area_list (list): + Collection of range of total floor area (in square meters) present in the + building numbers data + number_of_regular_employees_list (list): + Collection of range of number of regular employees present in the building + numbers data + """ + + # Read all columns from the input CSV file for number of buildings with + # corporate industry and construction material for designated cities + building_numbers_corporate_industry_construction_material_city_input = pandas.read_csv( + building_numbers_corporate_industry_construction_material_city_filepath + ) + + # Read all columns from the input CSV file for number of buildings by + # their corporate industry and construction material for prefectures + building_numbers_corporate_industry_construction_material_pref_input = pandas.read_csv( + building_numbers_corporate_industry_construction_material_pref_filepath + ) + + # Merge the number of buildings for cities and prefectures given by + # their corporate industry and construction material dataframes + building_numbers_corporate_industry_construction_material = ( + building_numbers_corporate_industry_construction_material_city_input.merge( + building_numbers_corporate_industry_construction_material_pref_input, + how="outer", # noqa: E501 + ) + ) + + # Read all columns from the input CSV file for number of buildings by + # their corporate industry and earthquake resistance code presence for designated cities + building_numbers_corporate_industry_eq_resistance_code_presence_city_input = ( + pandas.read_csv( # noqa: E501 + building_numbers_corporate_industry_eq_resistance_code_presence_city_filepath + ) + ) + + # Read all columns from the input CSV file for number of buildings by + # their corporate industry and earthquake resistance code presence for prefectures + building_numbers_corporate_industry_eq_resistance_code_presence_pref_input = ( + pandas.read_csv( # noqa: E501 + building_numbers_corporate_industry_eq_resistance_code_presence_pref_filepath + ) + ) + + # Merge the number of buildings for cities and prefectures given by + # their corporate industry and earthquake resistance code presence type dataframes + building_numbers_corporate_industry_earthquake_resistance_code_presence = ( + building_numbers_corporate_industry_eq_resistance_code_presence_city_input.merge( + building_numbers_corporate_industry_eq_resistance_code_presence_pref_input, + how="outer", + ) + ) + + # Read all columns from the input CSV file for number of buildings by + # their corporate industry and total floor area (in square meters) range for + # designated cities + building_numbers_corporate_industry_total_floor_area_city_input = pandas.read_csv( + building_numbers_corporate_industry_total_floor_area_city_filepath + ) + + # Read all columns from the input CSV file for number of buildings by + # their corporate industry and total floor area (in square meters) range for prefectures + building_numbers_corporate_industry_total_floor_area_pref_input = pandas.read_csv( + building_numbers_corporate_industry_total_floor_area_pref_filepath + ) + + # Merge the number of buildings for cities and prefectures given by + # their corporate industry and total floor area (in square meters) range dataframes + building_numbers_corporate_industry_total_floor_area = ( + building_numbers_corporate_industry_total_floor_area_city_input.merge( + building_numbers_corporate_industry_total_floor_area_pref_input, how="outer" + ) + ) + + # Read all columns from the input CSV file for number of buildings by their total floor + # area (in square meters) and number of regular employees range for designated cities + building_numbers_total_floor_area_number_of_regular_employees_city_input = ( + pandas.read_csv( # noqa: E501 + building_numbers_total_floor_area_number_of_regular_employees_city_filepath + ) + ) + + # Read all columns from the input CSV file for number of buildings by their total floor + # area (in square meters) and number of regular employees range for prefectures + building_numbers_total_floor_area_number_of_regular_employees_pref_input = ( + pandas.read_csv( # noqa: E501 + building_numbers_total_floor_area_number_of_regular_employees_pref_filepath + ) + ) + + # Merge the number of buildings for cities and prefectures given by their total floor + # area (in square meters) and number of regular employees range dataframes + building_numbers_total_floor_area_number_of_employees = ( + building_numbers_total_floor_area_number_of_regular_employees_city_input.merge( + building_numbers_total_floor_area_number_of_regular_employees_pref_input, + how="outer", # noqa: E501 + ) + ) + + # Merge the dataframes with number of buildings by construction material, basement + # presence, earthquake resistance code presence, total floor area (in square meters) + # and number of regular employees range and replace the None values with `Unidentified` + building_numbers = ( + ( + pandas.concat( + [ + building_numbers_corporate_industry_construction_material, + building_numbers_corporate_industry_earthquake_resistance_code_presence, + building_numbers_corporate_industry_total_floor_area, + building_numbers_total_floor_area_number_of_employees, + ], + axis=0, + ignore_index=True, + ) + ) + .astype(object) + .replace(numpy.nan, "Unidentified") + ) + building_numbers.to_csv("building_numbers.csv") + # Iterate through the building_numbers dataframe + for index, row in building_numbers.iterrows(): + + # Get admin_id + admin_id = row["area_code"] + + # Identify district_id based on admin_id from the `District` table + district_id_result = self.get_district_id(admin_id) + if district_id_result is None: # Only data for which a district exist matter + continue + district_id = district_id_result[0] + + # Get ID of corporate industry + if row["corporate_industry_H25_land_building"] == "Unidentified": + corporate_industry_id = constants.UNIDENTIFIED + else: + corporate_industry_id = add_element_and_get_index( + row["corporate_industry_H25_land_building"], corporate_industry_list + ) + + # Get ID of construction material + if row["construction_material"] == "Unidentified": + construction_material_id = constants.UNIDENTIFIED + else: + construction_material_id = add_element_and_get_index( + row["construction_material"], construction_material_list + ) + + # Get ID of earthquake resistance code presence type + if row["earthquake_resistance_std"] == "Unidentified": + eq_resistance_code_presence_id = constants.UNIDENTIFIED + else: + eq_resistance_code_presence_id = add_element_and_get_index( + row["earthquake_resistance_std"], eq_resistance_code_presence_list + ) + + # Get ID of total floor area (in square meters) range + if row["total_floor_area"] == "Unidentified": + total_floor_area_id = constants.UNIDENTIFIED + else: + total_floor_area_id = add_element_and_get_index( + row["total_floor_area"], total_floor_area_list + ) + + # Get ID of number of employees range + if row["number_of_regular_employees"] == "Unidentified": + number_of_regular_employees_id = constants.UNIDENTIFIED + else: + number_of_regular_employees_id = add_element_and_get_index( + row["number_of_regular_employees"], number_of_regular_employees_list + ) + + # Get building numbers + building_number = row["value"] + + # Insert the data to the `BuildingNumber` table + sql_statement = ( + "INSERT INTO BuildingNumber (district_id, corporate_industry_id, " + "construction_material_id, eq_resistance_code_presence_id, " + "total_floor_area_id, number_of_regular_employees_id, number_building) " + "VALUES (%d, %d, %d, %d, %d, %d, %f)" + % ( + district_id, + corporate_industry_id, + construction_material_id, + eq_resistance_code_presence_id, + total_floor_area_id, + number_of_regular_employees_id, + building_number, + ) + ) + self.cursor.execute(sql_statement) + + self.connection.commit() + logger.info("Building numbers added") + + def import_exposure_data( + self, + building_numbers_corporate_industry_construction_material_city_filepath, + building_numbers_corporate_industry_construction_material_pref_filepath, + building_numbers_corporate_industry_eq_resistance_code_presence_city_filepath, + building_numbers_corporate_industry_eq_resistance_code_presence_pref_filepath, + building_numbers_corporate_industry_total_floor_area_city_filepath, + building_numbers_corporate_industry_total_floor_area_pref_filepath, + building_numbers_total_floor_area_number_of_regular_employees_city_filepath, + building_numbers_total_floor_area_number_of_regular_employees_pref_filepath, + ): + """ + Imports all commercial exposure data from the CSV files provided by E-Stat, Japan. + + The following files are needed (The filepath includes their respective codes from + the E-Stat website): + - List of number of buildings by their corporate industry and construction material + for each designated city + (building_numbers_corporate_industry_construction_material_city_filepath) + - List of number of buildings by their corporate industry and construction material + for each prefecture + (building_numbers_corporate_industry_construction_material_pref_filepath) + - List of the number of buildings by their corporate industry and earthquake resistance + code presence during design and construction of buildings for each designated city + (building_numbers_corporate_industry_eq_resistance_code_presence_city_filepath) + - List of the number of buildings by their corporate industry and earthquake resistance + code presence during design and construction of buildings for each prefecture + (building_numbers_corporate_industry_eq_resistance_code_presence_pref_filepath) + - List of the number of buildings by their corporate industry and total floor area + (in square meters) range of the building for each designated city + (building_numbers_corporate_industry_total_floor_area_city_filepath) + - List of the number of buildings by their corporate industry and total floor area + (in square meters) range of the building for each prefecture + (building_numbers_corporate_industry_total_floor_area_pref_filepath) + - List of the number of buildings by their total floor area (in square meters) + and number of regular employees range of the building for each city + (building_numbers_total_floor_area_number_of_regular_employees_city_filepath) + - List of the number of buildings by their total floor area (in square meters) + and number of regular employees range of the building for each prefecture + (building_numbers_total_floor_area_number_of_regular_employees_pref_filepath) + + Args: + building_numbers_corporate_industry_construction_material_city_filepath (str): + Filepath of the file containing building numbers for corporate industry + and construction material for designated cities. + building_numbers_corporate_industry_construction_material_pref_filepath (str): + Filepath of the file containing building numbers for corporate industry + and construction material for prefectures. + building_numbers_corporate_industry_eq_resistance_code_presence_city_filepath (str): + Filepath of the file containing the building numbers for corporate industry + and earthquake resistance code presence for designated cities. + building_numbers_corporate_industry_eq_resistance_code_presence_pref_filepath (str): + Filepath of the file containing the building numbers for corporate industry + and earthquake resistance code presence for prefecture. + building_numbers_corporate_industry_total_floor_area_city_filepath (str): + Filepath of the file containing the building numbers for corporate industry + and total floor area (in square meters) range for designated cities. + building_numbers_corporate_industry_total_floor_area_pref_filepath (str): + Filepath of the file containing the building numbers for corporate industry + and total floor area (in square meters) range for prefecture. + building_numbers_total_floor_area_number_of_regular_employees_city_filepath (str): + Filepath of the file containing the building numbers for total floor + area (in square meters) and number of employees range for designated cities. + building_numbers_total_floor_area_number_of_regular_employees_pref_filepath (str: + Filepath of the file containing the building numbers for total floor + area (in square meters) and number of employees range for prefecture. + """ + + # Create lists to store building attribute classifications + + corporate_industry_list = [] + construction_material_list = [] + eq_resistance_code_presence_list = [] + total_floor_area_list = [] + number_of_regular_employees_list = [] + + # Import building numbers data into the database + self.import_building_numbers( + building_numbers_corporate_industry_construction_material_city_filepath, + building_numbers_corporate_industry_construction_material_pref_filepath, + building_numbers_corporate_industry_eq_resistance_code_presence_city_filepath, + building_numbers_corporate_industry_eq_resistance_code_presence_pref_filepath, + building_numbers_corporate_industry_total_floor_area_city_filepath, + building_numbers_corporate_industry_total_floor_area_pref_filepath, + building_numbers_total_floor_area_number_of_regular_employees_city_filepath, + building_numbers_total_floor_area_number_of_regular_employees_pref_filepath, + corporate_industry_list, + construction_material_list, + eq_resistance_code_presence_list, + total_floor_area_list, + number_of_regular_employees_list, + ) + + # Add the main usage types to the database + for corporate_industry_id, main_usage in enumerate(corporate_industry_list): + self.insert_corporate_industry(corporate_industry_id, main_usage) + logger.info("Corporate-industry types added") + + # Add the types of construction material to the database + for construction_material_id, construction_material in enumerate( + construction_material_list + ): + self.insert_construction_material(construction_material_id, construction_material) + logger.info("Construction-material types added") + + # Add the types of earthquake resistance code presence to the database + for ( + eq_resistance_code_presence_id, + eq_resistance_code_presence, + ) in enumerate(eq_resistance_code_presence_list): + self.insert_earthquake_resistance_code_presence( + eq_resistance_code_presence_id, eq_resistance_code_presence + ) + logger.info("Earthquake resistance code presence types added") + + # Add the ranges of total floor area (in square meters) to the database + for total_floor_area_id, total_floor_area in enumerate(total_floor_area_list): + self.insert_total_floor_area(total_floor_area_id, total_floor_area) + logger.info("Total floor areas (in square meters) types added") + + # Add the ranges of number of regular employees to the database + for number_of_regular_employees_id, number_of_regular_employees in enumerate( + number_of_regular_employees_list + ): # noqa: E501 + self.insert_number_of_regular_employees( + number_of_regular_employees_id, number_of_regular_employees + ) # noqa: E501 + logger.info("Range of number of regular employees types added") + + self.connection.commit() diff --git a/exposurejapan/residential.py b/exposurejapan/residential.py index 5791820..22cea8b 100644 --- a/exposurejapan/residential.py +++ b/exposurejapan/residential.py @@ -17,7 +17,7 @@ # along with this program. If not, see http://www.gnu.org/licenses/. import logging -from exposurelib.database import SpatialiteDatabase +from databaselib.database import SpatiaLiteDatabase import pandas from exposurejapan import constants import shapely.wkt @@ -50,7 +50,7 @@ def add_element_and_get_index(element, element_list): return element_list.index(element) -class ResidentialAggregatedExposure(SpatialiteDatabase): +class ResidentialAggregatedExposure(SpatiaLiteDatabase): """ The ResidentialAggregatedExposure class represents a Spatialite database for the residential exposure model for Japan. It is derived from the generic Database class. @@ -67,7 +67,7 @@ class ResidentialAggregatedExposure(SpatialiteDatabase): """ def __init__(self, database_filepath, spatialite_filepath="mod_spatialite"): - SpatialiteDatabase.__init__(self, database_filepath, spatialite_filepath) + SpatiaLiteDatabase.__init__(self, database_filepath, spatialite_filepath) def create_tables(self): """ diff --git a/setup.py b/setup.py index 337d46a..a516915 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,7 @@ setup( license="AGPLv3+", install_requires=[ "pandas", - "exposurelib@https://git.gfz-potsdam.de/dynamicexposure/globaldynamicexposure/exposure-lib/-/archive/master/exposure-lib-master.zip", # noqa: E501 + "databaselib@https://git.gfz-potsdam.de/dynamicexposure/coding/database-lib/-/archive/main/database-lib-main.zip", # noqa: E501 "pyproj==3.0.0.post1", "shapely", "scipy", -- GitLab