diff --git a/examples/precipitation_accumulation_nowcast.py b/examples/precipitation_accumulation_nowcast.py index e69de29..fd78178 100644 --- a/examples/precipitation_accumulation_nowcast.py +++ b/examples/precipitation_accumulation_nowcast.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import os, sys +import pyximport +import copy + +#from pysteps_custom_utils.utils import convert_dbz_to_mm + +pyximport.install() + +from tendo import singleton + +me = singleton.SingleInstance() # will sys.exit(-1) if other instance is running + + +"""Stochastic ensemble precipitation nowcasting + +The script shows how to run a stochastic ensemble of precipitation nowcasts with +pysteps. + +More info: https://pysteps.github.io/ +""" +import datetime +import numpy as np +sys.path.append(os.path.join(os.path.dirname(__file__), '../')) + +import pysteps as stp +import config as cfg + +# List of case studies that can be used in this tutorial + +#+-------+--------------+-------------+----------------------------------------+ +#| event | start_time | data_source | description | +#+=======+==============+=============+========================================+ +#| 01 | 201701311030 | mch | orographic precipitation | +#+-------+--------------+-------------+----------------------------------------+ +#| 02 | 201505151630 | mch | non-stationary field, apparent rotation| +#+-------+--------------+------------------------------------------------------+ +#| 03 | 201609281530 | fmi | stratiform rain band | +#+-------+--------------+-------------+----------------------------------------+ +#| 04 | 201705091130 | fmi | widespread convective activity | +#+-------+--------------+-------------+----------------------------------------+ +#| 05 | 201806161100 | bom | bom example data | +#+-------+--------------+-------------+----------------------------------------+ + +# Set parameters for this tutorial +data_source="gimet" + +## import data specifications +ds = cfg.get_specifications(data_source) + + +## input data (copy/paste values from table above) +archive_dir=ds.root_path+"/"+max(os.listdir(ds.root_path)) +last_fname=max(os.listdir(archive_dir)) +print(last_fname) +startdate_str=last_fname[-18:-10]+last_fname[-9:-5] + +print(startdate_str) + +## methods +oflow_method = "lucaskanade" # lucaskanade, darts, None + +## forecast parameters +n_prvs_times = 6 # use at least 9 with DARTS +n_leadtimes = 6 # use 6 for one hour extrapolation and 12 for 2 hours extrapolation +r_threshold = 0.1 # rain/no-rain threshold [mm/h] +unit = "mm/h" # mm/h or dBZ +transformation = "dB" # None or dB +adjust_domain = None # None or square +output_time_step = 1 +a = 316.0 +b = 1.5 + +# Read-in the data +print('Read the data...', startdate_str) +startdate = datetime.datetime.strptime(startdate_str, "%Y%m%d%H%M") +# startdate = datetime.datetime(2019, 10, 7, 18, 40) +## import data specifications +ds = cfg.get_specifications(data_source) + +## find radar field filenames +input_files = stp.io.find_by_date(startdate, ds.root_path, ds.path_fmt, ds.fn_pattern, + ds.fn_ext, ds.timestep, n_prvs_times, 0) + +## read radar field files +importer = stp.io.get_method(ds.importer, "importer") +R, _, metadata = stp.io.read_timeseries(input_files, importer, **ds.importer_kwargs) + +# Preprocess the data +# R = convert_dbz_to_mm(R) + +# Prepare input files +print("Prepare the data...") + +## if requested, make sure we work with a square domain +reshaper = stp.utils.get_method(adjust_domain) +R, metadata = reshaper(R, metadata, method="pad") + +## if necessary, convert to rain rates [mm/h] +converter = stp.utils.get_method("mm/h") +R, metadata = converter(R, metadata, a=a, b=b) + +## threshold the data +R[R