Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
R, metadata = converter(R, metadata)
## readjust to initial domain shape
R_fct, _ = reshaper(R_fct, metadata, inverse=True)
R, metadata = reshaper(R, metadata, inverse=True)
## plot the nowcast..
R[Rmask] = np.nan # reapply radar mask
stp.plt.animate(R, nloops=2, timestamps=metadata["timestamps"],
R_fct=R_fct, timestep_min=ds.timestep,
UV=UV,
motion_plot=stp.rcparams.plot.motion_plot,
geodata=metadata,
colorscale=stp.rcparams.plot.colorscale,
plotanimation=True, savefig=False,
path_outputs=stp.rcparams.outputs.path_outputs)
# Forecast verification
print("Forecast verification...")
## find the verifying observations
input_files_verif = stp.io.find_by_date(startdate, ds.root_path, ds.path_fmt, ds.fn_pattern,
ds.fn_ext, ds.timestep, 0, n_lead_times)
## read observations
R_obs, _, metadata_obs = stp.io.read_timeseries(input_files_verif, importer,
**ds.importer_kwargs)
R_obs = R_obs[1:,:,:]
metadata_obs["timestamps"] = metadata_obs["timestamps"][1:]
## if necessary, convert to rain rates [mm/h]
R_obs, metadata_obs = converter(R_obs, metadata_obs)
## if necessary, transform back all data
R_fct, _ = transformer(R_fct, metadata, inverse=True)
R, metadata = transformer(R, metadata, inverse=True)
## convert all data to mm/h
converter = stp.utils.get_method("mm/h")
R_fct, _ = converter(R_fct, metadata)
R, metadata = converter(R, metadata)
## plot the nowcast...
R[Rmask] = np.nan # reapply radar mask
stp.plt.animate(R, nloops=2, timestamps=metadata["timestamps"],
R_fct=R_fct, timestep_min=ds.timestep,
UV=UV,
motion_plot=stp.rcparams.plot.motion_plot,
geodata=metadata,
colorscale=stp.rcparams.plot.colorscale,
plotanimation=True, savefig=False,
path_outputs=stp.rcparams.outputs.path_outputs)
# Forecast verification
print("Forecast verification...")
## find the verifying observations
input_files_verif = stp.io.find_by_date(startdate, ds.root_path, ds.path_fmt, ds.fn_pattern,
ds.fn_ext, ds.timestep, 0, n_lead_times)
## read observations
R_obs, _, metadata_obs = stp.io.read_timeseries(input_files_verif, importer, **ds.importer_kwargs)
R_obs = R_obs[1:,:,:]
import pysteps as sp
import datetime as dt
import matplotlib.pyplot as pl
import numpy as np
import os
###############################################################################
# How to use xarray with pysteps
# ------------------------------
#
# First, we will show how a netcdf file is currenty imported in the pysteps
# workflow and how this can be done using xarray.
# The path to an example BOM netcdf file
root_path = sp.rcparams.data_sources["bom"]["root_path"]
filename = os.path.join(
root_path, "prcp-cscn/2/2018/06/16/2_20180616_150000.prcp-cscn.nc"
)
###############################################################################
# pysteps original
# ~~~~~~~~~~~~~~~~
# Read data
R, __, metadata = sp.io.import_bom_rf3(filename)
metadata
# Visualization
sp.visualization.plot_precip_field(
R,
map=None,# "cartopy",
###############################################################################
# Read the radar input images
# ---------------------------
#
# First thing, the sequence of radar composites is imported, converted and
# transformed into units of dBR.
date = datetime.strptime("201609281600", "%Y%m%d%H%M")
data_source = "fmi"
n_leadtimes = 12
# Load data source config
root_path = rcparams.data_sources[data_source]["root_path"]
path_fmt = rcparams.data_sources[data_source]["path_fmt"]
fn_pattern = rcparams.data_sources[data_source]["fn_pattern"]
fn_ext = rcparams.data_sources[data_source]["fn_ext"]
importer_name = rcparams.data_sources[data_source]["importer"]
importer_kwargs = rcparams.data_sources[data_source]["importer_kwargs"]
timestep = rcparams.data_sources[data_source]["timestep"]
# Find the input files from the archive
fns = io.archive.find_by_date(
date, root_path, path_fmt, fn_pattern, fn_ext, timestep, num_prev_files=2
)
# Read the radar composites
importer = io.get_method(importer_name, "importer")
Z, _, metadata = io.read_timeseries(fns, importer, **importer_kwargs)
# Convert to rain rate using the finnish Z-R relationship
R, metadata = conversion.to_rainrate(Z, metadata, 223.0, 1.53)
from pysteps import io, motion, nowcasts, rcparams, verification
from pysteps.utils import conversion, transformation
from pysteps.visualization import plot_precip_field, quiver
################################################################################
# Read the radar input images
# ---------------------------
#
# First, we will import the sequence of radar composites.
# You need the pysteps-data archive downloaded and the pystepsrc file
# configured with the data_source paths pointing to data folders.
# Selected case
date = datetime.strptime("201607112100", "%Y%m%d%H%M")
data_source = rcparams.data_sources["mch"]
###############################################################################
# Load the data from the archive
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
root_path = data_source["root_path"]
path_fmt = data_source["path_fmt"]
fn_pattern = data_source["fn_pattern"]
fn_ext = data_source["fn_ext"]
importer_name = data_source["importer"]
importer_kwargs = data_source["importer_kwargs"]
timestep = data_source["timestep"]
# Find the two input files from the archive
fns = io.archive.find_by_date(
date, root_path, path_fmt, fn_pattern, fn_ext, timestep=5, num_prev_files=1
# Read precipitation field
# ------------------------
#
# First thing, the sequence of Swiss radar composites is imported, converted and
# transformed into units of dBR.
date = datetime.strptime("201607112100", "%Y%m%d%H%M")
data_source = "mch"
# Load data source config
root_path = rcparams.data_sources[data_source]["root_path"]
path_fmt = rcparams.data_sources[data_source]["path_fmt"]
fn_pattern = rcparams.data_sources[data_source]["fn_pattern"]
fn_ext = rcparams.data_sources[data_source]["fn_ext"]
importer_name = rcparams.data_sources[data_source]["importer"]
importer_kwargs = rcparams.data_sources[data_source]["importer_kwargs"]
timestep = rcparams.data_sources[data_source]["timestep"]
# Find the radar files in the archive
fns = io.find_by_date(
date, root_path, path_fmt, fn_pattern, fn_ext, timestep, num_prev_files=2
)
# Read the data from the archive
importer = io.get_method(importer_name, "importer")
R, _, metadata = io.read_timeseries(fns, importer, **importer_kwargs)
# Convert to rain rate
R, metadata = conversion.to_rainrate(R, metadata)
# Upscale data to 2 km to limit memory usage
R, metadata = dimension.aggregate_fields_space(R, metadata, 2000)
from pysteps import motion, io, rcparams
from pysteps.motion.vet import morph
from pysteps.visualization import plot_precip_field, quiver
################################################################################
# Load the reference precipitation data
# -------------------------------------
#
# First, we will import a radar composite from the archive.
# You need the pysteps-data archive downloaded and the pystepsrc file
# configured with the data_source paths pointing to data folders.
# Selected case
date = datetime.strptime("201505151630", "%Y%m%d%H%M")
data_source = rcparams.data_sources["mch"]
###############################################################################
# Load the data from the archive
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
root_path = data_source["root_path"]
path_fmt = data_source["path_fmt"]
fn_pattern = data_source["fn_pattern"]
fn_ext = data_source["fn_ext"]
importer_name = data_source["importer"]
importer_kwargs = data_source["importer_kwargs"]
# Find the reference field in the archive
fns = io.archive.find_by_date(date, root_path, path_fmt, fn_pattern, fn_ext,
timestep=5, num_prev_files=0)