{ "cells": [ { "cell_type": "markdown", "id": "72733dce", "metadata": {}, "source": [ "# Downloading meteorological data\n", "In `nlmod` we can download meteorological data from the Dutch meteorlogical institute, using the Python package `hydropandas` in the background. In the following sections we will show different options for downloading and storing meteorological data:\n", "- Calculate recharge by subtracting evaporation from precipitation\n", "- Store precipitation and evaporation to seperate variables\n", "- Seperate the meteorological measurement values and the station locations" ] }, { "cell_type": "code", "execution_count": null, "id": "bf6cddc4", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import nlmod" ] }, { "cell_type": "code", "execution_count": null, "id": "6001e746", "metadata": {}, "outputs": [], "source": [ "nlmod.util.get_color_logger(\"INFO\")\n", "nlmod.show_versions()" ] }, { "cell_type": "markdown", "id": "01582cee", "metadata": {}, "source": [ "## Generate a model Datset\n", "First we create a model Dataset for a specific part of the Netherlands." ] }, { "cell_type": "code", "execution_count": null, "id": "93beb4bf", "metadata": {}, "outputs": [], "source": [ "extent = [100_000, 110_000, 400_000, 410_000]\n", "ds = nlmod.get_ds(extent)\n", "nlmod.plot.get_map(extent, background=True);" ] }, { "cell_type": "markdown", "id": "18c2a6f0", "metadata": {}, "source": [ "We need to set the time dimension of the model dataset, so we know what period we need to download meteorological data for.\n", "\n", "We set our simulation time to be every day of the year 2024, and we set the start of our siumlation at the start of 2023. In this way we start with a steady state stress period with average meteorological data from the year 2023." ] }, { "cell_type": "code", "execution_count": null, "id": "06471272", "metadata": {}, "outputs": [], "source": [ "time = pd.date_range(\"2024-01-01\", \"2025-1-1\", freq=\"D\")\n", "start = \"2023-01-01\"\n", "ds = nlmod.time.set_ds_time(ds, start=start, time=time)\n", "# show the contents of our time dimension\n", "ds.time" ] }, { "cell_type": "markdown", "id": "6c04bfc8", "metadata": {}, "source": [ "## Calculate recharge by subtracting evaporation from precipitation\n", "We use the method `nlmod.read.knmi.get_recharge` to download recharge data from the KNMI for our entire model area. This method downloads precipitation-data (\"RD\") from precipitation-stations (\"neerslagstations\") and Makking-evaporation data (\"EV24\") from the meteoroogical stations (weerstations) of the KNMI. As can be seen from the info-messages below, we see that data from several precipitation-stations is downloaded, and date from one meteoroogical station.\n", "\n", "By default, `nlmod.read.knmi.get_recharge` subtracts the evaporation form the precipitation, to calculate the groundwater recharge. This recharge is returned as the variable `recharge` in the returned xarray Dataset." ] }, { "cell_type": "code", "execution_count": null, "id": "4e7c4162", "metadata": {}, "outputs": [], "source": [ "meteo = nlmod.read.knmi.get_recharge(ds)\n", "# show the contents of the returned dataset\n", "meteo" ] }, { "cell_type": "markdown", "id": "a1f41ede", "metadata": {}, "source": [ "We can plot the average rainfall over the entire time period. We see a Thiessen-polygon containing the precipitation-values." ] }, { "cell_type": "code", "execution_count": null, "id": "866074c3", "metadata": {}, "outputs": [], "source": [ "nlmod.plot.map_array(meteo['recharge'][1:].mean(dim='time'), cmap='Blues', ds=ds);" ] }, { "cell_type": "markdown", "id": "3f55ef58", "metadata": {}, "source": [ "## Store precipitation and evaporation to seperate variables\n", "We can also return the precipitation and evaporation data in separate variables `recharge` and `evaporation`, to be used in the RCH-, EVT- and UZF-packages. We can use `ds.update(meteo)` to add these variables to the model dataset `ds`." ] }, { "cell_type": "code", "execution_count": null, "id": "7bfe9057", "metadata": {}, "outputs": [], "source": [ "meteo = nlmod.read.knmi.get_recharge(ds, method=\"separate\")\n", "# show the contents of the returned dataset\n", "meteo" ] }, { "cell_type": "code", "execution_count": null, "id": "7a184748", "metadata": {}, "outputs": [], "source": [ "f, ax = nlmod.plot.get_map(extent, ncols=2)\n", "qm = nlmod.plot.data_array(meteo['recharge'][1:].mean(dim='time') * 1000, cmap='Blues', ds=ds, ax=ax[0])\n", "nlmod.plot.colorbar_inside(qm, ax=ax[0], label='Recharge (mm/day)')\n", "qm = nlmod.plot.data_array(meteo['evaporation'][1:].mean(dim='time') * 1000, cmap='Blues', ds=ds, ax=ax[1])\n", "nlmod.plot.colorbar_inside(qm, ax=ax[1], label='Evaporation (mm/day)');" ] }, { "cell_type": "markdown", "id": "b51a7e8e", "metadata": {}, "source": [ "## Seperate the meteorological measurement values and the station locations\n", "The previous data is transformed to xarray DataArrays with dimensions `time`, `y` and `x`, with many duplicate values for cells near to the same station. If we do not want this 3d-array with a lot of duplicate values, we can use the optional parameter `add_stn_dimensions`. If we set this parameter to True, the `recharge` and `evaporation` variables contain the dimensions `stn_RD` and `stn_EV24`, and the variables `recharge_stn` and `evaporation_stn` contain the station-number that is used in every model cell. This way of storing meteorlogiscal data in the model dataset is also supported in the generation of the RCH- EVT- and UZF-packages." ] }, { "cell_type": "code", "execution_count": null, "id": "1e56d62e", "metadata": {}, "outputs": [], "source": [ "meteo = nlmod.read.knmi.get_recharge(ds, add_stn_dimensions=True)\n", "# show the contents of the returned dataset\n", "meteo" ] }, { "cell_type": "code", "execution_count": null, "id": "b802e743", "metadata": {}, "outputs": [], "source": [ "f, ax = nlmod.plot.get_map(extent, ncols=2)\n", "qm = nlmod.plot.data_array(meteo['recharge_stn'], ds=ds, ax=ax[0])\n", "nlmod.plot.colorbar_inside(qm, ax=ax[0], label='Recharge station')\n", "qm = nlmod.plot.data_array(meteo['evaporation_stn'], ds=ds, ax=ax[1])\n", "nlmod.plot.colorbar_inside(qm, ax=ax[1], label='Evaporation station');" ] }, { "cell_type": "markdown", "id": "b3b9cdfb", "metadata": {}, "source": [ "We can now better plot the measurement-values from the indiviudeal measurement-stations." ] }, { "cell_type": "code", "execution_count": null, "id": "94e67d45", "metadata": {}, "outputs": [], "source": [ "f, axes = plt.subplots(figsize=(10, 10), nrows=2, sharex=True, layout=\"constrained\")\n", "\n", "meteo['recharge'].to_pandas().plot(ax=axes[0])\n", "axes[0].set_ylabel('Recharge (m/day)')\n", "meteo['evaporation'].to_pandas().plot(ax=axes[1])\n", "axes[1].set_ylabel('Evaporation (m/day)');" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }