Skip to content

Commit

Permalink
pre-release updates (#27)
Browse files Browse the repository at this point in the history
* 24 functionrole of exposure units by drf (#26)

* separate depths table for mrb

* update mrb

* add depths column name joining

* exposure unit harmonization working on backend

* fix ui test parameter handling

* add exposure units to plots

* fix labels

* add units section to documentation

* Squashed commit of the following:

commit d4fb374a6eebc67faa4d4f5b1b1ff1b5ebc0a6f5
Author: Seth Bryant <bryant.seth@gmail.com>
Date:   Wed Oct 30 17:10:58 2024 -0600

    comment updates

commit 623332e4cd011dd0016f209bde1ada19c2a99335
Author: Seth Bryant <bryant.seth@gmail.com>
Date:   Wed Oct 30 10:26:03 2024 -0600

    lint fixes

* fix 'storys'

* documentation tweaks

* update to 3.34.12

* Update README.md

rtd badge
  • Loading branch information
cefect authored Oct 31, 2024
1 parent 089f0f5 commit d94894f
Show file tree
Hide file tree
Showing 34 changed files with 870 additions and 330 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Documentation Status](https://readthedocs.org/projects/cancurve/badge/?version=latest)](https://cancurve.readthedocs.io/en/latest/?badge=latest)

# CanCurve
CanCurve is an open-source tool for developing flood depth-damage (stage-damage) functions for use flood assessments.
<p> <em>It is presently undergoing evaluation and validation. </em></p>
Expand All @@ -8,26 +10,18 @@ CanCurve is an open-source tool for developing flood depth-damage (stage-damage)


## Updates
- 2024-10-31: add sphinx documentation. improve treatment of units. update to QGIS 3.34.12 v1.0.0.
- 2024-08-22: priority A and B fixes [v0.1.0](https://github.com/NRCan/CanCurve/releases/tag/v0.1.0)
- 2024-05-09: small fixes and updates based on initial comments
- 2024-05-01: initial working release (un tested) [v0.0.1](https://github.com/NRCan/CanCurve/releases/tag/v0.0.1)


## Documentation
CanCurve is an open-source tool which can be used to create depth-damage (stage-damage) functions for use in flood loss estimation and flood risk assessments.
## Background
In Canada, a limited number of developed damage functions are available to support flood risk assessments. The existing functions lack a standardized process, and the underlying algorithms and data to derive them are unclear, making them a bit of a ‘black box.’ Additionally, transferability from one region to another can be challenging.
<p>
Previous work in 2023 explored the development of a framework for developing depth damage functions. This work resulted in a synthesis of the existing methods being used in Canada to develop depth damage functions. Additionally, it included some details on work done internationally. Several limitations to existing approaches were identified, and a novel and more transparent way to develop depth damage curves was proposed.
<p></p>
CanCurve uses room component replacement costs to generate Depth Damage Functions (DDF) from detailed restoration cost data. This approach allows for a clearer understanding of the contributing components to the overall losses experienced during a flood event. The tool joins cost data to a database of item vulnerability. Then, it groups the data by water depth to create a simple function for flood damage against flood depth.
<p></p>
The tool also allows users to aggregate data using pivot tables to view items, rooms, and damage estimates at various levels of aggregation. This added flexibility and transparency will provide users with a better understanding of the DDF data used in the calculation, allowing for more informed decisions on the applicability of curves to use and allow for easier translation for use in other regions.
<p></p>
Project documentation is [here](https://cancurve.readthedocs.io/en/latest/)


## Installing for the first time
- Install [QGIS 3.34.5](https://download.qgis.org/downloads/) (with Qt 5.15.13)
- Install [QGIS 3.34.12](https://download.qgis.org/downloads/) (with Qt 5.15.13)
- download the `cancurve.zip` file from the latest release to your local machine
- in QGIS, `Manage and Install Plugins...` > `Install from ZIP` > select the downloaded file
- it is recommended to also install the **First Aid** plugin for more detailed error messages.
Expand Down
48 changes: 37 additions & 11 deletions cancurve/bldgs/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
expected_tables_base = ['project_meta','project_settings','c00_bldg_meta', 'c00_cost_items','c00_drf']



#===============================================================================
# helpers--------
#===============================================================================
def _assert_sqlite_table_exists(conn, table_name):
cursor = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table_name, ))
result = cursor.fetchone()
if not result:
raise AssertionError(f"Table '{table_name}' not found in database") # Check if DRF table exists


def assert_ci_df(df, msg=''):
"""
Asserts that the provided DataFrame conforms to CI data expectations.
Expand Down Expand Up @@ -100,21 +111,23 @@ def assert_proj_db(conn,


#===============================================================================
# DRF database
# DRF database-------
#===============================================================================
def assert_drf_db(conn, table_name='drf'):
"""check the drf database meets expectations"""

try:
# Check if the table exists
cursor = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table_name,))
result = cursor.fetchone()

if not result:
raise AssertionError(f"Table '{table_name}' not found in database")


def assert_drf_db(conn):
"""check the drf database meets expectations"""

try:
_assert_sqlite_table_exists(conn, 'drf')
_assert_sqlite_table_exists(conn, 'depths')



except sqlite3.Error as e:
raise AssertionError(f"Error checking database': {e}")
raise AssertionError(f"MasterRuleBook failed expectation check\n {e}")


def assert_drf_df(df):
Expand Down Expand Up @@ -149,6 +162,17 @@ def assert_drf_df(df):
if not 'float' in df[col].dtype.name: # Assuming you want specifically float64
raise TypeError(f'DRF column \'{col}\' ({i}) expected as dtype float. instead got \'{df[col].dtype}\'')

def assert_mrb_depths_df(df):

# Check if it's a DataFrame
if not isinstance(df, pd.DataFrame):
raise TypeError("Input must be a Pandas DataFrame")

# Check index
if not set(df.index.names).difference(['meters', 'feet']) == set():
raise KeyError("Incorrect index names in DataFrame")


def assert_bldg_meta_d(bldg_meta, msg=''):
"""check the bldg_meta_d meets expectations"""

Expand Down Expand Up @@ -188,7 +212,9 @@ def assert_fixed_costs_d(d, msg=''):
raise TypeError(k)
assert v>=0


#===============================================================================
# MISC-----------
#===============================================================================

def assert_CanFlood_ddf(df, msg=''):
from cancurve.bldgs.core import DFunc
Expand Down
6 changes: 2 additions & 4 deletions cancurve/bldgs/bldg_meta_rqmts.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
,,tag,str,FALSE,TRUE,?,,test_case1,test_case2,heather_0509,R_2-L-BD-CU_ABCA,R_1-L-C-ST_ABCA
,currency,impact_units,str,FALSE,TRUE,$CAD,currency_ComboBox,,,,,
,costBasis,impact_var,str,FALSE,FALSE,damage,costBasis_ComboBox,,,Depreciated Costs,,
,,exposure_units,str,FALSE,FALSE,m,comboBox_tab3dataInput_expoUnits,,,,,
expo_units,expoUnits,exposure_units,str,FALSE,FALSE,meters,basementHeightUnits_label,meters,meters,meters,feet,meters
,,exposure_var,str,FALSE,FALSE,flood depth above floor,,,,,,
,,scale_var,str,FALSE,FALSE,building footprint,,,,,,
bldg_layout,buildingLayout,,str,TRUE,FALSE,,buildingLayout_ComboBox,default,default,default,default,
,basementHeight,,float,FALSE,FALSE,,basementHeight_DoubleSpinBox,1.8,2.1,0,2.7,0
,basementHeightUnits,,str,FALSE,FALSE,,basementHeightUnits_ComboBox,m,m,m,m,m
basement_height_m,,,float,TRUE,FALSE,,,1.8,2.1,0,2.7,0
basement_height,basementHeight,,float,FALSE,FALSE,,basementHeight_DoubleSpinBox,1.8,2.1,0,10,0
,sizeOrAreaValue,,float,FALSE,FALSE,,sizeOrAreaValue_DoubleSpinBox,232.1,232.2,344,139,232
,sizeOrAreaUnits,scale_units,str,FALSE,FALSE,m2,sizeOrAreaUnits_ComboBox,m2,m2,m2,m2,m2
scale_value_m2,,,float,TRUE,FALSE,,,232.1,232.2,344,139,232
Expand Down
Loading

0 comments on commit d94894f

Please sign in to comment.