Exemplo n.º 1
0
    def panel(self, dmaps):
        xy, zy, xz = dmaps

        self._update_dynamic_values(xy, zy, xz)

        zy.opts(
            opts.Image(frame_width=self.frame_z_size,
                       frame_height=self.frame_y_size),
            opts.RGB(frame_width=self.frame_z_size,
                     frame_height=self.frame_y_size),
        )

        if self.add_crosshairs:
            self.get_crosshair()
            panel_xy = self.z_viewer.panel(
                (xy * self.xy_h * self.xy_v).relabel(group='orthoview'))
            panel_zy = self.x_viewer.panel(
                (zy * self.zy_h * self.zy_v).relabel(group='orthoview'))
            panel_xz = self.y_viewer.panel(
                (xz * self.xz_h * self.xz_v).relabel(group='orthoview'))
        else:
            panel_xy = self.z_viewer.panel(xy.relabel(group='orthoview'))
            panel_zy = self.x_viewer.panel(zy.relabel(group='orthoview'))
            panel_xz = self.y_viewer.panel(xz.relabel(group='orthoview'))

        self._link_crosshairs()

        return pn.Column(pn.Row(panel_xy, panel_zy),
                         pn.Row(panel_xz, self.param.navigaton_on))
Exemplo n.º 2
0
    def __init__(self, adh_mod, **params):
        super(InterpolateMesh, self).__init__(adh_mod=adh_mod, **params)
        # set defaults for initialized example
        self.display_range.param.color_range.bounds = (10, 90)
        self.display_range.color_range = (10, 90)
        self.cmap_opts.colormap = cc.rainbow
        self.scatter_projection.set_crs(ccrs.GOOGLE_MERCATOR)
        self.adh_mod.wmts.source = gv.tile_sources.EsriImagery

        # print(self.projection.param.UTM_zone_hemi.constant, self.projection.crs_label)
        self.opts = (opts.Curve(height=self.map_height,
                                width=self.map_width,
                                xaxis=None,
                                line_width=1.50,
                                color='red',
                                tools=['hover']),
                     opts.Path(height=self.map_height,
                               width=self.map_width,
                               line_width=3,
                               color='black'),
                     opts.Image(height=self.map_height,
                                width=self.map_width,
                                cmap=self.cmap_opts.param.colormap,
                                clim=self.display_range.param.color_range,
                                colorbar=True,
                                clipping_colors={
                                    'NaN': 'transparent',
                                    'min': 'transparent'
                                },
                                axiswise=True),
                     opts.RGB(height=self.map_height, width=self.map_width),
                     opts.Points(height=self.map_height,
                                 width=self.map_width,
                                 color_index='z',
                                 cmap=self.cmap_opts.param.colormap,
                                 clim=self.display_range.param.color_range,
                                 size=10,
                                 tools=['hover'],
                                 padding=(0.1, 0.1),
                                 colorbar=True),
                     opts.TriMesh(height=self.map_height,
                                  width=self.map_width,
                                  color_index='z',
                                  cmap=self.cmap_opts.param.colormap,
                                  clim=self.display_range.param.color_range,
                                  tools=['hover'],
                                  padding=(0.1, 0.1),
                                  colorbar=True), opts.VLine(color='black'))
Exemplo n.º 3
0
def rgb_plot(rgb, da, label='RGB Plot', width=800, height=800):
    '''Use Holoviews for an RGB plot of a rgb data array'''
    TOOLTIPS = [
        ("(x,y)", "($x{0,0.0}, $y{0,0.0})"),
    ]
    hover = HoverTool(tooltips=TOOLTIPS)
    xmin, ymax = da.transform[2], da.transform[5]
    xmax = xmin + da.transform[0] * da.shape[2]
    ymin = ymax + da.transform[4] * da.shape[1]
    bounds = (xmin, ymin, xmax, ymax)
    epsg = da.crs.split(':')[1]
    kdims = [f'Easting [m] (EPSG:{epsg})', 'Northing [m]']
    hv_rgb = hv.RGB(rgb, bounds=bounds, kdims=kdims, label=label)
    hv_rgb = hv_rgb.options(
        opts.RGB(width=width,
                 height=height,
                 tools=[hover],
                 xformatter='%.0f',
                 yformatter='%.0f'))
    return hv_rgb
Exemplo n.º 4
0
    def __call__(self, dset, **params):
        self.p = ParamOverrides(self, params)
        if self.p.xdim not in dset.dimensions():
            raise ValueError("{} not in Dataset.".format(self.p.xdim))
        if self.p.ydim not in dset.dimensions():
            raise ValueError("{} not in Dataset.".format(self.p.ydim))
        if ("ra" not in dset.dimensions()) or ("dec" not in dset.dimensions()):
            raise ValueError("ra and/or dec not in Dataset.")

        # Compute sampling
        ra_range = (ra0, ra1) = dset.range("ra")
        if self.p.ra_sampling:
            ra_sampling = (ra1 - ra0) / self.p.x_sampling
        else:
            ra_sampling = None

        dec_range = (dec0, dec1) = dset.range("dec")
        if self.p.dec_sampling:
            dec_sampling = (dec1 - dec0) / self.p.y_sampling
        else:
            dec_sampling = None

        x_range = (x0, x1) = dset.range(self.p.xdim)
        if self.p.x_sampling:
            x_sampling = (x1 - x0) / self.p.x_sampling
        else:
            x_sampling = None

        y_range = (y0, y1) = dset.range(self.p.ydim)
        if self.p.y_sampling:
            y_sampling = (y1 - y0) / self.p.y_sampling
        else:
            y_sampling = None

        # Set up scatter plot
        scatter_range = RangeXY()
        if self.p.scatter_range_stream:

            def redim_scatter(dset, x_range, y_range):
                ranges = {}
                if x_range and all(isfinite(v) for v in x_range):
                    ranges[self.p.xdim] = x_range
                if y_range and all(isfinite(v) for v in x_range):
                    ranges[self.p.ydim] = y_range
                return dset.redim.range(**ranges) if ranges else dset

            dset_scatter = dset.apply(redim_scatter,
                                      streams=[self.p.scatter_range_stream])
            link_streams(self.p.scatter_range_stream, scatter_range)
        else:
            dset_scatter = dset
        scatter_pts = dset_scatter.apply(filterpoints,
                                         streams=[self.p.filter_stream],
                                         xdim=self.p.xdim,
                                         ydim=self.p.ydim)
        scatter_streams = [scatter_range, PlotSize()]
        scatter_rasterize = rasterize.instance(streams=scatter_streams,
                                               x_sampling=x_sampling,
                                               y_sampling=y_sampling)
        cmap = (process_cmap(self.p.scatter_cmap)[:250]
                if self.p.scatter_cmap == "fire" else self.p.scatter_cmap)
        scatter_rasterized = apply_when(
            scatter_pts,
            operation=scatter_rasterize,
            predicate=lambda pts: len(pts) > self.p.max_points
        ).opts(
            opts.Image(clim=(1, np.nan),
                       clipping_colors={"min": "transparent"},
                       cmap=cmap),
            opts.Points(clim=(1, np.nan),
                        clipping_colors={"min": "transparent"},
                        cmap=cmap),
            opts.Overlay(
                hooks=[partial(reset_hook, x_range=x_range, y_range=y_range)]),
        )

        # Set up sky plot
        sky_range = RangeXY()
        if self.p.sky_range_stream:

            def redim_sky(dset, x_range, y_range):
                ranges = {}
                if x_range and all(isfinite(v) for v in x_range):
                    ranges["ra"] = x_range
                if y_range and all(isfinite(v) for v in x_range):
                    ranges["dec"] = y_range
                return dset.redim.range(**ranges) if ranges else dset

            dset_sky = dset.apply(redim_sky, streams=[self.p.sky_range_stream])
            link_streams(self.p.sky_range_stream, sky_range)
        else:
            dset_sky = dset
        sky_pts = dset_sky.apply(filterpoints,
                                 xdim="ra",
                                 ydim="dec",
                                 set_title=False,
                                 streams=[self.p.filter_stream])
        skyplot_streams = [sky_range, PlotSize()]
        sky_rasterize = rasterize.instance(
            aggregator=ds.mean(self.p.ydim),
            streams=skyplot_streams,
            x_sampling=ra_sampling,
            y_sampling=dec_sampling,
        )
        sky_rasterized = apply_when(
            sky_pts,
            operation=sky_rasterize,
            predicate=lambda pts: len(pts) > self.p.max_points).opts(
                opts.Image(bgcolor="black",
                           cmap=self.p.sky_cmap,
                           symmetric=True),
                opts.Points(bgcolor="black",
                            cmap=self.p.sky_cmap,
                            symmetric=True),
                opts.Overlay(hooks=[
                    partial(reset_hook, x_range=ra_range, y_range=dec_range)
                ]),
            )

        # Set up BoundsXY streams to listen to box_select events and notify FilterStream
        scatter_select = BoundsXY(source=scatter_pts)
        scatter_notifier = partial(notify_stream,
                                   filter_stream=self.p.filter_stream,
                                   xdim=self.p.xdim,
                                   ydim=self.p.ydim)
        scatter_select.add_subscriber(scatter_notifier)

        sky_select = BoundsXY(source=sky_pts)
        sky_notifier = partial(notify_stream,
                               filter_stream=self.p.filter_stream,
                               xdim="ra",
                               ydim="dec")
        sky_select.add_subscriber(sky_notifier)

        # Reset
        reset = PlotReset(source=sky_pts)
        reset.add_subscriber(
            partial(reset_stream, self.p.filter_stream,
                    [self.p.sky_range_stream, self.p.scatter_range_stream]))

        raw_scatterpts = filterpoints(dset, xdim=self.p.xdim, ydim=self.p.ydim)
        raw_scatter = datashade(
            raw_scatterpts,
            cmap=list(Greys9[::-1][:5]),
            streams=scatter_streams,
            x_sampling=x_sampling,
            y_sampling=y_sampling,
        )
        scatter_p = raw_scatter * scatter_rasterized

        if self.p.show_rawsky:
            raw_skypts = filterpoints(dset, xdim=self.p.xdim, ydim=self.p.ydim)
            raw_sky = datashade(
                rawskypts,
                cmap=list(Greys9[::-1][:5]),
                streams=skyplot_streams,
                x_sampling=ra_sampling,
                y_sampling=dec_sampling,
            )
            sky_p = raw_sky * sky_rasterized
        else:
            sky_p = sky_rasterized

        if self.p.show_table:
            table = dset.apply(summary_table,
                               ydim=self.p.ydim,
                               streams=[self.p.filter_stream])
            table = table.opts()
            layout = table + scatter_p + sky_p
        else:
            layout = (scatter_p + sky_p).opts(sizing_mode="stretch_width")

        return layout.opts(
            opts.Image(colorbar=True,
                       responsive=True,
                       tools=["box_select", "hover"]),
            opts.Layout(sizing_mode="stretch_width"),
            opts.Points(color=self.p.ydim, tools=["hover"]),
            opts.RGB(alpha=0.5),
            opts.Table(width=200),
        )
Exemplo n.º 5
0
from inter_view.utils import blend_overlay

# defines default options for all viewers
opts.defaults(
    opts.Image('channel',
               frame_width=600,
               invert_yaxis=True,
               xaxis='bare',
               yaxis='bare',
               bgcolor='black',
               active_tools=['pan', 'wheel_zoom'],
               show_title=False),
    opts.RGB('composite',
             frame_width=600,
             invert_yaxis=True,
             xaxis='bare',
             yaxis='bare',
             bgcolor='black',
             active_tools=['pan', 'wheel_zoom'],
             show_title=False),
    opts.HLine('orthoview',
               line_dash='dashed',
               line_width=1,
               line_color='white'),
    opts.VLine('orthoview',
               line_dash='dashed',
               line_width=1,
               line_color='white'),
    opts.Overlay('orthoview', shared_axes=False, show_title=False),
    opts.Overlay('segmentation', show_title=False),
    opts.Image('segmentation',
               frame_width=600,