Example #1
0
def test_visualization_plot_precip_field(source, map_kwargs, pass_geodata):
    field, metadata = get_precipitation_fields(0, 0, True, True, None, source)
    field = field.squeeze()
    field, __ = to_rainrate(field, metadata)

    if not pass_geodata:
        metadata = None

    plot_precip_field(field, ptype="intensity", geodata=metadata, map_kwargs=map_kwargs)
Example #2
0
def test_visualization_plot_precip_field(source, map, drawlonlatlines, lw):

    field, metadata = get_precipitation_fields(0, 0, True, True, None, source)
    field = field.squeeze()
    field, __ = to_rainrate(field, metadata)

    ax = plot_precip_field(
        field,
        type="intensity",
        geodata=metadata,
        map=map,
        drawlonlatlines=drawlonlatlines,
        lw=lw,
    )
Example #3
0
timestep = rcparams.data_sources["mch"]["timestep"]
importer_name = rcparams.data_sources["mch"]["importer"]
importer_kwargs = rcparams.data_sources["mch"]["importer_kwargs"]

# read precip field
date = datetime.strptime("201607112100", "%Y%m%d%H%M")
fns = io.find_by_date(date,
                      root,
                      fmt,
                      pattern,
                      ext,
                      timestep,
                      num_prev_files=2)
importer = io.get_method(importer_name, "importer")
precip, __, metadata = io.read_timeseries(fns, importer, **importer_kwargs)
precip, metadata = utils.to_rainrate(precip, metadata)
# precip[np.isnan(precip)] = 0

# motion
motion = dense_lucaskanade(precip)

# parameters
nleadtimes = 6
thr = 1  # mm / h
slope = 1 * timestep  # km / min

# compute probability forecast
extrap_kwargs = dict(allow_nonfinite_values=True)
fct = forecast(precip[-1],
               motion,
               nleadtimes,
Example #4
0
###############################################################################
# Read the input data
# -------------------
#
# As first step, we need to import the precipitation field that we are going
# to use in this example.

# Import the example radar composite
root_path = rcparams.data_sources["mch"]["root_path"]
filename = os.path.join(root_path, "20160711", "AQC161932100V_00005.801.gif")
precip, _, metadata = io.import_mch_gif(
    filename, product="AQC", unit="mm", accutime=5.0
)

# Convert to mm/h
precip, metadata = to_rainrate(precip, metadata)

# Reduce to a square domain
precip, metadata = square_domain(precip, metadata, "crop")

# Nicely print the metadata
pprint(metadata)

# Plot the original rainfall field
plot_precip_field(precip, geodata=metadata)
plt.show()

# Assign the fill value to all the Nans
precip[~np.isfinite(precip)] = metadata["zerovalue"]

###############################################################################
Example #5
0
                                      datasource["fn_ext"],
                                      datasource["timestep"],
                                      num_prev_files=2)

        R, _, metadata = io.readers.read_timeseries(
            fns, importer, **datasource["importer_kwargs"])
        missing_data = False
        for i in range(R.shape[0]):
            if not np.any(np.isfinite(R[i, :, :])):
                print("Skipping, no finite values found for time step %d" %
                      (i + 1))
                missing_data = True
                break

        # convert to mm/h
        R, metadata = utils.to_rainrate(R, metadata)

        # threshold the data
        R[R < 0.1] = 0.0
        metadata["threshold"] = 0.1

        # set NaN equal to zero
        R[~np.isfinite(R)] = 0.0

        # transform to dBR
        R, metadata = utils.dB_transform(R, metadata, zerovalue=zero_value_dbr)

        R_ = R.copy()

        # Remove rain/no-rain discontinuity so that dBR field starts from 0
        if remove_norain_step:
Example #6
0
importer_name = data_source["importer"]
importer_kwargs = data_source["importer_kwargs"]

# Find the input files in the archive. Use history length of 5 timesteps
filenames = io.archive.find_by_date(
    date, root_path, path_fmt, fn_pattern, fn_ext, timestep=5, num_prev_files=5
)

# Read the input time series
importer = io.get_method(importer_name, "importer")
rainrate_field, quality, metadata = io.read_timeseries(
    filenames, importer, **importer_kwargs
)

# Convert to rain rate (mm/h)
rainrate_field, metadata = utils.to_rainrate(rainrate_field, metadata)

################################################################################
# Compute the advection field
# ---------------------------
#
# Apply the Lucas-Kanade method with the parameters given in Pulkkinen et al.
# (2020) to compute the advection field.

fd_kwargs = {}
fd_kwargs["max_corners"] = 1000
fd_kwargs["quality_level"] = 0.01
fd_kwargs["min_distance"] = 2
fd_kwargs["block_size"] = 8

lk_kwargs = {}