diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f84f562..f1fdee64f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Changed +- Rename Building Portfolio Analysis to Building Cluster Recovery Analysis [#559](https://github.com/IN-CORE/pyincore/issues/559) + + ## [1.18.1] - 2024-04-30 ### Changed diff --git a/pyincore/analyses/buildingclusterrecovery/__init__.py b/pyincore/analyses/buildingclusterrecovery/__init__.py new file mode 100644 index 000000000..863b9caf1 --- /dev/null +++ b/pyincore/analyses/buildingclusterrecovery/__init__.py @@ -0,0 +1,10 @@ +# Copyright (c) 2018 University of Illinois and others. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Mozilla Public License v2.0 which accompanies this distribution, +# and is available at https://www.mozilla.org/en-US/MPL/2.0/ + + +from pyincore.analyses.buildingclusterrecovery.buildingclusterrecovery import BuildingClusterRecovery +from pyincore.analyses.buildingclusterrecovery.buildingdamage import BuildingDamage +from pyincore.analyses.buildingclusterrecovery.buildingdata import BuildingData diff --git a/pyincore/analyses/buildingportfolio/BuildingPortfolioRecoveryAnalysis.py b/pyincore/analyses/buildingclusterrecovery/buildingclusterrecovery.py similarity index 97% rename from pyincore/analyses/buildingportfolio/BuildingPortfolioRecoveryAnalysis.py rename to pyincore/analyses/buildingclusterrecovery/buildingclusterrecovery.py index 81f8d9a7b..82e9ca9cc 100644 --- a/pyincore/analyses/buildingportfolio/BuildingPortfolioRecoveryAnalysis.py +++ b/pyincore/analyses/buildingclusterrecovery/buildingclusterrecovery.py @@ -1,3 +1,5 @@ +# Copyright (c) 2018 University of Illinois and others. All rights reserved. +# # This program and the accompanying materials are made available under the # terms of the Mozilla Public License v2.0 which accompanies this distribution, # and is available at https://www.mozilla.org/en-US/MPL/2.0/ @@ -10,11 +12,11 @@ import scipy.stats import concurrent.futures -from pyincore.analyses.buildingportfolio.BuildingData import BuildingData +from pyincore.analyses.buildingclusterrecovery.buildingdata import BuildingData from pyincore import BaseAnalysis, Dataset -class BuildingPortfolioRecoveryAnalysis(BaseAnalysis): +class BuildingClusterRecovery(BaseAnalysis): """The Building Portfolio Recovery analysis uses damage probabilities of structural components, nonstructural drift-sensitive components, and nonstructural acceleration-sensitive components to calculate building’s initial functionality loss. @@ -24,12 +26,12 @@ class BuildingPortfolioRecoveryAnalysis(BaseAnalysis): """ def __init__(self, incore_client): - super(BuildingPortfolioRecoveryAnalysis, self).__init__(incore_client) + super(BuildingClusterRecovery, self).__init__(incore_client) def get_spec(self): return { - 'name': 'building-portfolio-damage-analysis', - 'description': 'Building Portfolio Damage Analysis (with uncertainty)', + 'name': 'building-cluster-recovery-analysis', + 'description': 'Building Cluster Recovery Analysis (with uncertainty)', 'input_parameters': [ { 'id': 'result_name', @@ -116,9 +118,9 @@ def get_spec(self): 'output_datasets': [ { 'id': 'result', - 'parent_type': 'buildingPortfolio', - 'description': 'Building portfolio recovery result.', - 'type': 'incore:portfolioRecovery' + 'parent_type': 'buildingClusterRecovery', + 'description': 'Building cluster recovery result.', + 'type': 'incore:clusterRecovery' } ] } @@ -343,7 +345,7 @@ def run(self): upper_bound95[t] = 1 # END: Additional Code for uncertainty Analysis - with open(output_base_name + '_portfolio-recovery.csv', 'w+', newline='') as output_file: + with open(output_base_name + '_cluster-recovery.csv', 'w+', newline='') as output_file: spam_writer = csv.writer(output_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) spam_writer.writerow(['Week', 'Recovery_Percent_Func_Probability', '75P_Upper_Bound', '75P_Lower_Bound', '95P_Upper_Bound', '95P_Lower_Bound', @@ -354,14 +356,14 @@ def run(self): lower_bound95[i], upper_bound95[i]] + list(mean_recovery[i]) + [pdf[i]]) else: - with open(output_base_name + '_portfolio-recovery.csv', 'w+', newline='') as output_file: + with open(output_base_name + '_cluster-recovery.csv', 'w+', newline='') as output_file: spam_writer = csv.writer(output_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) spam_writer.writerow(['Week', 'Recovery_Percent_Func_Probability', 'RecPercent_RE', 'RecPercent_RU', 'RecPercent_RO', 'RecPercent_BF', 'RecPercent_FF']) for i in range(time_steps): spam_writer.writerow([i + 1, mean_recovery_output[i]] + list(mean_recovery[i])) - self.set_output_dataset("result", Dataset.from_file(output_base_name + '_portfolio-recovery.csv', + self.set_output_dataset("result", Dataset.from_file(output_base_name + '_cluster-recovery.csv', data_type=self.output_datasets["result"]["spec"]["type"])) print("INFO: Finished executing Building Portfolio Recovery Analysis") diff --git a/pyincore/analyses/buildingportfolio/BuildingDamage.py b/pyincore/analyses/buildingclusterrecovery/buildingdamage.py similarity index 62% rename from pyincore/analyses/buildingportfolio/BuildingDamage.py rename to pyincore/analyses/buildingclusterrecovery/buildingdamage.py index 11003dd47..fe4ec4c72 100644 --- a/pyincore/analyses/buildingportfolio/BuildingDamage.py +++ b/pyincore/analyses/buildingclusterrecovery/buildingdamage.py @@ -1,3 +1,10 @@ +# Copyright (c) 2018 University of Illinois and others. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Mozilla Public License v2.0 which accompanies this distribution, +# and is available at https://www.mozilla.org/en-US/MPL/2.0/ + + class BuildingDamage(object): def __init__(self, distance_to_center, restricted_entry, restricted_use, reoccupancy, best_line_functionality, diff --git a/pyincore/analyses/buildingportfolio/BuildingData.py b/pyincore/analyses/buildingclusterrecovery/buildingdata.py similarity index 69% rename from pyincore/analyses/buildingportfolio/BuildingData.py rename to pyincore/analyses/buildingclusterrecovery/buildingdata.py index 9695e78f8..cbd5b0e46 100644 --- a/pyincore/analyses/buildingportfolio/BuildingData.py +++ b/pyincore/analyses/buildingclusterrecovery/buildingdata.py @@ -1,3 +1,10 @@ +# Copyright (c) 2018 University of Illinois and others. All rights reserved. +# +# This program and the accompanying materials are made available under the +# terms of the Mozilla Public License v2.0 which accompanies this distribution, +# and is available at https://www.mozilla.org/en-US/MPL/2.0/ + + class BuildingData: def __init__(self, tract_id, lon, lat, structural, code_level, epsa_node_id, pwsa_node_id, tep_id, build_id_x, epsa_id, pwsa_id, finance, ep_pw_id, occupation_code): diff --git a/pyincore/analyses/buildingportfolio/__init__.py b/pyincore/analyses/buildingportfolio/__init__.py deleted file mode 100644 index 8ef9ff126..000000000 --- a/pyincore/analyses/buildingportfolio/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from pyincore.analyses.buildingportfolio.BuildingPortfolioRecoveryAnalysis import BuildingPortfolioRecoveryAnalysis -from pyincore.analyses.buildingportfolio.BuildingDamage import BuildingDamage -from pyincore.analyses.buildingportfolio.BuildingData import BuildingData diff --git a/tests/pyincore/analyses/buildingclusterrecovery/test_buildingclusterrecovery.py b/tests/pyincore/analyses/buildingclusterrecovery/test_buildingclusterrecovery.py new file mode 100644 index 000000000..b079819ff --- /dev/null +++ b/tests/pyincore/analyses/buildingclusterrecovery/test_buildingclusterrecovery.py @@ -0,0 +1,43 @@ +# This program and the accompanying materials are made available under the +# terms of the Mozilla Public License v2.0 which accompanies this distribution, +# and is available at https://www.mozilla.org/en-US/MPL/2.0/ + + +from pyincore.analyses.buildingclusterrecovery import BuildingClusterRecovery +from pyincore import IncoreClient +import pyincore.globals as pyglobals + +if __name__ == "__main__": + cred = None + try: + client = IncoreClient(pyglobals.INCORE_API_PROD_URL) + bldg_data_dataset = "5c756966c11bb369a33a0b0a" + occupancy_dataset = "5c7569f9c11bb369a33a0b16" + bldg_damage_dataset = "5c756a2fc11bb369a33a0b22" + mean_repair_dataset = "5c756ac5c11bb369a33a0b34" + utility_dataset = "5c756af4c11bb369a33a0b40" + utility_partial_dataset = "5c756b1ec11bb369a33a0b4c" + coefFL_dataset = "5c756b56c11bb369a33a0b58" + + bldg_cluster_recovery = BuildingClusterRecovery(client) + bldg_cluster_recovery.set_parameter("uncertainty", True) + bldg_cluster_recovery.set_parameter("sample_size", 35) # default none. Gets size form input dataset + bldg_cluster_recovery.set_parameter("random_sample_size", 50) # default 10000 + bldg_cluster_recovery.set_parameter("no_of_weeks", 100) # default 250 + bldg_cluster_recovery.set_parameter("num_cpu", 1) + bldg_cluster_recovery.set_parameter("result_name", "memphis") + + bldg_cluster_recovery.load_remote_input_dataset("building_data", bldg_data_dataset) + bldg_cluster_recovery.load_remote_input_dataset("occupancy_mapping", occupancy_dataset) + bldg_cluster_recovery.load_remote_input_dataset("building_damage", bldg_damage_dataset) + bldg_cluster_recovery.load_remote_input_dataset("dmg_ratios", mean_repair_dataset) + bldg_cluster_recovery.load_remote_input_dataset("utility", utility_dataset) + bldg_cluster_recovery.load_remote_input_dataset("utility_partial", utility_partial_dataset) + bldg_cluster_recovery.load_remote_input_dataset("coefFL", coefFL_dataset) + + bldg_cluster_recovery.run_analysis() + print(bldg_cluster_recovery.get_output_dataset("result").get_dataframe_from_csv().head()) + + except EnvironmentError: + raise + # traceback.print_exc() diff --git a/tests/pyincore/analyses/buildingportfolio/test_buildingportfolio.py b/tests/pyincore/analyses/buildingportfolio/test_buildingportfolio.py deleted file mode 100644 index 761d5d38c..000000000 --- a/tests/pyincore/analyses/buildingportfolio/test_buildingportfolio.py +++ /dev/null @@ -1,43 +0,0 @@ -# This program and the accompanying materials are made available under the -# terms of the Mozilla Public License v2.0 which accompanies this distribution, -# and is available at https://www.mozilla.org/en-US/MPL/2.0/ - - -from pyincore.analyses.buildingportfolio import BuildingPortfolioRecoveryAnalysis -from pyincore import IncoreClient -import pyincore.globals as pyglobals - -if __name__ == "__main__": - cred = None - try: - client = IncoreClient(pyglobals.INCORE_API_PROD_URL) - bldg_data_dataset = "5c756966c11bb369a33a0b0a" - occupancy_dataset = "5c7569f9c11bb369a33a0b16" - bldg_damage_dataset = "5c756a2fc11bb369a33a0b22" - mean_repair_dataset = "5c756ac5c11bb369a33a0b34" - utility_dataset = "5c756af4c11bb369a33a0b40" - utility_partial_dataset = "5c756b1ec11bb369a33a0b4c" - coefFL_dataset = "5c756b56c11bb369a33a0b58" - - bldg_portfolio_recovery = BuildingPortfolioRecoveryAnalysis(client) - bldg_portfolio_recovery.set_parameter("uncertainty", True) - bldg_portfolio_recovery.set_parameter("sample_size", 35) # default none. Gets size form input dataset - bldg_portfolio_recovery.set_parameter("random_sample_size", 50) # default 10000 - bldg_portfolio_recovery.set_parameter("no_of_weeks", 100) # default 250 - bldg_portfolio_recovery.set_parameter("num_cpu", 1) - bldg_portfolio_recovery.set_parameter("result_name", "memphis") - - bldg_portfolio_recovery.load_remote_input_dataset("building_data", bldg_data_dataset) - bldg_portfolio_recovery.load_remote_input_dataset("occupancy_mapping", occupancy_dataset) - bldg_portfolio_recovery.load_remote_input_dataset("building_damage", bldg_damage_dataset) - bldg_portfolio_recovery.load_remote_input_dataset("dmg_ratios", mean_repair_dataset) - bldg_portfolio_recovery.load_remote_input_dataset("utility", utility_dataset) - bldg_portfolio_recovery.load_remote_input_dataset("utility_partial", utility_partial_dataset) - bldg_portfolio_recovery.load_remote_input_dataset("coefFL", coefFL_dataset) - - bldg_portfolio_recovery.run_analysis() - print(bldg_portfolio_recovery.get_output_dataset("result").get_dataframe_from_csv().head()) - - except EnvironmentError: - raise - # traceback.print_exc()