{ "cells": [ { "cell_type": "markdown", "id": "e71410cb", "metadata": {}, "source": [ "# Example notebook Peak Removal Filter" ] }, { "cell_type": "markdown", "id": "7e5efded", "metadata": {}, "source": [ "In this notebook it is shown how to use the different functions of the Peak Removal Filter." ] }, { "cell_type": "code", "execution_count": 1, "id": "85350855", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "id": "ea761e62", "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "import matplotlib.pyplot as plt\n", "import xarray as xr\n", "\n", "import pypwsqc.peak_removal_filter as prf\n", "import pypwsqc.peak_removal_filter_plots as prfp" ] }, { "cell_type": "markdown", "id": "003b665e", "metadata": {}, "source": [ "## Data download and preparation" ] }, { "cell_type": "code", "execution_count": 3, "id": "1384c9ad", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Your current directory: /home/illich/pypwsqc/docs/notebooks\n" ] } ], "source": [ "print(\"Your current directory:\", Path.cwd())" ] }, { "cell_type": "markdown", "id": "a3a7764d", "metadata": {}, "source": [ "In this example, we use an open PWS dataset from Amsterdam, published by de Vos et al. (2019). By running the cell below, a NetCDF-file will be downloaded to your current repository (if your machine is connected to the internet).\n", "\n", "You can specify the directory and the name for the test dataset in the next cell." ] }, { "cell_type": "code", "execution_count": 4, "id": "28765d11", "metadata": {}, "outputs": [], "source": [ "name = \"test_dataset_prf.nc\"\n", "path = Path.cwd() / \"data\" / name # or specify your own directory" ] }, { "cell_type": "code", "execution_count": 5, "id": "262a3374", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " % Total % Received % Xferd Average Speed Time Time Time Current\n", " Dload Upload Total Spent Left Speed\n", " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0" ] }, { "name": "stdout", "output_type": "stream", "text": [ " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n", "100 5687k 100 5687k 0 0 5163k 0 0:00:01 0:00:01 --:--:-- 26.3M\n" ] } ], "source": [ "if path.exists():\n", " print(f\"File {name} already exists in the current directory.\")\n", "else:\n", " !curl -o \"$path\" -L https://github.com/OpenSenseAction/OS_data_format_conventions/raw/main/notebooks/data/OpenSense_PWS_example_format_data.nc" ] }, { "cell_type": "markdown", "id": "69aa5e8a", "metadata": {}, "source": [ "### Use your own data\n", "If you want to use your own datasets, undo the commenting and enter your own path as name. \n", "\n", "Later, there are also options to use a second reference dataset. You can make use of that by adding a path to a second dataset to name_ref." ] }, { "cell_type": "code", "execution_count": 6, "id": "7c402c70", "metadata": {}, "outputs": [], "source": [ "# name =\n", "# name_ref =" ] }, { "cell_type": "markdown", "id": "1487a468", "metadata": {}, "source": [ "## Load data" ] }, { "cell_type": "code", "execution_count": 7, "id": "cabd4162", "metadata": {}, "outputs": [], "source": [ "ds_test = xr.open_dataset(path)\n", "# ds_test_ref = xr.open_dataset(name_ref) # undo comment to use reference dataset" ] }, { "cell_type": "code", "execution_count": 8, "id": "436c7244", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 237MB\n",
"Dimensions: (time: 219168, id: 134)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2MB 2016-05-01T00:05:00 ... 2018-06-01\n",
" * id (id) <U6 3kB 'ams1' 'ams2' 'ams3' ... 'ams132' 'ams133' 'ams134'\n",
" elevation (id) <U3 2kB ...\n",
" latitude (id) float64 1kB ...\n",
" longitude (id) float64 1kB ...\n",
"Data variables:\n",
" rainfall (id, time) float64 235MB ...\n",
"Attributes:\n",
" title: PWS data from Amsterdam\n",
" file author: Maximilian Graf\n",
" institution: Wageningen University and Research, Department of ...\n",
" date: 2022-10-18 10:32:00\n",
" source: Netamo PWS\n",
" history: Data derived and reformated from the originally pu...\n",
" naming convention: OpenSense-0.1\n",
" license restrictions: CC-BY 4.0 https://creativecommons.org/licenses/by/...\n",
" reference: https://doi.org/10.1029/2019GL083731\n",
" comment: <xarray.Dataset> Size: 237MB\n",
"Dimensions: (time: 219168, id: 134)\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2MB 2016-05-01T00:05:00 ... 2018-06-01\n",
" * id (id) <U6 3kB 'ams1' 'ams2' 'ams3' ... 'ams132' 'ams133' 'ams134'\n",
" elevation (id) <U3 2kB ...\n",
" latitude (id) float64 1kB 52.31 52.3 52.31 52.35 ... 52.43 52.3 52.26\n",
" longitude (id) float64 1kB 4.671 4.675 4.677 4.678 ... 5.036 5.041 5.045\n",
" x (id) float64 1kB 6.139e+05 6.142e+05 ... 6.392e+05 6.396e+05\n",
" y (id) float64 1kB 5.796e+06 5.796e+06 ... 5.797e+06 5.792e+06\n",
"Data variables:\n",
" rainfall (id, time) float64 235MB ...\n",
"Attributes:\n",
" title: PWS data from Amsterdam\n",
" file author: Maximilian Graf\n",
" institution: Wageningen University and Research, Department of ...\n",
" date: 2022-10-18 10:32:00\n",
" source: Netamo PWS\n",
" history: Data derived and reformated from the originally pu...\n",
" naming convention: OpenSense-0.1\n",
" license restrictions: CC-BY 4.0 https://creativecommons.org/licenses/by/...\n",
" reference: https://doi.org/10.1029/2019GL083731\n",
" comment: "
],
"text/plain": [
"