Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_geographic_conversion(self):
self.assertEqual(Dataset(self.cube, kdims=['longitude', 'latitude']).to.image(), Image(self.cube, kdims=['longitude', 'latitude']))
def test_auto_guess_bounds(self):
# Check that the `get_data()` method automatically adds bounds
# when they're missing.
cube = lat_lon_cube()
element = Image(cube.copy())
plot = GeoImagePlot(element)
ranges = {}
style = {'interpolation': None}
plot_args, style, axis_kwargs = plot.get_data(element, ranges, style)
for name in ('latitude', 'longitude'):
cube.coord(name).guess_bounds()
self.assertEqual(plot_args, (cube,))
self.assertEqual(style, {'vmax': 11, 'vmin': 0})
self.assertEqual(axis_kwargs, {})
def test_auto_guess_bounds_not_needed(self):
# Check that the `get_data()` method *doesn't* try to add or
# modify the bounds when they're already present.
cube = lat_lon_cube()
for name in ('latitude', 'longitude'):
coord = cube.coord(name)
coord.guess_bounds()
coord.bounds = coord.bounds + 0.1
element = Image(cube.copy())
plot = GeoImagePlot(element)
ranges = {}
style = {'interpolation': None}
plot_args, style, axis_kwargs = plot.get_data(element, ranges, style)
self.assertEqual(plot_args, (cube,))
self.assertEqual(style, {'vmax': 11, 'vmin': 0})
self.assertEqual(axis_kwargs, {})
fast = param.Boolean(default=False, doc="""
Whether to enable fast reprojection with (much) better
performance but poorer handling in polar regions.""")
width = param.Integer(default=None, doc="""
Width of the reprojectd Image""")
height = param.Integer(default=None, doc="""
Height of the reprojected Image""")
link_inputs = param.Boolean(default=True, doc="""
By default, the link_inputs parameter is set to True so that
when applying project_image, backends that support linked streams
update RangeXY streams on the inputs of the operation.""")
supported_types = [Image, RGB]
def _process(self, img, key=None):
if self.p.fast:
return self._fast_process(img, key)
proj = self.p.projection
x0, x1 = img.range(0, dimension_range=False)
y0, y1 = img.range(1, dimension_range=False)
yn, xn = img.interface.shape(img, gridded=True)[:2]
(px0, py0, px1, py1) = project_extents((x0, y0, x1, y1), img.crs, proj)
# Some bug in cartopy is causing zero values
eps = sys.float_info.epsilon
src_extent = tuple(e+v if e == 0 else e for e, v in
zip((x0, x1, y0, y1), (eps, -eps, eps, -eps)))
tgt_extent = (px0, px1, py0, py1)
def draw_annotation(self, axis, data, crs, opts):
(x, y, text, fontsize,
horizontalalignment, verticalalignment, rotation) = data
opts['fontsize'] = fontsize
if crs:
x, y = axis.projection.transform_point(x, y, src_crs=crs)
return [axis.text(x, y, text,
horizontalalignment=horizontalalignment,
verticalalignment=verticalalignment,
rotation=rotation, **opts)]
# Register plots with HoloViews
Store.register({LineContours: LineContourPlot,
FilledContours: FilledContourPlot,
Image: GeoImagePlot,
Feature: FeaturePlot,
WMTS: WMTSPlot,
Tiles: WMTSPlot,
Points: GeoPointPlot,
Labels: GeoLabelsPlot,
VectorField: GeoVectorFieldPlot,
Text: GeoTextPlot,
Layout: LayoutPlot,
NdLayout: LayoutPlot,
Overlay: GeoOverlayPlot,
Polygons: GeoPolygonPlot,
Path: GeoPathPlot,
Contours: GeoContourPlot,
RGB: GeoRGBPlot,
Shape: GeoShapePlot,
Graph: GeoGraphPlot,
compositor = Compositor(
"HexTiles", geo_hex_binning, None, 'data', output_type=HexTiles,
transfer_options=True, transfer_parameters=True, backends=['bokeh']
)
Compositor.register(compositor)
Store.register({WMTS: TilePlot,
Points: GeoPointPlot,
Labels: GeoLabelsPlot,
VectorField: GeoVectorFieldPlot,
Polygons: GeoPolygonPlot,
Contours: GeoContourPlot,
Path: GeoPathPlot,
Shape: GeoShapePlot,
Image: GeoRasterPlot,
RGB: GeoRGBPlot,
LineContours: LineContourPlot,
FilledContours: FilledContourPlot,
Feature: FeaturePlot,
HexTiles: HexTilesPlot,
Text: GeoTextPlot,
Overlay: GeoOverlayPlot,
NdOverlay: GeoOverlayPlot,
Graph: GeoGraphPlot,
TriMesh: GeoTriMeshPlot,
Nodes: GeoPointPlot,
EdgePaths: GeoPathPlot,
QuadMesh: GeoQuadMeshPlot}, 'bokeh')
options = Store.options(backend='bokeh')
def _process(self, element, key=None):
regridder, arrays = self._get_regridder(element)
x, y = element.kdims
ds = xr.Dataset({vd: regridder(arr) for vd, arr in arrays.items()})
ds = ds.rename({'lon': x.name, 'lat': y.name})
params = get_param_values(element)
if is_geographic(element):
try:
return Image(ds, crs=element.crs, **params)
except:
return QuadMesh(ds, crs=element.crs, **params)
try:
return HvImage(ds, **params)
except:
return HvQuadMesh(ds, **params)