Quantitative Precipitation Forecast (QPF)

This example demonstrates how to perform QPF using radar data

import xarray as xr
import swirlspy.qpf.qpfrover as rov
import numpy as np
import os
from swirlspy.rad.cinrad import read_cinrad
from swirlspy.rad.xrnd import xrnd

import os.path

try:
    THIS_DIR = os.path.dirname(os.path.abspath(__file__))
except NameError:
    import sys
    THIS_DIR = os.path.dirname(os.path.abspath(sys.argv[0]))

Initialising

Read data from files (in this example, the files are in cinrad format) and storing data as xarrays.

file_type = 'cinrad-cband'
valid_time = '201805150624'
xllcenter = 113.35
yllcenter = 23.0
steps = 6
time_step_size = 5
# radar_radius = 256

os.chdir(THIS_DIR + "/../tests/test_qpf")
file_name1 = "Z_RADR_I_Z9290_20180515062400_O_DOR_CB_CAP.bin"
file_name2 = "Z_RADR_I_Z9290_20180515062900_O_DOR_CB_CAP.bin"

# Reading file data, storing as xarray
xarray1 = read_cinrad(file_name1, 113.35, 23.0,
                      480, 480, '201805150624', 5, 'aeqd', 256, 'c-band')
xarray2 = read_cinrad(file_name2, 113.35, 23.0,
                      480, 480, '201805150629', 5, 'aeqd', 256, 'c-band')
qpf_xarray = xrnd(xarray1, xarray2)
os.chdir(THIS_DIR)
Importing wradlib..
......xyz..............
[[[[ 3.49350600e-01  3.57482977e-01 -1.26522724e-02]
   [-3.49350599e-01 -3.57482976e-01  1.26523003e-02]
   [-1.04805179e+00 -1.07244892e+00  3.79569903e-02]
   ...
   [-3.18956663e+02 -3.26381514e+02  1.15637882e+01]
   [-3.19655363e+02 -3.27096478e+02  1.15891465e+01]
   [-3.20354062e+02 -3.27811442e+02  1.16145049e+01]]

  [[ 3.55602194e-01  3.51264858e-01 -1.26522724e-02]
   [-3.55602193e-01 -3.51264856e-01  1.26523003e-02]
   [-1.06680658e+00 -1.05379457e+00  3.79569903e-02]
   ...
   [-3.24664361e+02 -3.20704378e+02  1.15637882e+01]
   [-3.25375563e+02 -3.21406906e+02  1.15891465e+01]
   [-3.26086766e+02 -3.22109434e+02  1.16145049e+01]]

  [[ 3.61478458e-01  3.45214780e-01 -1.26522724e-02]
   [-3.61478457e-01 -3.45214779e-01  1.26523003e-02]
   [-1.08443537e+00 -1.03564433e+00  3.79569903e-02]
   ...
   [-3.30029383e+02 -3.15180665e+02  1.15637882e+01]
   [-3.30752338e+02 -3.15871093e+02  1.15891465e+01]
   [-3.31475293e+02 -3.16561521e+02  1.16145049e+01]]

  ...

  [[ 3.36523249e-01  3.69583581e-01 -1.26522724e-02]
   [-3.36523248e-01 -3.69583580e-01  1.26523003e-02]
   [-1.00956974e+00 -1.10875074e+00  3.79569903e-02]
   ...
   [-3.07245308e+02 -3.37429350e+02  1.15637882e+01]
   [-3.07918352e+02 -3.38168515e+02  1.15891465e+01]
   [-3.08591397e+02 -3.38907681e+02  1.16145049e+01]]

  [[ 3.42990292e-01  3.63589852e-01 -1.26522724e-02]
   [-3.42990291e-01 -3.63589851e-01  1.26523003e-02]
   [-1.02897087e+00 -1.09076955e+00  3.79569903e-02]
   ...
   [-3.13149710e+02 -3.31957083e+02  1.15637882e+01]
   [-3.13835689e+02 -3.32684260e+02  1.15891465e+01]
   [-3.14521667e+02 -3.33411438e+02  1.16145049e+01]]

  [[ 3.49076311e-01  3.57750820e-01 -1.26522724e-02]
   [-3.49076310e-01 -3.57750819e-01  1.26523003e-02]
   [-1.04722893e+00 -1.07325245e+00  3.79569903e-02]
   ...
   [-3.18706238e+02 -3.26626054e+02  1.15637882e+01]
   [-3.19404389e+02 -3.27341554e+02  1.15891465e+01]
   [-3.20102539e+02 -3.28057054e+02  1.16145049e+01]]]]
(1, 366, 460, 3)
...........grid_xy.................
[[-458.34392837 -458.35242191]
 [-456.4301615  -458.35242191]
 [-454.51639464 -458.35242191]
 ...
 [ 454.5228659   458.34163647]
 [ 456.43663277  458.34163647]
 [ 458.35039963  458.34163647]]
(230400, 2)
[[ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 ...
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]]
2018-05-15 06:24:00
Importing wradlib..
......xyz..............
[[[[ 4.76384470e-01 -1.51320049e-01 -1.26522724e-02]
   [-4.76384469e-01  1.51320048e-01  1.26523003e-02]
   [-1.42915340e+00  4.53960143e-01  3.79569903e-02]
   ...
   [-4.34938429e+02  1.38155016e+02  1.15637882e+01]
   [-4.35891195e+02  1.38457656e+02  1.15891465e+01]
   [-4.36843962e+02  1.38760295e+02  1.16145049e+01]]

  [[ 4.73641082e-01 -1.59699861e-01 -1.26522724e-02]
   [-4.73641081e-01  1.59699861e-01  1.26523003e-02]
   [-1.42092324e+00  4.79099582e-01  3.79569903e-02]
   ...
   [-4.32433719e+02  1.45805775e+02  1.15637882e+01]
   [-4.33380999e+02  1.46125174e+02  1.15891465e+01]
   [-4.34328278e+02  1.46444573e+02  1.16145049e+01]]

  [[ 4.70750302e-01 -1.68029977e-01 -1.26522724e-02]
   [-4.70750301e-01  1.68029977e-01  1.26523003e-02]
   [-1.41225090e+00  5.04089929e-01  3.79569903e-02]
   ...
   [-4.29794441e+02  1.53411160e+02  1.15637882e+01]
   [-4.30735939e+02  1.53747220e+02  1.15891465e+01]
   [-4.31677437e+02  1.54083279e+02  1.16145049e+01]]

  ...

  [[ 4.81218935e-01 -1.35160117e-01 -1.26522724e-02]
   [-4.81218933e-01  1.35160117e-01  1.26523003e-02]
   [-1.44365680e+00  4.05480350e-01  3.79569903e-02]
   ...
   [-4.39352289e+02  1.23401019e+02  1.15637882e+01]
   [-4.40314724e+02  1.23671339e+02  1.15891465e+01]
   [-4.41277160e+02  1.23941658e+02  1.16145049e+01]]

  [[ 4.78869874e-01 -1.43260478e-01 -1.26522724e-02]
   [-4.78869872e-01  1.43260477e-01  1.26523003e-02]
   [-1.43660961e+00  4.29781430e-01  3.79569903e-02]
   ...
   [-4.37207599e+02  1.30796638e+02  1.15637882e+01]
   [-4.38165337e+02  1.31083158e+02  1.15891465e+01]
   [-4.39123074e+02  1.31369678e+02  1.16145049e+01]]

  [[ 4.76268269e-01 -1.51685386e-01 -1.26522724e-02]
   [-4.76268267e-01  1.51685386e-01  1.26523003e-02]
   [-1.42880480e+00  4.55056157e-01  3.79569903e-02]
   ...
   [-4.34832337e+02  1.38488569e+02  1.15637882e+01]
   [-4.35784871e+02  1.38791939e+02  1.15891465e+01]
   [-4.36737405e+02  1.39095309e+02  1.16145049e+01]]]]
(1, 366, 460, 3)
...........grid_xy.................
[[-458.35134336 -458.35134336]
 [-456.43757452 -458.35134336]
 [-454.52380569 -458.35134336]
 ...
 [ 454.5163907   458.34163647]
 [ 456.43015953  458.34163647]
 [ 458.34392837  458.34163647]]
(230400, 2)
[[ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 ...
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]
 [ -0.5   0.5   1.5 ... 456.5 457.5 458.5]]
2018-05-15 06:29:00

Extrapolation

Perform rover extrapolation

# Calling rover
motion_u, motion_v, reflectivity = rov.rover_qpf(qpf_xarray, xllcenter,
                                                 yllcenter, valid_time, steps,
                                                 time_step_size, THIS_DIR)
Traceback (most recent call last):
  File "/tmp/build/docs/swirlspy/swirlspy/examples/example_qpf.py", line 57, in <module>
    time_step_size, THIS_DIR)
  File "/tmp/build/docs/swirlspy/swirlspy/qpf/qpfrover.py", line 325, in rover_qpf
    from rover.rover import rover
ImportError: libopencv_core.so.3.4: cannot open shared object file: No such file or directory

Generating radar plots

Here we generate radar colour-images based on forecasted data over the next six timesteps.

rov.rover_map(reflectivity, THIS_DIR)

Total running time of the script: ( 0 minutes 12.922 seconds)

Gallery generated by Sphinx-Gallery