Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

86 sensitivity analysis sampling #97

Merged
merged 72 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
91bd1eb
Initial commit
barneydobson Mar 16, 2024
e68530e
Update test_swmmanywhere.py
barneydobson Mar 16, 2024
6d9f7fb
Update test_swmmanywhere.py
barneydobson Mar 16, 2024
48e8863
Create test_experimenter.py
barneydobson Mar 16, 2024
4f070f7
Update test_experimenter.py
barneydobson Mar 16, 2024
9a7355e
Merge branch 'main' into 86-sensitivity-analysis-sampling
Mar 18, 2024
5e2459b
Merge branch 'main' into 86-sensitivity-analysis-sampling
Mar 18, 2024
8af45bd
Merge branch 'fix-geometries' into 86-sensitivity-analysis-sampling
Mar 18, 2024
4c0d958
Merge branch '51-gridded-metrics' into 86-sensitivity-analysis-sampling
Mar 18, 2024
f1a69b0
Merge branch '91-design-output-metrics-as-in-metrics-for-the-networks…
Mar 18, 2024
e349f48
Update swmmanywhere.py
Mar 18, 2024
2d936c3
Merge branch 'main' into 86-sensitivity-analysis-sampling
Mar 18, 2024
5206bc4
Merge verbosity
Mar 18, 2024
c2f4d90
Update test_metric_utilities.py
Mar 18, 2024
61bf093
typo
Mar 18, 2024
93cac80
Update graph_utilities.py
Mar 18, 2024
8663bb2
Use design storm
Mar 19, 2024
c11a10a
Update metric_utilities.py
Mar 19, 2024
db9585d
Update swmmanywhere.py
Mar 19, 2024
88eb5f3
Update pyproject.toml
Mar 19, 2024
c688a4c
Revert "Update metric_utilities.py"
Mar 19, 2024
ff69382
Update metric_utilities.py
Mar 19, 2024
6113088
Update metric_utilities.py
Mar 19, 2024
692b46d
redo fixes
Mar 19, 2024
6f6ffea
update for new storm
Mar 19, 2024
9588122
Update schema.yml
Mar 19, 2024
790bcb2
Update metric_utilities.py
Mar 19, 2024
7f28274
Update experimenter.py
Mar 19, 2024
6a26247
Update to new experimenter
Mar 19, 2024
b864338
Merge branch '86-sensitivity-analysis-sampling' of https://github.com…
Mar 19, 2024
f009c39
log
Mar 19, 2024
4b82b23
Update experimenter.py
Mar 19, 2024
484ca89
Update metric_utilities.py
Mar 19, 2024
d8d2b99
Update experimenter.py
Mar 19, 2024
469a9ff
Update experimenter.py
Mar 19, 2024
d12530e
Update test_graph_utilities.py
Mar 19, 2024
4f2c1c7
move numba stuff to geospatial
Mar 19, 2024
af58539
Update graph_utilities.py
Mar 19, 2024
e4a38e5
Undo that, didn't seem to work
Mar 19, 2024
9046178
Merge branch 'main' into 86-sensitivity-analysis-sampling
Mar 20, 2024
2103147
Update experimenter.py
Mar 20, 2024
1496d9d
allow set model_number
Mar 20, 2024
e4f9c06
handle model number in create_project_structure
Mar 21, 2024
36a074a
Update experimenter.py
Mar 21, 2024
e9e742e
lock the bounding box file to prevent json error
Mar 21, 2024
57dddaa
Merge branch '7-downloader-mock' into 86-sensitivity-analysis-sampling
Mar 21, 2024
50164e4
Revert "lock the bounding box file to prevent json error"
Mar 21, 2024
aa24eb6
Update preprocessing.py
Mar 21, 2024
0c627b7
merge
Mar 25, 2024
841f519
Update experimenter.py
Mar 25, 2024
f02c1f1
Update experimenter.py
Mar 25, 2024
5bf2f4e
Update experimenter.py
barneydobson Mar 25, 2024
8679c56
Update swmmanywhere/paper/experimenter.py
barneydobson Mar 26, 2024
f26ce5d
Update experimenter.py
barneydobson Mar 26, 2024
2ab1373
Merge branch '86-sensitivity-analysis-sampling' of https://github.com…
barneydobson Mar 26, 2024
e014ef7
Update experimenter.py
barneydobson Mar 26, 2024
0a85214
Update swmmanywhere.py
barneydobson Mar 26, 2024
649b635
Update swmmanywhere.py
barneydobson Mar 26, 2024
c710cec
Update typing
barneydobson Mar 26, 2024
e7feb7a
Update graph_utilities.py
barneydobson Mar 26, 2024
edb8b64
Update geospatial_utilities.py
barneydobson Mar 26, 2024
c3a0bbb
Merge branch 'main' into 86-sensitivity-analysis-sampling
barneydobson Mar 26, 2024
1da3f6f
Update experimenter.py
barneydobson Apr 1, 2024
ac9726d
Update experimenter.py
barneydobson Apr 1, 2024
d91ef66
import future imports
barneydobson Apr 1, 2024
ca59f50
Update metric_utilities.py
barneydobson Apr 1, 2024
20852d3
Update experimenter.py
barneydobson Apr 1, 2024
f2b4890
Update experimenter.py
barneydobson Apr 1, 2024
7930b00
Update metric_utilities.py
barneydobson Apr 1, 2024
ec9d19b
Update graph_utilities.py
barneydobson Apr 1, 2024
ac43542
Update experimenter.py
barneydobson Apr 1, 2024
3f8e89b
Merge branch 'main' into 86-sensitivity-analysis-sampling
barneydobson Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dependencies = [
# TODO definitely don't need all of these
"cdsapi",
"cytoolz",
"fastparquet",
Expand All @@ -37,7 +36,7 @@ dependencies = [
"matplotlib",
"netcdf4",
"netcomp@ git+https://github.com/barneydobson/NetComp.git",
"networkx",
"networkx>=3",
"numpy",
"osmnx",
"pandas",
Expand Down Expand Up @@ -90,6 +89,9 @@ select = ["D", "E", "F", "I"] # pydocstyle, pycodestyle, Pyflakes, isort
[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

[tool.codespell]
skip = "swmmanywhere/defs/iso_converter.yml,*.inp"
ignore-words-list = "gage,gages"
Expand Down
2 changes: 2 additions & 0 deletions swmmanywhere/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
"""The main module for MyProject."""
from __future__ import annotations

__version__ = "0.1.0"
8 changes: 4 additions & 4 deletions swmmanywhere/defs/basic_drainage_all_bits.inp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ MIN_SLOPE 0
ALLOW_PONDING NO
SKIP_STEADY_STATE NO

START_DATE 10/03/2020
START_DATE 01/01/2000
START_TIME 00:00:00
REPORT_START_DATE 10/03/2020
REPORT_START_DATE 01/01/2000
REPORT_START_TIME 00:00:00
END_DATE 10/08/2020
END_TIME 00:00:00
END_DATE 01/02/2000
END_TIME 23:59:00
SWEEP_START 1/1
SWEEP_END 12/31
DRY_DAYS 0
Expand Down
5 changes: 4 additions & 1 deletion swmmanywhere/defs/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ properties:
project: {type: string}
bbox: {type: array, items: {type: number}, minItems: 4, maxItems: 4}
api_keys: {type: string}
model_number: {type: integer}
run_settings:
type: object
properties:
Expand All @@ -17,7 +18,7 @@ properties:
real:
type: ['object', 'null']
properties:
inp: {type: string}
inp: {type: ['string', 'null']}
graph: {type: string}
subcatchments: {type: string}
results: {type: ['string', 'null']}
Expand All @@ -30,4 +31,6 @@ properties:
metric_list: {type: array, items: {type: string}}
address_overrides: {type: ['object', 'null']}
parameter_overrides: {type: ['object', 'null']}
parameters_to_sample: {type: ['array', 'null']}
sample_magnitude: {type: ['integer', 'null']}
required: [base_dir, project, bbox, api_keys, graphfcn_list]
149 changes: 5 additions & 144 deletions swmmanywhere/defs/storm.dat
Original file line number Diff line number Diff line change
@@ -1,144 +1,5 @@
1 2020 10 03 00 00 0.06383868499999999
1 2020 10 03 01 00 0.041554296
1 2020 10 03 02 00 0.05283641
1 2020 10 03 03 00 0.06305583499999999
1 2020 10 03 04 00 0.0631444
1 2020 10 03 05 00 0.025762885
1 2020 10 03 06 00 0.015543459999999999
1 2020 10 03 07 00 0.002143075
1 2020 10 03 08 00 0.0005809343000000001
1 2020 10 03 09 00 0.00029047078
1 2020 10 03 10 00 7.275957999999999e-09
1 2020 10 03 11 00 7.275957999999999e-09
1 2020 10 03 12 00 7.275957999999999e-09
1 2020 10 03 13 00 7.275957999999999e-09
1 2020 10 03 14 00 7.275957999999999e-09
1 2020 10 03 15 00 7.275957999999999e-09
1 2020 10 03 16 00 7.275957999999999e-09
1 2020 10 03 17 00 7.275957999999999e-09
1 2020 10 03 18 00 0.013442892
1 2020 10 03 19 00 0.05766097
1 2020 10 03 20 00 0.040084262
1 2020 10 03 21 00 0.0140769625
1 2020 10 03 22 00 0.012433353
1 2020 10 03 23 00 0.0035387275
1 2020 10 04 00 00 0.006939299
1 2020 10 04 01 00 0.004810397500000001
1 2020 10 04 02 00 0.0047572685
1 2020 10 04 03 00 0.007219139699999999
1 2020 10 04 04 00 0.0034714249
1 2020 10 04 05 00 0.0043428226
1 2020 10 04 06 00 0.006737391200000001
1 2020 10 04 07 00 7.275957999999999e-09
1 2020 10 04 08 00 7.275957999999999e-09
1 2020 10 04 09 00 7.275957999999999e-09
1 2020 10 04 10 00 0.0031667878
1 2020 10 04 11 00 0.011328164
1 2020 10 04 12 00 0.024292849999999998
1 2020 10 04 13 00 0.020297179
1 2020 10 04 14 00 0.022971587999999998
1 2020 10 04 15 00 0.023254965000000002
1 2020 10 04 16 00 0.026450084999999998
1 2020 10 04 17 00 0.02760841
1 2020 10 04 18 00 0.03214959
1 2020 10 04 19 00 0.13477959
1 2020 10 04 20 00 0.08938194000000001
1 2020 10 04 21 00 0.09367871
1 2020 10 04 22 00 0.07757912
1 2020 10 04 23 00 0.038086422
1 2020 10 05 00 00 0.0710649
1 2020 10 05 01 00 0.025242174
1 2020 10 05 02 00 0.019326595
1 2020 10 05 03 00 0.055535613
1 2020 10 05 04 00 0.025847905
1 2020 10 05 05 00 0.012900928
1 2020 10 05 06 00 0.0010201766
1 2020 10 05 07 00 0.00010981603
1 2020 10 05 08 00 7.275957999999999e-09
1 2020 10 05 09 00 7.275957999999999e-09
1 2020 10 05 10 00 7.275957999999999e-09
1 2020 10 05 11 00 0.0005809343000000001
1 2020 10 05 12 00 0.0005809343000000001
1 2020 10 05 13 00 0.0026885828
1 2020 10 05 14 00 0.009766023
1 2020 10 05 15 00 0.03863193
1 2020 10 05 16 00 0.018175357
1 2020 10 05 17 00 0.0071270406
1 2020 10 05 18 00 0.00036840356
1 2020 10 05 19 00 0.06358718399999999
1 2020 10 05 20 00 0.035277407999999996
1 2020 10 05 21 00 0.057979774
1 2020 10 05 22 00 0.06011222
1 2020 10 05 23 00 0.06900684
1 2020 10 06 00 00 0.07822027
1 2020 10 06 01 00 0.15135737999999999
1 2020 10 06 02 00 0.107465195
1 2020 10 06 03 00 0.08602388
1 2020 10 06 04 00 0.06740928
1 2020 10 06 05 00 0.0111085465
1 2020 10 06 06 00 0.0130497065
1 2020 10 06 07 00 0.0067621877
1 2020 10 06 08 00 0.0020120133
1 2020 10 06 09 00 0.0049308364
1 2020 10 06 10 00 0.008625414999999999
1 2020 10 06 11 00 0.010024611000000001
1 2020 10 06 12 00 0.019184903000000003
1 2020 10 06 13 00 0.015600133
1 2020 10 06 14 00 0.014664976
1 2020 10 06 15 00 0.028685259999999997
1 2020 10 06 16 00 0.099735975
1 2020 10 06 17 00 0.05485196
1 2020 10 06 18 00 0.06388118999999999
1 2020 10 06 19 00 0.08494349
1 2020 10 06 20 00 0.23213516
1 2020 10 06 21 00 0.09611933
1 2020 10 06 22 00 0.14322790000000002
1 2020 10 06 23 00 0.03817852
1 2020 10 07 00 00 0.014767706
1 2020 10 07 01 00 0.017080797999999998
1 2020 10 07 02 00 0.012560871
1 2020 10 07 03 00 0.020651401
1 2020 10 07 04 00 0.02854711
1 2020 10 07 05 00 0.028164540000000002
1 2020 10 07 06 00 0.020105894
1 2020 10 07 07 00 0.00052780524
1 2020 10 07 08 00 0.0014239921999999999
1 2020 10 07 09 00 0.0008253555
1 2020 10 07 10 00 0.007109331
1 2020 10 07 11 00 0.06388118999999999
1 2020 10 07 12 00 0.039464365
1 2020 10 07 13 00 0.025624737
1 2020 10 07 14 00 0.06524496
1 2020 10 07 15 00 0.08188297
1 2020 10 07 16 00 0.0747276
1 2020 10 07 17 00 0.04946063
1 2020 10 07 18 00 0.08798275
1 2020 10 07 19 00 0.019656029
1 2020 10 07 20 00 0.005929752700000001
1 2020 10 07 21 00 0.0019057406
1 2020 10 07 22 00 0.0037654318000000003
1 2020 10 07 23 00 0.0055011405
1 2020 10 08 00 00 0.010166303
1 2020 10 08 01 00 0.010956223999999999
1 2020 10 08 02 00 0.0071553804
1 2020 10 08 03 00 0.0034112018
1 2020 10 08 04 00 0.00032943353
1 2020 10 08 05 00 7.275957999999999e-09
1 2020 10 08 06 00 7.275957999999999e-09
1 2020 10 08 07 00 7.275957999999999e-09
1 2020 10 08 08 00 7.275957999999999e-09
1 2020 10 08 09 00 7.275957999999999e-09
1 2020 10 08 10 00 7.275957999999999e-09
1 2020 10 08 11 00 7.275957999999999e-09
1 2020 10 08 12 00 7.275957999999999e-09
1 2020 10 08 13 00 7.275957999999999e-09
1 2020 10 08 14 00 0.0019942962999999997
1 2020 10 08 15 00 0.017066632
1 2020 10 08 16 00 0.1024281
1 2020 10 08 17 00 0.09838992
1 2020 10 08 18 00 0.04274804
1 2020 10 08 19 00 0.013393306
1 2020 10 08 20 00 0.005975802
1 2020 10 08 21 00 0.0024016626
1 2020 10 08 22 00 0.01663802
1 2020 10 08 23 00 0.048688416
;File: "storm.dat"
1 2000 01 01 00 00 0.0
1 2000 01 01 00 05 28
1 2000 01 01 00 10 32
1 2000 01 01 00 15 3
12 changes: 10 additions & 2 deletions swmmanywhere/geospatial_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
A module containing functions to perform a variety of geospatial operations,
such as reprojecting coordinates and handling raster data.
"""
from __future__ import annotations

import itertools
import json
import math
Expand All @@ -25,6 +27,7 @@
from scipy.interpolate import RegularGridInterpolator
from shapely import geometry as sgeom
from shapely import ops as sops
from shapely.errors import GEOSException
from shapely.strtree import STRtree
from tqdm import tqdm

Expand Down Expand Up @@ -655,8 +658,13 @@ def derive_rc(polys_gdf: gpd.GeoDataFrame,
building_footprints[['geometry']],
how='union')
result = gpd.overlay(polys_gdf, result)

dissolved_result = result.dissolve(by='id').reset_index()
try:
dissolved_result = result.dissolve(by='id').reset_index()
except GEOSException:
# Temporary fix for bug:
# https://github.com/ImperialCollegeLondon/SWMManywhere/issues/115
result['geometry'] = result['geometry'].simplify(0.1)
dissolved_result = result.dissolve(by='id').reset_index()
dissolved_result['impervious_area'] = dissolved_result.geometry.area
polys_gdf = pd.merge(polys_gdf,
dissolved_result[['id','impervious_area']],
Expand Down
7 changes: 5 additions & 2 deletions swmmanywhere/graph_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
A module to contain graphfcns, the graphfcn registry object, and other graph
utilities (such as save/load functions).
"""
from __future__ import annotations

import json
import os
import tempfile
Expand Down Expand Up @@ -695,11 +697,12 @@ def __call__(self, G: nx.Graph,
bounds[w][1] = max(bounds[w][1], d.get(w, -np.Inf))

G = G.copy()
eps = np.finfo(float).eps
for u, v, d in G.edges(data=True):
total_weight = 0
for attr, bds in bounds.items():
# Normalise
weight = (d[attr] - bds[0]) / (bds[1] - bds[0])
weight = max((d[attr] - bds[0]) / (bds[1] - bds[0]), eps)
# Exponent
weight = weight ** getattr(topology_derivation,f'{attr}_exponent')
# Scaling
Expand Down Expand Up @@ -845,7 +848,7 @@ def __call__(self, G: nx.Graph,

# Check for negative cycles
if nx.negative_edge_cycle(G, weight = 'weight'):
raise ValueError('Graph contains negative cycle')
logger.warning('Graph contains negative cycle')

# Initialize the dictionary with infinity for all nodes
shortest_paths = {node: float('inf') for node in G.nodes}
Expand Down
2 changes: 2 additions & 0 deletions swmmanywhere/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
>>> logger.add("file.log") # Add a log file # doctest: +SKIP
>>> os.environ["SWMMANYWHERE_VERBOSE"] = "false" # Disable logging
"""
from __future__ import annotations

import os
import sys

Expand Down
Loading