|
| 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 | +} |
0 commit comments