{ "cells": [ { "cell_type": "markdown", "id": "f478ddab", "metadata": {}, "source": [ "# Groundwater Analysis Report (GAR)" ] }, { "cell_type": "code", "execution_count": null, "id": "d4dbf32c-76d0-4e90-a8ce-9315beb98b98", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import brodata" ] }, { "cell_type": "markdown", "id": "160ca9be", "metadata": {}, "source": [ "Download a GroundwaterAnalysisReport using `GroundwaterAnalysisReport.from_bro_id(bro_id)`. The object contains the data from the BRO XML file." ] }, { "cell_type": "code", "execution_count": null, "id": "c31ba251", "metadata": {}, "outputs": [], "source": [ "gar = brodata.gar.GroundwaterAnalysisReport.from_bro_id(\"GAR000000019636\")\n", "gar" ] }, { "cell_type": "markdown", "id": "b7a2f472", "metadata": {}, "source": [ "Measurements are stored in the `laboratoryAnalysis` attribute (a pandas DataFrame)." ] }, { "cell_type": "code", "execution_count": null, "id": "8d68cb85", "metadata": {}, "outputs": [], "source": [ "gar.laboratoryAnalysis" ] }, { "cell_type": "markdown", "id": "2f723311", "metadata": {}, "source": [ "Use `to_dict()` to view the remaining contents of the GroundwaterAnalysisReport." ] }, { "cell_type": "code", "execution_count": null, "id": "2fcb9c48", "metadata": {}, "outputs": [], "source": [ "gar_data = gar.to_dict()\n", "gar_data.pop(\"laboratoryAnalysis\")\n", "gar_data" ] }, { "cell_type": "markdown", "id": "4736603f-f644-4bec-a223-5d1b5a3ce5f6", "metadata": {}, "source": [ "## Multiple objects" ] }, { "cell_type": "markdown", "id": "0f5708ba-b730-4047-8649-06c87ad4896f", "metadata": {}, "source": [ "### All measurements of one tube" ] }, { "cell_type": "code", "execution_count": null, "id": "1877a680-b797-4330-ae99-2a7de998a914", "metadata": {}, "outputs": [], "source": [ "gmw_id = \"GMW000000017707\"\n", "tube_number = 1\n", "df = brodata.gmw.get_tube_observations(gmw_id, tube_number, kind=\"gar\")\n", "df" ] }, { "cell_type": "code", "execution_count": null, "id": "00093c5d-40a7-405e-819c-d08e5c7dc494", "metadata": {}, "outputs": [], "source": [ "parameter_list = brodata.gar.get_parameter_list()\n", "parameter_list" ] }, { "cell_type": "code", "execution_count": null, "id": "c7634825-2877-4729-8144-395bb1e847c6", "metadata": {}, "outputs": [], "source": [ "# add the parameter description\n", "df[\"parameter_description\"] = parameter_list.loc[df[\"parameter\"], \"description\"].values" ] }, { "cell_type": "code", "execution_count": null, "id": "e3fb4a55-9257-4800-a229-2c833c4a143d", "metadata": {}, "outputs": [], "source": [ "# show all the unique parameters and the number of measurements\n", "parameter_description_counts = df[\"parameter_description\"].value_counts()\n", "parameter_description_counts" ] }, { "cell_type": "code", "execution_count": null, "id": "233742f0-1b44-442f-9e29-980643b3be6b", "metadata": {}, "outputs": [], "source": [ "parameter_description = \"sulfaat\"\n", "parameter_code = brodata.gar.get_parameter_code(parameter_description, parameter_list=parameter_list)\n", "mask = df[\"parameter\"] == parameter_code\n", "ax = df.loc[mask, \"analysisMeasurementValue\"].plot(marker=\".\")\n", "uom = df.loc[mask, \"uom\"].unique()\n", "assert len(uom) == 1\n", "ax.set_ylabel(uom[0])\n", "ax.set_title(f\"{parameter_description} {gmw_id}_{tube_number}\");" ] }, { "cell_type": "markdown", "id": "c29168b6-62ad-4d93-8f19-f493cc48660a", "metadata": {}, "source": [ "### All measurements within an extent\n", "As with Groundwater Level Dossiers, you can download GAR data within an extent via `brodata.gm.get_data_in_extent` or `brodata.gmw.get_data_in_extent`. Both return a GeoDataFrame where `laboratoryAnalysis` contains measurement data and `groundwaterAnalysisReport` lists GAR BRO IDs for each tube.\n", "\n", "For simplicity we use `brodata.gm.get_data_in_extent` (see the GLD example)." ] }, { "cell_type": "code", "execution_count": null, "id": "6c6c5cdf-465e-4105-8839-6f05bea84cf9", "metadata": {}, "outputs": [], "source": [ "extent = [115000, 120000, 438000, 441000]\n", "gdf = brodata.gm.get_data_in_extent(extent=extent, kind=\"gar\", combine=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "a503d6cd-2818-4410-810f-44f21e023163", "metadata": {}, "outputs": [], "source": [ "gdf.T" ] }, { "cell_type": "markdown", "id": "4b9ca7c1", "metadata": {}, "source": [ "Plot the GeoDataFrame to inspect locations; some monitoring wells may overlap." ] }, { "cell_type": "code", "execution_count": null, "id": "289d1c11", "metadata": {}, "outputs": [], "source": [ "f, ax = plt.subplots()\n", "ax.axis(\"scaled\")\n", "ax.axis(extent)\n", "gdf.plot(ax=ax);" ] }, { "cell_type": "markdown", "id": "1d835b70", "metadata": {}, "source": [ "Plot measurement series for the tubes in a single figure." ] }, { "cell_type": "code", "execution_count": null, "id": "0f92ab53", "metadata": {}, "outputs": [], "source": [ "f, ax = plt.subplots()\n", "parameter_description = \"sulfaat\"\n", "parameter_code = brodata.gar.get_parameter_code(parameter_description, parameter_list=parameter_list)\n", "uom = \"mg/l\"\n", "for index in gdf.index:\n", " df = gdf.at[index, \"laboratoryAnalysis\"]\n", " mask = df[\"parameter\"] == parameter_code\n", " if not mask.any():\n", " continue\n", " assert (df.loc[mask, \"uom\"] == uom).all()\n", " ax = df.loc[mask, \"analysisMeasurementValue\"].plot(marker=\".\", ax=ax, label=index)\n", "ax.set_ylabel(uom)\n", "ax.set_title(parameter_description)\n", "ax.legend();" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }