Skip to content

Commit d94894f

Browse files
authored
pre-release updates (#27)
* 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 <[email protected]> Date: Wed Oct 30 17:10:58 2024 -0600 comment updates commit 623332e4cd011dd0016f209bde1ada19c2a99335 Author: Seth Bryant <[email protected]> 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
1 parent 089f0f5 commit d94894f

34 files changed

+870
-330
lines changed

README.md

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Documentation Status](https://readthedocs.org/projects/cancurve/badge/?version=latest)](https://cancurve.readthedocs.io/en/latest/?badge=latest)
2+
13
# CanCurve
24
CanCurve is an open-source tool for developing flood depth-damage (stage-damage) functions for use flood assessments.
35
<p> <em>It is presently undergoing evaluation and validation. </em></p>
@@ -8,26 +10,18 @@ CanCurve is an open-source tool for developing flood depth-damage (stage-damage)
810

911

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

1518

1619
## Documentation
17-
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.
18-
## Background
19-
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.
20-
<p>
21-
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.
22-
<p></p>
23-
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.
24-
<p></p>
25-
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.
26-
<p></p>
20+
Project documentation is [here](https://cancurve.readthedocs.io/en/latest/)
2721

2822

2923
## Installing for the first time
30-
- Install [QGIS 3.34.5](https://download.qgis.org/downloads/) (with Qt 5.15.13)
24+
- Install [QGIS 3.34.12](https://download.qgis.org/downloads/) (with Qt 5.15.13)
3125
- download the `cancurve.zip` file from the latest release to your local machine
3226
- in QGIS, `Manage and Install Plugins...` > `Install from ZIP` > select the downloaded file
3327
- it is recommended to also install the **First Aid** plugin for more detailed error messages.

cancurve/bldgs/assertions.py

+37-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
expected_tables_base = ['project_meta','project_settings','c00_bldg_meta', 'c00_cost_items','c00_drf']
1616

1717

18+
19+
#===============================================================================
20+
# helpers--------
21+
#===============================================================================
22+
def _assert_sqlite_table_exists(conn, table_name):
23+
cursor = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table_name, ))
24+
result = cursor.fetchone()
25+
if not result:
26+
raise AssertionError(f"Table '{table_name}' not found in database") # Check if DRF table exists
27+
28+
1829
def assert_ci_df(df, msg=''):
1930
"""
2031
Asserts that the provided DataFrame conforms to CI data expectations.
@@ -100,21 +111,23 @@ def assert_proj_db(conn,
100111

101112

102113
#===============================================================================
103-
# DRF database
114+
# DRF database-------
104115
#===============================================================================
105-
def assert_drf_db(conn, table_name='drf'):
106-
"""check the drf database meets expectations"""
107116

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

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

119+
120+
def assert_drf_db(conn):
121+
"""check the drf database meets expectations"""
122+
123+
try:
124+
_assert_sqlite_table_exists(conn, 'drf')
125+
_assert_sqlite_table_exists(conn, 'depths')
126+
127+
128+
116129
except sqlite3.Error as e:
117-
raise AssertionError(f"Error checking database': {e}")
130+
raise AssertionError(f"MasterRuleBook failed expectation check\n {e}")
118131

119132

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

165+
def assert_mrb_depths_df(df):
166+
167+
# Check if it's a DataFrame
168+
if not isinstance(df, pd.DataFrame):
169+
raise TypeError("Input must be a Pandas DataFrame")
170+
171+
# Check index
172+
if not set(df.index.names).difference(['meters', 'feet']) == set():
173+
raise KeyError("Incorrect index names in DataFrame")
174+
175+
152176
def assert_bldg_meta_d(bldg_meta, msg=''):
153177
"""check the bldg_meta_d meets expectations"""
154178

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

191-
215+
#===============================================================================
216+
# MISC-----------
217+
#===============================================================================
192218

193219
def assert_CanFlood_ddf(df, msg=''):
194220
from cancurve.bldgs.core import DFunc

cancurve/bldgs/bldg_meta_rqmts.csv

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
,,tag,str,FALSE,TRUE,?,,test_case1,test_case2,heather_0509,R_2-L-BD-CU_ABCA,R_1-L-C-ST_ABCA
33
,currency,impact_units,str,FALSE,TRUE,$CAD,currency_ComboBox,,,,,
44
,costBasis,impact_var,str,FALSE,FALSE,damage,costBasis_ComboBox,,,Depreciated Costs,,
5-
,,exposure_units,str,FALSE,FALSE,m,comboBox_tab3dataInput_expoUnits,,,,,
5+
expo_units,expoUnits,exposure_units,str,FALSE,FALSE,meters,basementHeightUnits_label,meters,meters,meters,feet,meters
66
,,exposure_var,str,FALSE,FALSE,flood depth above floor,,,,,,
77
,,scale_var,str,FALSE,FALSE,building footprint,,,,,,
88
bldg_layout,buildingLayout,,str,TRUE,FALSE,,buildingLayout_ComboBox,default,default,default,default,
9-
,basementHeight,,float,FALSE,FALSE,,basementHeight_DoubleSpinBox,1.8,2.1,0,2.7,0
10-
,basementHeightUnits,,str,FALSE,FALSE,,basementHeightUnits_ComboBox,m,m,m,m,m
11-
basement_height_m,,,float,TRUE,FALSE,,,1.8,2.1,0,2.7,0
9+
basement_height,basementHeight,,float,FALSE,FALSE,,basementHeight_DoubleSpinBox,1.8,2.1,0,10,0
1210
,sizeOrAreaValue,,float,FALSE,FALSE,,sizeOrAreaValue_DoubleSpinBox,232.1,232.2,344,139,232
1311
,sizeOrAreaUnits,scale_units,str,FALSE,FALSE,m2,sizeOrAreaUnits_ComboBox,m2,m2,m2,m2,m2
1412
scale_value_m2,,,float,TRUE,FALSE,,,232.1,232.2,344,139,232

0 commit comments

Comments
 (0)