.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_manila.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_manila.py: Quantitative Precipitation Estimate (QPE) ==================================================== This example demonstrates how to perform QPE, using raingauge data from Manila. .. GENERATED FROM PYTHON SOURCE LINES 8-26 .. code-block:: default import os import pandas import numpy as np import pandas as pd from pyresample import utils import matplotlib from matplotlib.colors import BoundaryNorm import matplotlib.pyplot as plt import cartopy.crs as ccrs import swirlspy.qpe.rfmap as rfmap from swirlspy.obs.rain import Rain from swirlspy.qpe.utils import locate_file, timestamps_ending THIS_DIR = os.getcwd() .. GENERATED FROM PYTHON SOURCE LINES 27-34 Initialising --------------------------------------- 1. Generate timestamps with timestamps_ending() 2. Locate rainfall data files with locate_file() 3. Define target grid as a pyresample AreaDefinition 4. Construct a Rain object containing rainfall data .. GENERATED FROM PYTHON SOURCE LINES 34-71 .. code-block:: default dir = THIS_DIR+"/../tests/samples" located_files = [] timestamps = timestamps_ending( pd.Timestamp(2018, 8, 11, 00, 40), duration=pd.Timedelta('1 hour'), interval=pd.Timedelta('10 minutes'), exclude_end=False ) for timestamp in timestamps: located_files.append(locate_file(dir, timestamp)) # Writing AreaDefinition of target grid area_id = "WGS84" description = "Plate Carree" proj_id = "WGS84" projection = '+proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees' x_size = 500 y_size = 500 area_extent = ( 119.8, 13.6, 122.0, 16.5 ) area_def = utils.get_area_def( area_id, description, proj_id, projection, x_size, y_size, area_extent ) # Constructing a Rain object using data from the text file rg_object = Rain( located_files, proj="Plate Carree", duration=pd.Timedelta('10 minutes'), NAN=3276.7 ) .. rst-class:: sphx-glr-script-out .. code-block:: pytb Traceback (most recent call last): File "/tmp/build/docs/swirlspy/swirlspy/examples/plot_manila.py", line 59, in area_id, description, proj_id, projection, x_size, y_size, area_extent File "/opt/conda/envs/swirlspy/lib/python3.6/site-packages/pyresample/utils/__init__.py", line 36, in get_area_def return get_area_def(*args, **kwargs) File "/opt/conda/envs/swirlspy/lib/python3.6/site-packages/pyresample/area_config.py", line 375, in get_area_def proj_dict = _get_proj4_args(proj4_args) File "/opt/conda/envs/swirlspy/lib/python3.6/site-packages/pyresample/area_config.py", line 385, in _get_proj4_args return proj4_str_to_dict(str(proj4_args)) File "/opt/conda/envs/swirlspy/lib/python3.6/site-packages/pyresample/utils/proj4.py", line 53, in proj4_str_to_dict crs = CRS(proj4_str) File "/opt/conda/envs/swirlspy/lib/python3.6/site-packages/pyproj/crs/crs.py", line 296, in __init__ super().__init__(projstring) File "pyproj/_crs.pyx", line 2309, in pyproj._crs._CRS.__init__ pyproj.exceptions.CRSError: Invalid projection: +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees +type=crs: (Internal Proj Error: proj_create: Error -7 (unknown unit conversion id)) .. GENERATED FROM PYTHON SOURCE LINES 72-77 Interpolation ------------- Perform RBF interpolation. Interpolated rainfall is returned along with metadata as an xarray.DataArray. .. GENERATED FROM PYTHON SOURCE LINES 77-83 .. code-block:: default # Interpolate into target grid specified by AreaDefinition interpolated_rf = rfmap.rg_interpolate( rg_object, area_def, 'rbf', coord_label=['Longitude', 'Latitude'] ) .. GENERATED FROM PYTHON SOURCE LINES 84-89 Generate rainfall map --------------------- Define the colour scale and format of the reflectivity plots. Generate the image using xarray.DataArray.plot(). .. GENERATED FROM PYTHON SOURCE LINES 89-136 .. code-block:: default # Plotting levels = [ 0, 0.5, 2, 5, 10, 20, 30, 40, 50, 70, 100, 150, 200, 300, 400, 500, 600, 700 ] cmap = matplotlib.colors.ListedColormap([ '#ffffff', '#9bf7f7', '#00ffff', '#00d5cc', '#00bd3d', '#2fd646', '#9de843', '#ffdd41', '#ffac33', '#ff621e', '#d23211', '#9d0063', '#e300ae', '#ff00ce', '#ff57da', '#ff8de6', '#ffe4fd' ]) norm = BoundaryNorm(levels, ncolors=cmap.N, clip=True) plt.figure(figsize=(15, 15)) plt.axis("equal") # AreaDefinition.to_cartopy_crs() does not work for # Geographic Coordinate Systems ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_extent( [area_extent[0], area_extent[2], area_extent[1], area_extent[3]] ) ax.coastlines(resolution='10m') # plot coastlines # Plot data interpolated_rf.plot( cmap=cmap, norm=norm, extend='neither' ) # Show stations rfmap.show_raingauge(rg_object) # Plot title plt.title( "Accumulated rainfall from " f"{rg_object.start_time} to {rg_object.end_time}" ) # timestring start_timestr = rg_object.start_time.strftime("%Y%m%d%H%M") end_timestr = rg_object.end_time.strftime("%Y%m%d%H%M") plt.savefig( os.path.join( THIS_DIR, "../tests/outputs", f"RBF_{start_timestr}_{end_timestr}.png" ) ) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.009 seconds) .. _sphx_glr_download_auto_examples_plot_manila.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_manila.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_manila.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_