{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Reading water connect observations\n", "\n", "This notebook introduces how to use the `hydropandas` package to read, process and visualise data from the South Australia Water Connect database." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import contextily as cx\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "import hydropandas as hpd\n", "from hydropandas.io.water_connect import get_locations_gdf, get_locations_within_extent\n", "\n", "# enabling logging so we can see what happens in the background\n", "hpd.util.get_color_logger(\"INFO\");" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get water connect observations within an extent\n", "extent = (\n", " 140.86,\n", " 140.9,\n", " -38.05,\n", " -38.00,\n", ") # (left, right, lower, upper) bounds in lat/lon\n", "oc = hpd.read_waterconnect(extent=extent, tmin=\"2000-1-1\")\n", "oc" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# plot locations on map\n", "ax = oc.to_gdf(crs=4326).plot(\n", " figsize=(10, 10),\n", ")\n", "cx.add_basemap(ax=ax, crs=4326)\n", "\n", "# add labels\n", "for idx, row in oc.iterrows():\n", " ax.annotate(text=idx, xy=(row[\"x\"], row[\"y\"]), horizontalalignment=\"center\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# plot measurements from a single observation\n", "o = oc.get_obs(105147)\n", "o[\"rswl\"].plot(marker=\".\", label=o.name, ylabel=o.unit, legend=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get data from a certain measurement well based on the drillhole number (dh_no)\n", "o1 = hpd.GroundwaterObs.from_waterconnect(95360)\n", "o1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get water levels from another drillhole and plot both\n", "o2 = hpd.GroundwaterObs.from_waterconnect(119988)\n", "\n", "# plot data\n", "f, ax = plt.subplots(figsize=(10, 4))\n", "o1[\"rswl\"].plot(ylabel=o1.unit, label=o1.name, marker=\".\", color=\"b\", ax=ax)\n", "o2[\"rswl\"].plot(ylabel=o2.unit, label=o2.name, marker=\".\", ax=ax, color=\"g\")\n", "ax.axhline(o1.ground_level, ls=\":\", color=\"b\", label=f\"ground level {o1.name}\")\n", "ax.axhline(o2.ground_level, ls=\":\", color=\"g\", label=f\"ground level {o2.name}\")\n", "ax.legend()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Find selection criteria\n", "\n", "Very often you don't know exactly the drillhole numbers (dh_no) of the measurements you want to download and it may be unfeasable to download all the observations in the extent. To get the data that you want you can follow these steps:\n", "\n", "1. get a geodataframe with the metadata of all the locations in the extent\n", "2. query the geodataframe by any metadata property such as REF_ELEV, STATUS, MAX_DEPTH\n", "3. request the measurement for the locations you obtained at step 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# step 1\n", "extent = (\n", " 140.86,\n", " 140.9,\n", " -38.05,\n", " -38.00,\n", ") # (left, right, lower, upper) bounds in lat/lon\n", "\n", "# get all locations\n", "gdf = get_locations_gdf()\n", "gdf_extent = get_locations_within_extent(gdf, extent)\n", "gdf_extent" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 2 query the GeoDataFrame\n", "\n", "# print statistics of the reference elevation\n", "gdf_extent.loc[gdf_extent[\"REF_ELEV\"] == -9999, \"REF_ELEV\"] = np.nan\n", "print(f\"statistics of the reference elevation:\\n{gdf_extent['REF_ELEV'].describe()}\\n\")\n", "\n", "# print unique names\n", "print(f\"unique value in status column:\\n {gdf_extent['STAT_DESC'].unique()}\\n\")\n", "\n", "# print statistics of the maximum depth\n", "gdf_extent.loc[gdf_extent[\"MAX_DEPTH\"] == -9999, \"MAX_DEPTH\"] = np.nan\n", "print(f\"statistics of the max depth:\\n{gdf_extent['MAX_DEPTH'].describe()}\\n\")\n", "\n", "# select all observation points with some conditions\n", "gdf_selection = gdf_extent.loc[\n", " (gdf_extent[\"REF_ELEV\"] > 12.5) & (gdf_extent[\"MAX_DEPTH\"] > 15)\n", "]\n", "print(\"selected data:\\n\")\n", "display(gdf_selection)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 3 read data for selection criteria\n", "oc = hpd.read_waterconnect(location_gdf=gdf_selection)\n", "oc" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# plot the data on an interactive map\n", "oc[\"lat\"] = oc[\"y\"]\n", "oc[\"lon\"] = oc[\"x\"]\n", "oc.plots.interactive_map(popup_width=350)" ] } ], "metadata": { "kernelspec": { "display_name": "dev2", "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.12.9" } }, "nbformat": 4, "nbformat_minor": 4 }