Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
points : array_like
Array of shape (p, 2) indicating the pixel coordinates of *p* detected
corners.
References
----------
Jianbo Shi and Carlo Tomasi. Good features to track. In Computer Vision and
Pattern Recognition, 1994. Proceedings CVPR'94., 1994 IEEE Computer Society
Conference on, pages 593–600. IEEE, 1994.
"""
if not CV2_IMPORTED:
raise MissingOptionalDependency(
"opencv package is required for the goodFeaturesToTrack() "
"routine but it is not installed"
)
input_image = np.copy(input_image)
if input_image.ndim != 2:
raise ValueError("input_image must be a two-dimensional array")
# masked array
if not isinstance(input_image, MaskedArray):
input_image = np.ma.masked_invalid(input_image)
np.ma.set_fill_value(input_image, input_image.min())
# buffer the quality mask to ensure that no vectors are computed nearby
Allow incremental writing of datasets into the netCDF file.\n
The available options are: 'timestep' = write a forecast or a forecast
ensemble for a given time step; 'member' = write a forecast sequence
for a given ensemble member. If set to None, incremental writing is
disabled.
Returns
-------
exporter : dict
The return value is a dictionary containing an exporter object. This c
an be used with :py:func:`pysteps.io.exporters.export_forecast_dataset`
to write datasets into the given file format.
"""
if not netcdf4_imported:
raise MissingOptionalDependency(
"netCDF4 package is required for netcdf "
"exporters but it is not installed")
if not pyproj_imported:
raise MissingOptionalDependency(
"pyproj package is required for netcdf "
"exporters but it is not installed")
if incremental not in [None, "timestep", "member"]:
raise ValueError("unknown option %s: incremental must be 'timestep' or 'member'" % incremental)
if incremental == "timestep":
n_timesteps = None
elif incremental == "member":
n_ens_members = None
elif incremental is not None:
+------+----------------------------+
unit : string
the physical unit of the data: 'mm/h', 'mm' or 'dBZ'
accutime : float
the accumulation time in minutes of the data
Returns
-------
out : tuple
A three-element tuple containing the precipitation field in mm/h imported
from a MeteoSwiss gif file and the associated quality field and metadata.
The quality field is currently set to None.
"""
if not metranet_imported:
raise MissingOptionalDependency(
"metranet package needed for importing MeteoSwiss "
"radar composites but it is not installed")
product = kwargs.get("product", "AQC")
unit = kwargs.get("unit", "mm")
accutime = kwargs.get("accutime", 5.)
ret = metranet.read_file(filename, physic_value=True, verbose=False)
R = ret.data
geodata = _import_mch_geodata()
# read metranet
metadata = geodata
metadata["institution"] = "MeteoSwiss"
metadata["accutime"] = accutime
Whether to plot longitudes and latitudes.
scale : {'10m', '50m', '110m'}
The scale (resolution) of the map. The available options are '10m',
'50m', and '110m'.
lw : float
Line width.
subplot : scalars (nrows, ncols, index)
Subplot dimensions (n_rows, n_cols) and subplot number (index).
Returns
-------
ax : axes
Cartopy axes. Compatible with matplotlib.
"""
if not cartopy_imported:
raise MissingOptionalDependency(
"map='cartopy' option passed to plot_map_cartopy function"
"but the cartopy package is not installed")
if isinstance(subplot, gridspec.SubplotSpec):
ax = plt.subplot(subplot, projection=crs)
else:
ax = plt.subplot(subplot[0], subplot[1], subplot[2], projection=crs)
ax.add_feature(cfeature.NaturalEarthFeature("physical", "ocean", scale = "50m" if scale is "10m" else scale,
edgecolor="none", facecolor=np.array([0.59375, 0.71484375, 0.8828125])), zorder=0)
ax.add_feature(cfeature.NaturalEarthFeature("physical", "land",
scale=scale, edgecolor="none", facecolor=np.array([0.9375, 0.9375, 0.859375])), zorder=0)
ax.add_feature(cfeature.NaturalEarthFeature("physical", "coastline", scale=scale,
edgecolor="black", facecolor="none", linewidth=lw), zorder=2)
ax.add_feature(cfeature.NaturalEarthFeature("physical", "lakes", scale=scale,
edgecolor="none", facecolor=np.array([0.59375, 0.71484375, 0.8828125])), zorder=0)
lakecolor : scalars (r, g, b)
Lakecolor color.
rivercolor : scalars (r, g, b)
Rivercolor color.
mapboundarycolor : scalars (r, g, b)
Mapboundarycolor color.
lw : float
Line width.
Returns
-------
ax : axes
Basemap axes.
"""
if not basemap_imported:
raise MissingOptionalDependency(
"map='basemap' option passed to plot_map_basemap function"
"but the basemap package is not installed")
ax = Basemap(**bm_params)
if coastlinecolor is not None:
ax.drawcoastlines(color=coastlinecolor, linewidth=lw, zorder=0.1)
if countrycolor is not None:
ax.drawcountries(color=countrycolor, linewidth=lw, zorder=0.2)
if rivercolor is not None:
ax.drawrivers(zorder=0.2, color=rivercolor)
if continentcolor is not None:
ax.fillcontinents(color=continentcolor, lake_color=lakecolor, zorder=0)
if mapboundarycolor is not None:
ax.drawmapboundary(fill_color=mapboundarycolor, zorder=-1)
if drawlonlatlines:
Whether to return the coordinates of the projected grid.
The default return_grid=None does not compute the grid,
return_grid='coords' returns the centers of projected grid points,
return_grid='quadmesh' returns the coordinates of the quadrilaterals
(e.g. to be used by pcolormesh).
Returns
-------
geodata : dictionary
Dictionary containing the reprojected geographical information
and optionally the required X_grid and Y_grid. \n
It also includes a fixed boolean attribute regular_grid=False to indicate
that the reprojected grid has no regular spacing.
"""
if not pyproj_imported:
raise MissingOptionalDependency(
"pyproj package is required for reproject_geodata function utility "
"but it is not installed")
geodata = geodata.copy()
s_proj4str = geodata["projection"]
extent = (geodata["x1"], geodata["x2"], geodata["y1"], geodata["y2"])
shape = (int((geodata["y2"]-geodata["y1"])/geodata["ypixelsize"]),
int((geodata["x2"]-geodata["x1"])/geodata["xpixelsize"]))
s_srs = pyproj.Proj(s_proj4str)
t_srs = pyproj.Proj(t_proj4str)
x1 = extent[0]
x2 = extent[1]
y1 = extent[2]
y2 = extent[3]
pysteps.motion.lucaskanade.dense_lucaskanade
References
----------
Bouguet, J.-Y.: Pyramidal implementation of the affine Lucas Kanade
feature tracker description of the algorithm, Intel Corp., 5, 4,
https://doi.org/10.1109/HPDC.2004.1323531, 2001
Lucas, B. D. and Kanade, T.: An iterative image registration technique with
an application to stereo vision, in: Proceedings of the 1981 DARPA Imaging
Understanding Workshop, pp. 121–130, 1981.
"""
if not CV2_IMPORTED:
raise MissingOptionalDependency(
"opencv package is required for the calcOpticalFlowPyrLK() "
"routine but it is not installed"
)
prvs_img = np.copy(prvs_image)
next_img = np.copy(next_image)
p0 = np.copy(points)
if ~isinstance(prvs_img, MaskedArray):
prvs_img = np.ma.masked_invalid(prvs_img)
np.ma.set_fill_value(prvs_img, prvs_img.min())
if ~isinstance(next_img, MaskedArray):
next_img = np.ma.masked_invalid(next_img)
np.ma.set_fill_value(next_img, next_img.min())
Parameters
----------
filename : str
Name of the file to import.
Returns
-------
out : tuple
A three-element tuple containing the rainfall field in mm/h imported
from the Bureau RF3 netcdf, the quality field and the metadata. The
quality field is currently set to None.
"""
if not netcdf4_imported:
raise MissingOptionalDependency(
"netCDF4 package is required to import BoM Rainfields3 products "
"but it is not installed")
R = _import_bom_rf3_data(filename)
geodata = _import_bom_rf3_geodata(filename)
metadata = geodata
# TODO(import_bom_rf3): Add missing georeferencing data.
metadata["transform"] = None
metadata["zerovalue"] = np.nanmin(R)
if np.any(np.isfinite(R)):
metadata["threshold"] = np.nanmin(R[R > np.nanmin(R)])
else:
metadata["threshold"] = np.nan
Parameters
----------
filename : str
Name of the file to import.
Returns
-------
out : tuple
A three-element tuple containing the precipitation field, the associated
quality field and metadata. The quality field is currently set to None.
"""
if not GDAL_IMPORTED:
raise MissingOptionalDependency(
"gdal package is required to import "
"FMI's radar reflectivity composite in GeoTIFF format "
"but it is not installed"
)
f = gdal.Open(filename, gdalconst.GA_ReadOnly)
rb = f.GetRasterBand(1)
precip = rb.ReadAsArray()
mask = precip == 255
precip = precip.astype(float) * rb.GetScale() + rb.GetOffset()
precip = (precip - 64.0) / 2.0
precip[mask] = np.nan
sr = osr.SpatialReference()
pr = f.GetProjection()
Other Parameters
----------------
gzipped : bool
If True, the input file is treated as a compressed gzip file.
Returns
-------
out : tuple
A three-element tuple containing the reflectivity composite in dBZ
and the associated quality field and metadata. The quality field is
currently set to None.
"""
if not pyproj_imported:
raise MissingOptionalDependency(
"pyproj package is required to import "
"FMI's radar reflectivity composite "
"but it is not installed")
gzipped = kwargs.get("gzipped", False)
pgm_metadata = _import_fmi_pgm_metadata(filename, gzipped=gzipped)
if gzipped == False:
R = imread(filename)
else:
R = imread(gzip.open(filename, 'r'))
geodata = _import_fmi_pgm_geodata(pgm_metadata)
MASK = R == pgm_metadata["missingval"]
R = R.astype(float)