{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to GeoST\n", "\n", "This introduction covers some of the key concepts and basic features of `GeoST` to help\n", "you get started. `GeoST` depends on popular data science libraries such as\n", "[Pandas](https://pandas.pydata.org/docs/index.html) and\n", "[GeoPandas](https://geopandas.org/en/stable/index.html), but provides readily available,\n", "frequently used selection methods for data held in\n", "[`pandas.DataFrame`](https://pandas.pydata.org/docs/reference/frame.html) or\n", "[`geopandas.GeoDataFrame`](https://geopandas.org/en/stable/docs/reference/geodataframe.html)\n", "objects. This makes GeoST an easy-to-use option for less experienced Python users, while\n", "more experienced users can easily access the underlying DataFrames and apply their own\n", "analyses. If you are not familiar with GeoPandas and Pandas, we recommend taking a quick\n", "look at the [10 minutes to pandas](https://pandas.pydata.org/docs/user_guide/10min.html#) and\n", "[Introduction to GeoPandas](https://geopandas.org/en/stable/getting_started/introduction.html)\n", "tutorials after this introduction.\n", "\n", "GeoST is designed to work with many different kinds of subsurface data. The package is a\n", "work in progress, and we aim to support an increasing number of data sources. Below is a\n", "list of data sources that are currently supported or planned for future support:\n", "\n", "**From local files**:\n", "- Tabular data of borehole, CPT, etc. (.parquet, .csv)\n", "- Geological boreholes xml (BHR-G)\n", "- Geotechnical boreholes xml (BHR-GT)\n", "- Pedological boreholes xml (BHR-P)\n", "- Cone Penetration Test xml/gef (CPT)\n", "- Pedological soilprofile descriptions xml (SFR)\n", "- BORIS xml (TNO borehole description software)\n", "- NLOG boreholes Excel\n", "\n", "**Directly from the [BRO REST-API](https://www.bro-productomgeving.nl/bpo/latest/url-s-publieke-rest-services)**:\n", "- BHR-G\n", "- BHR-GT\n", "- BHR-P\n", "- CPT\n", "- SFR\n", "\n", "**BRO models**:\n", "- GeoTOP: from local NetCDF or directly via [OPeNDAP server](https://dinodata.nl/opendap/)\n", "\n", "*Planned*:\n", "- BRO/PDOK GeoPackages:\n", " [BHR-G](https://service.pdok.nl/bzk/bro-geologisch-booronderzoek/atom/index.xml),\n", " [BHR-GT](https://service.pdok.nl/bzk/bro-geotechnischbooronderzoek/atom/v1_0/index.xml),\n", " [BHR-P](https://service.pdok.nl/bzk/brobhrpvolledigeset/atom/v1_1/index.xml),\n", " [CPT](https://service.pdok.nl/bzk/brocptvolledigeset/atom/v1_0/index.xml), and\n", " [SFR](https://service.pdok.nl/bzk/bodem/bro-wandonderzoek/atom/index.xml)\n", "- Well logs (LAS/ASCII)\n", "- REGIS II\n", "- Dino XML geological boreholes\n", "- BHR-G GEF\n", "- Soilmap of the Netherlands\n", "\n", "GeoST also plans support for several Geophysical data sources such as Seismic, ERT, EM and others.\n", "\n", "## Concept\n", "\n", "The core data structure is a [`geost.Collection`](../api_reference/collection.rst). This\n", "holds all the spatial information of any kind of data source in a **\"header\"** attribute\n", "(i.e., the header table), and the corresponding data in a **\"data\"** attribute (i.e., the\n", "data table).\n", "\n", "For example, a set of 100 boreholes is held in a `Collection`, where the **\"header\"**\n", "contains one row per data entry, so a 100 rows, and provides information about the ID, location,\n", "surface level, and depths. The **\"data\"** contains the survey information for each described\n", "layer. The structure of a `Collection` is illustrated below.\n", "\n", "

\n", " \"collection\"\n", "

\n", "\n", "When working with a `Collection`, GeoST automatically keeps track of the alignment between\n", "the two attributes and ensures that each data entry occurs in both the **\"header\"** and\n", "**\"data\"** attributes. For example, when a user deletes an individual borehole entry from\n", "the **\"header\"**, the `Collection` ensures that it is also deleted from the **\"data\"**.\n", "\n", "\n", "```{note}\n", "**User guide:**\n", "Checkout the [Data structures](../user_guide/data_structures.ipynb) section in the user guide for a more detailed explanation of the GeoST data structures.\n", "```\n", "\n", "## The Basics\n", "\n", "Data is usually loaded through various reader functions (see the\n", "[API reference](../api_reference/io.rst)). For this tutorial, `GeoST` provides a test set\n", "of boreholes in the area of the Utrecht Science Park that can be directly loaded as a\n", "`Collection`. Let's read the data, print the result to see what it contains, and also plot\n", "the locations to get an idea of where we are:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collection:\n", " header (rows, columns): (67, 5)\n", " data (rows, columns): (1398, 32)\n", "crs: EPSG:28992\n", "vertical datum: EPSG:5709\n", "# surveys = 67\n", "\n" ] }, { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import xyzservices.providers as xyz # For accessing background map providers\n", "\n", "import geost\n", "\n", "usp_boreholes = geost.data.boreholes_usp()\n", "print(usp_boreholes)\n", "usp_boreholes.header.explore(\n", " tiles=xyz.nlmaps.grijs, style_kwds={\"weight\": 4}\n", ") # Interactive plot of the borehole locations." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see, `usp_boreholes` is of type [`Collection`](../api_reference/borehole_collection.rst)\n", "and it shows the number of rows and columns in the header and data tables. Additionally,\n", "it shows a `Positional columns` and `Data columns` section, coordinate reference system,\n", "and the vertical datum. In the positional and data columns section you can see which columns\n", "are present in the `Collection` and in which table it can be found (i.e. header and/or data).\n", "Why we make the distinction between Positional columns and Data columns is explained in\n", "the [Positional columns](../user_guide/survey_data.ipynb#positional-columns) section on the\n", "[Survey data](../user_guide/survey_data.ipynb) page.\n", "\n", "The `\"header\"` attribute of a `Collection` contains information about each borehole, such\n", "as its ID, x- and y-coordinates, and other metadata. It also contains geometry objects for\n", "each borehole, which enable spatial selections and exports to GIS-supported formats provided\n", "by `GeoST`.\n", "\n", "The `\"header\"` attribute is a [`geopandas.GeoDataFrame`](https://geopandas.org/en/stable/docs/reference/geodataframe.html)\n", "instance. Let's see what the attribute looks like by printing it:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nrxysurfacegeometry
0B31H05411395854560001.20POINT (139585 456000)
1B31H06111396004550601.20POINT (139600 455060)
2B31H07181399504552001.30POINT (139950 455200)
3B31H08031396754550872.16POINT (139675 455087)
4B31H08061396844553841.00POINT (139684 455384)
\n", "
" ], "text/plain": [ " nr x y surface geometry\n", "0 B31H0541 139585 456000 1.20 POINT (139585 456000)\n", "1 B31H0611 139600 455060 1.20 POINT (139600 455060)\n", "2 B31H0718 139950 455200 1.30 POINT (139950 455200)\n", "3 B31H0803 139675 455087 2.16 POINT (139675 455087)\n", "4 B31H0806 139684 455384 1.00 POINT (139684 455384)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "usp_boreholes.header.head() # First five rows of the header data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since the header is a `GeoDataFrame`, we have direct access to all methods provided by\n", "GeoDataFrames. Therefore, the interactive plot of the borehole locations shown above was\n", "easily created using the `.explore()` method. More experienced Python users can use the\n", "header to perform any customized operations with GeoDataFrames that they would normally\n", "perform.\n", "\n", "The other key attribute of a `Collection` is the `\"data\"` attribute, which is a\n", "[`pandas.DataFrame`](https://pandas.pydata.org/docs/reference/frame.html) instance. This\n", "contains the actual logged data (i.e., layer descriptions) of the boreholes. In this case,\n", "the `\"data\"` attribute contains *layered* data because the borehole data are logged in\n", "terms of layers (i.e., depth intervals over which properties are the same), with `\"top\"`\n", "and `\"bottom\"` depths. Let's see what it looks like:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nrxysurfaceendtopbottomlithzmzmk...conscolorlutum_pctplantsshellskleibrokjesstrat_1975strat_2003strat_interdesc
0B31H05411395854560001.2-9.90.000.20KNaNNaN...NaNONNaN000NaNECNaN[TEELAARDE#***#****#*] ..........................
1B31H05411395854560001.2-9.90.200.60KNaNNaN...NaNBRNaN000NaNECNaN[KLEI#***#****#*] grysbruin.
2B31H05411395854560001.2-9.90.600.95VNaNNaN...NaNBRNaN000NaNNINaN[VEEN#***#****#*] donkerbruin.
3B31H05411395854560001.2-9.90.952.80ZNaNZMFO...NaNGRNaN000NaNECNaN[ZAND#***#****#*] FYN TOT matig fyn# iets slib...
4B31H05411395854560001.2-9.92.804.20ZNaNZFC...NaNBRNaN000NaNBXWINaN[ZAND#***#****#*] fyn# grysbruin.
\n", "

5 rows × 32 columns

\n", "
" ], "text/plain": [ " nr x y surface end top bottom lith zm zmk ... \\\n", "0 B31H0541 139585 456000 1.2 -9.9 0.00 0.20 K NaN NaN ... \n", "1 B31H0541 139585 456000 1.2 -9.9 0.20 0.60 K NaN NaN ... \n", "2 B31H0541 139585 456000 1.2 -9.9 0.60 0.95 V NaN NaN ... \n", "3 B31H0541 139585 456000 1.2 -9.9 0.95 2.80 Z NaN ZMFO ... \n", "4 B31H0541 139585 456000 1.2 -9.9 2.80 4.20 Z NaN ZFC ... \n", "\n", " cons color lutum_pct plants shells kleibrokjes strat_1975 strat_2003 \\\n", "0 NaN ON NaN 0 0 0 NaN EC \n", "1 NaN BR NaN 0 0 0 NaN EC \n", "2 NaN BR NaN 0 0 0 NaN NI \n", "3 NaN GR NaN 0 0 0 NaN EC \n", "4 NaN BR NaN 0 0 0 NaN BXWI \n", "\n", " strat_inter desc \n", "0 NaN [TEELAARDE#***#****#*] .......................... \n", "1 NaN [KLEI#***#****#*] grysbruin. \n", "2 NaN [VEEN#***#****#*] donkerbruin. \n", "3 NaN [ZAND#***#****#*] FYN TOT matig fyn# iets slib... \n", "4 NaN [ZAND#***#****#*] fyn# grysbruin. \n", "\n", "[5 rows x 32 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "usp_boreholes.data.head() # First five rows of the data table." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Also with the `\"data\"` attribute, we have direct access to all methods provided by\n", "DataFrames. More experienced Python users can therefore use it to perform any customized\n", "operations they would normally perform with DataFrames. The `\"data\"` attribute of this\n", "`Collection` contains 32 different columns holding the relevant borehole data, describing\n", "characteristics such as lithology, sand grain size, plant remains, and others.\n", "\n", "### Positional reference\n", "\n", "A `Collection` contains all spatial information about the data, both horizontally and\n", "vertically. These attributes can be accessed through the `\"crs\"` (coordinate reference\n", "system) and `\"vertical_datum\"` attributes:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "EPSG:28992\n", "EPSG:5709\n" ] } ], "source": [ "print(usp_boreholes.crs)\n", "print(usp_boreholes.vertical_datum)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These attributes can be used to reproject the data. For example, we can convert the Dutch\n", "\"Rijksdriehoekstelsel\" coordinates to \"WGS84\" coordinates. Any reprojection automatically\n", "updates the coordinates in the data. Let's change the coordinate reference system of\n", "`usp_boreholes` and check the `\"header\"` again to see this:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " nr x y surface geometry\n", "0 B31H0541 5.162268 52.092042 1.20 POINT (5.16227 52.09204)\n", "1 B31H0611 5.162530 52.083594 1.20 POINT (5.16253 52.08359)\n", "2 B31H0718 5.167630 52.084862 1.30 POINT (5.16763 52.08486)\n", "3 B31H0803 5.163622 52.083839 2.16 POINT (5.16362 52.08384)\n", "4 B31H0806 5.163740 52.086508 1.00 POINT (5.16374 52.08651)\n", "EPSG:4326\n" ] } ], "source": [ "usp_boreholes.to_crs(4326) # Change from RD to WGS 84\n", "print(usp_boreholes.header.head(), usp_boreholes.crs, sep=\"\\n\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the coordinates in the `\"x\"` and `\"y\"` columns have indeed been changed to latitude\n", "and longitude coordinates.\n", "\n", "### Adding data\n", "\n", "During analyses, you may need to add additional columns to a `Collection`. For example,\n", "you may be interested in the thickness of layers in the borehole data. The easiest way to\n", "do this is to use the [`add_colums`](../api_reference/generated/geost.base.Collection.add_columns.rst)\n", "method of a `Collection`. We can easily add \"thickness\" column to the data table:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "usp_boreholes = usp_boreholes.add_columns(\n", " thickness=(usp_boreholes.data[\"top\"] - usp_boreholes.data[\"bottom\"]).abs()\n", ")\n", "usp_boreholes.data.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since the `add_columns` method uses [`pandas.DataFrame.assign`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.assign.html#pandas.DataFrame.assign) under the hood, we can also use [`pandas.col`](https://pandas.pydata.org/docs/reference/api/pandas.col.html#pandas.col)\n", "for a cleaner syntax. For example, let's calculate the midpoint depth of each layer using\n", "this approach:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "usp_boreholes = usp_boreholes.add_columns(\n", " mid_depth=(pd.col(\"top\") + pd.col(\"bottom\")) / 2\n", ")\n", "usp_boreholes.data.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```{note}\n", "GeoST also provides the [`calculate_thickness`](../api_reference/generated/geost.accessor.GeostFrame.calculate_thickness.rst) and [`calculate_mid_depth`](../api_reference/generated/geost.accessor.GeostFrame.calculate_mid_depth.rst) methods through the GeoST accessor for DataFrames (see the\n", "[User Guide](../user_guide/data_structures.ipynb#geost-accessor)).\n", "```\n", "\n", "The `add_columns` method also allows to easily add columns to the header table. For demonstration\n", "purpose, let's add a column which multiplies the surface level by 2:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "usp_boreholes = usp_boreholes.add_columns(\n", " multiplied_surface=pd.col(\"surface\") * 2, to=\"header\"\n", ")\n", "usp_boreholes.header.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Selections and slices\n", "\n", "There are several ways to create subsets of a `Collection`, such as:\n", "\n", "**Spatial selections**\n", "\n", "- `select_within_bbox` - Select data points in the `Collection` within a bounding box.\n", "- `select_with_points` - Select data points in the `Collection` within a specified distance\n", " of other point geometries.\n", "- `select_with_lines` - Select data points in the `Collection` within a specified distance\n", " of line geometries.\n", "- `select_within_polygons` - Select data points in the `Collection` within polygon\n", " geometries.\n", "\n", "**Conditional selections**\n", "\n", "- `select_by_values` - Select data points in the `Collection` based on the presence of\n", " certain values in one or more data columns.\n", "- `select_by_length` - Select data points in the `Collection` based on length requirements.\n", "- `select_by_depth` - Select data points in the `Collection` based on depth constraints.\n", "\n", "**Slicing**\n", "\n", "- `slice_depth_interval` - Slice boreholes in the `Collection` to the specified depth\n", " interval.\n", "- `slice_by_values` - Slice boreholes in the `Collection` based on values (e.g., keep only\n", " sand layers and remove all others).\n", "\n", "We will not go through each of these methods in this quick start, but please see the\n", "[API Reference](../api_reference.rst) for more details." ] } ], "metadata": { "kernelspec": { "display_name": "default", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.5" } }, "nbformat": 4, "nbformat_minor": 2 }