{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "db3704f3",
   "metadata": {},
   "source": [
    "# Weather radar data processing"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a85f8f8b",
   "metadata": {},
   "source": [
    "Now we come to the most interesting process chain. The ```wr_routine_furuno``` currently contains all steps to generate precipitation products with a temporal resolution of 5 minutes from the raw data.\n",
    "\n",
    "First the **start** and **end time** have to be defined. The parameter **delta** specifies the time period for which a file list is to be generated. In this process chain, products of level 2a are generated, which is why the **data_type** is defined in this way. Again both parameters **elevation_angle** and **pattern** have to be defined to define the elevation angle for the HDF5 and SCN/SCNX files.\n",
    "\n",
    "Once the parameters are defined, the configuration file is loaded within the function and further parameters are defined. A reindexing of the azimuth resolution takes place, which is why start, end and distance of the azimuth angle must be defined in the configuration file. In addition, all submodules can be used for two- and three-dimensional datasets. In operational mode, which provides near-real-time information, the processing of individual files is faster than reading in several files with a time component. Furthermore, all variables are defined in the configuration file, which are to be contained later in the processed files.\n",
    "\n",
    "Then the static clutter map for the selected elevation angle is reading. The boolean data array is then extracted from the dataset. This is needed later for the clutter detection.\n",
    "\n",
    "In the next step the filenames of the Furuno raw data are stored in a list. The list always contains all files for one day, if delta=1 was set. With a for loop the data processing of the raw data starts. First the extension is used to check how to read the data. As described in the [data input section](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/jupyter_notebooks/read_furuno_data.html), there are two different data formats for which different reading routines are required. After reading the data the reindexing of the azimuth angle is done and errors in the data array of the elevation angle are corrected. \n",
    "\n",
    "Then the [clutter detection](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/tutorials_and_examples/clutter_detection_module.html) takes place and first the complete dataset is masked with the variable RHOHV. Clutter are removed from the uncorrected reflectivity with the loaded static clutter map and with the ```fuzzy_eccho_classification```. \n",
    "\n",
    "Then the [phase processing](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/jupyter_notebooks/attenuation_correction.html#Phase-processing) is performed in which PHIDP is recalculated and the specific attenuation is determined and KDP is derived. The recalculated PHIDP is then used for [attenuation correction](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/jupyter_notebooks/attenuation_correction.html#Attenuation-correction). After the attenuation correction, the [quantitative precipitation estimation](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/jupyter_notebooks/precipitation_estimation.html) can then be performed using the z-R conversion. This is followed by smoothing and [georeferencing](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/jupyter_notebooks/geometry_module.html) of the dataset. The precipitation product is then stored in the specified output directory as a NetCDF file."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8a30d12d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import wrainfo as wrf\n",
    "import datetime as dt\n",
    "import logging"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "674740e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "path_to_config_file=\"/tests/data/test_settings_wrainfo.json\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d01d5e87",
   "metadata": {},
   "outputs": [],
   "source": [
    "wrf.process_chains.wr_routine_furuno(starttime=dt.datetime(2022,2,15),\n",
    "                                     endtime=dt.datetime(2022,2,16),\n",
    "                                     delta=1,\n",
    "                                     path=path_to_config_file,\n",
    "                                     data_type=\"Level2a\",\n",
    "                                     elevation_angle=\"dataset1\",\n",
    "                                     pattern=\"_000.scnx.gz\",\n",
    "                                     logger=logging.getLogger())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2cc418ed",
   "metadata": {},
   "source": [
    "# Functions of WRaINfo"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a80a6be7",
   "metadata": {},
   "source": [
    "The following function of WRaINfo are used in the ```wr_routine_furuno```.:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b811021",
   "metadata": {},
   "source": [
    " - [wrainfo.reader.read_config_file](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/_modules/wrainfo/reader.html#read_config_file)\n",
    " - [wrainfo.reader.create_filelist](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/_modules/wrainfo/reader.html#create_filelist)\n",
    " - [wrainfo.clutter.fuzzy_echo_classification](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/_modules/wrainfo/clutter.html#fuzzy_echo_classification)\n",
    " - [wrainfo.clutter.dbzh_no_clutter](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/_modules/wrainfo/clutter.html#dbzh_no_clutter)\n",
    " - [wrainfo.attenuation_corr.attenuation_correction](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/_modules/wrainfo/attenuation_corr.html#attenuation_correction)\n",
    " - [wrainfo.precipitation.qpe_zr](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/_modules/wrainfo/precipitation.html#qpe_zr)\n",
    " - [wrainfo.geometry.furuno_georeferencing](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/_modules/wrainfo/geometry.html#furuno_georeferencing)\n",
    " - [wrainfo.geometry.furuno_sweep_to_netcdf](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/_modules/wrainfo/geometry.html#furuno_sweep_to_netcdf)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
