Skip to content

Commit 9166acf

Browse files
authored
Merge pull request #59 from bedrock-engineer/dev
Align docstrings with function signatures and add inspec GeoPackage marimo nb
2 parents 079f745 + 9e0681a commit 9166acf

File tree

17 files changed

+2092
-1745
lines changed

17 files changed

+2092
-1745
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# /// script
2+
# requires-python = ">=3.12"
3+
# dependencies = [
4+
# "folium==0.19.5",
5+
# "mapclassify==2.8.1",
6+
# "matplotlib==3.9.4",
7+
# "pandas==2.2.3",
8+
# "shapely==2.0.7",
9+
# ]
10+
# ///
11+
12+
import marimo
13+
14+
__generated_with = "0.13.2"
15+
app = marimo.App(width="medium")
16+
17+
18+
@app.cell(hide_code=True)
19+
def _():
20+
from pathlib import Path
21+
22+
import geopandas as gpd
23+
import marimo as mo
24+
import pandas as pd
25+
import pyogrio
26+
from shapely import Point
27+
28+
return Path, Point, gpd, mo, pd, pyogrio
29+
30+
31+
@app.cell
32+
def _(Path):
33+
gpkg_path = Path(
34+
r"S:\Shared drives\Bedrock\Case Studies\A2TunnelMaastricht\data\A2_Maastricht.gpkg"
35+
)
36+
return (gpkg_path,)
37+
38+
39+
@app.cell(hide_code=True)
40+
def _(gpd, gpkg_path, pyogrio):
41+
gpkg_layers = gpd.list_layers(gpkg_path)
42+
43+
brgi_geodb = {}
44+
for layer in gpkg_layers["name"]:
45+
brgi_geodb[layer] = pyogrio.read_dataframe(gpkg_path, layer=layer)
46+
47+
gpkg_layers
48+
return (brgi_geodb,)
49+
50+
51+
@app.cell(hide_code=True)
52+
def _(brgi_geodb, mo):
53+
sel_brgi_table = mo.ui.dropdown(brgi_geodb, value="Project")
54+
mo.md(f"Select the Bedrock GI table you want to explore: {sel_brgi_table}")
55+
return (sel_brgi_table,)
56+
57+
58+
@app.cell(hide_code=True)
59+
def _(pd, sel_brgi_table):
60+
df = pd.DataFrame(sel_brgi_table.value.copy())
61+
if "geometry" in df.columns:
62+
df = df.assign(geometry=df.geometry.astype(str))
63+
64+
df
65+
return
66+
67+
68+
@app.cell(hide_code=True)
69+
def _(Point, sel_brgi_table):
70+
if "geometry" in sel_brgi_table.value.columns:
71+
gdf = sel_brgi_table.value.copy()
72+
gdf = gdf["geometry"].apply(lambda geom: Point(geom.coords[0]))
73+
map = gdf.explore()
74+
else:
75+
map = f"The {sel_brgi_table.selected_key} table doesn't contain GIS geometry."
76+
77+
map
78+
return
79+
80+
81+
if __name__ == "__main__":
82+
app.run()

examples/hk_kaitak_ags3/hk_kaitak_ags3_to_brgi_geodb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# /// script
22
# requires-python = ">=3.12"
33
# dependencies = [
4-
# "bedrock-ge==0.3.1",
4+
# "bedrock-ge==0.3.2",
55
# "folium==0.20.0",
66
# "geopandas==1.1.0",
77
# "mapclassify==2.9.0",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "bedrock-ge"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
description = "Bedrock's Python library for geotechnical engineering."
55
authors = [
66
{name = "Bedrock", email = "[email protected]"}

src/bedrock_ge/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Bedrock, the open source foundation for ground engineering."""
22

3-
__version__ = "0.3.1"
3+
__version__ = "0.3.2"

src/bedrock_ge/gi/ags.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@ def ags_to_brgi_db_mapping(
1717
"""Map AGS 3 or AGS 4 data to the Bedrock GI data model.
1818
1919
Args:
20-
source (str | Path | IO[str] | IO[bytes] | bytes): The AGS file (str or Path)
21-
or a file-like object that represents the AGS file.
22-
projected_crs (CRS): Projected Coordinate Reference System (CRS). For example:
20+
source: The AGS file (str or Path) or a file-like object that represents the AGS file.
21+
projected_crs: Projected Coordinate Reference System (CRS). For example:
2322
- OSGB36 / British National Grid: `pyproj.CRS("EPSG:27700")`
2423
- Hong Kong 1980 Grid System: `pyproj.CRS("EPSG:2326")`
25-
vertical_crs (CRS, optional): Vertical CRS. Defaults to EGM2008 height, EPSG:3855
24+
vertical_crs: Vertical CRS. Defaults to EGM2008 height, EPSG:3855,
2625
which measures the orthometric height w.r.t. the Earth Gravitational Model 2008.
2726
- Ordnance Datum Newlyn (ODN) Height: `pyproj.CRS("EPSG:5701")`
2827
- Hong Kong Principle Datum (HKPD) Height: `pyproj.CRS("EPSG:5738")`
29-
encoding (str | None, optional): Encoding of the text file or bytes stream.
30-
Defaults to None. An attempt at detecting the encoding will be made if None.
28+
encoding: Encoding of the text file or bytes stream. Defaults to None.
29+
An attempt at detecting the encoding will be made if None.
3130
3231
Raises:
3332
ValueError: If the data does not match AGS 3 or AGS 4 format.
3433
3534
Returns:
36-
BedrockGIDatabaseMapping: Object that maps AGS 3 or AGS 4 data to Bedrock GI data model.
35+
Object that maps AGS 3 or AGS 4 data to Bedrock GI data model.
3736
"""
3837
if not encoding:
3938
encoding = detect_encoding(source)

src/bedrock_ge/gi/ags3.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ def ags3_to_dfs(
2626
make the rest of the code more generic.
2727
2828
Args:
29-
source (str | Path | IO[str] | IO[bytes] | bytes): The AGS 3 file (str or Path)
30-
or a file-like object that represents the AGS 3 file.
31-
encoding (str): Encoding of file or object.
29+
source: The AGS 3 file (str or Path) or a file-like object that represents the AGS 3 file.
30+
encoding: Encoding of the text file or bytes stream.
3231
3332
Returns:
34-
dict[str, pd.DataFrame]: A dictionary of pandas DataFrames, i.e. a database,
35-
where each key is an AGS 3 group, and the corresponding value is
36-
a pandas DataFrame containing the data for that group.
33+
A dictionary of pandas DataFrames, i.e. a database, where each key is
34+
an AGS 3 group, and the corresponding value is a pandas DataFrame
35+
containing the data for that group.
3736
"""
3837
# Initialize dictionary and variables used in the AGS 3 read loop
3938
ags3_dfs = {}
@@ -134,16 +133,18 @@ def ags3_to_brgi_db_mapping(
134133
"""Map AGS 3 data to the Bedrock GI data model.
135134
136135
Args:
137-
ags3_db (dict[str, pd.DataFrame]): A dictionary of pandas DataFrames, i.e. database,
138-
where each key is an AGS 3 group, and the corresponding value is
139-
a pandas DataFrame containing the data for that group.
140-
projected_crs (CRS): Projected coordinate reference system (CRS).
141-
vertical_crs (CRS, optional): Vertical CRS. Defaults to EGM2008 height, EPSG:3855
136+
source: The AGS 3 file (str or Path) or a file-like object that represents the AGS 3 file.
137+
projected_crs: Projected Coordinate Reference System (CRS). For example:
138+
- OSGB36 / British National Grid: `pyproj.CRS("EPSG:27700")`
139+
- Hong Kong 1980 Grid System: `pyproj.CRS("EPSG:2326")`
140+
vertical_crs: Vertical CRS. Defaults to EGM2008 height, EPSG:3855,
142141
which measures the orthometric height w.r.t. the Earth Gravitational Model 2008.
143-
encoding (str): Encoding of the text file or bytes stream.
142+
- Ordnance Datum Newlyn (ODN) Height: `pyproj.CRS("EPSG:5701")`
143+
- Hong Kong Principle Datum (HKPD) Height: `pyproj.CRS("EPSG:5738")`
144+
encoding: Encoding of the text file or bytes stream.
144145
145146
Returns:
146-
BedrockGIDatabaseMapping: Object that maps AGS 3 data to Bedrock GI data model.
147+
Object that maps AGS 3 data to Bedrock GI data model.
147148
"""
148149
ags3_dfs = ags3_to_dfs(source, encoding)
149150

@@ -269,7 +270,7 @@ def _get_depth_columns(group: str, headers: list[str]) -> tuple[str | None, str
269270
base_depth = None
270271
if not top_depth and not base_depth:
271272
raise ValueError(
272-
'The in-situ test group "{group}" group in this AGS 3 file does not contain a top or base depth heading!'
273+
f'The in-situ test group "{group}" group in this AGS 3 file does not contain a top or base depth heading!'
273274
)
274275

275276
return top_depth, base_depth

0 commit comments

Comments
 (0)