Skip to content

Commit 7304954

Browse files
committed
Fix Silvertown Tunnel, UK WASM data requests
1 parent 95230a3 commit 7304954

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

examples/uk_silvertown_tunnel_ags4/uk_silvertown_tunnel_ags4_to_brgi_geodb.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def _():
2525

2626
import geopandas as gpd
2727
import marimo as mo
28-
import requests
2928
from python_ags4 import AGS4
3029

31-
print(platform.system())
30+
platform_system = platform.system()
31+
print(platform_system)
3232
print(sys.version)
3333
# print(sys.executable)
34-
return AGS4, gpd, io, mo, requests
34+
return AGS4, gpd, io, mo, platform_system
3535

3636

3737
@app.cell(hide_code=True)
@@ -46,7 +46,8 @@ def _(mo):
4646
4747
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):
4848
[**Title**: Preliminary GI for Silvertown Tunnel
49-
**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)
49+
**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)
50+
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).
5051
5152
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/)):
5253
[AGSi Guidance / Example files](https://ags-data-format-wg.gitlab.io/agsi/AGSi_Documentation/Example_Silvertown)
@@ -56,20 +57,22 @@ def _(mo):
5657

5758

5859
@app.cell
59-
def _(requests):
60-
# 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"
61-
# ags_bytes = requests.get(raw_githubusercontent_url).content
62-
63-
# Preferribly, the data can be directly used from the BGS webservice, but maybe this will not be possible in the marimo playground?
60+
async def _(io, platform_system):
6461
bgs_url = "https://webservices.bgs.ac.uk/accessions/download/162465?fileName=20110770%20-%202021-02-16%201308%20-%20Final%20-%206.ags"
65-
ags_bytes = requests.get(bgs_url).content
66-
ags_bytes
67-
return (ags_bytes,)
62+
# When running this marimo notebook in WebAssembly (WASM, a.k.a. Emscripten), use pyodide to request the data
63+
if platform_system == "Emscripten":
64+
from pyodide.http import pyfetch
65+
response = await pyfetch(bgs_url)
66+
ags = io.BytesIO(await response.bytes())
67+
else:
68+
import requests
69+
ags = io.BytesIO(requests.get(bgs_url).content)
70+
return (ags,)
6871

6972

7073
@app.cell
71-
def _(AGS4, ags_bytes, io):
72-
ags_tables, headings = AGS4.AGS4_to_dataframe(io.BytesIO(ags_bytes))
74+
def _(AGS4, ags):
75+
ags_tables, headings = AGS4.AGS4_to_dataframe(ags)
7376
for group, data in ags_tables.items():
7477
ags_tables[group] = (
7578
AGS4.convert_to_numeric(data).drop(columns=["HEADING"])

0 commit comments

Comments
 (0)