{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "de3fe411",
   "metadata": {},
   "source": [
    "# Reading configuration file"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07ed065c",
   "metadata": {},
   "source": [
    "It is necessary to use the configuration file for defining parameters of functions and for path dependencies. All functions include the path to the configuration file and load the specific settings for the executed function. You have to adapt the configuration file for your paths. The settings of the functions are default values specified for WR2120 and can be used to test the functions with the test files of WR2120.\n",
    "\n",
    "We have to import WRaINfo before we can load the configuration file.\n",
    "\n",
    "```python\n",
    "import wrainfo as wrf\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aac46780",
   "metadata": {},
   "source": [
    "Set the path to the configuration file as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6d562d72",
   "metadata": {},
   "outputs": [],
   "source": [
    "path_to_config_file=\"/tests/data/test_settings_wrainfo.json\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a65c7f35",
   "metadata": {},
   "source": [
    "Now we can execute the function:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f1a221b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'raw_data_directory': './tests/data/raw/',\n",
       " 'subfolder_structure_raw_data': '{0}/{1:02}/{2:02d}',\n",
       " 'error_flist_directory': './tests/data/error_flist/error_flist',\n",
       " 'monthly_clutter_directory': '/example/path/',\n",
       " 'subfolder_structure_clutter_directory': '{year}',\n",
       " 'static_clutter_directory': '/example/path/static_cmaps/',\n",
       " 'output_directory_tar_gz_files': '/example/path/compressed_files/',\n",
       " 'output_path_level2a': '/example/path/',\n",
       " 'output_path_processed_files': '/example/path/',\n",
       " 'output_path_error_flist': '/example/path/error_files.ob',\n",
       " 'radar_location_identifier': 'location_serialnumber',\n",
       " 'epsg_code': 32633,\n",
       " 'nb_pixels': 1400,\n",
       " 'chunksize': [1, 720, 936],\n",
       " 'dimensions': ['azimuth', 'range'],\n",
       " 'scan_interval': 300,\n",
       " 're_index_parameters': [0.25, 360, 0.5],\n",
       " 'moments_in_processed_files': ['RATE',\n",
       "  'DBZH',\n",
       "  'VRAD',\n",
       "  'ZDR',\n",
       "  'KDP',\n",
       "  'PHIDP',\n",
       "  'RHOHV',\n",
       "  'WRADH',\n",
       "  'FUZZ',\n",
       "  'DBZH_no_clutter',\n",
       "  'DBZH_CORR',\n",
       "  'PREC_ZR']}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "config_file=wrf.reader.read_config_file(path=path_to_config_file,\n",
    "                                        selection=None)\n",
    "display(config_file)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d72fd34",
   "metadata": {},
   "source": [
    "<div class=\"alert alert-info\">\n",
    "\n",
    "**Note** <br>\n",
    "\n",
    "If we do not choose a selection, we can read the total content of the configuration file.\n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e5791bd",
   "metadata": {},
   "source": [
    "# Get error file list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5de83be",
   "metadata": {},
   "source": [
    "It happens that the recorded data are erroneous, which is why there is an error list. This list with faulty files can be loaded with the following function ```load_error_filelist ```. An example error list is loaded here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e886f103",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/tests/data/raw/2021/12/23/2006_20211223_161500.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_162000.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_162500.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_163000.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_163500.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_164500.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_165000.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_165500.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_170000.h5',\n",
       " '/tests/data/raw/2021/12/23/2006_20211223_170500.h5']"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "error_flist=wrf.reader.load_error_flist(path=\"/tests/data/test_settings_wrainfo.json\")\n",
    "display(error_flist)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5cdfe575",
   "metadata": {},
   "source": [
    "<div class=\"alert alert-info\">\n",
    "\n",
    "**Seealso** <br>\n",
    "\n",
    "Get more information in the error [file list module](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/jupyter_notebooks/further_features.html#Error-file-list-module) or in the [library reference section](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/wrainfo.html#module-wrainfo.error_flist).\n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a368bfe7",
   "metadata": {},
   "source": [
    "# Get file list of FURUNO raw data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9baf29d1",
   "metadata": {},
   "source": [
    "Furuno files are available in HDF5 or SCN/SCNX format. In the ```create_filelist``` function both data formats are read. In order not to integrate data with the same timestamp in HDF5 and SCN/SCNX format in the file list, SCN/SCNX data are preferred. In addition, the function checks whether the file name is present in the error file list. If this is the case, the file will not be included in the file list."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4870c88",
   "metadata": {},
   "source": [
    "<div class=\"alert alert-info\">\n",
    "\n",
    "**Note** <br>\n",
    "\n",
    "Another reason for preferring SCN/SCNX files, is that these data have a 16-bit resolution at the variable PHIDP. This is reduced to 8-bit when converting to HDF5, which has a negative effect on the phase processing and attenuation correction.\n",
    "\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "85913c18",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/tests/data/raw/2022/02/16/2006_20220216_134500.h5',\n",
       " '/tests/data/raw/2022/02/16/2006_20220216_135000.h5',\n",
       " '/tests/data/raw/2022/02/16/2006_20220216_135500.h5',\n",
       " '/tests/data/raw/2022/04/05/2006_20220405_123000_000.scnx.gz',\n",
       " '/tests/data/raw/2022/04/05/2006_20220405_123500_000.scnx.gz',\n",
       " '/tests/data/raw/2022/04/05/2006_20220405_124500_000.scnx.gz']"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "flist=wrf.reader.create_filelist(starttime=dt.datetime(2022,2,15), \n",
    "                                 endtime=dt.datetime(2022,4,6), \n",
    "                                 path=\"/tests/data/test_settings_wrainfo.json\", \n",
    "                                 pattern=\"_000.scnx.gz\")\n",
    "\n",
    "display(flist)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a557319a",
   "metadata": {},
   "source": [
    "# Library Reference"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "047d79f1",
   "metadata": {},
   "source": [
    "<div class=\"alert alert-info\">\n",
    "\n",
    "**Seealso** <br>\n",
    "\n",
    "Get more information about the reader module in the [library reference section](https://fernlab.git-pages.gfz-potsdam.de/products/furuno/wrainfo/doc/wrainfo.html#module-wrainfo.reader).\n",
    "\n",
    "</div>"
   ]
  }
 ],
 "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
}
