Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 18 additions & 14 deletions examples/hk_kaitak_ags3/hk_kaitak_ags3_to_brgi_geodb.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "bedrock-ge==0.3.1
# "bedrock-ge==0.3.1",
# "folium==0.20.0",
# "geopandas==1.1.0",
# "mapclassify==2.9.0",
# "marimo",
# "matplotlib==3.10.3",
# "numpy==2.3.1",
# "pandas==2.3.0",
# "pyarrow==20.0.0",
# "pyproj==3.7.1",
# "requests==2.32.4",
# "shapely==2.1.1",
Expand All @@ -31,19 +30,14 @@ def _():
import platform
import sys
import zipfile
from pathlib import Path

import folium
import geopandas as gpd
import mapclassify
import marimo as mo
import matplotlib
import numpy as np
import pandas as pd
import requests
from pyproj import CRS, Transformer
from pyproj.crs.crs import CompoundCRS
from shapely import Point, wkt
from pyproj import CRS
from shapely import Point

from bedrock_ge.gi.ags import ags_to_brgi_db_mapping
from bedrock_ge.gi.db_operations import merge_dbs
Expand All @@ -52,7 +46,8 @@ def _():
from bedrock_ge.gi.mapper import map_to_brgi_db
from bedrock_ge.gi.write import write_brgi_db_to_file

print(platform.system())
platform_system = platform.system()
print(platform_system)
print(sys.version)
# print(sys.executable)
return (
Expand All @@ -67,7 +62,7 @@ def _():
merge_dbs,
mo,
platform,
requests,
platform_system,
write_brgi_db_to_file,
zipfile,
)
Expand Down Expand Up @@ -122,13 +117,22 @@ def _(mo):


@app.cell
def _(io, requests):
async def _(io, platform_system):
# Read ZIP from disk after downloading manually
# zip = Path.home() / "Downloads" / "kaitak_ags3.zip"

# Request ZIP from GitHub
raw_githubusercontent_url = "https://raw.githubusercontent.com/bedrock-engineer/bedrock-ge/main/examples/hk_kaitak_ags3/kaitak_ags3.zip"
zip = io.BytesIO(requests.get(raw_githubusercontent_url).content)
# When running this marimo notebook in WebAssembly (WASM, a.k.a. Emscripten), use pyodide to request the data
if platform_system == "Emscripten":
from pyodide.http import pyfetch

response = await pyfetch(raw_githubusercontent_url)
zip = io.BytesIO(await response.bytes())
else:
import requests

zip = io.BytesIO(requests.get(raw_githubusercontent_url).content)
return (zip,)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def _():

import geopandas as gpd
import marimo as mo
import requests
from python_ags4 import AGS4

print(platform.system())
platform_system = platform.system()
print(platform_system)
print(sys.version)
# print(sys.executable)
return AGS4, gpd, io, mo, requests
return AGS4, gpd, io, mo, platform_system


@app.cell(hide_code=True)
Expand All @@ -46,7 +46,8 @@ def _(mo):

The GI data for the Silvertown tunnel can be found on the British Geological Survey's ([BGS](https://www.bgs.ac.uk/)) [Deposited data search page](https://webapps.bgs.ac.uk/services/ngdc/accessions/index.html):
[**Title**: Preliminary GI for Silvertown Tunnel
**Description**: 77 exploratory holes carried out for the design of the Silvertown Tunnel, London](https://webapps.bgs.ac.uk/services/ngdc/accessions/index.html?simpleText=silvertown#item162465)
**Description**: 77 exploratory holes carried out for the design of the Silvertown Tunnel, London](https://webapps.bgs.ac.uk/services/ngdc/accessions/index.html?simpleText=silvertown#item162465)
For convenience, the AGS 4 file has also been uploaded to GitHub such that you can have a quick look what this AGS 4 data [looks like 🔎](https://raw.githubusercontent.com/bedrock-engineer/bedrock-ge/refs/heads/main/examples/uk_silvertown_tunnel_ags4/20110770-2021-02-16_1308-Final-6.ags).

The ground model has been published as an [AGSi Ground Model](https://www.ags.org.uk/data-format/agsi-ground-model/) by the Association of Geotechnical & Geoenvironmental Specialists ([AGS](https://www.ags.org.uk/)):
[AGSi Guidance / Example files](https://ags-data-format-wg.gitlab.io/agsi/AGSi_Documentation/Example_Silvertown)
Expand All @@ -56,20 +57,22 @@ def _(mo):


@app.cell
def _(requests):
# raw_githubusercontent_url = "https://raw.githubusercontent.com/bedrock-engineer/bedrock-ge/refs/heads/main/examples/uk_silvertown_tunnel_ags4/20110770-2021-02-16_1308-Final-6.ags"
# ags_bytes = requests.get(raw_githubusercontent_url).content

# Preferribly, the data can be directly used from the BGS webservice, but maybe this will not be possible in the marimo playground?
async def _(io, platform_system):
bgs_url = "https://webservices.bgs.ac.uk/accessions/download/162465?fileName=20110770%20-%202021-02-16%201308%20-%20Final%20-%206.ags"
ags_bytes = requests.get(bgs_url).content
ags_bytes
return (ags_bytes,)
# When running this marimo notebook in WebAssembly (WASM, a.k.a. Emscripten), use pyodide to request the data
if platform_system == "Emscripten":
from pyodide.http import pyfetch
response = await pyfetch(bgs_url)
ags = io.BytesIO(await response.bytes())
else:
import requests
ags = io.BytesIO(requests.get(bgs_url).content)
return (ags,)


@app.cell
def _(AGS4, ags_bytes, io):
ags_tables, headings = AGS4.AGS4_to_dataframe(io.BytesIO(ags_bytes))
def _(AGS4, ags):
ags_tables, headings = AGS4.AGS4_to_dataframe(ags)
for group, data in ags_tables.items():
ags_tables[group] = (
AGS4.convert_to_numeric(data).drop(columns=["HEADING"])
Expand Down