├── .github └── workflows │ ├── main.yml │ └── render.yml ├── .gitignore ├── .pre-commit-config.yaml ├── LICENSE.txt ├── README.md ├── ci └── requirements │ └── notebooks.yml ├── conftest.py ├── notebooks ├── __init__.py ├── attenuation │ └── attenuation.ipynb ├── basics │ ├── basics.ipynb │ ├── wradlib_get_rainfall.ipynb │ ├── wradlib_in_an_hour.ipynb │ ├── wradlib_introduction.ipynb │ └── wradlib_workflow.ipynb ├── beamblockage │ └── beamblockage.ipynb ├── classify.ipynb ├── classify │ ├── 2d_hmc.ipynb │ ├── clutter_cloud.ipynb │ ├── clutter_gabella.ipynb │ ├── fuzzy_echo.ipynb │ ├── histo_cut.ipynb │ ├── hmcp_gpm.ipynb │ └── hmcp_nexrad.ipynb ├── compositing.ipynb ├── compositing │ ├── max_reflectivity.ipynb │ └── transform.ipynb ├── fileio.ipynb ├── fileio │ ├── backends │ │ ├── cfradial1_backend.ipynb │ │ ├── cfradial2_backend.ipynb │ │ ├── furuno_backend.ipynb │ │ ├── gamic_backend.ipynb │ │ ├── iris_backend.ipynb │ │ ├── odim_backend.ipynb │ │ ├── radolan_backend.ipynb │ │ └── rainbow_backend.ipynb │ ├── gis │ │ ├── raster_data.ipynb │ │ └── vector_data.ipynb │ ├── legacy │ │ ├── read_dx.ipynb │ │ ├── read_gamic.ipynb │ │ ├── read_hdf5.ipynb │ │ ├── read_iris.ipynb │ │ ├── read_netcdf.ipynb │ │ ├── read_odim.ipynb │ │ └── read_rainbow.ipynb │ ├── legacy_readers.ipynb │ ├── radolan.ipynb │ ├── radolan │ │ ├── radolan_format.ipynb │ │ ├── radolan_grid.ipynb │ │ ├── radolan_network.ipynb │ │ ├── radolan_quickstart.ipynb │ │ └── radolan_showcase.ipynb │ └── xarray_backends.ipynb ├── files │ ├── cover_image.png │ └── wradlib_logo.svg.png ├── georeferencing.ipynb ├── georeferencing │ ├── coords.ipynb │ └── georef.ipynb ├── interpolation │ └── interpolation.ipynb ├── multisensor │ └── gauge_adjustment.ipynb ├── overview.ipynb ├── plotting.ipynb ├── python │ ├── learnpython.ipynb │ ├── mplintro.ipynb │ ├── numpyintro.ipynb │ ├── quickstart.ipynb │ └── timeseries.ipynb ├── recipes.ipynb ├── verification │ └── verification.ipynb ├── visualisation │ ├── gis_overlay.ipynb │ ├── gis_overlay_cartopy.ipynb │ ├── plot_curvelinear_grids.ipynb │ ├── plot_ppi.ipynb │ ├── plot_rhi.ipynb │ └── plot_scan_strategy.ipynb ├── workflow │ ├── fig2_schwaller_morris_2011.png │ ├── fig3_schwaller_morris_2011.png │ ├── recipe1.ipynb │ ├── recipe2.ipynb │ ├── recipe3.ipynb │ ├── recipe4.ipynb │ ├── recipe5.ipynb │ └── recipe6.ipynb └── zonalstats │ ├── zonalstats.ipynb │ └── zonalstats_quickstart.ipynb └── scripts ├── nbstripout_notebooks.sh └── render_notebooks.sh /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | env: 3 | micromamba_version: 1.5 4 | 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | workflow_dispatch: 13 | 14 | concurrency: 15 | group: ${{ github.workflow }}-${{ github.ref }} 16 | cancel-in-progress: true 17 | 18 | jobs: 19 | build_0: 20 | name: wradlib notebooks - linux 21 | runs-on: ubuntu-latest 22 | defaults: 23 | run: 24 | shell: bash -l {0} 25 | env: 26 | WRADLIB_DATA: ./wradlib-data 27 | CONDA_ENV_FILE: ci/requirements/notebooks.yml 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | python-version: ["3.12"] 32 | steps: 33 | - uses: actions/checkout@v3 34 | with: 35 | fetch-depth: 0 36 | - name: Install micromamba environment 37 | uses: mamba-org/setup-micromamba@v1 38 | with: 39 | environment-name: wradlib-notebooks 40 | environment-file: ${{env.CONDA_ENV_FILE}} 41 | cache-environment: true 42 | cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}" 43 | create-args: >- 44 | python=${{matrix.python-version}} 45 | - name: Install wradlib 46 | run: | 47 | git clone https://github.com/wradlib/wradlib.git 48 | cd wradlib 49 | echo "WRADLIB_TAG=`git name-rev --name-only --tags HEAD`" >> $GITHUB_ENV 50 | python -m pip install . --no-deps 51 | - name: Install wradlib-data 52 | run: | 53 | python -m pip install wradlib-data 54 | mkdir ./wradlib-data 55 | - name: Version Info 56 | run: | 57 | python -c "import wradlib; print(wradlib.version.version)" 58 | python -c "import wradlib; print(wradlib.show_versions())" 59 | - name: Render with pytest 60 | env: 61 | WRADLIB_EARTHDATA_BEARER_TOKEN: ${{ secrets.WRADLIB_EARTHDATA_BEARER_TOKEN }} 62 | run: | 63 | export WRADLIB_DATA=`realpath $WRADLIB_DATA` 64 | pytest -n auto --verbose --durations=15 --pyargs notebooks 65 | - name: Commit files 66 | if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' 67 | run: | 68 | git config --global user.email "wradlib-docs@wradlib.org" 69 | git config --global user.name "wradlib-docs-bot" 70 | git checkout --orphan render 71 | git add --all . 72 | git commit -m "Rendering at commit $GITHUB_SHA" 73 | - name: Push changes 74 | if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' 75 | run: | 76 | if [ $WRADLIB_TAG == 'undefined' ]; then 77 | BRANCH=devel 78 | else 79 | BRANCH=$WRADLIB_TAG 80 | fi 81 | git push https://${{ secrets.GITHUB_TOKEN }}@github.com/wradlib/wradlib-notebooks.git render:$BRANCH -fq 82 | 83 | build_1: 84 | name: wradlib notebooks - macosx 85 | runs-on: macos-latest 86 | defaults: 87 | run: 88 | shell: bash -l {0} 89 | env: 90 | WRADLIB_DATA: ./wradlib-data 91 | CONDA_ENV_FILE: ci/requirements/notebooks.yml 92 | strategy: 93 | fail-fast: false 94 | matrix: 95 | python-version: ["3.12"] 96 | steps: 97 | - uses: actions/checkout@v3 98 | with: 99 | fetch-depth: 0 100 | - name: Install micromamba environment 101 | uses: mamba-org/setup-micromamba@v1 102 | with: 103 | environment-name: wradlib-notebooks 104 | environment-file: ${{env.CONDA_ENV_FILE}} 105 | cache-environment: true 106 | cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}" 107 | create-args: >- 108 | python=${{matrix.python-version}} 109 | - name: Install wradlib 110 | run: | 111 | git clone https://github.com/wradlib/wradlib.git 112 | cd wradlib 113 | echo "WRADLIB_TAG=`git name-rev --name-only --tags HEAD`" >> $GITHUB_ENV 114 | python -m pip install . --no-deps 115 | - name: Install wradlib-data 116 | run: | 117 | python -m pip install wradlib-data 118 | mkdir ./wradlib-data 119 | - name: Version Info 120 | run: | 121 | python -c "import wradlib; print(wradlib.version.version)" 122 | python -c "import wradlib; print(wradlib.show_versions())" 123 | - name: Render with pytest 124 | env: 125 | WRADLIB_EARTHDATA_BEARER_TOKEN: ${{ secrets.WRADLIB_EARTHDATA_BEARER_TOKEN }} 126 | run: | 127 | export WRADLIB_DATA=`python -c "import os, sys; print(os.path.realpath(sys.argv[1]))" $WRADLIB_DATA` 128 | pytest -n auto --verbose --durations=15 --pyargs notebooks 129 | 130 | build_2: 131 | name: wradlib notebooks - windows 132 | runs-on: windows-latest 133 | defaults: 134 | run: 135 | shell: bash -l {0} 136 | env: 137 | WRADLIB_DATA: ./wradlib-data 138 | CONDA_ENV_FILE: ci/requirements/notebooks.yml 139 | strategy: 140 | fail-fast: false 141 | matrix: 142 | python-version: ["3.12"] 143 | steps: 144 | - uses: actions/checkout@v3 145 | with: 146 | fetch-depth: 0 147 | - name: Install micromamba environment 148 | uses: mamba-org/setup-micromamba@v1 149 | with: 150 | environment-name: wradlib-notebooks 151 | environment-file: ${{env.CONDA_ENV_FILE}} 152 | cache-environment: true 153 | cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}" 154 | create-args: >- 155 | python=${{matrix.python-version}} 156 | - name: Install wradlib 157 | run: | 158 | git clone https://github.com/wradlib/wradlib.git 159 | cd wradlib 160 | python -m pip install . --no-deps 161 | - name: Install wradlib-data 162 | run: | 163 | python -m pip install wradlib-data 164 | mkdir ./wradlib-data 165 | - name: Version Info 166 | run: | 167 | python -c "import wradlib; print(wradlib.version.version)" 168 | python -c "import wradlib; print(wradlib.show_versions())" 169 | - name: Test with pytest 170 | env: 171 | WRADLIB_EARTHDATA_BEARER_TOKEN: ${{ secrets.WRADLIB_EARTHDATA_BEARER_TOKEN }} 172 | run: | 173 | export WRADLIB_DATA=`python -c "import os, sys; print(os.path.realpath(sys.argv[1]))" $WRADLIB_DATA` 174 | pytest -n auto --verbose --durations=15 --pyargs notebooks 175 | 176 | trigger_rtd: 177 | if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' 178 | needs: [build_0] 179 | name: trigger readthedocs 180 | runs-on: ubuntu-latest 181 | defaults: 182 | run: 183 | shell: bash -l {0} 184 | env: 185 | RTD_TOKEN: ${{ secrets.RTD_TOKEN }} 186 | RTD_URL: ${{ secrets.RTD_URL }} 187 | steps: 188 | - name: trigger readthedocs 189 | run: | 190 | echo "triggering" 191 | curl -X POST -H "Authorization: Token $RTD_TOKEN" "$RTD_URL" 192 | -------------------------------------------------------------------------------- /.github/workflows/render.yml: -------------------------------------------------------------------------------- 1 | name: Render 2 | env: 3 | micromamba_version: 1.5 4 | 5 | on: 6 | workflow_dispatch: 7 | 8 | concurrency: 9 | group: ${{ github.workflow }}-${{ github.ref }} 10 | cancel-in-progress: true 11 | 12 | jobs: 13 | build_0: 14 | name: wradlib notebooks - linux 15 | runs-on: ubuntu-latest 16 | defaults: 17 | run: 18 | shell: bash -l {0} 19 | env: 20 | WRADLIB_DATA: ./wradlib-data 21 | CONDA_ENV_FILE: ci/requirements/notebooks.yml 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | python-version: ["3.12"] 26 | steps: 27 | - uses: actions/checkout@v3 28 | with: 29 | fetch-depth: 0 30 | - name: Install micromamba environment 31 | uses: mamba-org/setup-micromamba@v1 32 | with: 33 | environment-name: wradlib-notebooks 34 | environment-file: ${{env.CONDA_ENV_FILE}} 35 | cache-environment: true 36 | cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}" 37 | create-args: >- 38 | python=${{matrix.python-version}} 39 | - name: Install wradlib 40 | run: | 41 | git clone https://github.com/wradlib/wradlib.git 42 | cd wradlib 43 | echo "WRADLIB_TAG=`git name-rev --name-only --tags HEAD`" >> $GITHUB_ENV 44 | python -m pip install . --no-deps 45 | - name: Install wradlib-data 46 | run: | 47 | python -m pip install wradlib-data 48 | mkdir ./wradlib-data 49 | - name: Version Info 50 | run: | 51 | python -c "import wradlib; print(wradlib.version.version)" 52 | python -c "import wradlib; print(wradlib.show_versions())" 53 | - name: Render with pytest 54 | run: | 55 | export WRADLIB_DATA=`realpath $WRADLIB_DATA` 56 | pytest -n auto --verbose --durations=15 --pyargs notebooks 57 | - name: Commit files 58 | if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' 59 | run: | 60 | git config --global user.email "wradlib-docs@wradlib.org" 61 | git config --global user.name "wradlib-docs-bot" 62 | git checkout --orphan render 63 | git add --all . 64 | git commit -m "Rendering at commit $GITHUB_SHA" 65 | - name: Push changes 66 | if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' 67 | run: | 68 | if [ $WRADLIB_TAG == 'undefined' ]; then 69 | BRANCH=devel 70 | else 71 | BRANCH=$WRADLIB_TAG 72 | fi 73 | git push https://${{ secrets.GITHUB_TOKEN }}@github.com/wradlib/wradlib-notebooks.git render:$BRANCH -fq 74 | 75 | trigger_rtd: 76 | if: github.event_name == 'workflow_dispatch' 77 | needs: [build_0] 78 | name: trigger readthedocs 79 | runs-on: ubuntu-latest 80 | defaults: 81 | run: 82 | shell: bash -l {0} 83 | env: 84 | RTD_TOKEN: ${{ secrets.RTD_TOKEN }} 85 | RTD_URL: ${{ secrets.RTD_URL }} 86 | steps: 87 | - name: trigger readthedocs 88 | run: | 89 | echo "triggering" 90 | curl -X POST -H "Authorization: Token $RTD_TOKEN" "$RTD_URL" 91 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything 2 | * 3 | 4 | # whitelist notebooks, png and shell 5 | !*.ipynb 6 | !*.png 7 | !*.sh 8 | 9 | # whitelist scripts 10 | !scripts/ 11 | !/scripts/* 12 | 13 | # whitelist notebooks 14 | !notebooks/ 15 | #!/notebooks/** 16 | 17 | # whitelist .dask 18 | !.dask/ 19 | !/.dask/* 20 | 21 | # whitelist ci 22 | !ci/ 23 | 24 | # whitelist binder 25 | !binder/ 26 | !/binder/* 27 | 28 | # Whitelist root files 29 | !.gitignore 30 | !conftest.py 31 | !README.md 32 | !LICENSE.txt 33 | !Welcome_Pangeo.md 34 | 35 | # blacklist standard notebook copies 36 | *-Copy*.ipynb 37 | 38 | # blacklist checkpoints 39 | *checkpoint* 40 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v4.4.0 4 | hooks: 5 | - id: trailing-whitespace 6 | - id: end-of-file-fixer 7 | - id: check-docstring-first 8 | - id: check-json 9 | - id: check-yaml 10 | - id: debug-statements 11 | - id: mixed-line-ending 12 | - repo: https://github.com/asottile/pyupgrade 13 | rev: v3.3.1 14 | hooks: 15 | - id: pyupgrade 16 | args: 17 | - '--py38-plus' 18 | - repo: https://github.com/kynan/nbstripout 19 | rev: 0.6.1 20 | hooks: 21 | - id: nbstripout 22 | args: ['--extra-keys', 'metadata.kernelspec cell.metadata.pycharm cell.metadata.tags'] 23 | - repo: https://github.com/charliermarsh/ruff-pre-commit 24 | rev: 'v0.0.254' 25 | hooks: 26 | - id: ruff 27 | args: [ "--fix" ] 28 | - repo: https://github.com/psf/black 29 | rev: 23.1.0 30 | hooks: 31 | - id: black 32 | - id: black-jupyter 33 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2021 wradlib developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README # 2 | 3 | ## wradlib-notebooks ## 4 | 5 | This repository consists of jupyter notebooks to give examples of wradlib usage and help users via tutorials. 6 | 7 | Rendered versions are available in the tagged branches. In [devel-branch](https://github.com/wradlib/wradlib-notebooks/tree/devel) the most recent rendered snapshot comprising the latest changes in this repo as well as [wradlib](https://github.com/wradlib/wradlib) can be found. The notebooks are also rendered in the [wradlib documentation](https://docs.wradlib.org/en/latest/). 8 | 9 | Explore the contents - [Overview](notebooks/overview.ipynb). 10 | -------------------------------------------------------------------------------- /ci/requirements/notebooks.yml: -------------------------------------------------------------------------------- 1 | name: wradlib-notebooks 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - python>=3.9 6 | - bottleneck 7 | - cartopy 8 | - cartopy_offlinedata 9 | - codecov 10 | - coverage 11 | - dask 12 | - deprecation 13 | - gdal 14 | - geopandas 15 | - h5py 16 | - h5netcdf 17 | - lat_lon_parser 18 | - libgdal-hdf5 19 | - libgdal-netcdf 20 | - nbconvert 21 | - nc-time-axis 22 | - netCDF4 23 | - notebook 24 | - numpy 25 | - matplotlib-base 26 | - packaging 27 | - pint 28 | - pint-xarray 29 | - pip 30 | - pooch 31 | - psutil 32 | - pytest 33 | - pytest-cov 34 | - pytest-sugar 35 | - pytest-xdist 36 | - rioxarray 37 | - requests 38 | - scipy 39 | - semver 40 | - setuptools 41 | - tqdm 42 | - xarray 43 | - xmltodict 44 | - xradar 45 | -------------------------------------------------------------------------------- /conftest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright (c) 2019-2020, wradlib developers. 3 | # Distributed under the MIT License. See LICENSE.txt for more info. 4 | 5 | import os 6 | import sys 7 | 8 | import nbformat 9 | import pytest 10 | from nbconvert.preprocessors import ExecutePreprocessor 11 | from nbconvert.preprocessors.execute import CellExecutionError 12 | from packaging.version import Version 13 | 14 | 15 | def pytest_collect_file(parent, file_path): 16 | if file_path.suffix == ".ipynb" and "-Copy" not in file_path.name: 17 | return NotebookFile.from_parent(parent, path=file_path) 18 | 19 | 20 | class NotebookFile(pytest.File): 21 | if Version(pytest.__version__) < Version("5.4.0"): 22 | 23 | @classmethod 24 | def from_parent(cls, parent, path): 25 | return cls(parent=parent, path=path) 26 | 27 | def collect(self): 28 | for f in [self.path]: 29 | yield NotebookItem.from_parent(self, name=os.path.basename(f)) 30 | 31 | def setup(self): 32 | kernel = "python%d" % sys.version_info[0] 33 | self.exproc = ExecutePreprocessor(kernel_name=kernel, timeout=600) 34 | 35 | 36 | class NotebookItem(pytest.Item): 37 | def __init__(self, name, parent): 38 | super().__init__(name, parent) 39 | 40 | if Version(pytest.__version__) < Version("5.4.0"): 41 | 42 | @classmethod 43 | def from_parent(cls, parent, name): 44 | return cls(parent=parent, name=name) 45 | 46 | def runtest(self): 47 | cur_dir = os.path.dirname(self.path) 48 | 49 | # See https://bugs.python.org/issue37373 50 | if ( 51 | sys.version_info[0] == 3 52 | and sys.version_info[1] >= 8 53 | and sys.platform.startswith("win") 54 | ): 55 | import asyncio 56 | 57 | asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) 58 | 59 | with self.path.open() as f: 60 | nb = nbformat.read(f, as_version=4) 61 | try: 62 | self.parent.exproc.preprocess(nb, {"metadata": {"path": cur_dir}}) 63 | except CellExecutionError as e: 64 | raise NotebookException(e) 65 | 66 | with open(self.path, "w", encoding="utf-8") as f: 67 | nbformat.write(nb, f) 68 | 69 | def repr_failure(self, excinfo): 70 | if isinstance(excinfo.value, NotebookException): 71 | return excinfo.exconly() 72 | 73 | return super().repr_failure(excinfo) 74 | 75 | def reportinfo(self): 76 | return self.path, 0, "TestCase: %s" % self.name 77 | 78 | 79 | class NotebookException(Exception): 80 | pass 81 | -------------------------------------------------------------------------------- /notebooks/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, wradlib developers. 2 | # Distributed under the MIT License. See LICENSE.txt for more info. 3 | -------------------------------------------------------------------------------- /notebooks/basics/basics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Getting started with wradlib" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "This section provides a collection of example code snippets to make users familiar with $\\omega radlib$.\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "nbsphinx-toctree": { 33 | "hidden": true, 34 | "maxdepth": 2 35 | } 36 | }, 37 | "source": [ 38 | "## Examples List\n", 39 | "\n", 40 | "- [Get wradlib version](wradlib_introduction.ipynb)\n", 41 | "- [Typical Workflow for Radar-Based Rainfall Estimation](wradlib_workflow.ipynb)\n", 42 | "- [From Reflectivity to Rainfall](wradlib_get_rainfall.ipynb)\n", 43 | "- [wradlib in an hour](wradlib_in_an_hour.ipynb)" 44 | ] 45 | } 46 | ], 47 | "metadata": { 48 | "celltoolbar": "Edit Metadata", 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 3 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython3", 59 | "version": "3.11.0" 60 | }, 61 | "toc": { 62 | "colors": { 63 | "hover_highlight": "#DAA520", 64 | "navigate_num": "#000000", 65 | "navigate_text": "#333333", 66 | "running_highlight": "#FF0000", 67 | "selected_highlight": "#FFD700", 68 | "sidebar_border": "#EEEEEE", 69 | "wrapper_background": "#FFFFFF" 70 | }, 71 | "moveMenuLeft": true, 72 | "nav_menu": { 73 | "height": "68px", 74 | "width": "252px" 75 | }, 76 | "navigate_menu": true, 77 | "number_sections": false, 78 | "sideBar": true, 79 | "threshold": 4, 80 | "toc_cell": false, 81 | "toc_section_display": "block", 82 | "toc_window_display": false, 83 | "widenNotebook": false 84 | } 85 | }, 86 | "nbformat": 4, 87 | "nbformat_minor": 4 88 | } 89 | -------------------------------------------------------------------------------- /notebooks/basics/wradlib_get_rainfall.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) 2018, $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Converting Reflectivity to Rainfall" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "Reflectivity (Z) and precipitation rate (R) can be related in form of a power law $Z=a \\cdot R^b$. The parameters ``a`` and ``b`` depend on the type of precipitation (i.e. drop size distribution and water temperature). $\\omega radlib$ provides a couple of functions that could be useful in this context." 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "nbsphinx": "hidden" 34 | }, 35 | "outputs": [], 36 | "source": [ 37 | "import wradlib as wrl\n", 38 | "import wradlib_data\n", 39 | "import xarray as xr\n", 40 | "import datetime as dt\n", 41 | "import matplotlib.pyplot as plt\n", 42 | "import warnings\n", 43 | "\n", 44 | "warnings.filterwarnings(\"ignore\")\n", 45 | "try:\n", 46 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 47 | "except:\n", 48 | " plt.ion()\n", 49 | "import numpy as np" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "The following example demonstrates the steps to convert from the common unit *dBZ* (decibel of the reflectivity factor *Z*) to rainfall intensity (in the unit of mm/h). This is an array of typical reflectivity values (**unit: dBZ**)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "dBZ = np.array([20.0, 30.0, 40.0, 45.0, 50.0, 55.0])\n", 66 | "print(dBZ)" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": {}, 72 | "source": [ 73 | "Convert to reflectivity factor Z (**unit**: $mm^6/m^3$):" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "Z = wrl.trafo.idecibel(dBZ)\n", 83 | "print(Z)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "Convert to rainfall intensity (**unit: mm/h**) using the Marshall-Palmer Z(R) parameters:" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "R = wrl.zr.z_to_r(Z, a=200.0, b=1.6)\n", 100 | "print(np.round(R, 2))" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "Convert to rainfall depth (**unit: mm**) assuming a rainfall duration of five minutes (i.e. 300 seconds)" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "depth = wrl.trafo.r_to_depth(R, 300)\n", 117 | "print(np.round(depth, 2))" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "## An example with real radar data" 125 | ] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "metadata": {}, 130 | "source": [ 131 | "The following example is based on observations of the DWD C-band radar on mount Feldberg (SW-Germany).\n", 132 | "The figure shows a 15 minute accumulation of rainfall which was produced from three consecutive radar\n", 133 | "scans at 5 minute intervals between 17:30 and 17:45 on June 8, 2008.\n", 134 | "\n", 135 | "The radar data are read using [wradlib.io.read_dx](https://docs.wradlib.org/en/latest/generated/wradlib.io.radolan.read_dx.html) function which returns an array of dBZ values and a metadata dictionary (see also [Reading-DX-Data](../fileio/legacy/read_dx.ipynb#Reading-DX-Data)). The conversion is carried out the same way as in the example above. The plot is produced using\n", 136 | "the function [wradlib.vis.plot](https://docs.wradlib.org/en/latest/generated/wradlib.vis.plot.html)." 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": null, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "def read_data(dtimes):\n", 146 | " \"\"\"Helper function to read raw data for a list of datetimes \"\"\"\n", 147 | " dalist = []\n", 148 | " for i, dtime in enumerate(dtimes):\n", 149 | " f = wradlib_data.DATASETS.fetch(\n", 150 | " \"dx/raa00-dx_10908-{0}-fbg---bin.gz\".format(dtime)\n", 151 | " )\n", 152 | " data, attrs = wrl.io.read_dx(f)\n", 153 | " radar_location = (8.003611, 47.873611, 1516.0)\n", 154 | " dtime = dt.datetime.strptime(dtime, \"%y%m%d%H%M\")\n", 155 | " dalist.append(\n", 156 | " wrl.georef.create_xarray_dataarray(\n", 157 | " data,\n", 158 | " r=np.arange(500, data.shape[1] * 1000 + 500, 1000),\n", 159 | " phi=attrs[\"azim\"],\n", 160 | " theta=attrs[\"elev\"],\n", 161 | " site=radar_location,\n", 162 | " sweep_mode=\"azimuth_surveillance\",\n", 163 | " ).assign_coords(time=dtime)\n", 164 | " )\n", 165 | " ds = xr.concat(dalist, \"time\")\n", 166 | " return ds.assign_coords(elevation=ds.elevation.median(\"time\"))" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "Read data from radar Feldberg for three consecutive 5 minute intervals and compute the accumulated rainfall depth." 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": null, 179 | "metadata": {}, 180 | "outputs": [], 181 | "source": [ 182 | "# Read\n", 183 | "dtimes = [\"0806021735\", \"0806021740\", \"0806021745\"]\n", 184 | "dBZ = read_data(dtimes)\n", 185 | "# Convert to rainfall intensity (mm/h)\n", 186 | "Z = dBZ.wrl.trafo.idecibel()\n", 187 | "R = Z.wrl.zr.z_to_r(a=200.0, b=1.6)\n", 188 | "# Convert to rainfall depth (mm)\n", 189 | "depth = R.wrl.trafo.r_to_depth(300)\n", 190 | "# Accumulate 15 minute rainfall depth over all three 5 minute intervals\n", 191 | "accum = depth.sum(dim=\"time\")" 192 | ] 193 | }, 194 | { 195 | "cell_type": "markdown", 196 | "metadata": {}, 197 | "source": [ 198 | "Plot PPI of 15 minute rainfall depth" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [ 207 | "plt.figure(figsize=(10, 8))\n", 208 | "da = accum.wrl.georef.georeference()\n", 209 | "cf = da.wrl.vis.plot(cmap=\"viridis\")\n", 210 | "plt.xlabel(\"Easting from radar (m)\")\n", 211 | "plt.ylabel(\"Northing from radar (m)\")\n", 212 | "plt.title(\"Radar Feldberg\\n15 min. rainfall depth, 2008-06-02 17:30-17:45 UTC\")\n", 213 | "cb = plt.colorbar(cf, shrink=0.8)\n", 214 | "cb.set_label(\"mm\")\n", 215 | "plt.grid(color=\"grey\")" 216 | ] 217 | } 218 | ], 219 | "metadata": { 220 | "celltoolbar": "Edit Metadata", 221 | "language_info": { 222 | "codemirror_mode": { 223 | "name": "ipython", 224 | "version": 3 225 | }, 226 | "file_extension": ".py", 227 | "mimetype": "text/x-python", 228 | "name": "python", 229 | "nbconvert_exporter": "python", 230 | "pygments_lexer": "ipython3", 231 | "version": "3.11.0" 232 | }, 233 | "toc": { 234 | "colors": { 235 | "hover_highlight": "#DAA520", 236 | "navigate_num": "#000000", 237 | "navigate_text": "#333333", 238 | "running_highlight": "#FF0000", 239 | "selected_highlight": "#FFD700", 240 | "sidebar_border": "#EEEEEE", 241 | "wrapper_background": "#FFFFFF" 242 | }, 243 | "moveMenuLeft": true, 244 | "nav_menu": { 245 | "height": "49px", 246 | "width": "252px" 247 | }, 248 | "navigate_menu": true, 249 | "number_sections": false, 250 | "sideBar": true, 251 | "threshold": 4, 252 | "toc_cell": false, 253 | "toc_section_display": "block", 254 | "toc_window_display": false, 255 | "widenNotebook": false 256 | } 257 | }, 258 | "nbformat": 4, 259 | "nbformat_minor": 4 260 | } 261 | -------------------------------------------------------------------------------- /notebooks/basics/wradlib_introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden", 7 | "slideshow": { 8 | "slide_type": "skip" 9 | } 10 | }, 11 | "source": [ 12 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 13 | "\n", 14 | "Copyright (c) $\\omega radlib$ developers.\n", 15 | "Distributed under the MIT License. See LICENSE.txt for more info." 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "slideshow": { 22 | "slide_type": "slide" 23 | } 24 | }, 25 | "source": [ 26 | "# Import wradlib and check its version" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "slideshow": { 33 | "slide_type": "fragment" 34 | } 35 | }, 36 | "source": [ 37 | "This simple example shows the $\\omega radlib$ version at rendering time." 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": { 44 | "slideshow": { 45 | "slide_type": "fragment" 46 | } 47 | }, 48 | "outputs": [], 49 | "source": [ 50 | "import wradlib\n", 51 | "\n", 52 | "print(wradlib.__version__)" 53 | ] 54 | } 55 | ], 56 | "metadata": { 57 | "celltoolbar": "Slideshow", 58 | "language_info": { 59 | "codemirror_mode": { 60 | "name": "ipython", 61 | "version": 3 62 | }, 63 | "file_extension": ".py", 64 | "mimetype": "text/x-python", 65 | "name": "python", 66 | "nbconvert_exporter": "python", 67 | "pygments_lexer": "ipython3", 68 | "version": "3.11.0" 69 | }, 70 | "toc": { 71 | "colors": { 72 | "hover_highlight": "#DAA520", 73 | "navigate_num": "#000000", 74 | "navigate_text": "#333333", 75 | "running_highlight": "#FF0000", 76 | "selected_highlight": "#FFD700", 77 | "sidebar_border": "#EEEEEE", 78 | "wrapper_background": "#FFFFFF" 79 | }, 80 | "moveMenuLeft": true, 81 | "nav_menu": { 82 | "height": "31px", 83 | "width": "252px" 84 | }, 85 | "navigate_menu": true, 86 | "number_sections": false, 87 | "sideBar": true, 88 | "threshold": 4, 89 | "toc_cell": false, 90 | "toc_section_display": "block", 91 | "toc_window_display": false, 92 | "widenNotebook": false 93 | } 94 | }, 95 | "nbformat": 4, 96 | "nbformat_minor": 4 97 | } 98 | -------------------------------------------------------------------------------- /notebooks/classify.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Clutter and Echo Classification" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "This section provides a collection of example code snippets to show clutter detection and correction as well as echo classification capabilities of $\\omega radlib$.\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "nbsphinx-toctree": { 33 | "hidden": true, 34 | "maxdepth": 2 35 | } 36 | }, 37 | "source": [ 38 | "## Examples List\n", 39 | "\n", 40 | "- [Clutter detection using Gabella approach](classify/clutter_gabella.ipynb)\n", 41 | "- [Clutter detection by using space-born cloud images](classify/clutter_cloud.ipynb)\n", 42 | "- [Heuristic clutter detection](classify/histo_cut.ipynb)\n", 43 | "- [Fuzzy echo classification](classify/fuzzy_echo.ipynb)\n", 44 | "- [2D Membershipfunction HMC](classify/2d_hmc.ipynb)\n", 45 | "- [Hydrometeor partitioning ratio - GPM](classify/hmcp_gpm.ipynb)\n", 46 | "- [Hydrometeor partitioning ratio - GroundRadar](classify/hmcp_nexrad.ipynb)" 47 | ] 48 | } 49 | ], 50 | "metadata": { 51 | "celltoolbar": "Edit Metadata", 52 | "language_info": { 53 | "codemirror_mode": { 54 | "name": "ipython", 55 | "version": 3 56 | }, 57 | "file_extension": ".py", 58 | "mimetype": "text/x-python", 59 | "name": "python", 60 | "nbconvert_exporter": "python", 61 | "pygments_lexer": "ipython3", 62 | "version": "3.12.8" 63 | }, 64 | "toc": { 65 | "colors": { 66 | "hover_highlight": "#DAA520", 67 | "navigate_num": "#000000", 68 | "navigate_text": "#333333", 69 | "running_highlight": "#FF0000", 70 | "selected_highlight": "#FFD700", 71 | "sidebar_border": "#EEEEEE", 72 | "wrapper_background": "#FFFFFF" 73 | }, 74 | "moveMenuLeft": true, 75 | "nav_menu": { 76 | "height": "49px", 77 | "width": "252px" 78 | }, 79 | "navigate_menu": true, 80 | "number_sections": false, 81 | "sideBar": true, 82 | "threshold": 4, 83 | "toc_cell": false, 84 | "toc_section_display": "block", 85 | "toc_window_display": false, 86 | "widenNotebook": false 87 | } 88 | }, 89 | "nbformat": 4, 90 | "nbformat_minor": 4 91 | } 92 | -------------------------------------------------------------------------------- /notebooks/classify/clutter_cloud.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Clutter detection by using space-born cloud images" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import numpy as np\n", 29 | "\n", 30 | "import xarray as xr\n", 31 | "import xradar as xd\n", 32 | "import wradlib as wrl\n", 33 | "import wradlib_data\n", 34 | "import matplotlib.pyplot as plt\n", 35 | "from osgeo import osr\n", 36 | "\n", 37 | "try:\n", 38 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 39 | "except:\n", 40 | " plt.ion()" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "### Read the radar data into DataTree" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "# read the radar volume scan\n", 57 | "filename = \"hdf5/20130429043000.rad.bewid.pvol.dbzh.scan1.hdf\"\n", 58 | "filename = wradlib_data.DATASETS.fetch(filename)\n", 59 | "pvol = xd.io.open_odim_datatree(filename)\n", 60 | "display(pvol)" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "# Georeference sweeps" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "pvol1 = pvol.match(\"sweep*\")\n", 77 | "display(pvol1)\n", 78 | "vol = []\n", 79 | "for sweep in pvol1.values():\n", 80 | " vol.append(sweep.to_dataset().pipe(wrl.georef.georeference))\n", 81 | "vol = xr.concat(vol, dim=\"tilt\")\n", 82 | "vol = vol.assign_coords(sweep_mode=vol.sweep_mode)\n", 83 | "display(vol)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "### Construct collocated satellite data" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "proj_radar = osr.SpatialReference()\n", 100 | "proj_radar.ImportFromWkt(vol.crs_wkt.attrs[\"crs_wkt\"])" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "filename = \"hdf5/SAFNWC_MSG3_CT___201304290415_BEL_________.h5\"\n", 110 | "filename = wradlib_data.DATASETS.fetch(filename)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": null, 116 | "metadata": {}, 117 | "outputs": [], 118 | "source": [ 119 | "sat_gdal = wrl.io.read_safnwc(filename)\n", 120 | "val_sat = wrl.georef.read_gdal_values(sat_gdal)\n", 121 | "coord_sat = wrl.georef.read_gdal_coordinates(sat_gdal)\n", 122 | "proj_sat = wrl.georef.read_gdal_projection(sat_gdal)\n", 123 | "coord_sat = wrl.georef.reproject(coord_sat, src_crs=proj_sat, trg_crs=proj_radar)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "coord_radar = np.stack((vol.x, vol.y), axis=-1)\n", 133 | "coord_sat[..., 0:2].reshape(-1, 2).shape, coord_radar[..., 0:2].reshape(-1, 2).shape" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "interp = wrl.ipol.Nearest(\n", 143 | " coord_sat[..., 0:2].reshape(-1, 2), coord_radar[..., 0:2].reshape(-1, 2)\n", 144 | ")" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": null, 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [ 153 | "val_sat = interp(val_sat.ravel()).reshape(coord_radar.shape[:-1])" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "### Estimate localisation errors" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": null, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "timelag = 9 * 60\n", 170 | "wind = 10\n", 171 | "error = np.absolute(timelag) * wind" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "### Identify clutter based on collocated cloudtype" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": null, 184 | "metadata": {}, 185 | "outputs": [], 186 | "source": [ 187 | "rscale = vol.range.diff(\"range\").median().values\n", 188 | "clutter = wrl.classify.filter_cloudtype(\n", 189 | " vol.DBZH, val_sat, scale=rscale, smoothing=error\n", 190 | ")" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "metadata": {}, 196 | "source": [ 197 | "### Assign to vol" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": null, 203 | "metadata": {}, 204 | "outputs": [], 205 | "source": [ 206 | "vol = vol.assign(sat=([\"tilt\", \"azimuth\", \"range\"], val_sat))\n", 207 | "vol = vol.assign(clutter=([\"tilt\", \"azimuth\", \"range\"], clutter.values))\n", 208 | "display(vol)" 209 | ] 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "metadata": {}, 214 | "source": [ 215 | "### Plot the results" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": null, 221 | "metadata": {}, 222 | "outputs": [], 223 | "source": [ 224 | "fig = plt.figure(figsize=(16, 8))\n", 225 | "\n", 226 | "tilt = 0\n", 227 | "\n", 228 | "ax = fig.add_subplot(131)\n", 229 | "pm = vol.DBZH[tilt].wrl.vis.plot(ax=ax)\n", 230 | "# plt.colorbar(pm, shrink=0.5)\n", 231 | "plt.title(\"Radar reflectivity\")\n", 232 | "\n", 233 | "ax = fig.add_subplot(132)\n", 234 | "pm = vol.sat[tilt].wrl.vis.plot(ax=ax)\n", 235 | "# plt.colorbar(pm, shrink=0.5)\n", 236 | "plt.title(\"Satellite cloud classification\")\n", 237 | "\n", 238 | "ax = fig.add_subplot(133)\n", 239 | "pm = vol.clutter[tilt].wrl.vis.plot(ax=ax)\n", 240 | "# plt.colorbar(pm, shrink=0.5)\n", 241 | "plt.title(\"Detected clutter\")\n", 242 | "\n", 243 | "fig.tight_layout()" 244 | ] 245 | } 246 | ], 247 | "metadata": { 248 | "language_info": { 249 | "codemirror_mode": { 250 | "name": "ipython", 251 | "version": 3 252 | }, 253 | "file_extension": ".py", 254 | "mimetype": "text/x-python", 255 | "name": "python", 256 | "nbconvert_exporter": "python", 257 | "pygments_lexer": "ipython3", 258 | "version": "3.12.4" 259 | }, 260 | "toc": { 261 | "colors": { 262 | "hover_highlight": "#DAA520", 263 | "navigate_num": "#000000", 264 | "navigate_text": "#333333", 265 | "running_highlight": "#FF0000", 266 | "selected_highlight": "#FFD700", 267 | "sidebar_border": "#EEEEEE", 268 | "wrapper_background": "#FFFFFF" 269 | }, 270 | "moveMenuLeft": true, 271 | "nav_menu": { 272 | "height": "177px", 273 | "width": "252px" 274 | }, 275 | "navigate_menu": true, 276 | "number_sections": false, 277 | "sideBar": true, 278 | "threshold": 4, 279 | "toc_cell": false, 280 | "toc_section_display": "block", 281 | "toc_window_display": false, 282 | "widenNotebook": false 283 | } 284 | }, 285 | "nbformat": 4, 286 | "nbformat_minor": 4 287 | } 288 | -------------------------------------------------------------------------------- /notebooks/classify/clutter_gabella.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Clutter detection using the Gabella approach" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import matplotlib.pyplot as plt\n", 29 | "import numpy as np\n", 30 | "import wradlib as wrl\n", 31 | "import wradlib_data\n", 32 | "import warnings\n", 33 | "\n", 34 | "warnings.filterwarnings(\"ignore\")\n", 35 | "try:\n", 36 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 37 | "except:\n", 38 | " plt.ion()\n", 39 | "import numpy as np" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "### Read the data" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "filename = wradlib_data.DATASETS.fetch(\"misc/polar_dBZ_fbg.gz\")\n", 56 | "data = np.loadtxt(filename)\n", 57 | "data = wrl.georef.create_xarray_dataarray(data, rf=0.001).wrl.georef.georeference()\n", 58 | "data" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "### Apply filter" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "clmap = data.wrl.classify.filter_gabella(\n", 75 | " wsize=5, thrsnorain=0.0, tr1=6.0, n_p=8, tr2=1.3\n", 76 | ")\n", 77 | "clmap" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "### Plot results" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "fig = plt.figure(figsize=(12, 8))\n", 94 | "ax1 = fig.add_subplot(121)\n", 95 | "pm = data.wrl.vis.plot(ax=ax1)\n", 96 | "ax1.set_title(\"Reflectivity\")\n", 97 | "ax2 = fig.add_subplot(122)\n", 98 | "pm = clmap.wrl.vis.plot(ax=ax2)\n", 99 | "ax2.set_title(\"Cluttermap\")" 100 | ] 101 | } 102 | ], 103 | "metadata": { 104 | "language_info": { 105 | "codemirror_mode": { 106 | "name": "ipython", 107 | "version": 3 108 | }, 109 | "file_extension": ".py", 110 | "mimetype": "text/x-python", 111 | "name": "python", 112 | "nbconvert_exporter": "python", 113 | "pygments_lexer": "ipython3", 114 | "version": "3.11.0" 115 | }, 116 | "toc": { 117 | "colors": { 118 | "hover_highlight": "#DAA520", 119 | "navigate_num": "#000000", 120 | "navigate_text": "#333333", 121 | "running_highlight": "#FF0000", 122 | "selected_highlight": "#FFD700", 123 | "sidebar_border": "#EEEEEE", 124 | "wrapper_background": "#FFFFFF" 125 | }, 126 | "moveMenuLeft": true, 127 | "nav_menu": { 128 | "height": "102px", 129 | "width": "252px" 130 | }, 131 | "navigate_menu": true, 132 | "number_sections": false, 133 | "sideBar": true, 134 | "threshold": 4, 135 | "toc_cell": false, 136 | "toc_section_display": "block", 137 | "toc_window_display": false, 138 | "widenNotebook": false 139 | } 140 | }, 141 | "nbformat": 4, 142 | "nbformat_minor": 4 143 | } 144 | -------------------------------------------------------------------------------- /notebooks/classify/fuzzy_echo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden", 7 | "slideshow": { 8 | "slide_type": "skip" 9 | } 10 | }, 11 | "source": [ 12 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 13 | "\n", 14 | "Copyright (c) $\\omega radlib$ developers.\n", 15 | "Distributed under the MIT License. See LICENSE.txt for more info." 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "slideshow": { 22 | "slide_type": "slide" 23 | } 24 | }, 25 | "source": [ 26 | "# Simple fuzzy echo classification from dual-pol moments " 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "slideshow": { 34 | "slide_type": "fragment" 35 | } 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "import wradlib\n", 40 | "from wradlib.util import get_wradlib_data_file\n", 41 | "import os\n", 42 | "import numpy as np\n", 43 | "import matplotlib.pyplot as plt\n", 44 | "import warnings\n", 45 | "import xarray as xr\n", 46 | "\n", 47 | "warnings.filterwarnings(\"ignore\")\n", 48 | "try:\n", 49 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 50 | "except:\n", 51 | " plt.ion()" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": { 57 | "slideshow": { 58 | "slide_type": "slide" 59 | } 60 | }, 61 | "source": [ 62 | "## Setting the file paths" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": { 69 | "slideshow": { 70 | "slide_type": "fragment" 71 | } 72 | }, 73 | "outputs": [], 74 | "source": [ 75 | "rhofile = get_wradlib_data_file(\"netcdf/TAG-20120801-140046-02-R.nc\")\n", 76 | "phifile = get_wradlib_data_file(\"netcdf/TAG-20120801-140046-02-P.nc\")\n", 77 | "reffile = get_wradlib_data_file(\"netcdf/TAG-20120801-140046-02-Z.nc\")\n", 78 | "dopfile = get_wradlib_data_file(\"netcdf/TAG-20120801-140046-02-V.nc\")\n", 79 | "zdrfile = get_wradlib_data_file(\"netcdf/TAG-20120801-140046-02-D.nc\")\n", 80 | "mapfile = get_wradlib_data_file(\"hdf5/TAG_cmap_sweeps_0204050607.hdf5\")" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": { 86 | "slideshow": { 87 | "slide_type": "slide" 88 | } 89 | }, 90 | "source": [ 91 | "## Read the data (radar moments and static clutter map)" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": null, 97 | "metadata": { 98 | "slideshow": { 99 | "slide_type": "fragment" 100 | } 101 | }, 102 | "outputs": [], 103 | "source": [ 104 | "# We need to organize our data as a dictionary\n", 105 | "dat = {}\n", 106 | "dat[\"rho\"], attrs_rho = wradlib.io.read_edge_netcdf(rhofile)\n", 107 | "dat[\"phi\"], attrs_phi = wradlib.io.read_edge_netcdf(phifile)\n", 108 | "dat[\"ref\"], attrs_ref = wradlib.io.read_edge_netcdf(reffile)\n", 109 | "dat[\"dop\"], attrs_dop = wradlib.io.read_edge_netcdf(dopfile)\n", 110 | "dat[\"zdr\"], attrs_zdr = wradlib.io.read_edge_netcdf(zdrfile)\n", 111 | "dat[\"map\"] = wradlib.io.from_hdf5(mapfile)[0][0]\n", 112 | "\n", 113 | "dat = {k: ([\"azimuth\", \"range\"], v) for k, v in dat.items()}" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "az, rng = dat[\"rho\"][1].shape\n", 123 | "swp = xr.Dataset(dat, coords={\"azimuth\": np.arange(az), \"range\": np.arange(rng)})\n", 124 | "swp = swp.assign_coords(\n", 125 | " dict(\n", 126 | " longitude=7,\n", 127 | " latitude=53,\n", 128 | " altitude=0,\n", 129 | " elevation=1,\n", 130 | " sweep_mode=\"azimuth_surveillance\",\n", 131 | " )\n", 132 | ")\n", 133 | "swp = swp.wrl.georef.georeference()\n", 134 | "display(swp)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": { 140 | "slideshow": { 141 | "slide_type": "slide" 142 | } 143 | }, 144 | "source": [ 145 | "## Identify non-meteorological echoes using fuzzy echo classification" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "metadata": { 151 | "slideshow": { 152 | "slide_type": "fragment" 153 | } 154 | }, 155 | "source": [ 156 | "See [Crisologo et al. (2015)](https://link.springer.com/article/10.1007/s13143-014-0049-y) and [Vulpiani et al. (2012)](https://journals.ametsoc.org/doi/abs/10.1175/JAMC-D-10-05024.1) for details." 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "moments = dict(rho=\"rho\", phi=\"phi\", ref=\"ref\", dop=\"dop\", zdr=\"zdr\", map=\"map\")\n", 166 | "weights = {\"zdr\": 0.4, \"rho\": 0.4, \"rho2\": 0.4, \"phi\": 0.1, \"dop\": 0.1, \"map\": 0.5}\n", 167 | "prob, nanmask = swp.wrl.classify.classify_echo_fuzzy(moments, weights=weights)\n", 168 | "thresh = 0.5\n", 169 | "cmap = prob.where(prob < thresh, True, False)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": { 175 | "slideshow": { 176 | "slide_type": "slide" 177 | } 178 | }, 179 | "source": [ 180 | "## View classfication results" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": { 187 | "slideshow": { 188 | "slide_type": "fragment" 189 | } 190 | }, 191 | "outputs": [], 192 | "source": [ 193 | "fig = plt.figure(figsize=(12, 5))\n", 194 | "\n", 195 | "# Horizontal reflectivity\n", 196 | "ax = plt.subplot(121, aspect=\"equal\")\n", 197 | "pm = swp.ref.plot(x=\"x\", y=\"y\", ax=ax, cbar_kwargs=dict(label=\"dBZ\"))\n", 198 | "ax = wradlib.vis.plot_ppi_crosshair(site=(0, 0, 0), ranges=[80, 160, 240])\n", 199 | "plt.xlim(-240, 240)\n", 200 | "plt.ylim(-240, 240)\n", 201 | "plt.xlabel(\"# bins from radar\")\n", 202 | "plt.ylabel(\"# bins from radar\")\n", 203 | "\n", 204 | "# Echo classification\n", 205 | "ax = plt.subplot(122, aspect=\"equal\")\n", 206 | "pm = cmap.where(~np.isnan(swp.ref)).plot(\n", 207 | " x=\"x\",\n", 208 | " y=\"y\",\n", 209 | " ax=ax,\n", 210 | " cmap=\"bwr\",\n", 211 | " cbar_kwargs=dict(label=\"meterol. echo=0 - non-meteorol. echo=1\"),\n", 212 | ")\n", 213 | "ax = wradlib.vis.plot_ppi_crosshair(site=(0, 0, 0), ranges=[80, 160, 240])\n", 214 | "plt.xlim(-240, 240)\n", 215 | "plt.ylim(-240, 240)\n", 216 | "plt.xlabel(\"# bins from radar\")\n", 217 | "plt.ylabel(\"# bins from radar\")" 218 | ] 219 | } 220 | ], 221 | "metadata": { 222 | "celltoolbar": "Slideshow", 223 | "language_info": { 224 | "codemirror_mode": { 225 | "name": "ipython", 226 | "version": 3 227 | }, 228 | "file_extension": ".py", 229 | "mimetype": "text/x-python", 230 | "name": "python", 231 | "nbconvert_exporter": "python", 232 | "pygments_lexer": "ipython3", 233 | "version": "3.11.0" 234 | }, 235 | "livereveal": { 236 | "scroll": true 237 | }, 238 | "toc": { 239 | "colors": { 240 | "hover_highlight": "#DAA520", 241 | "navigate_num": "#000000", 242 | "navigate_text": "#333333", 243 | "running_highlight": "#FF0000", 244 | "selected_highlight": "#FFD700", 245 | "sidebar_border": "#EEEEEE", 246 | "wrapper_background": "#FFFFFF" 247 | }, 248 | "moveMenuLeft": true, 249 | "nav_menu": { 250 | "height": "121px", 251 | "width": "252px" 252 | }, 253 | "navigate_menu": true, 254 | "number_sections": false, 255 | "sideBar": true, 256 | "threshold": 4, 257 | "toc_cell": false, 258 | "toc_section_display": "block", 259 | "toc_window_display": false, 260 | "widenNotebook": false 261 | } 262 | }, 263 | "nbformat": 4, 264 | "nbformat_minor": 4 265 | } 266 | -------------------------------------------------------------------------------- /notebooks/classify/histo_cut.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Heuristic clutter detection based on distribution properties (\"histo cut\")\n", 20 | "\n", 21 | "Detects areas with anomalously low or high average reflectivity or precipitation. It is recommended to use long term average or sums (months to year)." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import wradlib as wrl\n", 31 | "import wradlib_data\n", 32 | "import numpy as np\n", 33 | "import matplotlib.pyplot as plt\n", 34 | "import warnings\n", 35 | "\n", 36 | "warnings.filterwarnings(\"ignore\")\n", 37 | "try:\n", 38 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 39 | "except:\n", 40 | " plt.ion()" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "### Load annual rainfall acummulation example (from DWD radar Feldberg)" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "filename = wradlib_data.DATASETS.fetch(\"misc/annual_rainfall_fbg.gz\")\n", 57 | "yearsum = np.loadtxt(filename)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "### Apply histo-cut filter to retrieve boolean array that highlights clutter as well as beam blockage\n", 65 | "\n", 66 | "Depending on your data and climate you can parameterize the upper and lower frequency percentage with the kwargs `upper_frequency`/`lower_frequency`. For European ODIM_H5 data these values have been found to be in the order of 0.05 in [EURADCLIM: The European climatological high-resolution gauge-adjusted radar precipitation dataset](https://essd.copernicus.org/preprints/essd-2022-334/). The current default is 0.01 for both values." 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": null, 72 | "metadata": {}, 73 | "outputs": [], 74 | "source": [ 75 | "mask = wrl.classify.histo_cut(yearsum)" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "### Plot results" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [ 91 | "fig = plt.figure(figsize=(14, 14))\n", 92 | "ax = fig.add_subplot(221)\n", 93 | "yearsum = wrl.georef.create_xarray_dataarray(yearsum).wrl.georef.georeference()\n", 94 | "pm = np.log(yearsum).wrl.vis.plot(ax=ax)\n", 95 | "plt.title(\"Logarithm of annual precipitation sum\")\n", 96 | "plt.colorbar(pm, shrink=0.75)\n", 97 | "ax = fig.add_subplot(222)\n", 98 | "mask = wrl.georef.create_xarray_dataarray(mask).wrl.georef.georeference()\n", 99 | "pm = mask.wrl.vis.plot(ax=ax)\n", 100 | "plt.title(\"Map of execptionally low and high values\\n(clutter and beam blockage)\")\n", 101 | "plt.colorbar(pm, shrink=0.75)\n", 102 | "ax = fig.add_subplot(223)\n", 103 | "pm = mask.where(mask == 1).wrl.vis.plot(ax=ax)\n", 104 | "plt.title(\"Map of execptionally high values\\n(clutter)\")\n", 105 | "plt.colorbar(pm, shrink=0.75)\n", 106 | "ax = fig.add_subplot(224)\n", 107 | "pm = mask.where(mask == 2).wrl.vis.plot(ax=ax)\n", 108 | "plt.title(\"Map of execptionally low values\\n(beam blockage)\")\n", 109 | "plt.colorbar(pm, shrink=0.75)" 110 | ] 111 | } 112 | ], 113 | "metadata": { 114 | "language_info": { 115 | "codemirror_mode": { 116 | "name": "ipython", 117 | "version": 3 118 | }, 119 | "file_extension": ".py", 120 | "mimetype": "text/x-python", 121 | "name": "python", 122 | "nbconvert_exporter": "python", 123 | "pygments_lexer": "ipython3", 124 | "version": "3.11.0" 125 | }, 126 | "toc": { 127 | "colors": { 128 | "hover_highlight": "#DAA520", 129 | "navigate_num": "#000000", 130 | "navigate_text": "#333333", 131 | "running_highlight": "#FF0000", 132 | "selected_highlight": "#FFD700", 133 | "sidebar_border": "#EEEEEE", 134 | "wrapper_background": "#FFFFFF" 135 | }, 136 | "moveMenuLeft": true, 137 | "nav_menu": { 138 | "height": "102px", 139 | "width": "252px" 140 | }, 141 | "navigate_menu": true, 142 | "number_sections": false, 143 | "sideBar": true, 144 | "threshold": 4, 145 | "toc_cell": false, 146 | "toc_section_display": "block", 147 | "toc_window_display": false, 148 | "widenNotebook": false 149 | } 150 | }, 151 | "nbformat": 4, 152 | "nbformat_minor": 4 153 | } 154 | -------------------------------------------------------------------------------- /notebooks/compositing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Compositing" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "This section provides a collection of examples related to the compositing of radar data.\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "nbsphinx-toctree": { 33 | "hidden": true, 34 | "maxdepth": 2 35 | } 36 | }, 37 | "source": [ 38 | "- [Production of a maximum reflectivity composite](compositing/max_reflectivity.ipynb)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": { 44 | "nbsphinx-toctree": { 45 | "hidden": true, 46 | "maxdepth": 2 47 | } 48 | }, 49 | "source": [ 50 | "- [Comparison of transformation methods](compositing/transform.ipynb)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [] 59 | } 60 | ], 61 | "metadata": { 62 | "celltoolbar": "Edit Metadata", 63 | "language_info": { 64 | "codemirror_mode": { 65 | "name": "ipython", 66 | "version": 3 67 | }, 68 | "file_extension": ".py", 69 | "mimetype": "text/x-python", 70 | "name": "python", 71 | "nbconvert_exporter": "python", 72 | "pygments_lexer": "ipython3", 73 | "version": "3.13.3" 74 | }, 75 | "toc": { 76 | "colors": { 77 | "hover_highlight": "#DAA520", 78 | "navigate_num": "#000000", 79 | "navigate_text": "#333333", 80 | "running_highlight": "#FF0000", 81 | "selected_highlight": "#FFD700", 82 | "sidebar_border": "#EEEEEE", 83 | "wrapper_background": "#FFFFFF" 84 | }, 85 | "moveMenuLeft": true, 86 | "nav_menu": { 87 | "height": "49px", 88 | "width": "252px" 89 | }, 90 | "navigate_menu": true, 91 | "number_sections": false, 92 | "sideBar": true, 93 | "threshold": 4, 94 | "toc_cell": false, 95 | "toc_section_display": "block", 96 | "toc_window_display": false, 97 | "widenNotebook": false 98 | } 99 | }, 100 | "nbformat": 4, 101 | "nbformat_minor": 4 102 | } 103 | -------------------------------------------------------------------------------- /notebooks/compositing/max_reflectivity.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Production of a maximum reflectivity composite" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import os\n", 29 | "import numpy as np\n", 30 | "import wradlib\n", 31 | "import xarray\n", 32 | "import xradar\n", 33 | "import matplotlib.pyplot as plt" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "Read volume reflectivity measurements from the three belgian radars" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "from wradlib_data import DATASETS\n", 50 | "\n", 51 | "filenames = [\"bejab.pvol.hdf\", \"bewid.pvol.hdf\", \"behel.pvol.hdf\"]\n", 52 | "paths = [DATASETS.fetch(f\"hdf5/{f}\") for f in filenames]\n", 53 | "volumes = [xradar.io.backends.odim.open_odim_datatree(p) for p in paths]" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "Define a raster dataset with a window including the 3 radars, a pixel size of 1km and the standard European projection." 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "crs = wradlib.georef.epsg_to_osr(3035)\n", 70 | "bounds = [0, 8, 48, 53]\n", 71 | "bounds = wradlib.georef.project_bounds(bounds, crs)\n", 72 | "print(bounds)\n", 73 | "size = 1000\n", 74 | "raster = wradlib.georef.create_raster_xarray(crs, bounds, size)" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "Define a geographic raster dataset with a window including the 3 radars, and an approximate pixel size of 1km. " 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "crs = wradlib.georef.epsg_to_osr(3035)\n", 91 | "bounds = [0, 8, 48, 53]\n", 92 | "size = 1000\n", 93 | "raster2 = wradlib.georef.create_raster_geographic(bounds, size, size_in_meters=True)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "Combine lowest radar sweep into a raster image for each radar" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "# raster = raster2\n", 110 | "metadata = xradar.model.required_sweep_metadata_vars\n", 111 | "rasters = []\n", 112 | "for volume in volumes:\n", 113 | " sweep = volume[\"sweep_0\"].to_dataset()\n", 114 | " sweep = sweep[[\"DBZH\"] + list(metadata)]\n", 115 | " sweep = sweep.sel(range=slice(0, 200e3))\n", 116 | " raster_sweep = wradlib.comp.sweep_to_raster(sweep, raster)\n", 117 | " rasters.append(raster_sweep)\n", 118 | "\n", 119 | "for raster in rasters:\n", 120 | " raster = raster.drop_vars(\"spatial_ref\")\n", 121 | " raster[\"DBZH\"].plot(vmin=0, vmax=50)\n", 122 | " plt.axis(\"equal\")\n", 123 | " plt.show()" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "metadata": {}, 129 | "source": [ 130 | "Take the maximum value from the 3 rasters" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": null, 136 | "metadata": {}, 137 | "outputs": [], 138 | "source": [ 139 | "rasters_concat = xarray.concat(rasters, dim=\"sweep\")\n", 140 | "comp = rasters_concat.max(dim=\"sweep\", keep_attrs=True)\n", 141 | "comp[\"DBZH\"].plot(vmin=0, vmax=50)\n", 142 | "with open(\"comp.nc\", \"wb\") as f:\n", 143 | " comp.to_netcdf(f)\n", 144 | "!gdalinfo comp.nc\n", 145 | "ds = xarray.open_dataset(\"comp.nc\", engine=\"rasterio\")\n", 146 | "comp = comp.drop_vars(\"spatial_ref\")\n", 147 | "plt.axis(\"equal\")\n", 148 | "plt.show()" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [] 157 | } 158 | ], 159 | "metadata": { 160 | "language_info": { 161 | "codemirror_mode": { 162 | "name": "ipython", 163 | "version": 3 164 | }, 165 | "file_extension": ".py", 166 | "mimetype": "text/x-python", 167 | "name": "python", 168 | "nbconvert_exporter": "python", 169 | "pygments_lexer": "ipython3", 170 | "version": "3.13.3" 171 | }, 172 | "toc": { 173 | "colors": { 174 | "hover_highlight": "#DAA520", 175 | "navigate_num": "#000000", 176 | "navigate_text": "#333333", 177 | "running_highlight": "#FF0000", 178 | "selected_highlight": "#FFD700", 179 | "sidebar_border": "#EEEEEE", 180 | "wrapper_background": "#FFFFFF" 181 | }, 182 | "moveMenuLeft": true, 183 | "nav_menu": { 184 | "height": "47px", 185 | "width": "252px" 186 | }, 187 | "navigate_menu": true, 188 | "number_sections": false, 189 | "sideBar": true, 190 | "threshold": 4, 191 | "toc_cell": false, 192 | "toc_section_display": "block", 193 | "toc_window_display": false, 194 | "widenNotebook": false 195 | } 196 | }, 197 | "nbformat": 4, 198 | "nbformat_minor": 4 199 | } 200 | -------------------------------------------------------------------------------- /notebooks/compositing/transform.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Comparaison of transformation methods" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import time\n", 29 | "\n", 30 | "import matplotlib.pyplot as plt\n", 31 | "import wradlib\n", 32 | "import xarray\n", 33 | "import xradar" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "Get a radar sweep with reflectivity measurements and metadata" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [ 49 | "from wradlib_data import DATASETS\n", 50 | "\n", 51 | "filename = \"hdf5/71_20181220_060628.pvol.h5\"\n", 52 | "filename = DATASETS.fetch(filename)\n", 53 | "volume = xradar.io.open_odim_datatree(filename)\n", 54 | "sweep = volume[\"sweep_0\"].ds\n", 55 | "metadata = xradar.model.required_sweep_metadata_vars\n", 56 | "sweep = sweep[[\"DBZH\"] + list(metadata)]" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "Interpolate radar sweep into a Cartesian grid using nearest neighbor method" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "window = [-200e3, 200e3, -200e3, 200e3]\n", 73 | "size = 1000\n", 74 | "lon = float(sweep.longitude.values)\n", 75 | "lat = float(sweep.latitude.values)\n", 76 | "crs = wradlib.georef.get_radar_projection((lon, lat))\n", 77 | "raster = wradlib.georef.create_raster_xarray(crs, window, size)\n", 78 | "grid = raster\n", 79 | "sweep = sweep.wrl.georef.georeference(crs=crs)\n", 80 | "tic = time.time()\n", 81 | "comp1 = sweep.DBZH.wrl.comp.togrid(\n", 82 | " grid, radius=250e3, center=(lon, lat), interpol=wradlib.ipol.Nearest\n", 83 | ")\n", 84 | "toc = time.time() - tic\n", 85 | "print(f\"Time elapsed: {toc}\")" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "Combine radar sweep into a raster image by taking the mean" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "tic = time.time()\n", 102 | "transform = wradlib.comp.transform_binned(sweep, raster)\n", 103 | "comp2 = wradlib.comp.sweep_to_raster(sweep, raster)\n", 104 | "toc = time.time() - tic\n", 105 | "print(f\"Time elapsed: {toc}\")" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "Compare the methods at close range" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": null, 118 | "metadata": {}, 119 | "outputs": [], 120 | "source": [ 121 | "sweep.DBZH.plot(x=\"x\", y=\"y\", cmap=\"PuBuGn\", vmin=10, vmax=60)\n", 122 | "plt.xlim(-10e3, 10e3)\n", 123 | "plt.ylim(-10e3, 10e3)\n", 124 | "plt.suptitle(\"Sweep\")\n", 125 | "plt.show()\n", 126 | "\n", 127 | "comp1.plot.pcolormesh(cmap=\"PuBuGn\", vmin=10, vmax=60)\n", 128 | "plt.xlim(-10e3, 10e3)\n", 129 | "plt.ylim(-10e3, 10e3)\n", 130 | "plt.suptitle(\"Grid (nearest)\")\n", 131 | "plt.show()\n", 132 | "\n", 133 | "comp2 = comp2.drop_vars(\"spatial_ref\")\n", 134 | "comp2[\"DBZH\"].plot.pcolormesh(cmap=\"PuBuGn\", vmin=10, vmax=60)\n", 135 | "plt.xlim(-10e3, 10e3)\n", 136 | "plt.ylim(-10e3, 10e3)\n", 137 | "plt.suptitle(\"Raster (binned)\")\n", 138 | "plt.show()" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": null, 144 | "metadata": {}, 145 | "outputs": [], 146 | "source": [] 147 | } 148 | ], 149 | "metadata": { 150 | "language_info": { 151 | "codemirror_mode": { 152 | "name": "ipython", 153 | "version": 3 154 | }, 155 | "file_extension": ".py", 156 | "mimetype": "text/x-python", 157 | "name": "python", 158 | "nbconvert_exporter": "python", 159 | "pygments_lexer": "ipython3", 160 | "version": "3.13.3" 161 | }, 162 | "toc": { 163 | "colors": { 164 | "hover_highlight": "#DAA520", 165 | "navigate_num": "#000000", 166 | "navigate_text": "#333333", 167 | "running_highlight": "#FF0000", 168 | "selected_highlight": "#FFD700", 169 | "sidebar_border": "#EEEEEE", 170 | "wrapper_background": "#FFFFFF" 171 | }, 172 | "moveMenuLeft": true, 173 | "nav_menu": { 174 | "height": "47px", 175 | "width": "252px" 176 | }, 177 | "navigate_menu": true, 178 | "number_sections": false, 179 | "sideBar": true, 180 | "threshold": 4, 181 | "toc_cell": false, 182 | "toc_section_display": "block", 183 | "toc_window_display": false, 184 | "widenNotebook": false 185 | } 186 | }, 187 | "nbformat": 4, 188 | "nbformat_minor": 4 189 | } 190 | -------------------------------------------------------------------------------- /notebooks/fileio.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Data Input - Data Output" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "The binary encoding of many radar products is a major obstacle for many potential radar users. Often, decoder software is not easily available. In case formats are documented, the implementation of decoders is a major programming effort. \n", 27 | "\n", 28 | "
\n", 29 | "\n", 30 | "**Note**
\n", 31 | " \n", 32 | "For radar data in polar format (eg. rays vs. range) the [openradar community](https://openradarscience.org/) published [xradar](https://docs.openradarscience.org/projects/xradar/en/latest/) where xarray-based readers/writers are implemented. That particular code was ported from $\\omega radlib$ to xradar. Please refer to xradar for enhancements for polar radar.\n", 33 | " \n", 34 | "
\n", 35 | "\n", 36 | "This section provides a collection of example code snippets to show which data formats $\\omega radlib$ can handle and and how to facilitate that." 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": { 42 | "nbsphinx-toctree": { 43 | "hidden": true, 44 | "maxdepth": 2 45 | } 46 | }, 47 | "source": [ 48 | "- [Legacy readers](fileio/legacy_readers.ipynb)\n", 49 | "- [Xarray readers](fileio/xarray_backends.ipynb)\n", 50 | "- [DWD RADOLAN](fileio/radolan.ipynb)\n", 51 | "- [GIS Vector Data](fileio/gis/vector_data.ipynb)\n", 52 | "- [GIS Raster Export](fileio/gis/raster_data.ipynb)" 53 | ] 54 | } 55 | ], 56 | "metadata": { 57 | "celltoolbar": "Edit Metadata", 58 | "language_info": { 59 | "codemirror_mode": { 60 | "name": "ipython", 61 | "version": 3 62 | }, 63 | "file_extension": ".py", 64 | "mimetype": "text/x-python", 65 | "name": "python", 66 | "nbconvert_exporter": "python", 67 | "pygments_lexer": "ipython3", 68 | "version": "3.12.8" 69 | }, 70 | "toc": { 71 | "colors": { 72 | "hover_highlight": "#DAA520", 73 | "navigate_num": "#000000", 74 | "navigate_text": "#333333", 75 | "running_highlight": "#FF0000", 76 | "selected_highlight": "#FFD700", 77 | "sidebar_border": "#EEEEEE", 78 | "wrapper_background": "#FFFFFF" 79 | }, 80 | "moveMenuLeft": true, 81 | "nav_menu": { 82 | "height": "49px", 83 | "width": "252px" 84 | }, 85 | "navigate_menu": true, 86 | "number_sections": false, 87 | "sideBar": true, 88 | "threshold": 4, 89 | "toc_cell": false, 90 | "toc_section_display": "block", 91 | "toc_window_display": false, 92 | "widenNotebook": false 93 | } 94 | }, 95 | "nbformat": 4, 96 | "nbformat_minor": 4 97 | } 98 | -------------------------------------------------------------------------------- /notebooks/fileio/backends/cfradial1_backend.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# xarray CfRadial1 backend\n", 20 | "\n", 21 | "In this example, we read CfRadial1 data files using the `xradar` `cfradial1` backend.\n", 22 | "\n", 23 | "Data is also exported to ODIM_H5 and CfRadial2." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "import wradlib as wrl\n", 33 | "import wradlib_data\n", 34 | "import warnings\n", 35 | "\n", 36 | "warnings.filterwarnings(\"ignore\")\n", 37 | "import matplotlib.pyplot as plt\n", 38 | "import numpy as np\n", 39 | "import xradar as xd\n", 40 | "import xarray as xr\n", 41 | "\n", 42 | "try:\n", 43 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 44 | "except:\n", 45 | " plt.ion()" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "## Load CfRadial1 Volume Data\n", 53 | "\n", 54 | "We use the functionality provided now by [xradar](https://docs.openradarscience.org/projects/xradar/en/stable/) to read the CfRadial1 data into a DataTree." 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "fpath = \"netcdf/cfrad.20080604_002217_000_SPOL_v36_SUR.nc\"\n", 64 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 65 | "vol = xd.io.open_cfradial1_datatree(f)" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "## Inspect RadarVolume" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "display(vol)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "## Inspect root group\n", 89 | "\n", 90 | "The `sweep` dimension contains the number of scans in this radar volume. Further the dataset consists of variables (location coordinates, time_coverage) and attributes (Conventions, metadata)." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "vol.root" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "## Inspect sweep group(s)\n", 107 | "\n", 108 | "The sweep-groups can be accessed via their respective keys. The dimensions consist of `range` and `time` with added coordinates `azimuth`, `elevation`, `range` and `time`. There will be variables like radar moments (DBZH etc.) and sweep-dependend metadata (like `fixed_angle`, `sweep_mode` etc.)." 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "display(vol[\"sweep_0\"])" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "## Georeferencing\n", 125 | "\n", 126 | "``sweep_mode`` is assigned coordinate, as we need it available on the DataArray." 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": null, 132 | "metadata": {}, 133 | "outputs": [], 134 | "source": [ 135 | "swp = vol[\"sweep_0\"].ds\n", 136 | "swp = swp.assign_coords(sweep_mode=swp.sweep_mode)\n", 137 | "swp = swp.wrl.georef.georeference()\n", 138 | "display(swp)" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": {}, 144 | "source": [ 145 | "## Inspect radar moments\n", 146 | "\n", 147 | "The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it's parent dataset. There are attributes connected which are defined by Cf/Radial standard." 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "display(swp.DBZ)" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "## Create simple plot\n", 164 | "\n", 165 | "Using xarray features a simple plot can be created like this. Note the `sortby('time')` method, which sorts the radials by time.\n", 166 | "\n", 167 | "For more details on plotting radar data see under [Visualization](../../plotting.ipynb)." 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [ 176 | "swp.DBZ.sortby(\"time\").plot(x=\"range\", y=\"time\", add_labels=False)" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "fig = plt.figure(figsize=(5, 5))\n", 186 | "pm = swp.DBZ.wrl.vis.plot(crs={\"latmin\": 3e3}, fig=fig)" 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": {}, 192 | "source": [ 193 | "## Use `xr.open_dataset` to retrieve explicit group\n", 194 | "\n", 195 | "
\n", 196 | "\n", 197 | "**Warning**
\n", 198 | " \n", 199 | "Since $\\omega radlib$ version 2.0 all xarray backend related functionality is imported from [xradar](https://github.com/openradar/xradar)-package.\n", 200 | " \n", 201 | "
\n" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": null, 207 | "metadata": {}, 208 | "outputs": [], 209 | "source": [ 210 | "swp_b = xr.open_dataset(\n", 211 | " f, engine=\"cfradial1\", group=\"sweep_1\", backend_kwargs=dict(reindex_angle=False)\n", 212 | ")\n", 213 | "display(swp_b)" 214 | ] 215 | } 216 | ], 217 | "metadata": { 218 | "language_info": { 219 | "codemirror_mode": { 220 | "name": "ipython", 221 | "version": 3 222 | }, 223 | "file_extension": ".py", 224 | "mimetype": "text/x-python", 225 | "name": "python", 226 | "nbconvert_exporter": "python", 227 | "pygments_lexer": "ipython3", 228 | "version": "3.12.4" 229 | } 230 | }, 231 | "nbformat": 4, 232 | "nbformat_minor": 4 233 | } 234 | -------------------------------------------------------------------------------- /notebooks/fileio/backends/cfradial2_backend.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# xarray CfRadial2 backend\n", 20 | "\n", 21 | "In this example, we read CfRadial2 data files using the xarray `cfradial2` backend." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import wradlib as wrl\n", 31 | "import wradlib_data\n", 32 | "import warnings\n", 33 | "\n", 34 | "warnings.filterwarnings(\"ignore\")\n", 35 | "import matplotlib.pyplot as plt\n", 36 | "import numpy as np\n", 37 | "import xradar as xd\n", 38 | "import xarray as xr\n", 39 | "\n", 40 | "try:\n", 41 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 42 | "except:\n", 43 | " plt.ion()" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Load CfRadial2 Volume Data" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "fpath = \"netcdf/cfrad.20080604_002217_000_SPOL_v36_SUR_cfradial2.nc\"\n", 60 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 61 | "vol = xr.open_datatree(f)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "# fix: remove when available in xradar\n", 71 | "for k in vol.groups[1:]:\n", 72 | " vol[k].ds = (\n", 73 | " vol[k]\n", 74 | " .ds.assign(sweep_fixed_angle=vol[k].ds.attrs[\"fixed_angle\"])\n", 75 | " .swap_dims(time=\"azimuth\")\n", 76 | " .sortby(\"azimuth\")\n", 77 | " )" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "## Inspect RadarVolume" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "display(vol)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "## Inspect root group\n", 101 | "\n", 102 | "The `sweep` dimension contains the number of scans in this radar volume. Further the dataset consists of variables (location coordinates, time_coverage) and attributes (Conventions, metadata)." 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [ 111 | "vol.root" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "## Inspect sweep group(s)\n", 119 | "\n", 120 | "The sweep-groups can be accessed via their respective keys. The dimensions consist of `range` and `time` with added coordinates `azimuth`, `elevation`, `range` and `time`. There will be variables like radar moments (DBZH etc.) and sweep-dependend metadata (like `fixed_angle`, `sweep_mode` etc.)." 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "display(vol[\"sweep_0\"])" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "## Georeferencing" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": null, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "swp = vol[\"sweep_0\"].ds.copy()\n", 146 | "swp = swp.assign_coords(sweep_mode=swp.sweep_mode)\n", 147 | "swp = swp.wrl.georef.georeference()" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "## Inspect radar moments\n", 155 | "\n", 156 | "The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it's parent dataset. There are attributes connected which are defined by Cf/Radial standard." 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "display(swp.DBZ)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": {}, 171 | "source": [ 172 | "## Create simple plot\n", 173 | "\n", 174 | "Using xarray features a simple plot can be created like this. Note the `sortby('time')` method, which sorts the radials by time.\n", 175 | "\n", 176 | "For more details on plotting radar data see under [Visualization](../../plotting.ipynb)." 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "metadata": {}, 183 | "outputs": [], 184 | "source": [ 185 | "swp.DBZ.sortby(\"time\").plot(x=\"range\", y=\"time\", add_labels=False)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": null, 191 | "metadata": {}, 192 | "outputs": [], 193 | "source": [ 194 | "fig = plt.figure(figsize=(5, 5))\n", 195 | "pm = swp.DBZ.wrl.vis.plot(crs={\"latmin\": 3e3}, fig=fig)" 196 | ] 197 | } 198 | ], 199 | "metadata": { 200 | "language_info": { 201 | "codemirror_mode": { 202 | "name": "ipython", 203 | "version": 3 204 | }, 205 | "file_extension": ".py", 206 | "mimetype": "text/x-python", 207 | "name": "python", 208 | "nbconvert_exporter": "python", 209 | "pygments_lexer": "ipython3", 210 | "version": "3.12.4" 211 | } 212 | }, 213 | "nbformat": 4, 214 | "nbformat_minor": 4 215 | } 216 | -------------------------------------------------------------------------------- /notebooks/fileio/backends/gamic_backend.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wrl.vis.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# xarray GAMIC backend\n", 20 | "\n", 21 | "In this example, we read GAMIC (HDF5) data files using the xradar `gamic` backend." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import glob\n", 31 | "import wradlib as wrl\n", 32 | "import wradlib_data\n", 33 | "import warnings\n", 34 | "\n", 35 | "warnings.filterwarnings(\"ignore\")\n", 36 | "import matplotlib.pyplot as plt\n", 37 | "import numpy as np\n", 38 | "import xradar as xd\n", 39 | "import xarray as xr\n", 40 | "\n", 41 | "try:\n", 42 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 43 | "except:\n", 44 | " plt.ion()" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "## Load GAMIC HDF5 Volume Data" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "fpath = \"hdf5/DWD-Vol-2_99999_20180601054047_00.h5\"\n", 61 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 62 | "vol = xd.io.open_gamic_datatree(f)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "## Inspect RadarVolume" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "display(vol)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "## Inspect root group\n", 86 | "\n", 87 | "The `sweep` dimension contains the number of scans in this radar volume. Further the dataset consists of variables (location coordinates, time_coverage) and attributes (Conventions, metadata)." 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": null, 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "vol.root" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "## Inspect sweep group(s)\n", 104 | "\n", 105 | "The sweep-groups can be accessed via their respective keys. The dimensions consist of `range` and `time` with added coordinates `azimuth`, `elevation`, `range` and `time`. There will be variables like radar moments (DBZH etc.) and sweep-dependend metadata (like `fixed_angle`, `sweep_mode` etc.)." 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "display(vol[\"sweep_0\"])" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "## Georeferencing" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "swp = vol[\"sweep_0\"].ds.copy()\n", 131 | "swp = swp.assign_coords(sweep_mode=swp.sweep_mode)" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "swp = swp.wrl.georef.georeference()\n", 141 | "display(swp)" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": {}, 147 | "source": [ 148 | "## Inspect radar moments\n", 149 | "\n", 150 | "The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it's parent dataset. There are attributes connected which are defined by ODIM_H5 standard." 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": null, 156 | "metadata": {}, 157 | "outputs": [], 158 | "source": [ 159 | "display(swp.DBZH)" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": {}, 165 | "source": [ 166 | "## Create simple plot\n", 167 | "\n", 168 | "Using xarray features a simple plot can be created like this. Note the `sortby('time')` method, which sorts the radials by time.\n", 169 | "\n", 170 | "For more details on plotting radar data see under [Visualization](../../plotting.ipynb)." 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": null, 176 | "metadata": {}, 177 | "outputs": [], 178 | "source": [ 179 | "swp.DBZH.sortby(\"time\").plot(x=\"range\", y=\"time\", add_labels=False)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [ 188 | "fig = plt.figure(figsize=(10, 10))\n", 189 | "pm = swp.DBZH.wrl.vis.plot(crs={\"latmin\": 3e3}, fig=fig)" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "## Retrieve explicit group\n" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "swp_b = xr.open_dataset(\n", 206 | " f, engine=\"gamic\", group=\"sweep_9\", backend_kwargs=dict(reindex_angle=False)\n", 207 | ")\n", 208 | "display(swp_b)" 209 | ] 210 | } 211 | ], 212 | "metadata": { 213 | "language_info": { 214 | "codemirror_mode": { 215 | "name": "ipython", 216 | "version": 3 217 | }, 218 | "file_extension": ".py", 219 | "mimetype": "text/x-python", 220 | "name": "python", 221 | "nbconvert_exporter": "python", 222 | "pygments_lexer": "ipython3", 223 | "version": "3.12.4" 224 | } 225 | }, 226 | "nbformat": 4, 227 | "nbformat_minor": 4 228 | } 229 | -------------------------------------------------------------------------------- /notebooks/fileio/backends/iris_backend.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# xarray IRIS backend\n", 20 | "\n", 21 | "In this example, we read IRIS (sigmet) data files using the xradar `iris` xarray backend." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import glob\n", 31 | "import gzip\n", 32 | "import io\n", 33 | "import wradlib as wrl\n", 34 | "import wradlib_data\n", 35 | "import warnings\n", 36 | "\n", 37 | "warnings.filterwarnings(\"ignore\")\n", 38 | "import matplotlib.pyplot as plt\n", 39 | "import numpy as np\n", 40 | "import xradar as xd\n", 41 | "import xarray as xr\n", 42 | "\n", 43 | "try:\n", 44 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 45 | "except:\n", 46 | " plt.ion()" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "## Load IRIS Volume Data" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "fpath = \"sigmet/SUR210819000227.RAWKPJV\"\n", 63 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 64 | "vol = xd.io.open_iris_datatree(f, reindex_angle=False)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "## Inspect RadarVolume" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "display(vol)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "## Inspect root group\n", 88 | "\n", 89 | "The `sweep` dimension contains the number of scans in this radar volume. Further the dataset consists of variables (location coordinates, time_coverage) and attributes (Conventions, metadata)." 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "vol.root" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "## Inspect sweep group(s)\n", 106 | "\n", 107 | "The sweep-groups can be accessed via their respective keys. The dimensions consist of `range` and `time` with added coordinates `azimuth`, `elevation`, `range` and `time`. There will be variables like radar moments (DBZH etc.) and sweep-dependend metadata (like `fixed_angle`, `sweep_mode` etc.)." 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "display(vol[\"sweep_0\"])" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "## Georeferencing" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "swp = vol[\"sweep_0\"].ds.copy()\n", 133 | "swp = swp.assign_coords(sweep_mode=swp.sweep_mode)\n", 134 | "swp = swp.wrl.georef.georeference()" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "## Inspect radar moments\n", 142 | "\n", 143 | "The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it's parent dataset." 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "metadata": {}, 150 | "outputs": [], 151 | "source": [ 152 | "display(swp.DBZH)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "## Create simple plot\n", 160 | "\n", 161 | "Using xarray features a simple plot can be created like this. Note the `sortby('time')` method, which sorts the radials by time.\n", 162 | "\n", 163 | "For more details on plotting radar data see under [Visualization](../../plotting.ipynb)." 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "swp.DBZH.sortby(\"time\").plot(x=\"range\", y=\"time\", add_labels=False)" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "fig = plt.figure(figsize=(5, 5))\n", 182 | "pm = swp.DBZH.wrl.vis.plot(crs={\"latmin\": 3e3}, fig=fig)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": {}, 188 | "source": [ 189 | "## Retrieve explicit group" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "swp_b = xr.open_dataset(\n", 199 | " f, engine=\"iris\", group=\"sweep_0\", backend_kwargs=dict(reindex_angle=False)\n", 200 | ")\n", 201 | "display(swp_b)" 202 | ] 203 | } 204 | ], 205 | "metadata": { 206 | "language_info": { 207 | "codemirror_mode": { 208 | "name": "ipython", 209 | "version": 3 210 | }, 211 | "file_extension": ".py", 212 | "mimetype": "text/x-python", 213 | "name": "python", 214 | "nbconvert_exporter": "python", 215 | "pygments_lexer": "ipython3", 216 | "version": "3.12.4" 217 | } 218 | }, 219 | "nbformat": 4, 220 | "nbformat_minor": 4 221 | } 222 | -------------------------------------------------------------------------------- /notebooks/fileio/backends/odim_backend.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# xarray ODIM backend\n", 20 | "\n", 21 | "In this example, we read ODIM_H5 (HDF5) data files using the xradar `odim` backend. Throughout the notebook xarray accessors are used to access wradlib functionality." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import glob\n", 31 | "import os\n", 32 | "import wradlib as wrl\n", 33 | "import wradlib_data\n", 34 | "import warnings\n", 35 | "\n", 36 | "warnings.filterwarnings(\"ignore\")\n", 37 | "import matplotlib.pyplot as plt\n", 38 | "import numpy as np\n", 39 | "import xradar as xd\n", 40 | "import xarray as xr\n", 41 | "\n", 42 | "try:\n", 43 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 44 | "except:\n", 45 | " plt.ion()" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "## Load ODIM_H5 Volume Data" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "fpath = \"hdf5/knmi_polar_volume.h5\"\n", 62 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 63 | "vol = xd.io.open_odim_datatree(f)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "## Inspect RadarVolume" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "display(vol)" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "## Inspect root group\n", 87 | "\n", 88 | "The `sweep` dimension contains the number of scans in this radar volume. Further the dataset consists of variables (location coordinates, time_coverage) and attributes (Conventions, metadata)." 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "vol.root" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "## Inspect sweep group(s)\n", 105 | "\n", 106 | "The sweep-groups can be accessed via their respective keys. The dimensions consist of `range` and `time` with added coordinates `azimuth`, `elevation`, `range` and `time`. There will be variables like radar moments (DBZH etc.) and sweep-dependend metadata (like `fixed_angle`, `sweep_mode` etc.)." 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "display(vol[\"sweep_0\"])" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "## Georeferencing" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "swp = vol[\"sweep_0\"].ds\n", 132 | "swp = swp.assign_coords(sweep_mode=swp.sweep_mode)\n", 133 | "swp = swp.wrl.georef.georeference()" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": {}, 139 | "source": [ 140 | "## Inspect radar moments\n", 141 | "\n", 142 | "The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it's parent dataset. There are attributes connected which are defined by ODIM_H5 standard." 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": null, 148 | "metadata": {}, 149 | "outputs": [], 150 | "source": [ 151 | "display(swp.DBZH)" 152 | ] 153 | }, 154 | { 155 | "cell_type": "markdown", 156 | "metadata": {}, 157 | "source": [ 158 | "## Create simple plot\n", 159 | "\n", 160 | "Using xarray features a simple plot can be created like this. Note the `sortby('time')` method, which sorts the radials by time.\n", 161 | "\n", 162 | "For more details on plotting radar data see under [Visualization](../../plotting.ipynb)." 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": null, 168 | "metadata": {}, 169 | "outputs": [], 170 | "source": [ 171 | "swp.DBZH.sortby(\"time\").plot(x=\"range\", y=\"time\", add_labels=False)" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": null, 177 | "metadata": {}, 178 | "outputs": [], 179 | "source": [ 180 | "fig = plt.figure(figsize=(10, 10))\n", 181 | "pm = swp.DBZH.wrl.vis.plot(crs={\"latmin\": 33e3}, fig=fig)" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "## Retrieve explicit group" 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": null, 194 | "metadata": {}, 195 | "outputs": [], 196 | "source": [ 197 | "swp_b = xr.open_dataset(\n", 198 | " f, engine=\"odim\", group=\"sweep_13\", backend_kwargs=dict(reindex_angle=False)\n", 199 | ")\n", 200 | "display(swp_b)" 201 | ] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "metadata": {}, 206 | "source": [ 207 | "### Use `xr.open_mfdataset` to retrieve timeseries of explicit group " 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "metadata": {}, 214 | "outputs": [], 215 | "source": [ 216 | "flist = [\"hdf5/71_20181220_060628.pvol.h5\", \"hdf5/71_20181220_061228.pvol.h5\"]\n", 217 | "flist = [wradlib_data.DATASETS.fetch(f) for f in flist]\n", 218 | "ts = xr.open_mfdataset(\n", 219 | " flist, engine=\"odim\", concat_dim=\"volume_time\", combine=\"nested\", group=\"sweep_0\"\n", 220 | ")\n", 221 | "display(ts)" 222 | ] 223 | } 224 | ], 225 | "metadata": { 226 | "language_info": { 227 | "codemirror_mode": { 228 | "name": "ipython", 229 | "version": 3 230 | }, 231 | "file_extension": ".py", 232 | "mimetype": "text/x-python", 233 | "name": "python", 234 | "nbconvert_exporter": "python", 235 | "pygments_lexer": "ipython3", 236 | "version": "3.12.8" 237 | } 238 | }, 239 | "nbformat": 4, 240 | "nbformat_minor": 4 241 | } 242 | -------------------------------------------------------------------------------- /notebooks/fileio/backends/radolan_backend.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# xarray RADOLAN backend\n", 20 | "\n", 21 | "In this example, we read RADOLAN data files using the xarray `radolan` backend." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import glob\n", 31 | "import os\n", 32 | "import wradlib as wrl\n", 33 | "import wradlib_data\n", 34 | "import warnings\n", 35 | "\n", 36 | "warnings.filterwarnings(\"ignore\")\n", 37 | "import matplotlib.pyplot as plt\n", 38 | "import numpy as np\n", 39 | "import xarray as xr\n", 40 | "\n", 41 | "try:\n", 42 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 43 | "except:\n", 44 | " plt.ion()" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "## Load RADOLAN Data" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "fpath = \"radolan/misc/raa01-rw_10000-1408030950-dwd---bin.gz\"\n", 61 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 62 | "comp = wrl.io.open_radolan_dataset(f)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "## Inspect Data" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [ 78 | "display(comp)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "## Inspect RADOLAN moments\n", 86 | "\n", 87 | "The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it's parent dataset." 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": null, 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "display(comp.RW)" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "## Create simple plot\n", 104 | "\n", 105 | "Using xarray features a simple plot can be created like this." 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "comp.RW.plot(x=\"x\", y=\"y\", add_labels=False)" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "fig = plt.figure(figsize=(10, 10))\n", 124 | "ax = fig.add_subplot(111)\n", 125 | "comp.RW.plot(x=\"x\", y=\"y\", ax=ax)" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "## Mask some values" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [ 141 | "ds = comp[\"RW\"].where(comp[\"RW\"] >= 1)\n", 142 | "ds.plot()" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "## Use `xr.open_dataset`\n" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "comp2 = xr.open_dataset(f, engine=\"radolan\")\n", 159 | "display(comp2)" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": {}, 165 | "source": [ 166 | "## Use `xr.open_mfdataset` to retrieve timeseries" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "flist = [\n", 176 | " \"radolan/misc/raa01-sf_10000-1305270050-dwd---bin.gz\",\n", 177 | " \"radolan/misc/raa01-sf_10000-1305280050-dwd---bin.gz\",\n", 178 | "]\n", 179 | "flist = [wradlib_data.DATASETS.fetch(f) for f in flist]" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [ 188 | "comp3 = xr.open_mfdataset(flist, engine=\"radolan\")\n", 189 | "display(comp3)" 190 | ] 191 | } 192 | ], 193 | "metadata": { 194 | "language_info": { 195 | "codemirror_mode": { 196 | "name": "ipython", 197 | "version": 3 198 | }, 199 | "file_extension": ".py", 200 | "mimetype": "text/x-python", 201 | "name": "python", 202 | "nbconvert_exporter": "python", 203 | "pygments_lexer": "ipython3", 204 | "version": "3.11.0" 205 | } 206 | }, 207 | "nbformat": 4, 208 | "nbformat_minor": 4 209 | } 210 | -------------------------------------------------------------------------------- /notebooks/fileio/backends/rainbow_backend.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# xarray Rainbow5 backend\n", 20 | "\n", 21 | "In this example, we read Rainbow5 data files using the xradar `rainbow` xarray backend." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "import glob\n", 31 | "import gzip\n", 32 | "import io\n", 33 | "import wradlib as wrl\n", 34 | "import wradlib_data\n", 35 | "import warnings\n", 36 | "\n", 37 | "warnings.filterwarnings(\"ignore\")\n", 38 | "import matplotlib.pyplot as plt\n", 39 | "import numpy as np\n", 40 | "import xradar as xd\n", 41 | "import xarray as xr\n", 42 | "\n", 43 | "try:\n", 44 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 45 | "except:\n", 46 | " plt.ion()" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "## Load Rainbow5 Volume Data" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "fpath = \"rainbow/2013051000000600dBZ.vol\"\n", 63 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 64 | "vol = xd.io.open_rainbow_datatree(f, reindex_angle=False)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "## Inspect RadarVolume" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "display(vol)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "## Inspect root group\n", 88 | "\n", 89 | "The `sweep` dimension contains the number of scans in this radar volume. Further the dataset consists of variables (location coordinates, time_coverage) and attributes (Conventions, metadata)." 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "vol.root" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "## Inspect sweep group(s)\n", 106 | "\n", 107 | "The sweep-groups can be accessed via their respective keys. The dimensions consist of `range` and `time` with added coordinates `azimuth`, `elevation`, `range` and `time`. There will be variables like radar moments (DBZH etc.) and sweep-dependend metadata (like `fixed_angle`, `sweep_mode` etc.)." 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "display(vol[\"sweep_0\"])" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "## Georeferencing" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "swp = vol[\"sweep_0\"].ds.copy()\n", 133 | "swp = swp.assign_coords(sweep_mode=swp.sweep_mode)\n", 134 | "swp = swp.wrl.georef.georeference()" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "## Inspect radar moments\n", 142 | "\n", 143 | "The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it's parent dataset." 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "metadata": {}, 150 | "outputs": [], 151 | "source": [ 152 | "display(swp.DBZH)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "## Create simple plot\n", 160 | "\n", 161 | "Using xarray features a simple plot can be created like this. Note the `sortby('time')` method, which sorts the radials by time.\n", 162 | "\n", 163 | "For more details on plotting radar data see under [Visualization](../../plotting.ipynb)." 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "swp.DBZH.sortby(\"time\").plot(x=\"range\", y=\"time\", add_labels=False)" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "fig = plt.figure(figsize=(5, 5))\n", 182 | "pm = swp.DBZH.wrl.vis.plot(crs={\"latmin\": 3e3}, fig=fig)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": {}, 188 | "source": [ 189 | "## Retrieve explicit group" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "swp_b = xr.open_dataset(\n", 199 | " f, engine=\"rainbow\", group=\"sweep_5\", backend_kwargs=dict(reindex_angle=False)\n", 200 | ")\n", 201 | "display(swp_b)" 202 | ] 203 | } 204 | ], 205 | "metadata": { 206 | "language_info": { 207 | "codemirror_mode": { 208 | "name": "ipython", 209 | "version": 3 210 | }, 211 | "file_extension": ".py", 212 | "mimetype": "text/x-python", 213 | "name": "python", 214 | "nbconvert_exporter": "python", 215 | "pygments_lexer": "ipython3", 216 | "version": "3.12.4" 217 | } 218 | }, 219 | "nbformat": 4, 220 | "nbformat_minor": 4 221 | } 222 | -------------------------------------------------------------------------------- /notebooks/fileio/legacy/read_gamic.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "58c3b804-207d-4553-bc71-32c71a215636", 6 | "metadata": { 7 | "nbsphinx": "hidden" 8 | }, 9 | "source": [ 10 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 11 | "\n", 12 | "Copyright (c) $\\omega radlib$ developers.\n", 13 | "Distributed under the MIT License. See LICENSE.txt for more info." 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "id": "accf8983-0237-4a46-9952-38d8e413ebf1", 19 | "metadata": { 20 | "slideshow": { 21 | "slide_type": "slide" 22 | } 23 | }, 24 | "source": [ 25 | "### GAMIC HDF5" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "id": "273acd30-bb6c-4005-a8d4-bc079500bf2d", 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "import wradlib as wrl\n", 36 | "import wradlib_data\n", 37 | "import matplotlib.pyplot as plt\n", 38 | "import numpy as np\n", 39 | "import warnings\n", 40 | "\n", 41 | "warnings.filterwarnings(\"ignore\")\n", 42 | "try:\n", 43 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 44 | "except:\n", 45 | " plt.ion()" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "id": "37c92691-012a-413c-a15c-516dbe73b32d", 51 | "metadata": { 52 | "slideshow": { 53 | "slide_type": "skip" 54 | } 55 | }, 56 | "source": [ 57 | "GAMIC refers to the commercial [GAMIC Enigma MURAN software](https://www.gamic.com) which exports data in hdf5 format. The concept is quite similar to the [OPERA HDF5 (ODIM_H5)](read_odim.ipynb#OPERA-HDF5-(ODIM_H5)) format. \n", 58 | "\n", 59 | "
\n", 60 | "\n", 61 | "**Note**
\n", 62 | " \n", 63 | "For radar data in GAMIC HDF5 format the [openradar community](https://openradarscience.org/) published [xradar](https://docs.openradarscience.org/projects/xradar/en/latest/) where xarray-based readers/writers are implemented. That particular code was ported from $\\omega radlib$ to xradar. Please refer to xradar for enhancements for polar radar. \n", 64 | " \n", 65 | "From $\\omega radlib$ version 1.19 `GAMIC HDF5` reading code is imported from [xradar](https://github.com/openradar/xradar)-package whenever and wherever necessary.\n", 66 | " \n", 67 | "Please read the more indepth notebook [gamic_backend](../backends/gamic_backend.ipynb).\n", 68 | " \n", 69 | "
\n", 70 | "\n", 71 | "Such a file (typical ending: *.mvol*) can be read by:" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "id": "f529a3aa-661a-48b4-a64e-e476438bcfbb", 78 | "metadata": { 79 | "slideshow": { 80 | "slide_type": "fragment" 81 | } 82 | }, 83 | "outputs": [], 84 | "source": [ 85 | "fpath = \"hdf5/2014-08-10--182000.ppi.mvol\"\n", 86 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 87 | "data, metadata = wrl.io.read_gamic_hdf5(f)" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "id": "3808e7a3-a8cc-44dd-8812-03ccad37d926", 93 | "metadata": { 94 | "slideshow": { 95 | "slide_type": "skip" 96 | } 97 | }, 98 | "source": [ 99 | "While metadata represents the usual dictionary of metadata, the data variable is a dictionary which might contain several numpy arrays with the keywords of the dictionary indicating different moments." 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "id": "bae34c98-34c7-4c79-888a-735a24facecf", 106 | "metadata": { 107 | "slideshow": { 108 | "slide_type": "fragment" 109 | } 110 | }, 111 | "outputs": [], 112 | "source": [ 113 | "print(metadata.keys())\n", 114 | "print(metadata[\"VOL\"])\n", 115 | "print(metadata[\"SCAN0\"].keys())" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "id": "9b192fca-d6b9-4eeb-bd80-8135a656e2b3", 122 | "metadata": { 123 | "slideshow": { 124 | "slide_type": "fragment" 125 | } 126 | }, 127 | "outputs": [], 128 | "source": [ 129 | "print(data[\"SCAN0\"].keys())\n", 130 | "print(data[\"SCAN0\"][\"PHIDP\"].keys())\n", 131 | "print(data[\"SCAN0\"][\"PHIDP\"][\"data\"].shape)" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "id": "56d21371-ae70-42a2-9e6a-6c65854c5f8f", 138 | "metadata": { 139 | "slideshow": { 140 | "slide_type": "subslide" 141 | } 142 | }, 143 | "outputs": [], 144 | "source": [ 145 | "fig = plt.figure(figsize=(10, 10))\n", 146 | "da = wrl.georef.create_xarray_dataarray(\n", 147 | " data[\"SCAN0\"][\"ZH\"][\"data\"]\n", 148 | ").wrl.georef.georeference()\n", 149 | "im = da.wrl.vis.plot(fig=fig, crs=\"cg\")" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": null, 155 | "id": "540110a3-2757-48db-8022-111959360360", 156 | "metadata": {}, 157 | "outputs": [], 158 | "source": [] 159 | } 160 | ], 161 | "metadata": { 162 | "language_info": { 163 | "codemirror_mode": { 164 | "name": "ipython", 165 | "version": 3 166 | }, 167 | "file_extension": ".py", 168 | "mimetype": "text/x-python", 169 | "name": "python", 170 | "nbconvert_exporter": "python", 171 | "pygments_lexer": "ipython3", 172 | "version": "3.11.0" 173 | } 174 | }, 175 | "nbformat": 4, 176 | "nbformat_minor": 5 177 | } 178 | -------------------------------------------------------------------------------- /notebooks/fileio/legacy/read_hdf5.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "f5838d14-848a-4cf6-a8dc-f9862f94c246", 6 | "metadata": { 7 | "nbsphinx": "hidden" 8 | }, 9 | "source": [ 10 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 11 | "\n", 12 | "Copyright (c) $\\omega radlib$ developers.\n", 13 | "Distributed under the MIT License. See LICENSE.txt for more info." 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "id": "cd92dd6d-5a9e-470f-a19a-d2054e657aca", 19 | "metadata": { 20 | "slideshow": { 21 | "slide_type": "slide" 22 | } 23 | }, 24 | "source": [ 25 | "# Reading HDF5 files with a generic reader\n", 26 | "\n", 27 | "This reader utilizes [h5py](https://docs.h5py.org).\n", 28 | "\n", 29 | "In this example, we read HDF5 files from different sources using a generic reader from $\\omega radlib's$ io module." 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": null, 35 | "id": "ea0b2623-278f-4159-80c2-1dd71b724c42", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "import wradlib as wrl\n", 40 | "import wradlib_data\n", 41 | "import matplotlib.pyplot as plt\n", 42 | "import warnings\n", 43 | "\n", 44 | "warnings.filterwarnings(\"ignore\")\n", 45 | "try:\n", 46 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 47 | "except:\n", 48 | " plt.ion()\n", 49 | "import numpy as np" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "id": "18c7c9f9-93f0-4c9c-9a9e-1a0cfc2c1bef", 55 | "metadata": {}, 56 | "source": [ 57 | "## Generic Reader" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "id": "12574a59-28ff-409b-aa7d-93c20bd2bef7", 63 | "metadata": { 64 | "slideshow": { 65 | "slide_type": "skip" 66 | } 67 | }, 68 | "source": [ 69 | "This is a generic hdf5 reader, which will read any hdf5 structure." 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "id": "1e44d485-81d4-4b6d-b8cc-c4814752ccec", 76 | "metadata": { 77 | "slideshow": { 78 | "slide_type": "fragment" 79 | } 80 | }, 81 | "outputs": [], 82 | "source": [ 83 | "fpath = \"hdf5/2014-08-10--182000.ppi.mvol\"\n", 84 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 85 | "fcontent = wrl.io.read_generic_hdf5(f)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "id": "fb681854-ba66-4aca-9a64-844e2bd20f5b", 92 | "metadata": { 93 | "slideshow": { 94 | "slide_type": "fragment" 95 | } 96 | }, 97 | "outputs": [], 98 | "source": [ 99 | "print(fcontent.keys())" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "id": "5e2e5a9d-df40-4810-8dad-560bc7f07ed1", 106 | "metadata": { 107 | "slideshow": { 108 | "slide_type": "fragment" 109 | } 110 | }, 111 | "outputs": [], 112 | "source": [ 113 | "print(fcontent[\"where\"])\n", 114 | "print(fcontent[\"how\"])\n", 115 | "print(fcontent[\"scan0/moment_3\"].keys())\n", 116 | "print(fcontent[\"scan0/moment_3\"][\"attrs\"])\n", 117 | "print(fcontent[\"scan0/moment_3\"][\"data\"].shape)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "id": "f9e02426-2961-4abf-98a9-58c01d25db57", 124 | "metadata": { 125 | "slideshow": { 126 | "slide_type": "subslide" 127 | } 128 | }, 129 | "outputs": [], 130 | "source": [ 131 | "fig = plt.figure(figsize=(10, 10))\n", 132 | "da = wrl.georef.create_xarray_dataarray(\n", 133 | " fcontent[\"scan0/moment_3\"][\"data\"]\n", 134 | ").wrl.georef.georeference()\n", 135 | "im = da.wrl.vis.plot(fig=fig, crs=\"cg\")" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "id": "cdaabab9-db25-4e9b-81ed-20e0579a3782", 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": null, 149 | "id": "ba1d5ed6-0b1d-4b4c-b6ff-5783c3d14025", 150 | "metadata": {}, 151 | "outputs": [], 152 | "source": [] 153 | } 154 | ], 155 | "metadata": { 156 | "language_info": { 157 | "codemirror_mode": { 158 | "name": "ipython", 159 | "version": 3 160 | }, 161 | "file_extension": ".py", 162 | "mimetype": "text/x-python", 163 | "name": "python", 164 | "nbconvert_exporter": "python", 165 | "pygments_lexer": "ipython3", 166 | "version": "3.11.0" 167 | } 168 | }, 169 | "nbformat": 4, 170 | "nbformat_minor": 5 171 | } 172 | -------------------------------------------------------------------------------- /notebooks/fileio/legacy/read_iris.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "206e392d-e28f-4534-9ba3-5ccf6a5cdff1", 6 | "metadata": { 7 | "nbsphinx": "hidden" 8 | }, 9 | "source": [ 10 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 11 | "\n", 12 | "Copyright (c) $\\omega radlib$ developers.\n", 13 | "Distributed under the MIT License. See LICENSE.txt for more info." 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "id": "b72524f2-03b3-4991-a786-3c764c36bab1", 19 | "metadata": { 20 | "slideshow": { 21 | "slide_type": "slide" 22 | } 23 | }, 24 | "source": [ 25 | "## Vaisala Sigmet IRIS " 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "id": "78391aec-6ef6-4808-bd74-639ceedc852f", 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "import wradlib as wrl\n", 36 | "import wradlib_data\n", 37 | "import matplotlib.pyplot as plt\n", 38 | "import numpy as np\n", 39 | "import warnings\n", 40 | "\n", 41 | "warnings.filterwarnings(\"ignore\")\n", 42 | "try:\n", 43 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 44 | "except:\n", 45 | " plt.ion()" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "id": "d756d935-fa85-47c8-824a-1107f7db61b2", 51 | "metadata": { 52 | "slideshow": { 53 | "slide_type": "skip" 54 | } 55 | }, 56 | "source": [ 57 | "[IRIS](https://www.vaisala.com/en/products/iris-focus-remote-sensing-software) refers to the commercial Vaisala Sigmet **I**nteractive **R**adar **I**nformation **S**ystem. The Vaisala Sigmet Digital Receivers export data in a [well documented](ftp://ftp.sigmet.com/outgoing/manuals/IRIS_Programmers_Manual.pdf) binary format.\n", 58 | "\n", 59 | "The philosophy behind the $\\omega radlib$ interface to the IRIS data model is very straightforward: $\\omega radlib$ simply translates the complete binary file structure to *one* dictionary and returns this dictionary to the user. Thus, the potential complexity of the stored data is kept and it is left to the user how to proceed with this data. The keys of the output dictionary are strings that correspond to the Sigmet Data Structures. \n", 60 | "\n", 61 | "\n", 62 | "
\n", 63 | "\n", 64 | "**Note**
\n", 65 | " \n", 66 | "For radar data in IRIS/Sigmet format the [openradar community](https://openradarscience.org/) published [xradar](https://docs.openradarscience.org/projects/xradar/en/latest/) where xarray-based readers/writers are implemented. That particular code was ported from $\\omega radlib$ to xradar. Please refer to xradar for enhancements for polar radar. \n", 67 | " \n", 68 | "From $\\omega radlib$ version 1.19 `IRIS/Sigmet` reading code is imported from [xradar](https://github.com/openradar/xradar)-package whenever and wherever necessary.\n", 69 | "\n", 70 | "Please read the more indepth notebook [iris_backend](../backends/iris_backend.ipynb).\n", 71 | " \n", 72 | "
\n", 73 | "\n", 74 | "Such a file (typical ending: *.RAWXXXX) can be read by:" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "id": "ac4df7e3-fbe1-44e6-988a-d4d282e41335", 81 | "metadata": { 82 | "slideshow": { 83 | "slide_type": "fragment" 84 | } 85 | }, 86 | "outputs": [], 87 | "source": [ 88 | "fpath = \"sigmet/cor-main131125105503.RAW2049\"\n", 89 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 90 | "fcontent = wrl.io.read_iris(f)" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "id": "8ed98453-3401-4bd9-8e07-577eeafab91b", 97 | "metadata": { 98 | "slideshow": { 99 | "slide_type": "fragment" 100 | } 101 | }, 102 | "outputs": [], 103 | "source": [ 104 | "# which keywords can be used to access the content?\n", 105 | "print(fcontent.keys())\n", 106 | "# print the entire content including values of data and\n", 107 | "# metadata of the first sweep\n", 108 | "# (numpy arrays will not be entirely printed)\n", 109 | "print(fcontent[\"data\"][1].keys())\n", 110 | "print()\n", 111 | "print(fcontent[\"data\"][1][\"ingest_data_hdrs\"].keys())\n", 112 | "print(fcontent[\"data\"][1][\"ingest_data_hdrs\"][\"DB_DBZ\"])\n", 113 | "print()\n", 114 | "print(fcontent[\"data\"][1][\"sweep_data\"].keys())\n", 115 | "print(fcontent[\"data\"][1][\"sweep_data\"][\"DB_DBZ\"])" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "id": "d7ac3d3f-0910-40ad-b4e5-cc60118ddb4f", 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [ 125 | "fig = plt.figure(figsize=(10, 10))\n", 126 | "swp = fcontent[\"data\"][1][\"sweep_data\"]\n", 127 | "da = wrl.georef.create_xarray_dataarray(\n", 128 | " swp[\"DB_DBZ\"],\n", 129 | ").wrl.georef.georeference()\n", 130 | "im = da.wrl.vis.plot(fig=fig, crs=\"cg\")" 131 | ] 132 | } 133 | ], 134 | "metadata": { 135 | "language_info": { 136 | "codemirror_mode": { 137 | "name": "ipython", 138 | "version": 3 139 | }, 140 | "file_extension": ".py", 141 | "mimetype": "text/x-python", 142 | "name": "python", 143 | "nbconvert_exporter": "python", 144 | "pygments_lexer": "ipython3", 145 | "version": "3.11.0" 146 | } 147 | }, 148 | "nbformat": 4, 149 | "nbformat_minor": 5 150 | } 151 | -------------------------------------------------------------------------------- /notebooks/fileio/legacy/read_odim.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "131e39c6-b9b4-43a7-8db7-a06ca2b0b725", 6 | "metadata": { 7 | "nbsphinx": "hidden" 8 | }, 9 | "source": [ 10 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 11 | "\n", 12 | "Copyright (c) $\\omega radlib$ developers.\n", 13 | "Distributed under the MIT License. See LICENSE.txt for more info." 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "id": "056ab6e7-d15d-4f8b-a9e0-1a7ffc315332", 19 | "metadata": { 20 | "slideshow": { 21 | "slide_type": "fragment" 22 | } 23 | }, 24 | "source": [ 25 | "### OPERA HDF5 (ODIM_H5)" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "id": "31e5b394-d82b-4b73-9f73-468029d7f111", 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "import wradlib as wrl\n", 36 | "import wradlib_data\n", 37 | "import matplotlib.pyplot as plt\n", 38 | "import numpy as np\n", 39 | "import warnings\n", 40 | "\n", 41 | "warnings.filterwarnings(\"ignore\")\n", 42 | "try:\n", 43 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 44 | "except:\n", 45 | " plt.ion()" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "id": "7d4aa2c7-3050-425c-b6d0-02ae04570ea8", 51 | "metadata": { 52 | "slideshow": { 53 | "slide_type": "skip" 54 | } 55 | }, 56 | "source": [ 57 | "[HDF5](https://www.hdfgroup.org/solutions/hdf5/) is a data model, library, and file format for storing and managing data. The [OPERA program](https://www.eumetnet.eu/activities/observations-programme/current-activities/opera/) developed a convention (or information model) on how to store and exchange radar data in hdf5 format. It is based on the work of [COST Action 717](https://www.cost.eu/actions/717/) and is used e.g. in real-time operations in the Nordic European countries. The OPERA Data and Information Model (ODIM) is documented [here under OPERA Publications](https://www.eumetnet.eu/activities/observations-programme/current-activities/opera/). Make use of these documents in order to understand the organization of OPERA hdf5 files!\n", 58 | "\n", 59 | "
\n", 60 | "\n", 61 | "**Note**
\n", 62 | " \n", 63 | "For radar data in ODIM_H5 format the [openradar community](https://openradarscience.org/) published [xradar](https://docs.openradarscience.org/projects/xradar/en/latest/) where xarray-based readers/writers are implemented. That particular code was ported from $\\omega radlib$ to xradar. Please refer to xradar for enhancements for polar radar. \n", 64 | " \n", 65 | "From $\\omega radlib$ version 1.19 `ODIM_H5` reading code is imported from [xradar](https://github.com/openradar/xradar)-package whenever and wherever necessary.\n", 66 | " \n", 67 | "Please read the more indepth notebook [odim_backend](../backends/odim_backend.ipynb).\n", 68 | " \n", 69 | "
\n", 70 | "\n", 71 | "The hierarchical nature of HDF5 can be described as being similar to directories, files, and links on a hard-drive. Actual metadata are stored as so-called *attributes*, and these attributes are organized together in so-called *groups*. Binary data are stored as so-called *datasets*. As for ODIM_H5, the ``root`` (or top level) group contains three groups of metadata: these are called ``what`` (object, information model version, and date/time information), ``where`` (geographical information), and ``how`` (quality and optional/recommended metadata). For a very simple product, e.g. a CAPPI, the data is organized in a group called ``dataset1`` which contains another group called ``data1`` where the actual binary data are found in ``data``. In analogy with a file system on a hard-disk, the HDF5 file containing this simple product is organized like this:\n", 72 | "\n", 73 | "```\n", 74 | " /\n", 75 | " /what\n", 76 | " /where\n", 77 | " /how\n", 78 | " /dataset1\n", 79 | " /dataset1/data1\n", 80 | " /dataset1/data1/data\n", 81 | "```\n", 82 | "\n", 83 | "The philosophy behind the $\\omega radlib$ interface to OPERA's data model is very straightforward: $\\omega radlib$ simply translates the complete file structure to *one* dictionary and returns this dictionary to the user. Thus, the potential complexity of the stored data is kept and it is left to the user how to proceed with this data. The keys of the output dictionary are strings that correspond to the \"directory trees\" shown above. Each key ending with ``/data`` points to a Dataset (i.e. a numpy array of data). Each key ending with ``/what``, ``/where`` or ``/how`` points to another dictionary of metadata. The entire output can be obtained by:" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "id": "530ed45d-c10c-4fcf-bc19-351604dbc518", 90 | "metadata": { 91 | "slideshow": { 92 | "slide_type": "fragment" 93 | } 94 | }, 95 | "outputs": [], 96 | "source": [ 97 | "fpath = \"hdf5/knmi_polar_volume.h5\"\n", 98 | "f = wradlib_data.DATASETS.fetch(fpath)\n", 99 | "fcontent = wrl.io.read_opera_hdf5(f)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "id": "11689e1b-3cac-4eea-8c65-6725e2a00f0f", 105 | "metadata": { 106 | "slideshow": { 107 | "slide_type": "skip" 108 | } 109 | }, 110 | "source": [ 111 | "The user should inspect the output obtained from his or her hdf5 file in order to see how access those items which should be further processed. In order to get a readable overview of the output dictionary, one can use the pretty printing module:" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "id": "7d70a9d5-949d-464d-9574-8fda632f3899", 118 | "metadata": { 119 | "slideshow": { 120 | "slide_type": "fragment" 121 | } 122 | }, 123 | "outputs": [], 124 | "source": [ 125 | "# which keyswords can be used to access the content?\n", 126 | "print(fcontent.keys())\n", 127 | "# print the entire content including values of data and metadata\n", 128 | "# (numpy arrays will not be entirely printed)\n", 129 | "print(fcontent[\"dataset1/data1/data\"])" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "id": "0eb6ac04-12a6-48c1-9de1-25f591f932ea", 135 | "metadata": { 136 | "slideshow": { 137 | "slide_type": "skip" 138 | } 139 | }, 140 | "source": [ 141 | "Please note that in order to experiment with such datasets, you can download hdf5 sample data from the [OPERA](https://www.eumetnet.eu/activities/observations-programme/current-activities/opera/) or use the example data provided with the [wradlib-data](https://github.com/wradlib/wradlib-data/) repository." 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "id": "74fe2c4d-8820-483e-944a-0b4bbe677590", 148 | "metadata": { 149 | "slideshow": { 150 | "slide_type": "subslide" 151 | } 152 | }, 153 | "outputs": [], 154 | "source": [ 155 | "fig = plt.figure(figsize=(10, 10))\n", 156 | "da = wrl.georef.create_xarray_dataarray(\n", 157 | " fcontent[\"dataset1/data1/data\"]\n", 158 | ").wrl.georef.georeference()\n", 159 | "im = da.wrl.vis.plot(fig=fig, crs=\"cg\")" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": null, 165 | "id": "11b089ae-a73c-43a6-8b83-37ffa3abff07", 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [] 169 | } 170 | ], 171 | "metadata": { 172 | "language_info": { 173 | "codemirror_mode": { 174 | "name": "ipython", 175 | "version": 3 176 | }, 177 | "file_extension": ".py", 178 | "mimetype": "text/x-python", 179 | "name": "python", 180 | "nbconvert_exporter": "python", 181 | "pygments_lexer": "ipython3", 182 | "version": "3.11.0" 183 | } 184 | }, 185 | "nbformat": 4, 186 | "nbformat_minor": 5 187 | } 188 | -------------------------------------------------------------------------------- /notebooks/fileio/legacy_readers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden", 7 | "slideshow": { 8 | "slide_type": "skip" 9 | } 10 | }, 11 | "source": [ 12 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 13 | "\n", 14 | "Copyright (c) $\\omega radlib$ developers.\n", 15 | "Distributed under the MIT License. See LICENSE.txt for more info." 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "slideshow": { 22 | "slide_type": "slide" 23 | } 24 | }, 25 | "source": [ 26 | "# Legacy readers" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "slideshow": { 33 | "slide_type": "skip" 34 | } 35 | }, 36 | "source": [ 37 | "
\n", 38 | "\n", 39 | "For radar data in polar format the [openradar community](https://openradarscience.org/) published [xradar](https://docs.openradarscience.org/projects/xradar/en/latest/) where xarray-based readers/writers are implemented. That particular code was ported from $\\omega radlib$ to xradar. Please refer to xradar for enhancements for polar radar. \n", 40 | " \n", 41 | "From $\\omega radlib$ version 1.19 that functionality is imported from [xradar](https://github.com/openradar/xradar)-package whenever and wherever necessary.\n", 42 | " \n", 43 | "Please refer to [xradar based examples](xarray_backends.ipynb) for an introduction.\n", 44 | " \n", 45 | "
\n", 46 | "\n", 47 | "Since new developments are done in xradar this chapter only covers the legacy readers with numpy output. They will work fine, but we recommend to use the available xarray based readers." 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": { 53 | "slideshow": { 54 | "slide_type": "fragment" 55 | } 56 | }, 57 | "source": [ 58 | "Reading weather radar files is done via the [wradlib.io](https://docs.wradlib.org/en/latest/io.html) module. There you will find a complete function reference. " 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": { 64 | "nbsphinx-toctree": { 65 | "hidden": true, 66 | "maxdepth": 2 67 | } 68 | }, 69 | "source": [ 70 | "- [DWD DX](legacy/read_dx.ipynb)\n", 71 | "- [NetCDF](legacy/read_netcdf.ipynb)\n", 72 | "- [HDF5](legacy/read_hdf5.ipynb)\n", 73 | "- [OPERA ODIM](legacy/read_odim.ipynb)\n", 74 | "- [GAMIC HDF](legacy/read_gamic.ipynb)\n", 75 | "- [Leonardo Rainbow](legacy/read_rainbow.ipynb)\n", 76 | "- [Vaisala IRIS/Sigmet](legacy/read_iris.ipynb)" 77 | ] 78 | } 79 | ], 80 | "metadata": { 81 | "celltoolbar": "Slideshow", 82 | "language_info": { 83 | "codemirror_mode": { 84 | "name": "ipython", 85 | "version": 3 86 | }, 87 | "file_extension": ".py", 88 | "mimetype": "text/x-python", 89 | "name": "python", 90 | "nbconvert_exporter": "python", 91 | "pygments_lexer": "ipython3", 92 | "version": "3.11.0" 93 | }, 94 | "livereveal": { 95 | "scroll": true 96 | }, 97 | "toc": { 98 | "colors": { 99 | "hover_highlight": "#DAA520", 100 | "navigate_num": "#000000", 101 | "navigate_text": "#333333", 102 | "running_highlight": "#FF0000", 103 | "selected_highlight": "#FFD700", 104 | "sidebar_border": "#EEEEEE", 105 | "wrapper_background": "#FFFFFF" 106 | }, 107 | "moveMenuLeft": true, 108 | "nav_menu": { 109 | "height": "269px", 110 | "width": "252px" 111 | }, 112 | "navigate_menu": true, 113 | "number_sections": false, 114 | "sideBar": true, 115 | "threshold": 4, 116 | "toc_cell": false, 117 | "toc_section_display": "block", 118 | "toc_window_display": false, 119 | "widenNotebook": false 120 | } 121 | }, 122 | "nbformat": 4, 123 | "nbformat_minor": 4 124 | } 125 | -------------------------------------------------------------------------------- /notebooks/fileio/radolan.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# RADOLAN " 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "RADOLAN is abbreviated from the german **RA**dar-**O**n**L**ine-**AN**eichung, which means Radar-Online-Adjustment.\n", 27 | "\n", 28 | "Using it's [network of 17 weather radar](https://www.dwd.de/SharedDocs/broschueren/DE/presse/wetterradar_pdf.pdf?__blob=publicationFile&v=5) the German Weather Service provides [many products](https://www.dwd.de/DE/leistungen/radolan/produktuebersicht/radolan_produktuebersicht_pdf.pdf?__blob=publicationFile&v=6) for high resolution precipitation analysis and forecast. A comprehensive product list can be found in chapter [RADOLAN Product Showcase](radolan/radolan_showcase.ipynb).\n", 29 | "\n", 30 | "These composite products are distributed in the [RADOLAN Binary Data Format](radolan/radolan_format.ipynb) with an ASCII header. All composites are available in [Polar Stereographic Projection](radolan/radolan_grid.ipynb#Polar-Stereographic-Projection) which will be discussed in the chapter [RADOLAN Grid](radolan/radolan_grid.ipynb).\n", 31 | "\n", 32 | "This notebook tutorial was prepared with material from the [DWD RADOLAN/RADVOR-OP Kompositformat](https://www.dwd.de/DE/leistungen/radolan/radolan_info/radolan_radvor_op_komposit_format_pdf.pdf?__blob=publicationFile&v=5).\n", 33 | "We also wish to thank Elmar Weigl, German Weather Service, for providing the extensive set of example data and his valuable information about the RADOLAN products." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": { 39 | "nbsphinx-toctree": { 40 | "hidden": true, 41 | "maxdepth": 2 42 | } 43 | }, 44 | "source": [ 45 | "- [RADOLAN Quick Start](radolan/radolan_quickstart.ipynb)\n", 46 | "- [RADOLAN Binary Data Format](radolan/radolan_format.ipynb)\n", 47 | "- [RADOLAN Product Showcase](radolan/radolan_showcase.ipynb)\n", 48 | "- [RADOLAN Grid](radolan/radolan_grid.ipynb)\n", 49 | "- [DWD Radar Network](radolan/radolan_network.ipynb)" 50 | ] 51 | } 52 | ], 53 | "metadata": { 54 | "celltoolbar": "Edit Metadata", 55 | "language_info": { 56 | "codemirror_mode": { 57 | "name": "ipython", 58 | "version": 3 59 | }, 60 | "file_extension": ".py", 61 | "mimetype": "text/x-python", 62 | "name": "python", 63 | "nbconvert_exporter": "python", 64 | "pygments_lexer": "ipython3", 65 | "version": "3.11.0" 66 | }, 67 | "toc": { 68 | "colors": { 69 | "hover_highlight": "#DAA520", 70 | "navigate_num": "#000000", 71 | "navigate_text": "#333333", 72 | "running_highlight": "#FF0000", 73 | "selected_highlight": "#FFD700", 74 | "sidebar_border": "#EEEEEE", 75 | "wrapper_background": "#FFFFFF" 76 | }, 77 | "moveMenuLeft": true, 78 | "nav_menu": { 79 | "height": "31px", 80 | "width": "252px" 81 | }, 82 | "navigate_menu": true, 83 | "number_sections": false, 84 | "sideBar": true, 85 | "threshold": 4, 86 | "toc_cell": false, 87 | "toc_section_display": "block", 88 | "toc_window_display": false, 89 | "widenNotebook": false 90 | } 91 | }, 92 | "nbformat": 4, 93 | "nbformat_minor": 4 94 | } 95 | -------------------------------------------------------------------------------- /notebooks/fileio/radolan/radolan_format.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# RADOLAN data formats" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "## RADOLAN binary data format" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "The RADOLAN binary data file format is described in the RADOLAN Kompositformat. The radolan composite files consists of an ascii header containing all needed information to decode the following binary data block. $\\omega radlib$ provides [wradlib.io.read_radolan_composite()](https://docs.wradlib.org/en/latest/generated/wradlib.io.radolan.read_radolan_composite.html) to read the data.\n", 34 | "\n", 35 | "The function `wradlib.io.parse_dwd_composite_header()` takes care of correctly decoding the ascii header. All available header information is transferred into the metadata dictionary." 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "import wradlib as wrl\n", 45 | "import wradlib_data\n", 46 | "import matplotlib.pyplot as plt\n", 47 | "import warnings\n", 48 | "import io\n", 49 | "import tarfile\n", 50 | "\n", 51 | "warnings.filterwarnings(\"ignore\")\n", 52 | "try:\n", 53 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 54 | "except:\n", 55 | " plt.ion()\n", 56 | "import numpy as np" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "# load radolan files\n", 66 | "rw_filename = wradlib_data.DATASETS.fetch(\n", 67 | " \"radolan/misc/raa01-rw_10000-1408102050-dwd---bin.gz\"\n", 68 | ")\n", 69 | "filehandle = wrl.io.get_radolan_filehandle(rw_filename)\n", 70 | "header = wrl.io.read_radolan_header(filehandle)\n", 71 | "print(header)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "attrs = wrl.io.parse_dwd_composite_header(header)\n", 81 | "print(attrs)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "In the following example, the header information of four different composites is extracted." 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "# load radolan file\n", 98 | "filename = \"radolan/showcase/raa01-rx_10000-1408102050-dwd---bin.gz\"\n", 99 | "rx_filename = wradlib_data.DATASETS.fetch(filename)\n", 100 | "filename = \"radolan/showcase/raa01-ex_10000-1408102050-dwd---bin.gz\"\n", 101 | "ex_filename = wradlib_data.DATASETS.fetch(filename)\n", 102 | "filename = \"radolan/showcase/raa01-rw_10000-1408102050-dwd---bin.gz\"\n", 103 | "rw_filename = wradlib_data.DATASETS.fetch(filename)\n", 104 | "filename = \"radolan/showcase/raa01-sf_10000-1408102050-dwd---bin.gz\"\n", 105 | "sf_filename = wradlib_data.DATASETS.fetch(filename)\n", 106 | "\n", 107 | "rxdata, rxattrs = wrl.io.read_radolan_composite(rx_filename)\n", 108 | "exdata, exattrs = wrl.io.read_radolan_composite(ex_filename)\n", 109 | "rwdata, rwattrs = wrl.io.read_radolan_composite(rw_filename)\n", 110 | "sfdata, sfattrs = wrl.io.read_radolan_composite(sf_filename)\n", 111 | "\n", 112 | "# print the available attributes\n", 113 | "print(\"RX Attributes:\")\n", 114 | "for key, value in rxattrs.items():\n", 115 | " print(key + \":\", value)\n", 116 | "print(\"----------------------------------------------------------------\")\n", 117 | "# print the available attributes\n", 118 | "print(\"EX Attributes:\")\n", 119 | "for key, value in exattrs.items():\n", 120 | " print(key + \":\", value)\n", 121 | "print(\"----------------------------------------------------------------\")\n", 122 | "\n", 123 | "# print the available attributes\n", 124 | "print(\"RW Attributes:\")\n", 125 | "for key, value in rwattrs.items():\n", 126 | " print(key + \":\", value)\n", 127 | "print(\"----------------------------------------------------------------\")\n", 128 | "\n", 129 | "# print the available attributes\n", 130 | "print(\"SF Attributes:\")\n", 131 | "for key, value in sfattrs.items():\n", 132 | " print(key + \":\", value)\n", 133 | "print(\"----------------------------------------------------------------\")" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": {}, 139 | "source": [ 140 | "## RADOLAN ASCII data format" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "The ASCII GIS Format is prepended by a limited header and has two flavours as follows:\n", 148 | "\n", 149 | "- RADOLAN / reproc (RADARKLIMATOLOGIE) 2001 – 2019\n", 150 | "\n", 151 | "```\n", 152 | " ncols 900\n", 153 | " nrows 1100\n", 154 | " xllcorner -443462\n", 155 | " yllcorner -4758645\n", 156 | " cellsize 1000\n", 157 | " nodata_value -9999.0\n", 158 | "``` \n", 159 | " Units: 1.0 mm\n", 160 | "\n", 161 | "- RADOLAN / recent, 2020 – jetzt :\n", 162 | "```\n", 163 | " ncols 900\n", 164 | " nrows 900\n", 165 | " xllcorner -523462y\n", 166 | " llcorner -4658645\n", 167 | " cellsize 1000\n", 168 | " NODATA_value -1\n", 169 | "```\n", 170 | " Units: 0.1 mm\n", 171 | " \n", 172 | "Product and Datetime need to be extracted from the filename, so extra care has to be taken to not tamper with the filenames." 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "fname = wradlib_data.DATASETS.fetch(\"radolan/asc/RW-20221018.tar.gz\")\n", 182 | "fp = tarfile.open(fname)\n", 183 | "names = fp.getnames()\n", 184 | "buffer = [io.BytesIO(fp.extractfile(name).read()) for name in names]\n", 185 | "for buf, name in zip(buffer, names):\n", 186 | " buf.name = name\n", 187 | "ds = wrl.io.open_radolan_mfdataset(buffer)" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "display(ds)" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "ds.RW.plot(col=\"time\", col_wrap=6, vmax=20)" 206 | ] 207 | } 208 | ], 209 | "metadata": { 210 | "celltoolbar": "Edit Metadata", 211 | "language_info": { 212 | "codemirror_mode": { 213 | "name": "ipython", 214 | "version": 3 215 | }, 216 | "file_extension": ".py", 217 | "mimetype": "text/x-python", 218 | "name": "python", 219 | "nbconvert_exporter": "python", 220 | "pygments_lexer": "ipython3", 221 | "version": "3.11.0" 222 | }, 223 | "toc": { 224 | "colors": { 225 | "hover_highlight": "#DAA520", 226 | "navigate_num": "#000000", 227 | "navigate_text": "#333333", 228 | "running_highlight": "#FF0000", 229 | "selected_highlight": "#FFD700", 230 | "sidebar_border": "#EEEEEE", 231 | "wrapper_background": "#FFFFFF" 232 | }, 233 | "moveMenuLeft": true, 234 | "nav_menu": { 235 | "height": "31px", 236 | "width": "252px" 237 | }, 238 | "navigate_menu": true, 239 | "number_sections": false, 240 | "sideBar": true, 241 | "threshold": 4, 242 | "toc_cell": false, 243 | "toc_section_display": "block", 244 | "toc_window_display": false, 245 | "widenNotebook": false 246 | } 247 | }, 248 | "nbformat": 4, 249 | "nbformat_minor": 4 250 | } 251 | -------------------------------------------------------------------------------- /notebooks/fileio/xarray_backends.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# xarray backends" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "This section gives an overview on the available xarray backends.\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "
\n", 34 | "\n", 35 | "**Warning**
\n", 36 | " \n", 37 | "For radar data in polar format the [openradar community](https://openradarscience.org/) published [xradar](https://docs.openradarscience.org/projects/xradar/en/latest/) where xarray-based readers/writers are implemented. That particular code was ported from $\\omega radlib$ to xradar. Please refer to xradar for enhancements for polar radar. \n", 38 | " \n", 39 | "Since $\\omega radlib$ version 1.19 almost all backend code has been transferred to [xradar](https://github.com/openradar/xradar)-package and is imported from there. \n", 40 | " \n", 41 | "
\n" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": { 47 | "nbsphinx-toctree": { 48 | "maxdepth": 2 49 | } 50 | }, 51 | "source": [ 52 | "# Native Backends\n", 53 | "\n", 54 | "- [RADOLAN](backends/radolan_backend.ipynb)" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": { 60 | "nbsphinx-toctree": { 61 | "maxdepth": 2 62 | } 63 | }, 64 | "source": [ 65 | "# Imported Backends from xradar\n", 66 | "- [ODIM](backends/odim_backend.ipynb)\n", 67 | "- [GAMIC](backends/gamic_backend.ipynb)\n", 68 | "- [CfRadial1](backends/cfradial1_backend.ipynb)\n", 69 | "- [CfRadial2](backends/cfradial2_backend.ipynb)\n", 70 | "- [Iris/sigmet](backends/iris_backend.ipynb)\n", 71 | "- [Rainbow5](backends/rainbow_backend.ipynb)\n", 72 | "- [Furuno SCN/SCNX](backends/furuno_backend.ipynb)" 73 | ] 74 | } 75 | ], 76 | "metadata": { 77 | "celltoolbar": "Edit Metadata", 78 | "language_info": { 79 | "codemirror_mode": { 80 | "name": "ipython", 81 | "version": 3 82 | }, 83 | "file_extension": ".py", 84 | "mimetype": "text/x-python", 85 | "name": "python", 86 | "nbconvert_exporter": "python", 87 | "pygments_lexer": "ipython3", 88 | "version": "3.12.8" 89 | }, 90 | "toc": { 91 | "colors": { 92 | "hover_highlight": "#DAA520", 93 | "navigate_num": "#000000", 94 | "navigate_text": "#333333", 95 | "running_highlight": "#FF0000", 96 | "selected_highlight": "#FFD700", 97 | "sidebar_border": "#EEEEEE", 98 | "wrapper_background": "#FFFFFF" 99 | }, 100 | "moveMenuLeft": true, 101 | "nav_menu": { 102 | "height": "49px", 103 | "width": "252px" 104 | }, 105 | "navigate_menu": true, 106 | "number_sections": false, 107 | "sideBar": true, 108 | "threshold": 4, 109 | "toc_cell": false, 110 | "toc_section_display": "block", 111 | "toc_window_display": false, 112 | "widenNotebook": false 113 | } 114 | }, 115 | "nbformat": 4, 116 | "nbformat_minor": 4 117 | } 118 | -------------------------------------------------------------------------------- /notebooks/files/cover_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wradlib/wradlib-notebooks/b1f696a0f5f6e83f95a42fb22f50aeb2e319e297/notebooks/files/cover_image.png -------------------------------------------------------------------------------- /notebooks/files/wradlib_logo.svg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wradlib/wradlib-notebooks/b1f696a0f5f6e83f95a42fb22f50aeb2e319e297/notebooks/files/wradlib_logo.svg.png -------------------------------------------------------------------------------- /notebooks/georeferencing.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Georeferencing" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "This section provides a collection of example code snippets to show how georeferencing of radar and ancillary data is done in $\\omega radlib$.\n" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "nbsphinx-toctree": { 33 | "hidden": true, 34 | "maxdepth": 2 35 | } 36 | }, 37 | "source": [ 38 | "- [Computing Cartesian Coordinates from Polar Data](georeferencing/coords.ipynb)\n", 39 | "- [Georeferencing a Radar Dataset](georeferencing/georef.ipynb)" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "## Examples" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "- [RADOLAN Grid Calculations](fileio/radolan/radolan_grid.ipynb)\n", 54 | "- [Overlay Ancillary Data](visualisation/gis_overlay.ipynb)\n", 55 | "- [Managing Georeferenced Data](zonalstats/zonalstats.ipynb)" 56 | ] 57 | } 58 | ], 59 | "metadata": { 60 | "celltoolbar": "Edit Metadata", 61 | "language_info": { 62 | "codemirror_mode": { 63 | "name": "ipython", 64 | "version": 3 65 | }, 66 | "file_extension": ".py", 67 | "mimetype": "text/x-python", 68 | "name": "python", 69 | "nbconvert_exporter": "python", 70 | "pygments_lexer": "ipython3", 71 | "version": "3.11.0" 72 | }, 73 | "toc": { 74 | "colors": { 75 | "hover_highlight": "#DAA520", 76 | "navigate_num": "#000000", 77 | "navigate_text": "#333333", 78 | "running_highlight": "#FF0000", 79 | "selected_highlight": "#FFD700", 80 | "sidebar_border": "#EEEEEE", 81 | "wrapper_background": "#FFFFFF" 82 | }, 83 | "moveMenuLeft": true, 84 | "nav_menu": { 85 | "height": "49px", 86 | "width": "252px" 87 | }, 88 | "navigate_menu": true, 89 | "number_sections": false, 90 | "sideBar": true, 91 | "threshold": 4, 92 | "toc_cell": false, 93 | "toc_section_display": "block", 94 | "toc_window_display": false, 95 | "widenNotebook": false 96 | } 97 | }, 98 | "nbformat": 4, 99 | "nbformat_minor": 4 100 | } 101 | -------------------------------------------------------------------------------- /notebooks/georeferencing/coords.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Computing cartesian and geographical coordinates for polar data" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import numpy as np\n", 29 | "import wradlib as wrl\n", 30 | "import wradlib_data\n", 31 | "import xradar as xd\n", 32 | "import warnings\n", 33 | "\n", 34 | "warnings.filterwarnings(\"ignore\")" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "## Read the data\n", 42 | "\n", 43 | "Here, we use an OPERA hdf5 dataset." 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "filename = \"hdf5/20130429043000.rad.bewid.pvol.dbzh.scan1.hdf\"\n", 53 | "filename = wradlib_data.DATASETS.fetch(filename)\n", 54 | "pvol = xd.io.open_odim_datatree(filename)\n", 55 | "display(pvol)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "## Retrieve azimuthal equidistant coordinates and projection" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "for key in list(pvol.children):\n", 72 | " if \"sweep\" in key:\n", 73 | " pvol[key].ds = pvol[key].ds.wrl.georef.georeference()" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "pvol[\"sweep_0\"].ds.DBZH.plot(x=\"x\", y=\"y\")" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "## Retrieve geographic coordinates (longitude and latitude)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "### Using crs-keyword argument." 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "for key in list(pvol.children):\n", 106 | " if \"sweep\" in key:\n", 107 | " pvol[key].ds = pvol[key].ds.wrl.georef.georeference(\n", 108 | " crs=wrl.georef.get_default_projection()\n", 109 | " )" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "metadata": {}, 116 | "outputs": [], 117 | "source": [ 118 | "ds1 = pvol[\"sweep_0\"].ds.wrl.georef.georeference(\n", 119 | " crs=wrl.georef.get_default_projection()\n", 120 | ")\n", 121 | "ds1.DBZH.plot(x=\"x\", y=\"y\")" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "### Using reproject" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": null, 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "ds2 = pvol[\"sweep_0\"].ds.wrl.georef.reproject(\n", 138 | " trg_crs=wrl.georef.epsg_to_osr(32632),\n", 139 | ")\n", 140 | "ds2.DBZH.plot(x=\"x\", y=\"y\")" 141 | ] 142 | } 143 | ], 144 | "metadata": { 145 | "language_info": { 146 | "codemirror_mode": { 147 | "name": "ipython", 148 | "version": 3 149 | }, 150 | "file_extension": ".py", 151 | "mimetype": "text/x-python", 152 | "name": "python", 153 | "nbconvert_exporter": "python", 154 | "pygments_lexer": "ipython3", 155 | "version": "3.11.0" 156 | }, 157 | "toc": { 158 | "colors": { 159 | "hover_highlight": "#DAA520", 160 | "navigate_num": "#000000", 161 | "navigate_text": "#333333", 162 | "running_highlight": "#FF0000", 163 | "selected_highlight": "#FFD700", 164 | "sidebar_border": "#EEEEEE", 165 | "wrapper_background": "#FFFFFF" 166 | }, 167 | "moveMenuLeft": true, 168 | "nav_menu": { 169 | "height": "177px", 170 | "width": "252px" 171 | }, 172 | "navigate_menu": true, 173 | "number_sections": false, 174 | "sideBar": true, 175 | "threshold": 4, 176 | "toc_cell": false, 177 | "toc_section_display": "block", 178 | "toc_window_display": false, 179 | "widenNotebook": false 180 | } 181 | }, 182 | "nbformat": 4, 183 | "nbformat_minor": 4 184 | } 185 | -------------------------------------------------------------------------------- /notebooks/georeferencing/georef.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Example for georeferencing a radar dataset" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": {}, 26 | "outputs": [], 27 | "source": [ 28 | "import wradlib as wrl\n", 29 | "import xarray as xr\n", 30 | "import xradar as xd\n", 31 | "import numpy as np\n", 32 | "import matplotlib.pyplot as plt\n", 33 | "import matplotlib as mpl\n", 34 | "from matplotlib.patches import Rectangle\n", 35 | "import warnings\n", 36 | "\n", 37 | "warnings.filterwarnings(\"ignore\")\n", 38 | "try:\n", 39 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 40 | "except:\n", 41 | " plt.ion()" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "**1st step:** Compute centroid coordinates and vertices of all radar bins in WGS84 (longitude and latitude)." 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "swp = (\n", 58 | " xd.model.create_sweep_dataset(rng=1000)\n", 59 | " .swap_dims(time=\"azimuth\")\n", 60 | " .isel(range=slice(0, 100))\n", 61 | ")\n", 62 | "swp = swp.assign_coords(sweep_mode=\"azimuthal_surveillance\")\n", 63 | "swp = swp.wrl.georef.georeference()\n", 64 | "swp" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "We can now generate the polgon vertices of the radar bins - with **each vertex in lon/lat coordinates**." 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "proj_wgs84 = wrl.georef.epsg_to_osr(4326)\n", 81 | "polygons = swp.wrl.georef.spherical_to_polyvert(crs=proj_wgs84, keep_attrs=True)\n", 82 | "polygons" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "... or we can compute the corresponding centroids of all bins - - with **each centroid in lon/lat coordinates**." 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "centroids = swp.wrl.georef.spherical_to_centroids(crs=proj_wgs84, keep_attrs=True)\n", 99 | "centroids" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "In order to understand how vertices and centroids correspond, we can plot them together." 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": {}, 113 | "outputs": [], 114 | "source": [ 115 | "fig = plt.figure(figsize=(16, 16))\n", 116 | "site = (polygons.longitude.values, polygons.latitude.values)\n", 117 | "\n", 118 | "aspect = (centroids[..., 0].max() - centroids[..., 0].min()) / (\n", 119 | " centroids[..., 1].max() - centroids[..., 1].min()\n", 120 | ")\n", 121 | "ax = fig.add_subplot(121, aspect=aspect)\n", 122 | "polycoll = mpl.collections.PolyCollection(\n", 123 | " polygons.isel(xy=slice(0, 2)), closed=True, facecolors=\"None\", linewidth=0.1\n", 124 | ")\n", 125 | "ax.add_collection(polycoll, autolim=True)\n", 126 | "# ax.plot(centroids[..., 0], centroids[..., 1], 'r+')\n", 127 | "plt.title(\"Zoom in\\n(only possible for interactive plots).\")\n", 128 | "ax.add_patch(\n", 129 | " Rectangle(\n", 130 | " (site[0] + 0.25, site[1] + 0.25),\n", 131 | " 0.2,\n", 132 | " 0.2 / aspect,\n", 133 | " edgecolor=\"red\",\n", 134 | " facecolor=\"None\",\n", 135 | " zorder=3,\n", 136 | " )\n", 137 | ")\n", 138 | "plt.xlim(centroids[..., 0].min(), centroids[..., 0].max())\n", 139 | "plt.ylim(centroids[..., 1].min(), centroids[..., 1].max())\n", 140 | "\n", 141 | "ax = fig.add_subplot(122, aspect=aspect)\n", 142 | "polycoll = mpl.collections.PolyCollection(\n", 143 | " polygons.isel(xy=slice(0, 2)), closed=True, facecolors=\"None\"\n", 144 | ")\n", 145 | "ax.add_collection(polycoll, autolim=True)\n", 146 | "ax.plot(centroids[..., 0], centroids[..., 1], \"r+\")\n", 147 | "plt.title(\"Zoom into red box of left plot\")\n", 148 | "plt.xlim(site[0] + 0.25, site[0] + 0.25 + 0.2)\n", 149 | "plt.ylim(site[1] + 0.25, site[1] + 0.25 + 0.2 / aspect)" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "**2nd step:** Reproject the centroid coordinates to Gauss-Krueger Zone 3 (i.e. EPSG-Code 31467)." 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": null, 162 | "metadata": {}, 163 | "outputs": [], 164 | "source": [ 165 | "centroids_xyz = centroids.assign_coords(xyz=[\"x\", \"y\", \"z\"]).to_dataset(\"xyz\")\n", 166 | "centroids_xyz" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": null, 172 | "metadata": {}, 173 | "outputs": [], 174 | "source": [ 175 | "proj_gk3 = wrl.georef.epsg_to_osr(31467)\n", 176 | "centroids_xyz = centroids_xyz.wrl.georef.reproject(trg_crs=proj_gk3)\n", 177 | "centroids_xyz" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": null, 183 | "metadata": {}, 184 | "outputs": [], 185 | "source": [] 186 | } 187 | ], 188 | "metadata": { 189 | "language_info": { 190 | "codemirror_mode": { 191 | "name": "ipython", 192 | "version": 3 193 | }, 194 | "file_extension": ".py", 195 | "mimetype": "text/x-python", 196 | "name": "python", 197 | "nbconvert_exporter": "python", 198 | "pygments_lexer": "ipython3", 199 | "version": "3.11.0" 200 | }, 201 | "toc": { 202 | "colors": { 203 | "hover_highlight": "#DAA520", 204 | "navigate_num": "#000000", 205 | "navigate_text": "#333333", 206 | "running_highlight": "#FF0000", 207 | "selected_highlight": "#FFD700", 208 | "sidebar_border": "#EEEEEE", 209 | "wrapper_background": "#FFFFFF" 210 | }, 211 | "moveMenuLeft": true, 212 | "nav_menu": { 213 | "height": "47px", 214 | "width": "252px" 215 | }, 216 | "navigate_menu": true, 217 | "number_sections": false, 218 | "sideBar": true, 219 | "threshold": 4, 220 | "toc_cell": false, 221 | "toc_section_display": "block", 222 | "toc_window_display": false, 223 | "widenNotebook": false 224 | } 225 | }, 226 | "nbformat": 4, 227 | "nbformat_minor": 4 228 | } 229 | -------------------------------------------------------------------------------- /notebooks/overview.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Tutorials and Examples\n", 20 | "\n", 21 | "This section provides a collection of example code snippets to make users familiar with $\\omega radlib$ and weather radar data processing." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": { 27 | "nbsphinx-toctree": { 28 | "hidden": true, 29 | "maxdepth": 2 30 | } 31 | }, 32 | "source": [ 33 | "- [Python Intro](python/learnpython.ipynb)\n", 34 | "- [wradlib Basics](basics/basics.ipynb)\n", 35 | "- [Data Input/Output](fileio.ipynb)\n", 36 | "- [Visualization](plotting.ipynb)\n", 37 | "- [Attenuation Correction](attenuation/attenuation.ipynb)\n", 38 | "- [Beam Blockage](beamblockage/beamblockage.ipynb)\n", 39 | "- [Echo Classification](classify.ipynb)\n", 40 | "- [Georeferencing](georeferencing.ipynb)\n", 41 | "- [Interpolation](interpolation/interpolation.ipynb)\n", 42 | "- [Compositing](compositing.ipynb)\n", 43 | "- [Gauge Adjustment](multisensor/gauge_adjustment.ipynb)\n", 44 | "- [Verification](verification/verification.ipynb)\n", 45 | "- [Zonal Statistics](zonalstats/zonalstats.ipynb)\n", 46 | "- [Recipes](recipes.ipynb)" 47 | ] 48 | } 49 | ], 50 | "metadata": { 51 | "celltoolbar": "Edit Metadata", 52 | "language_info": { 53 | "codemirror_mode": { 54 | "name": "ipython", 55 | "version": 3 56 | }, 57 | "file_extension": ".py", 58 | "mimetype": "text/x-python", 59 | "name": "python", 60 | "nbconvert_exporter": "python", 61 | "pygments_lexer": "ipython3", 62 | "version": "3.13.3" 63 | }, 64 | "toc": { 65 | "colors": { 66 | "hover_highlight": "#DAA520", 67 | "navigate_num": "#000000", 68 | "navigate_text": "#333333", 69 | "running_highlight": "#FF0000", 70 | "selected_highlight": "#FFD700", 71 | "sidebar_border": "#EEEEEE", 72 | "wrapper_background": "#FFFFFF" 73 | }, 74 | "moveMenuLeft": true, 75 | "nav_menu": { 76 | "height": "68px", 77 | "width": "252px" 78 | }, 79 | "navigate_menu": true, 80 | "number_sections": false, 81 | "sideBar": true, 82 | "threshold": 4, 83 | "toc_cell": false, 84 | "toc_section_display": "block", 85 | "toc_window_display": false, 86 | "widenNotebook": false 87 | } 88 | }, 89 | "nbformat": 4, 90 | "nbformat_minor": 4 91 | } 92 | -------------------------------------------------------------------------------- /notebooks/plotting.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Plotting with wradlib" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "This section provides a collection of example code snippets to make users familiar with $\\omega radlib$'s plotting capabilities." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "nbsphinx-toctree": { 33 | "hidden": true, 34 | "maxdepth": 2 35 | } 36 | }, 37 | "source": [ 38 | "## Examples List\n", 39 | "\n", 40 | "- [Plot PPI](visualisation/plot_ppi.ipynb)\n", 41 | "- [Plot RHI](visualisation/plot_rhi.ipynb)\n", 42 | "- [Plot Curvelinear Grids](visualisation/plot_curvelinear_grids.ipynb)\n", 43 | "- [Plot geodata](visualisation/gis_overlay.ipynb)\n", 44 | "- [Plot geodata with cartopy](visualisation/gis_overlay_cartopy.ipynb)\n", 45 | "- [Plot radar scan strategy](visualisation/plot_scan_strategy.ipynb)" 46 | ] 47 | } 48 | ], 49 | "metadata": { 50 | "celltoolbar": "Edit Metadata", 51 | "language_info": { 52 | "codemirror_mode": { 53 | "name": "ipython", 54 | "version": 3 55 | }, 56 | "file_extension": ".py", 57 | "mimetype": "text/x-python", 58 | "name": "python", 59 | "nbconvert_exporter": "python", 60 | "pygments_lexer": "ipython3", 61 | "version": "3.11.0" 62 | }, 63 | "toc": { 64 | "colors": { 65 | "hover_highlight": "#DAA520", 66 | "navigate_num": "#000000", 67 | "navigate_text": "#333333", 68 | "running_highlight": "#FF0000", 69 | "selected_highlight": "#FFD700", 70 | "sidebar_border": "#EEEEEE", 71 | "wrapper_background": "#FFFFFF" 72 | }, 73 | "moveMenuLeft": true, 74 | "nav_menu": { 75 | "height": "68px", 76 | "width": "252px" 77 | }, 78 | "navigate_menu": true, 79 | "number_sections": false, 80 | "sideBar": true, 81 | "threshold": 4, 82 | "toc_cell": false, 83 | "toc_section_display": "block", 84 | "toc_window_display": false, 85 | "widenNotebook": false 86 | } 87 | }, 88 | "nbformat": 4, 89 | "nbformat_minor": 4 90 | } 91 | -------------------------------------------------------------------------------- /notebooks/python/learnpython.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# An incomplete introduction to Python" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "In order to use $\\omega radlib$, you need to be able to use Python. The notebooks in this section will give you a glimpse of the Python language and important scientific packages, confront you with some Python exercises, and refer you to further online material. In addition, we will address some issues that are relevant to $\\omega radlib$, but do not necessarily address $\\omega radlib$ functionality.\n", 27 | "\n", 28 | "As an introduction to scientific python, **this section is necessarily incomplete**. There are better and more comprehensive courses such as the [SciPy Lecture Notes](https://scipy-lectures.org/index.html) or the [Dive into Python](https://en.wikipedia.org/wiki/Mark_Pilgrim#Dive_into_Python) book. \n", 29 | "\n", 30 | "Mostly, we will assume that you have some basic knowledge about programming, e.g. from other interpreted languages such as [R](https://www.r-project.org/) or Matlab. Otherwise, a fundamental course such as [learnpython.org](https://www.learnpython.org/) might help you more." 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": { 36 | "nbsphinx-toctree": { 37 | "hidden": true, 38 | "maxdepth": 2 39 | } 40 | }, 41 | "source": [ 42 | "## List of Python related articles in this section\n", 43 | "\n", 44 | "- [A quick start to Python](quickstart.ipynb)\n", 45 | "- [Numpy: manipulating numerical data](numpyintro.ipynb)\n", 46 | "- [Visualising data with Matplotlib](mplintro.ipynb)\n", 47 | "- [Dealing with time series](timeseries.ipynb)" 48 | ] 49 | } 50 | ], 51 | "metadata": { 52 | "celltoolbar": "Edit Metadata", 53 | "language_info": { 54 | "codemirror_mode": { 55 | "name": "ipython", 56 | "version": 3 57 | }, 58 | "file_extension": ".py", 59 | "mimetype": "text/x-python", 60 | "name": "python", 61 | "nbconvert_exporter": "python", 62 | "pygments_lexer": "ipython3", 63 | "version": "3.11.0" 64 | }, 65 | "toc": { 66 | "colors": { 67 | "hover_highlight": "#DAA520", 68 | "navigate_num": "#000000", 69 | "navigate_text": "#333333", 70 | "running_highlight": "#FF0000", 71 | "selected_highlight": "#FFD700", 72 | "sidebar_border": "#EEEEEE", 73 | "wrapper_background": "#FFFFFF" 74 | }, 75 | "moveMenuLeft": true, 76 | "nav_menu": { 77 | "height": "65px", 78 | "width": "252px" 79 | }, 80 | "navigate_menu": true, 81 | "number_sections": false, 82 | "sideBar": true, 83 | "threshold": 4, 84 | "toc_cell": false, 85 | "toc_section_display": "block", 86 | "toc_window_display": false, 87 | "widenNotebook": false 88 | } 89 | }, 90 | "nbformat": 4, 91 | "nbformat_minor": 4 92 | } 93 | -------------------------------------------------------------------------------- /notebooks/python/numpyintro.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden", 7 | "slideshow": { 8 | "slide_type": "skip" 9 | } 10 | }, 11 | "source": [ 12 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 13 | "\n", 14 | "Copyright (c) $\\omega radlib$ developers.\n", 15 | "Distributed under the MIT License. See LICENSE.txt for more info." 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "slideshow": { 22 | "slide_type": "slide" 23 | } 24 | }, 25 | "source": [ 26 | "# NumPy: manipulating numerical data" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "slideshow": { 33 | "slide_type": "fragment" 34 | } 35 | }, 36 | "source": [ 37 | "*NumPy* is the key Python package for creating and manipulating (multi-dimensional) numerical arrays. *NumPy* arrays are also the most important data objects in $\\omega radlib$. It has become a convention to import *NumPy* as follows:" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": { 44 | "slideshow": { 45 | "slide_type": "fragment" 46 | } 47 | }, 48 | "outputs": [], 49 | "source": [ 50 | "import numpy as np" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": { 56 | "slideshow": { 57 | "slide_type": "slide" 58 | } 59 | }, 60 | "source": [ 61 | "## Creating and inspecting NumPy arrays" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": { 67 | "slideshow": { 68 | "slide_type": "fragment" 69 | } 70 | }, 71 | "source": [ 72 | "The `ndarray`, a numerical array, is the most important data type in NumPy. " 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": { 79 | "slideshow": { 80 | "slide_type": "fragment" 81 | } 82 | }, 83 | "outputs": [], 84 | "source": [ 85 | "a = np.array([0, 1, 2, 3])\n", 86 | "print(a)\n", 87 | "print(type(a))" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": { 93 | "slideshow": { 94 | "slide_type": "slide" 95 | } 96 | }, 97 | "source": [ 98 | "Inspect the `shape` (i.e. the number and size of the dimensions of an array)." 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": { 105 | "slideshow": { 106 | "slide_type": "fragment" 107 | } 108 | }, 109 | "outputs": [], 110 | "source": [ 111 | "print(a.shape)\n", 112 | "# This creates a 2-dimensional array\n", 113 | "a2 = np.array([[0, 1], [2, 3]])\n", 114 | "print(a2.shape)" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": { 120 | "slideshow": { 121 | "slide_type": "slide" 122 | } 123 | }, 124 | "source": [ 125 | "There are various ways to create arrays: from lists (as above), using convenience functions, or from file." 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": null, 131 | "metadata": { 132 | "slideshow": { 133 | "slide_type": "fragment" 134 | } 135 | }, 136 | "outputs": [], 137 | "source": [ 138 | "# From lists\n", 139 | "a = np.array([0, 1, 2, 3])\n", 140 | "print(\"a looks like:\\n%r\\n\" % a)\n", 141 | "\n", 142 | "# Convenience functions\n", 143 | "b = np.ones(shape=(2, 3))\n", 144 | "print(\"b looks like:\\n%r\\nand has shape %r\\n\" % (b, b.shape))\n", 145 | "\n", 146 | "c = np.zeros(shape=(2, 1))\n", 147 | "print(\"c looks like:\\n%r\\nand has shape %r\\n\" % (c, c.shape))\n", 148 | "\n", 149 | "d = np.arange(2, 10)\n", 150 | "print(\"d looks like:\\n%r\\nand has shape %r\\n\" % (d, d.shape))\n", 151 | "\n", 152 | "e = np.linspace(0, 10, 5)\n", 153 | "print(\"e looks like:\\n%r\\nand has shape %r\\n\" % (e, e.shape))" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": { 159 | "slideshow": { 160 | "slide_type": "slide" 161 | } 162 | }, 163 | "source": [ 164 | "You can change the shape of an array without changing its size." 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": null, 170 | "metadata": { 171 | "slideshow": { 172 | "slide_type": "fragment" 173 | } 174 | }, 175 | "outputs": [], 176 | "source": [ 177 | "a = np.arange(10)\n", 178 | "b = np.reshape(a, (2, 5))\n", 179 | "print(\"Array a has shape %r.\\nArray b has shape %r\" % (a.shape, b.shape))" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": { 185 | "slideshow": { 186 | "slide_type": "slide" 187 | } 188 | }, 189 | "source": [ 190 | "## Indexing and slicing" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "metadata": { 196 | "slideshow": { 197 | "slide_type": "fragment" 198 | } 199 | }, 200 | "source": [ 201 | "You can index an `ndarray` in the same way as a `list`:" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": null, 207 | "metadata": { 208 | "slideshow": { 209 | "slide_type": "fragment" 210 | } 211 | }, 212 | "outputs": [], 213 | "source": [ 214 | "a = np.arange(10)\n", 215 | "print(a)\n", 216 | "print(a[0], a[2], a[-1])" 217 | ] 218 | }, 219 | { 220 | "cell_type": "markdown", 221 | "metadata": { 222 | "slideshow": { 223 | "slide_type": "slide" 224 | } 225 | }, 226 | "source": [ 227 | "Just follow your intuition for indexing multi-dimensional arrays:" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": null, 233 | "metadata": { 234 | "slideshow": { 235 | "slide_type": "fragment" 236 | } 237 | }, 238 | "outputs": [], 239 | "source": [ 240 | "a = np.diag(np.arange(3))\n", 241 | "print(a, end=\"\\n\\n\")\n", 242 | "\n", 243 | "print(\"Second row, second column: %r\\n\" % a[1, 1])\n", 244 | "\n", 245 | "# Setting an array item\n", 246 | "a[2, 1] = 10 # third line, second column\n", 247 | "print(a, end=\"\\n\\n\")\n", 248 | "\n", 249 | "# Acessing a full row\n", 250 | "print(\"Second row:\\n%r\" % a[1])" 251 | ] 252 | }, 253 | { 254 | "cell_type": "markdown", 255 | "metadata": { 256 | "slideshow": { 257 | "slide_type": "slide" 258 | } 259 | }, 260 | "source": [ 261 | "Slicing is just a way to access multiple array items at once:" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": null, 267 | "metadata": { 268 | "slideshow": { 269 | "slide_type": "fragment" 270 | } 271 | }, 272 | "outputs": [], 273 | "source": [ 274 | "a = np.arange(10)\n", 275 | "print(a, end=\"\\n\\n\")\n", 276 | "\n", 277 | "print(\"1st:\", a[2:9])\n", 278 | "print(\"2nd:\", a[2:])\n", 279 | "print(\"3rd:\", a[:5])\n", 280 | "print(\"4th:\", a[2:9:3]) # [start:end:step]\n", 281 | "print(\"5th:\", a[a > 5]) # using a mask" 282 | ] 283 | }, 284 | { 285 | "cell_type": "markdown", 286 | "metadata": { 287 | "slideshow": { 288 | "slide_type": "slide" 289 | } 290 | }, 291 | "source": [ 292 | "Get further info on NumPy arrays [here](https://scipy-lectures.org/intro/numpy/array_object.html#indexing-and-slicing)!" 293 | ] 294 | } 295 | ], 296 | "metadata": { 297 | "celltoolbar": "Slideshow", 298 | "language_info": { 299 | "codemirror_mode": { 300 | "name": "ipython", 301 | "version": 3 302 | }, 303 | "file_extension": ".py", 304 | "mimetype": "text/x-python", 305 | "name": "python", 306 | "nbconvert_exporter": "python", 307 | "pygments_lexer": "ipython3", 308 | "version": "3.11.0" 309 | }, 310 | "livereveal": { 311 | "scroll": true 312 | }, 313 | "toc": { 314 | "colors": { 315 | "hover_highlight": "#DAA520", 316 | "navigate_num": "#000000", 317 | "navigate_text": "#333333", 318 | "running_highlight": "#FF0000", 319 | "selected_highlight": "#FFD700", 320 | "sidebar_border": "#EEEEEE", 321 | "wrapper_background": "#FFFFFF" 322 | }, 323 | "moveMenuLeft": true, 324 | "nav_menu": { 325 | "height": "68px", 326 | "width": "252px" 327 | }, 328 | "navigate_menu": true, 329 | "number_sections": false, 330 | "sideBar": true, 331 | "threshold": 4, 332 | "toc_cell": false, 333 | "toc_section_display": "block", 334 | "toc_window_display": false, 335 | "widenNotebook": false 336 | } 337 | }, 338 | "nbformat": 4, 339 | "nbformat_minor": 1 340 | } 341 | -------------------------------------------------------------------------------- /notebooks/python/timeseries.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Dealing with time series" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "Dealing with radar data typically means implies dealing with time series (of radar records or rain gauge observations). This article gives a brief intro on how to deal with times series and datetimes in Python. " 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## The datetime module\n", 34 | "\n", 35 | "The datetime module provides a number of types to deal with dates, times, and time intervals. " 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "import datetime as dt" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "There are different ways to create datetime objects. " 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "# This is now (system time)\n", 61 | "now = dt.datetime.now()\n", 62 | "# Just using the date\n", 63 | "birth_van_rossum = dt.datetime(1956, 1, 31)\n", 64 | "# Providing both date and time\n", 65 | "first_wradlib_commit = dt.datetime(2011, 10, 26, 11, 54, 58)\n", 66 | "# Or initialising from a string\n", 67 | "erad_2016_begins = dt.datetime.strptime(\"2016-10-09 09:00:00\", \"%Y-%m-%d %H:%M:%S\")" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "You can compute the difference between two datetime objects." 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": null, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "# Age of Guido van Rossum\n", 84 | "age_van_rossum = now - birth_van_rossum\n", 85 | "print(\"This is a %r object.\\n\" % type(age_van_rossum))\n", 86 | "print(\"It looks like this: %r\" % age_van_rossum)\n", 87 | "print(\n", 88 | " \"and consists of\\n\\t%d days,\\n\\t%d seconds,\\n\\tand %d microseconds.\\n\"\n", 89 | " % (age_van_rossum.days, age_van_rossum.seconds, age_van_rossum.microseconds)\n", 90 | ")\n", 91 | "# Age of wradlib\n", 92 | "age_wradlib = now - first_wradlib_commit\n", 93 | "# Time until (or since) beginning of ERAD 2016 OSS Short course\n", 94 | "from_to_erad2016 = now - erad_2016_begins\n", 95 | "\n", 96 | "print(\"Guido van Rossum is %d seconds old.\" % age_van_rossum.total_seconds())\n", 97 | "print(\"wradlib's first commit was %d days ago.\" % age_wradlib.days)\n", 98 | "if from_to_erad2016.total_seconds() < 0:\n", 99 | " print(\n", 100 | " \"The ERAD 2016 OSS Short course will start in %d days.\" % -from_to_erad2016.days\n", 101 | " )\n", 102 | "else:\n", 103 | " print(\n", 104 | " \"The ERAD 2016 OSS Short course took place %d days ago.\" % from_to_erad2016.days\n", 105 | " )" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "Or you can create a `datetime.timedelta` object yourself \n", 113 | "and add/subtract a time interval from/to a `datetime` object.\n", 114 | "You can use any of these keywords: `days, seconds, microseconds, milliseconds, minutes, hours, weeks`,\n", 115 | "but `datetime.timedelta` will always represent the result in `days, seconds, microseconds`." 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [ 124 | "# This is an interval of two minutes\n", 125 | "print(dt.timedelta(minutes=1, seconds=60))\n", 126 | "# And this is, too\n", 127 | "print(dt.timedelta(minutes=2))\n", 128 | "now = dt.datetime.now()\n", 129 | "print(\"This is now: %s\" % now)\n", 130 | "print(\"This is two minutes before: %s\" % (now - dt.timedelta(minutes=2)))" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "The default string format of a `datetime` object corresponds to the [isoformat](https://en.wikipedia.org/wiki/ISO_8601). Using the `strftime` function, however, you can control string formatting yourself. The following example shows this feature together with other features we have learned before. The idea is to loop over time and generate corresponding string representations. We also store the `datetime` objects in a list." 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": null, 143 | "metadata": {}, 144 | "outputs": [], 145 | "source": [ 146 | "start = dt.datetime(2016, 10, 9)\n", 147 | "end = dt.datetime(2016, 10, 14)\n", 148 | "interval = dt.timedelta(days=1)\n", 149 | "dtimes = []\n", 150 | "print(\"These are the ERAD 2016 conference days (incl. short courses):\")\n", 151 | "while start <= end:\n", 152 | " print(start.strftime(\"\\t%A, %d. %B %Y\"))\n", 153 | " dtimes.append(start)\n", 154 | " start += interval" 155 | ] 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "metadata": {}, 160 | "source": [ 161 | "[matplotlib](../python/mplintro.ipynb) generally understands `datetime` objects and tries to make sense of them in plots." 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": null, 167 | "metadata": {}, 168 | "outputs": [], 169 | "source": [ 170 | "# Instead of %matplotlib inline\n", 171 | "import matplotlib.pyplot as plt\n", 172 | "\n", 173 | "try:\n", 174 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 175 | "except:\n", 176 | " plt.ion()\n", 177 | "import numpy as np" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": null, 183 | "metadata": {}, 184 | "outputs": [], 185 | "source": [ 186 | "# Create some dummy data\n", 187 | "level = np.linspace(100, 0, len(dtimes))\n", 188 | "\n", 189 | "# And add a time series plot\n", 190 | "fig = plt.figure(figsize=(10, 5))\n", 191 | "ax = fig.add_subplot(111)\n", 192 | "plt.plot(dtimes, level, \"bo\", linestyle=\"dashed\")\n", 193 | "plt.xlabel(\"Day of the conference\", fontsize=15)\n", 194 | "plt.ylabel(\"Relative attentiveness (%)\", fontsize=15)\n", 195 | "plt.title(\n", 196 | " \"Development of participants' attentiveness during the conference\", fontsize=15\n", 197 | ")\n", 198 | "plt.tick_params(labelsize=12)" 199 | ] 200 | } 201 | ], 202 | "metadata": { 203 | "celltoolbar": "Edit Metadata", 204 | "language_info": { 205 | "codemirror_mode": { 206 | "name": "ipython", 207 | "version": 3 208 | }, 209 | "file_extension": ".py", 210 | "mimetype": "text/x-python", 211 | "name": "python", 212 | "nbconvert_exporter": "python", 213 | "pygments_lexer": "ipython3", 214 | "version": "3.11.0" 215 | }, 216 | "toc": { 217 | "colors": { 218 | "hover_highlight": "#DAA520", 219 | "navigate_num": "#000000", 220 | "navigate_text": "#333333", 221 | "running_highlight": "#FF0000", 222 | "selected_highlight": "#FFD700", 223 | "sidebar_border": "#EEEEEE", 224 | "wrapper_background": "#FFFFFF" 225 | }, 226 | "moveMenuLeft": true, 227 | "nav_menu": { 228 | "height": "49px", 229 | "width": "252px" 230 | }, 231 | "navigate_menu": true, 232 | "number_sections": false, 233 | "sideBar": true, 234 | "threshold": 4, 235 | "toc_cell": false, 236 | "toc_section_display": "block", 237 | "toc_window_display": false, 238 | "widenNotebook": false 239 | } 240 | }, 241 | "nbformat": 4, 242 | "nbformat_minor": 1 243 | } 244 | -------------------------------------------------------------------------------- /notebooks/recipes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Recipes" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": { 25 | "nbsphinx-toctree": { 26 | "hidden": true, 27 | "maxdepth": 2 28 | } 29 | }, 30 | "source": [ 31 | "- [Recipe1: Clutter and attenuation correction plus composition for two DWD radars](workflow/recipe1.ipynb)\n", 32 | "- [Recipe2: Reading and visualizing an ODIM_H5 polar volume](workflow/recipe2.ipynb)\n", 33 | "- [Recipe3: Match spaceborn SR (GPM/TRRM) with ground radars GR](workflow/recipe3.ipynb)\n", 34 | "- [Recipe4: Load ODIM_H5 Volume data from DWD Open Data](workflow/recipe4.ipynb)\n", 35 | "- [Recipe5: Zonalstats on Cartesian Grid](workflow/recipe5.ipynb)\n", 36 | "- [Recipe6: Zonalstats on Polar Grid](workflow/recipe6.ipynb)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "This recipe section provides a collection of code snippets for exemplary $\\omega radlib$ applications. Compared to the other notebooks, the level of documentation is a bit lower. For each recipe, we provide a short summary and a link to the example code.\n", 44 | "\n", 45 | "Please feel to send us your recipes so we can include them on this page. Please open an issue at the [wradlib-notebooks github issue tracker](https://github.com/wradlib/wradlib-notebooks) containing:\n", 46 | "\n", 47 | "- *optional*: name and affiliation\n", 48 | "\n", 49 | "- a suggested title of the recipe\n", 50 | "\n", 51 | "- a short decription of the recipe (max. 100 words)\n", 52 | "\n", 53 | "- the recipe code (please add comments within the code!)\n", 54 | "\n", 55 | "- *optional*: the data needed to run the code (or a hyperlink to the data)\n", 56 | "\n", 57 | "- *optional*: some test output of the recipe (e.g. an image file)\n" 58 | ] 59 | } 60 | ], 61 | "metadata": { 62 | "celltoolbar": "Edit Metadata", 63 | "language_info": { 64 | "codemirror_mode": { 65 | "name": "ipython", 66 | "version": 3 67 | }, 68 | "file_extension": ".py", 69 | "mimetype": "text/x-python", 70 | "name": "python", 71 | "nbconvert_exporter": "python", 72 | "pygments_lexer": "ipython3", 73 | "version": "3.11.0" 74 | }, 75 | "toc": { 76 | "colors": { 77 | "hover_highlight": "#DAA520", 78 | "navigate_num": "#000000", 79 | "navigate_text": "#333333", 80 | "running_highlight": "#FF0000", 81 | "selected_highlight": "#FFD700", 82 | "sidebar_border": "#EEEEEE", 83 | "wrapper_background": "#FFFFFF" 84 | }, 85 | "moveMenuLeft": true, 86 | "nav_menu": { 87 | "height": "49px", 88 | "width": "252px" 89 | }, 90 | "navigate_menu": true, 91 | "number_sections": false, 92 | "sideBar": true, 93 | "threshold": 4, 94 | "toc_cell": false, 95 | "toc_section_display": "block", 96 | "toc_window_display": false, 97 | "widenNotebook": false 98 | } 99 | }, 100 | "nbformat": 4, 101 | "nbformat_minor": 4 102 | } 103 | -------------------------------------------------------------------------------- /notebooks/visualisation/plot_rhi.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden", 7 | "slideshow": { 8 | "slide_type": "skip" 9 | } 10 | }, 11 | "source": [ 12 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 13 | "\n", 14 | "Copyright (c) $\\omega radlib$ developers.\n", 15 | "Distributed under the MIT License. See LICENSE.txt for more info." 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "slideshow": { 22 | "slide_type": "slide" 23 | } 24 | }, 25 | "source": [ 26 | "# Quick-view a RHI sweep in polar or cartesian reference systems" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "slideshow": { 34 | "slide_type": "slide" 35 | } 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "import numpy as np\n", 40 | "import matplotlib.pyplot as plt\n", 41 | "import wradlib as wrl\n", 42 | "import wradlib_data\n", 43 | "import warnings\n", 44 | "\n", 45 | "warnings.filterwarnings(\"ignore\")\n", 46 | "try:\n", 47 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 48 | "except:\n", 49 | " plt.ion()" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": { 55 | "slideshow": { 56 | "slide_type": "slide" 57 | } 58 | }, 59 | "source": [ 60 | "## Read a RHI polar data set from University Bonn XBand radar" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": { 67 | "slideshow": { 68 | "slide_type": "fragment" 69 | } 70 | }, 71 | "outputs": [], 72 | "source": [ 73 | "filename = wradlib_data.DATASETS.fetch(\"hdf5/2014-06-09--185000.rhi.mvol\")\n", 74 | "data1, metadata = wrl.io.read_gamic_hdf5(filename)\n", 75 | "img = data1[\"SCAN0\"][\"ZH\"][\"data\"]\n", 76 | "# mask data array for better presentation\n", 77 | "mask_ind = np.where(img <= np.nanmin(img))\n", 78 | "img[mask_ind] = np.nan\n", 79 | "img = np.ma.array(img, mask=np.isnan(img))\n", 80 | "\n", 81 | "r = metadata[\"SCAN0\"][\"r\"]\n", 82 | "th = metadata[\"SCAN0\"][\"el\"]\n", 83 | "print(th.shape)\n", 84 | "az = metadata[\"SCAN0\"][\"az\"]\n", 85 | "site = (\n", 86 | " metadata[\"VOL\"][\"Longitude\"],\n", 87 | " metadata[\"VOL\"][\"Latitude\"],\n", 88 | " metadata[\"VOL\"][\"Height\"],\n", 89 | ")\n", 90 | "img = wrl.georef.create_xarray_dataarray(\n", 91 | " img, r=r, phi=az, theta=th, site=site, dim0=\"elevation\", sweep_mode=\"rhi\"\n", 92 | ")\n", 93 | "img" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": { 99 | "slideshow": { 100 | "slide_type": "fragment" 101 | } 102 | }, 103 | "source": [ 104 | "Inspect the data set a little" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": null, 110 | "metadata": { 111 | "slideshow": { 112 | "slide_type": "fragment" 113 | } 114 | }, 115 | "outputs": [], 116 | "source": [ 117 | "print(\"Shape of polar array: %r\\n\" % (img.shape,))\n", 118 | "print(\"Some meta data of the RHI file:\")\n", 119 | "print(\"\\tdatetime: %r\" % (metadata[\"SCAN0\"][\"Time\"],))" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": { 125 | "slideshow": { 126 | "slide_type": "slide" 127 | } 128 | }, 129 | "source": [ 130 | "## The simplest way to plot this dataset" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": null, 136 | "metadata": { 137 | "slideshow": { 138 | "slide_type": "fragment" 139 | } 140 | }, 141 | "outputs": [], 142 | "source": [ 143 | "img = img.wrl.georef.georeference()\n", 144 | "pm = img.wrl.vis.plot()\n", 145 | "txt = plt.title(\"Simple RHI - Rays/Bins\")\n", 146 | "# plt.gca().set_xlim(0,100000)\n", 147 | "# plt.gca().set_ylim(0,100000)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "pm = img.wrl.vis.plot()\n", 157 | "plt.gca().set_ylim(0, 15000)\n", 158 | "txt = plt.title(\"Simple RHI - Rays/Bins - with ylimits\")" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": null, 164 | "metadata": {}, 165 | "outputs": [], 166 | "source": [ 167 | "pm = img.wrl.vis.plot(crs=\"cg\")\n", 168 | "plt.gca().set_title(\"Curvelineart Grid RHI\", y=1.0, pad=20)" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": { 174 | "slideshow": { 175 | "slide_type": "slide" 176 | } 177 | }, 178 | "source": [ 179 | "## More decorations and annotations" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": { 185 | "slideshow": { 186 | "slide_type": "fragment" 187 | } 188 | }, 189 | "source": [ 190 | "You can annotate these plots by using standard matplotlib methods." 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": null, 196 | "metadata": { 197 | "slideshow": { 198 | "slide_type": "fragment" 199 | } 200 | }, 201 | "outputs": [], 202 | "source": [ 203 | "pm = img.wrl.vis.plot()\n", 204 | "ax = plt.gca()\n", 205 | "ylabel = ax.set_xlabel(\"Ground Range [m]\")\n", 206 | "ylabel = ax.set_ylabel(\"Height [m]\")\n", 207 | "title = ax.set_title(\"RHI manipulations/colorbar\", y=1, pad=20)\n", 208 | "# you can now also zoom - either programmatically or interactively\n", 209 | "xlim = ax.set_xlim(25000, 40000)\n", 210 | "ylim = ax.set_ylim(0, 15000)\n", 211 | "# as the function returns the axes- and 'mappable'-objects colorbar needs, adding a colorbar is easy\n", 212 | "cb = plt.colorbar(pm, ax=ax)" 213 | ] 214 | } 215 | ], 216 | "metadata": { 217 | "celltoolbar": "Slideshow", 218 | "language_info": { 219 | "codemirror_mode": { 220 | "name": "ipython", 221 | "version": 3 222 | }, 223 | "file_extension": ".py", 224 | "mimetype": "text/x-python", 225 | "name": "python", 226 | "nbconvert_exporter": "python", 227 | "pygments_lexer": "ipython3", 228 | "version": "3.11.0" 229 | }, 230 | "livereveal": { 231 | "scroll": true 232 | }, 233 | "toc": { 234 | "colors": { 235 | "hover_highlight": "#DAA520", 236 | "navigate_num": "#000000", 237 | "navigate_text": "#333333", 238 | "running_highlight": "#FF0000", 239 | "selected_highlight": "#FFD700", 240 | "sidebar_border": "#EEEEEE", 241 | "wrapper_background": "#FFFFFF" 242 | }, 243 | "moveMenuLeft": true, 244 | "nav_menu": { 245 | "height": "177px", 246 | "width": "252px" 247 | }, 248 | "navigate_menu": true, 249 | "number_sections": false, 250 | "sideBar": true, 251 | "threshold": 4, 252 | "toc_cell": false, 253 | "toc_section_display": "block", 254 | "toc_window_display": false, 255 | "widenNotebook": false 256 | } 257 | }, 258 | "nbformat": 4, 259 | "nbformat_minor": 4 260 | } 261 | -------------------------------------------------------------------------------- /notebooks/workflow/fig2_schwaller_morris_2011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wradlib/wradlib-notebooks/b1f696a0f5f6e83f95a42fb22f50aeb2e319e297/notebooks/workflow/fig2_schwaller_morris_2011.png -------------------------------------------------------------------------------- /notebooks/workflow/fig3_schwaller_morris_2011.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wradlib/wradlib-notebooks/b1f696a0f5f6e83f95a42fb22f50aeb2e319e297/notebooks/workflow/fig3_schwaller_morris_2011.png -------------------------------------------------------------------------------- /notebooks/workflow/recipe2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "nbsphinx": "hidden" 7 | }, 8 | "source": [ 9 | "This notebook is part of the $\\omega radlib$ documentation: https://docs.wradlib.org.\n", 10 | "\n", 11 | "Copyright (c) $\\omega radlib$ developers.\n", 12 | "Distributed under the MIT License. See LICENSE.txt for more info." 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "# Recipe #2: Reading and visualizing an ODIM_H5 polar volume" 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "This recipe shows how extract the polar volume data from an ODIM_H5 hdf5 file (KNMI example file from OPERA), contruct a 3-dimensional Cartesian volume and produce a diagnostic plot. The challenge for this file is that for each elevation angle, the scan strategy is different." 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "nbsphinx": "hidden" 34 | }, 35 | "outputs": [], 36 | "source": [ 37 | "import wradlib as wrl\n", 38 | "import wradlib_data\n", 39 | "import xarray as xr\n", 40 | "import xradar as xd\n", 41 | "import matplotlib.pyplot as plt\n", 42 | "import warnings\n", 43 | "\n", 44 | "warnings.filterwarnings(\"ignore\")\n", 45 | "try:\n", 46 | " get_ipython().run_line_magic(\"matplotlib inline\")\n", 47 | "except:\n", 48 | " plt.ion()\n", 49 | "import numpy as np" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": null, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "import datetime as dt\n", 59 | "from osgeo import osr\n", 60 | "\n", 61 | "# read the data (sample file in WRADLIB_DATA)\n", 62 | "filename = wradlib_data.DATASETS.fetch(\"hdf5/knmi_polar_volume.h5\")\n", 63 | "\n", 64 | "raw_dt = xd.io.open_odim_datatree(filename)\n", 65 | "display(raw_dt)" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "proj = osr.SpatialReference()\n", 75 | "proj.ImportFromEPSG(32632)\n", 76 | "for key in list(raw_dt.children):\n", 77 | " if \"sweep\" in key:\n", 78 | " raw_dt[key].ds = raw_dt[key].ds.wrl.georef.georeference(crs=proj)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "swp_list = []\n", 88 | "for key in list(raw_dt.children):\n", 89 | " if \"sweep\" in key:\n", 90 | " ds = raw_dt[key].ds\n", 91 | " xyz = (\n", 92 | " xr.concat(\n", 93 | " [\n", 94 | " ds.coords[\"x\"].reset_coords(drop=True),\n", 95 | " ds.coords[\"y\"].reset_coords(drop=True),\n", 96 | " ds.coords[\"z\"].reset_coords(drop=True),\n", 97 | " ],\n", 98 | " \"xyz\",\n", 99 | " )\n", 100 | " .stack(npoints=(\"azimuth\", \"range\"))\n", 101 | " .transpose(..., \"xyz\")\n", 102 | " )\n", 103 | " swp_list.append(xyz)\n", 104 | "xyz = xr.concat(swp_list, \"npoints\")" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": null, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "swp_list[0]" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "data_list = []\n", 123 | "for key in list(raw_dt.children):\n", 124 | " if \"sweep\" in key:\n", 125 | " ds = raw_dt[key].ds\n", 126 | " data = ds.DBZH.stack(npoints=(\"azimuth\", \"range\"))\n", 127 | " data_list.append(data)\n", 128 | "data = xr.concat(data_list, \"npoints\")" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": null, 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "# generate 3-D Cartesian target grid coordinates\n", 138 | "sitecoords = (raw_dt.longitude.values, raw_dt.latitude.values, raw_dt.altitude.values)\n", 139 | "maxrange = 200000.0\n", 140 | "minelev = 0.1\n", 141 | "maxelev = 25.0\n", 142 | "maxalt = 5000.0\n", 143 | "horiz_res = 2000.0\n", 144 | "vert_res = 250.0\n", 145 | "trgxyz, trgshape = wrl.vpr.make_3d_grid(\n", 146 | " sitecoords, proj, maxrange, maxalt, horiz_res, vert_res\n", 147 | ")" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "# interpolate to Cartesian 3-D volume grid\n", 157 | "tstart = dt.datetime.now()\n", 158 | "gridder = wrl.vpr.CAPPI(\n", 159 | " xyz.values,\n", 160 | " trgxyz,\n", 161 | " # gridshape=trgshape,\n", 162 | " maxrange=maxrange,\n", 163 | " minelev=minelev,\n", 164 | " maxelev=maxelev,\n", 165 | ")\n", 166 | "vol = np.ma.masked_invalid(gridder(data.values).reshape(trgshape))\n", 167 | "print(\"3-D interpolation took:\", dt.datetime.now() - tstart)" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [ 176 | "# diagnostic plot\n", 177 | "trgx = trgxyz[:, 0].reshape(trgshape)[0, 0, :]\n", 178 | "trgy = trgxyz[:, 1].reshape(trgshape)[0, :, 0]\n", 179 | "trgz = trgxyz[:, 2].reshape(trgshape)[:, 0, 0]\n", 180 | "wrl.vis.plot_max_plan_and_vert(\n", 181 | " trgx,\n", 182 | " trgy,\n", 183 | " trgz,\n", 184 | " vol,\n", 185 | " unit=\"dBZH\",\n", 186 | " levels=range(-32, 60),\n", 187 | " cmap=\"turbo\",\n", 188 | ")" 189 | ] 190 | }, 191 | { 192 | "cell_type": "markdown", 193 | "metadata": { 194 | "raw_mimetype": "text/restructuredtext" 195 | }, 196 | "source": [ 197 | "
\n", 198 | "\n", 199 | "**Note**
\n", 200 | "\n", 201 | "In order to run the recipe code, you need to extract the sample data into a directory pointed to by environment variable ``WRADLIB_DATA``.\n", 202 | "
" 203 | ] 204 | } 205 | ], 206 | "metadata": { 207 | "celltoolbar": "Raw Cell Format", 208 | "language_info": { 209 | "codemirror_mode": { 210 | "name": "ipython", 211 | "version": 3 212 | }, 213 | "file_extension": ".py", 214 | "mimetype": "text/x-python", 215 | "name": "python", 216 | "nbconvert_exporter": "python", 217 | "pygments_lexer": "ipython3", 218 | "version": "3.11.0" 219 | }, 220 | "toc": { 221 | "colors": { 222 | "hover_highlight": "#DAA520", 223 | "navigate_num": "#000000", 224 | "navigate_text": "#333333", 225 | "running_highlight": "#FF0000", 226 | "selected_highlight": "#FFD700", 227 | "sidebar_border": "#EEEEEE", 228 | "wrapper_background": "#FFFFFF" 229 | }, 230 | "moveMenuLeft": true, 231 | "nav_menu": { 232 | "height": "47px", 233 | "width": "252px" 234 | }, 235 | "navigate_menu": true, 236 | "number_sections": false, 237 | "sideBar": true, 238 | "threshold": 4, 239 | "toc_cell": false, 240 | "toc_section_display": "block", 241 | "toc_window_display": false, 242 | "widenNotebook": false 243 | } 244 | }, 245 | "nbformat": 4, 246 | "nbformat_minor": 4 247 | } 248 | -------------------------------------------------------------------------------- /scripts/nbstripout_notebooks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) 2016, wradlib developers. 3 | # Distributed under the MIT License. See LICENSE.txt for more info. 4 | 5 | # get notebooks list 6 | notebooks=`find notebooks -path notebooks/*.ipynb_checkpoints -prune -o -name *.ipynb -print` 7 | echo $notebooks 8 | 9 | # convert notebooks to python scripts 10 | for nb in $notebooks; do 11 | nbstripout --extra-keys "metadata.kernelspec cell.metadata.pycharm cell.metadata.tags" $nb 12 | done 13 | -------------------------------------------------------------------------------- /scripts/render_notebooks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) 2016-2018, wradlib developers. 3 | # Distributed under the MIT License. See LICENSE.txt for more info. 4 | 5 | pytest -n auto --verbose --durations=15 --pyargs notebooks 6 | --------------------------------------------------------------------------------