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

Decouple core elements #123

Merged
merged 46 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5a49b70
New utils progress
dalmijn Jul 8, 2024
4d90b63
Deleted
dalmijn Jul 11, 2024
632f364
Update checks for exposure decoupling
dalmijn Jul 11, 2024
ef2f3ec
Update I/O
dalmijn Jul 11, 2024
7d57a24
Further add exposure utils
dalmijn Jul 11, 2024
5b4ddbd
Decouple integrated pieces of code
dalmijn Jul 11, 2024
27088f4
Added new submodule
dalmijn Jul 11, 2024
e1ddb12
Update submodule name
dalmijn Jul 12, 2024
e407ea9
Add hidden import
dalmijn Jul 12, 2024
2b3ddfe
Update build gdal version, pin numpy version
dalmijn Jul 12, 2024
8e67f46
Quartodoc from conda
dalmijn Jul 12, 2024
405d4a2
Update init file
dalmijn Jul 12, 2024
5830483
Further separation of methods
dalmijn Jul 12, 2024
a98e272
Updated tests with refactoring
dalmijn Jul 12, 2024
a32bd93
Update testdata
dalmijn Jul 12, 2024
716c927
Removal op exposure table object, relying on tablelazy and workflow m…
dalmijn Jul 12, 2024
d7f2dc3
Update example index string
dalmijn Jul 12, 2024
9bd3c00
type change
dalmijn Jul 18, 2024
f5772cf
Some progress
dalmijn Jul 18, 2024
9b1b65f
Moved fields type map
dalmijn Jul 18, 2024
297fc91
Update GeomSource functionality
dalmijn Jul 18, 2024
695e49d
Add libgdal-netcdf as opt-dep
dalmijn Aug 12, 2024
e626395
Update env build
dalmijn Aug 12, 2024
dd710ea
Split geom drivers in read and write
dalmijn Aug 15, 2024
ccee0c1
Merge branch 'master' into decouple
dalmijn Aug 22, 2024
8564264
Merge branch 'master' into decouple
dalmijn Aug 26, 2024
a41201b
Driver not found error fix
dalmijn Aug 26, 2024
1e54b90
Fix map type
dalmijn Aug 26, 2024
7ad8129
Update quarto to v1.5.x, add working dark image
dalmijn Sep 2, 2024
7a02a95
Fix architecture error
dalmijn Sep 2, 2024
475b5c6
Merge branch 'master' into decouple
dalmijn Sep 17, 2024
9961103
Merge branch 'master' into decouple
dalmijn Sep 18, 2024
7f4f7b7
Renamed 'math' submodule to 'methods'
dalmijn Sep 18, 2024
c16bc89
Rename old geom file
dalmijn Sep 18, 2024
5e8c0e4
Small progress
dalmijn Sep 24, 2024
c3ff00f
Merge branch 'master' into decouple
dalmijn Sep 24, 2024
cdae4c5
Chunk differently
dalmijn Sep 27, 2024
65a5fc5
Rename add_feature methods
dalmijn Sep 27, 2024
5a5f577
First time running no csv workflow
dalmijn Sep 27, 2024
685f843
Improved locking and chunking
dalmijn Sep 28, 2024
3822228
Implemented risk, different exposure types
dalmijn Sep 30, 2024
61f17ac
f*ck if I know
dalmijn Oct 2, 2024
f7701f0
Removed unused object
dalmijn Oct 3, 2024
51f2448
Updated docs
dalmijn Oct 3, 2024
c5c65b6
Added reproject for hazard and exposure in gridmodel
dalmijn Oct 3, 2024
62dac57
Small docstring fix
dalmijn Oct 3, 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
2 changes: 1 addition & 1 deletion .build/build.spec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ a = Analysis(
pathex=[Path(build_dir), Path(project_root, "src")],
binaries=[],
datas=[],
hiddenimports=["fiat_build_time"],
hiddenimports=["fiat_build_time", "fiat.methods"],
hookspath=[build_dir.as_posix()],
hooksconfig={},
runtime_hooks=[Path(build_dir, 'runtime_hooks.py')],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
sudo apt install -y curl
sudo apt install -y gdebi-core
mkdir tmp
curl -L https://github.com/quarto-dev/quarto-cli/releases/download/v1.3.450/quarto-1.3.450-linux-amd64.deb --output tmp/quarto.deb
curl -L https://github.com/quarto-dev/quarto-cli/releases/download/v1.5.57/quarto-1.5.57-linux-amd64.deb --output tmp/quarto.deb
chmod +x tmp/quarto.deb
sudo gdebi -n tmp/quarto.deb

Expand Down
36 changes: 17 additions & 19 deletions .testdata/create_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def create_dbase_stucture():
def create_exposure_dbase():
"""_summary_."""
with open(Path(p, "exposure", "spatial.csv"), "w") as f:
f.write("Object ID,Extraction Method,Ground Floor Height,Ground Elevation,")
f.write("Damage Function: Structure,Max Potential Damage: Structure\n")
f.write("object_id,extract_method,ground_flht,ground_elevtn,")
f.write("fn_damage_structure,max_damage_structure\n")
for n in range(5):
if (n + 1) % 2 != 0:
dmc = "struct_1"
Expand Down Expand Up @@ -63,13 +63,13 @@ def create_exposure_geoms():
)

field = ogr.FieldDefn(
"Object ID",
"object_id",
ogr.OFTInteger,
)
layer.CreateField(field)

field = ogr.FieldDefn(
"ObjectName",
"object_name",
ogr.OFTString,
)
field.SetWidth(50)
Expand All @@ -78,8 +78,8 @@ def create_exposure_geoms():
for idx, geom in enumerate(geoms):
geom = ogr.CreateGeometryFromWkt(geom)
ft = ogr.Feature(layer.GetLayerDefn())
ft.SetField("Object ID", idx + 1)
ft.SetField("ObjectName", f"fp_{idx+1}")
ft.SetField("object_id", idx + 1)
ft.SetField("object_name", f"fp_{idx+1}")
ft.SetGeometry(geom)

layer.CreateFeature(ft)
Expand Down Expand Up @@ -110,22 +110,22 @@ def create_exposure_geoms_2():
)

field = ogr.FieldDefn(
"Object ID",
"object_id",
ogr.OFTInteger,
)
layer.CreateField(field)

field = ogr.FieldDefn(
"ObjectName",
"object_name",
ogr.OFTString,
)
field.SetWidth(50)
layer.CreateField(field)

geom = ogr.CreateGeometryFromWkt(geoms[0])
ft = ogr.Feature(layer.GetLayerDefn())
ft.SetField("Object ID", 5)
ft.SetField("ObjectName", f"fp_{5}")
ft.SetField("object_id", 5)
ft.SetField("object_name", f"fp_{5}")
ft.SetGeometry(geom)

layer.CreateFeature(ft)
Expand Down Expand Up @@ -158,22 +158,22 @@ def create_exposure_geoms_3():
)

field = ogr.FieldDefn(
"Object ID",
"object_id",
ogr.OFTInteger,
)
layer.CreateField(field)

field = ogr.FieldDefn(
"ObjectName",
"object_name",
ogr.OFTString,
)
field.SetWidth(50)
layer.CreateField(field)

geom = ogr.CreateGeometryFromWkt(geoms[0])
ft = ogr.Feature(layer.GetLayerDefn())
ft.SetField("Object ID", 5)
ft.SetField("ObjectName", f"fp_{5}")
ft.SetField("object_id", 5)
ft.SetField("object_name", f"fp_{5}")
ft.SetGeometry(geom)

layer.CreateFeature(ft)
Expand All @@ -182,8 +182,8 @@ def create_exposure_geoms_3():

geom = ogr.CreateGeometryFromWkt(geoms[1])
ft = ogr.Feature(layer.GetLayerDefn())
ft.SetField("Object ID", 6)
ft.SetField("ObjectName", f"fp_{6}")
ft.SetField("object_id", 6)
ft.SetField("object_name", f"fp_{6}")
ft.SetGeometry(geom)

layer.CreateFeature(ft)
Expand Down Expand Up @@ -226,7 +226,7 @@ def create_exposure_grid():
for x, y in product(oneD, oneD):
data[x, y] = 2000 + ((x + y) * 100)
band.WriteArray(data)
band.SetMetadataItem("damage_function", "struct_1")
band.SetMetadataItem("fn_damage", "struct_1")

band.FlushCache()
src.FlushCache()
Expand Down Expand Up @@ -325,7 +325,6 @@ def create_settings_geom():
doc = {
"global": {
"crs": "EPSG:4326",
"keep_temp_files": True,
},
"output": {
"path": "output/geom_event",
Expand Down Expand Up @@ -403,7 +402,6 @@ def create_settings_grid():
doc = {
"global": {
"crs": "EPSG:4326",
"keep_temp_files": True,
},
"output": {
"path": "output/grid_event",
Expand Down
12 changes: 6 additions & 6 deletions docs/PDF_Documentation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ damages per asset
[**exposure.geom**]
`csv`: This will create an exposure CSV file within the exposure folder ([folder strucute](index.qmd)) that contains the [required information](exposure.qmd) per asset.
`crs`: The projection of the exposure vector file.
`file1`: This will create an exposure vector file within the exposure folder with the assets'geometry and Object ID.
`file1`: This will create an exposure vector file within the exposure folder with the assets'geometry and object_id.

[**vulnerability**]
`file`: This will create an vulnerability curves CSV file within the vulnerability folder ([folder strucute](index.qmd)) that contains the damage curves.
Expand Down Expand Up @@ -254,9 +254,9 @@ If the user prefers to create a more advanced model or to utilize grid data inst
| var_ as_band | True/False Read netCDF subdatasets as raster bands | No | False |
| **[exposure.geom]** | | | |
| csv | File path to exposure.csv file, that contains information about e.g. asset type, max. potential damage, aggregation and so forth) | Yes | 'exposure/exposure.csv' |
| file1 | File path of exposure vector file with Object ID column to enable linking exposure.csv output to vector file. | Yes | 'exposure/buildings.gpkg' |
| file1 | File path of exposure vector file with object_id column to enable linking exposure.csv output to vector file. | Yes | 'exposure/buildings.gpkg' |
| crs | Projection of exposure data | Yes, if crs is unknown in dataset | 'EPSG:32617' |
| index | Define the name of the index column of the data to link the exposure CSV file with the exposure vector file. | No | 'Object ID' |
| index | Define the name of the index column of the data to link the exposure CSV file with the exposure vector file. | No | 'object_id' |
| **[exposure.grid]** | | | |
| file | File path to exposure.nc grid file, that contains the spatial information and information about the maximum potential damage per cell. | Yes, if netCDF is provided as input | 'exposure/raster.nc' |
| crs | Output projection | Yes, if crs is unknown in dataset | 'EPSG:32617' |
Expand Down Expand Up @@ -324,7 +324,7 @@ For users who would want to create their own exposure data, or modify existing e

| Field | Description | Required | Example |
|----------------------------------------|--------------------------------------------------------------------------------------------|------------------------------------------|----------------------------|
| Object ID | Unique numerical indentifier of the object | Yes | 1 |
| object_id | Unique numerical indentifier of the object | Yes | 1 |
| Object Name | Unique name of the object | No | fp_1 |
| Primary Object Type | Object type | No | RES1_1SNB |
| Secondary Object Type | More specification about object type | No | Res 1,1 Story no basement |
Expand All @@ -342,8 +342,8 @@ For users who would want to create their own exposure data, or modify existing e

A more detailed description of the data fields in the *exposure.csv* can be found below;

**Object ID/Object name**
Object ID and Object name are administrative information, which the user is free to choose. Input must be unique for each object, if they are not unique, FIAT gives a warning and stops the model built-up.
**object_id/Object name**
object_id and Object name are administrative information, which the user is free to choose. Input must be unique for each object, if they are not unique, FIAT gives a warning and stops the model built-up.

**Primary/Secondary object type**
The primary object type describes the category of the asset (e.g. residential or commercial). The secondary object type allows for a more detailed profile of the object (e.g. single-story home, or grocery store). The developer of the exposure dataset is free to set their own categories of object types. (*Exception: FIAT requires **roads** to be assigned as **primary object type = ‘road**’, to summarize road damages separately from buildings and utilities*.)
Expand Down
38 changes: 27 additions & 11 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ website:
page-footer:
left: |
Made possible by:
<a href="https://www.deltares.nl/en" target="_blank" rel="noreferrer noopener">
<img
src="/_static/images/deltares-blue.svg"
alt="Deltares"
style="height: 40px;"
/>
</a>
<a href="https://www.deltares.nl/en" target="_blank" rel="noreferrer noopener">
<img
src="/_static/images/deltares-blue.svg"
alt="Deltares"
class="footer-image-light"
style="height: 40px;"
/>
<img
src="/_static/images/deltares-white.svg"
alt="Deltares"
class="footer-image-dark"
style="height: 40px;"
/>
</a>
navbar:
logo: _static/fiat.svg
search: true
Expand Down Expand Up @@ -86,9 +93,9 @@ website:
- "setup_guide/general/docker.qmd"
- section: "FIAT package"
contents:
- setup_guide/kernel/installation.qmd
- setup_guide/kernel/application.qmd
- setup_guide/kernel/linux.qmd
- setup_guide/kernel/install.qmd
- setup_guide/kernel/dev.qmd
- setup_guide/kernel/build.qmd
- title: "User guide"
collapse-level: 1
contents:
Expand All @@ -108,8 +115,9 @@ website:
- text: Exposure data
file: user_guide/data/exposure.qmd
contents:
- user_guide/data/exposure/csv.qmd
- user_guide/data/exposure/data.qmd
- user_guide/data/exposure/geometries.qmd
- user_guide/data/exposure/csv.qmd
- user_guide/data/vulnerability.qmd
- user_guide/data/supported.qmd
- title: Examples
Expand Down Expand Up @@ -176,6 +184,14 @@ quartodoc:
children: separate
- name: GridModel
children: separate
- subtitle: Methods
desc: The hazard functions
package: fiat.methods
contents:
- ead.risk_density
- ead.calc_ead
- flood.calculate_hazard
- flood.calculate_damage

# Logging
- title: Logging
Expand Down
17 changes: 17 additions & 0 deletions docs/_static/theme-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ $navbar-hl: $links ;

// Code blocks
$code-block-bg-alpha: -.8;
$code-bg: $highlight;
$code-color: $text;

.navbar-nav .dropdown-menu {
background-color: $highlight; // Dark mode dropdown background color
Expand Down Expand Up @@ -68,3 +70,18 @@ $code-block-bg-alpha: -.8;
// border-color: rgb(255, 72, 0);
// // border-width: 1px;
// }

// :root {
// --footer-image: url('/_static/images/deltares-white.svg');
// }
//
// footer img {
// content: var(--footer-image);
// }

.footer-image-light {
display: none;
}
.footer-image-dark {
display: inline;
}
7 changes: 7 additions & 0 deletions docs/_static/theme-light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ $navbar-hl: $links ;
border-color: $links;
border: 1px solid $links;
}

.footer-image-dark {
display: none;
}
.footer-image-light {
display: inline;
}
27 changes: 24 additions & 3 deletions docs/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,59 @@ title: "What's new?"
This contains the unreleased changes to Delft-FIAT.

### Added
- Attribute `size` of `GeomSource` object for in situ size return; `count` becomes private
- Attribute `size` of `GridSource` object for in situ size return; `count` becomes private
- Attributes `dtypes` and `geom_type` of `GeomModel`
- Build time to FIAT cli (when build with pyinstaller), viewed with `fiat --version`
- Different types of exposure (e.g. 'damage', 'affected', 'outage' etc.)
- Docker file for docker image creation
- Extra arguments to `grid.reproject`
- Function (`generate_jobs`) to generate jobs for parallelization
- Function (`execute_pool`) to execute code in parallel using `multiprocessing`
- Flood hazard/ damage functions (`methods` submodule)
- General method of creating output files in `GeomModel` (`_setup_output_files`)
- Method `_create_model_dirs` of `ConfigReader` object for creating result directories in one go
- Method `add_handler` of the `Log` object; user setting of custom stream
- Method `add_feature_with_map` of `GeomModel` to set features with extra info
- Method `create` of `GeomModel` to create an ogr.DataSource (new dataset)
- Method `create_equal_grids` of `GridModel` for making hazard and exposure grid spatially equal
- Method `set` of `ConfigReader` object
- Method `size` of `GeomSource` object for in situ size return; `count` becomes private
- Method `size` of `GridSource` object for in situ size return; `count` becomes private
- Not stopping when exposure and hazard grids (`GridModel`), but instead make them spatially equal
- Numpy >= 2.0.0 support
- Python 3.12 support
- Settings toml file: global setting 'loglevel'
- Settings toml file: global setting 'global.loglevel'; default 'INFO'
- Settings toml file: exposure setting 'exposure.types'; default 'flood'
- Setting return period as a variable in hazard map bands (risk)
- Support for using pixi for binary creation (properly)

### Changed
- Better version of `BufferHandler`
- Exposure data headers are now lower-/ snakecase ('object_id' -> 'objectId'), see [docs](./user_guide/data/exposure/data.qmd)
- Fixed binary creation in general, but also specifically for `GDAL >= v3.9.1`
- Made read methods of `BaseModel`, `GeomModel` and `GridModel` public (removed underscore)
- Made csv files (exposure data) optional
- Moved hazard/ damage calculation function to `methods` submodule
- Proper checking for duplicate columns in csv files
- Settings toml file: exposure setting 'exposure.csv.file' (becomes optional)
- Testing of workers (not properly caught due to using `multiprocessing`)
- Testing only based on integers

### Deprecated
- Base object `_BaseHandler`; incompatible with Python 3.12
- Function `open_exp` from `fiat.io`, superseded by general use of `open_csv`
- Method `add_c_handler` in favour of the more generalized `add_handler`
- Methods `_create_output_dir`, `_create_tmp_dir` and `_create_risk_dir` of the `ConfigReader` object
- Object `ExposureTable`, now done via `TableLazy`
- Resolve stage of `GeomModel`; now properly handled in `GeomModel.run`
- Setting return period via the name of the hazard band (risk)
- Settings toml file: global setting 'global.keep_temp_files'
- Settings toml file: output setting 'output.geom.chunk'; superseded by 'global.geom.chunk'
- Support of `Python` versions under `3.9.0`
- Temporary files (`GeomModel`)
- `TextHandler` object; unused

### Documentation
- Added methods to the api
- Cleaner home page
- Getting started remade into `Information`

Expand Down
8 changes: 4 additions & 4 deletions docs/examples/single_event.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"from pathlib import Path\n",
"\n",
"# check the output\n",
"out = open_csv(Path(\"../../.testdata/output/geom_event\", \"output.csv\"), index=\"Object ID\")\n",
"out = open_csv(Path(\"../../.testdata/output/geom_event\", \"output.csv\"), index=\"object_id\")\n",
"print(out.columns)"
]
},
Expand All @@ -98,8 +98,8 @@
"metadata": {},
"outputs": [],
"source": [
"assert float(out[2, \"Total Damage\"]) == 740\n",
"assert float(out[3, \"Total Damage\"]) == 1038"
"assert float(out[2, \"total_damage\"]) == 740\n",
"assert float(out[3, \"total_damage\"]) == 1038"
]
}
],
Expand All @@ -119,7 +119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
3 changes: 2 additions & 1 deletion docs/setup_guide/general/conda.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ In order to develop on **FIAT** locally, the Python package manager **Miniforge3

Download and install [Miniforge3](https://github.com/conda-forge/miniforge#mambaforge)

Initialize conda by running the following in the Miniforge prompt:
Make sure the conda binary (and mamba) is added to PATH. In windows this is simply done via the 'set environment variables' screen, on linux one can append the 'PATH' variable via the `.bashrc` configurations file (or another rc file corresponding with the shell in use).
Initialize conda by running the following command in your shell.

```bash
conda init
Expand Down
Loading
Loading