{ "cells": [ { "cell_type": "markdown", "id": "858846c1", "metadata": {}, "source": [ "# Bias Correction Example" ] }, { "cell_type": "code", "execution_count": 2, "id": "6f594617", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "ename": "ImportError", "evalue": "cannot import name 'bias_correction' from 'pypwsqc' (/home/IWS/seidel/miniconda3/envs/opensense_training/lib/python3.11/site-packages/pypwsqc/__init__.py)", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mImportError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpoligrain\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mplg\u001b[39;00m\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mxarray\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mxr\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpypwsqc\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m bias_correction \u001b[38;5;28;01mas\u001b[39;00m bc\n", "\u001b[31mImportError\u001b[39m: cannot import name 'bias_correction' from 'pypwsqc' (/home/IWS/seidel/miniconda3/envs/opensense_training/lib/python3.11/site-packages/pypwsqc/__init__.py)" ] } ], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import poligrain as plg\n", "import xarray as xr\n", "\n", "from pypwsqc import bias_correction as bc" ] }, { "cell_type": "markdown", "id": "7965ba48", "metadata": {}, "source": [ "## Data download and preparation" ] }, { "cell_type": "markdown", "id": "5960c6ee", "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)." ] }, { "cell_type": "code", "execution_count": 9, "id": "bdf540a5", "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\n", "100 5687k 100 5687k 0 0 19.4M 0 --:--:-- --:--:-- --:--:-- 19.4M\n" ] } ], "source": [ "!curl -OL https://github.com/OpenSenseAction/OS_data_format_conventions/raw/main/notebooks/data/OpenSense_PWS_example_format_data.nc" ] }, { "cell_type": "markdown", "id": "36fa8a22", "metadata": {}, "source": [ "### Load the PWS data set" ] }, { "cell_type": "code", "execution_count": 10, "id": "bb2305bf", "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 'nan' 'nan' 'nan' 'nan' ... 'nan' 'nan' 'nan' 'nan'\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",
"Data variables:\n",
" rainfall (id, time) float64 235MB 0.0 0.0 0.0 0.0 0.0 ... nan 0.0 0.0 0.0\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: 292kB\n",
"Dimensions: (time: 18265)\n",
"Coordinates:\n",
" id <U6 24B 'ams1'\n",
" elevation <U3 12B 'nan'\n",
" latitude float64 8B 52.31\n",
" longitude float64 8B 4.671\n",
" * time (time) datetime64[ns] 146kB 2016-05-01 ... 2018-06-01\n",
" x float64 8B 6.139e+05\n",
" y float64 8B 5.796e+06\n",
"Data variables:\n",
" rainfall (time) float64 146kB 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 nan\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": [
"<xarray.Dataset> Size: 40B\n",
"Dimensions: (id: 1, n_closest: 1)\n",
"Coordinates:\n",
" * id (id) <U6 24B 'ams65'\n",
"Dimensions without coordinates: n_closest\n",
"Data variables:\n",
" distance (id, n_closest) float64 8B 784.0\n",
" neighbor_id (id, n_closest) object 8B '4'"
],
"text/plain": [
"<xarray.Dataset> Size: 292kB\n",
"Dimensions: (time: 18265)\n",
"Coordinates:\n",
" id <U6 24B 'ams65'\n",
" elevation <U3 12B 'nan'\n",
" latitude float64 8B 52.35\n",
" longitude float64 8B 4.885\n",
" * time (time) datetime64[ns] 146kB 2016-05-01 ... 2018-06-01\n",
" x float64 8B 6.284e+05\n",
" y float64 8B 5.801e+06\n",
"Data variables:\n",
" rainfall (time) float64 146kB nan nan nan nan nan ... 0.0 0.0 0.0 0.0 nan\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: