示例#1
0
    def extract_foreground(self, **kwargs):
        img = self.image
        if self._initialized:
            bg, fg = self.draw_bg.element, self.draw_fg.element
        else:
            self._initialized = True
            bg, fg = self.bg_paths, self.fg_paths
        bg, fg = (gv.project(g, projection=img.crs) for g in (bg, fg))

        if not len(bg) or not len(fg):
            return gv.Path([], img.kdims, crs=img.crs)

        if self.downsample != 1:
            kwargs = {'dynamic': False}
            h, w = img.interface.shape(img, gridded=True)
            kwargs['width'] = int(w * self.downsample)
            kwargs['height'] = int(h * self.downsample)
            img = regrid(img, **kwargs)

        foreground = extract_foreground(img,
                                        background=bg,
                                        foreground=fg,
                                        iterations=self.iterations)
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore')
            foreground = gv.Path(
                [contours(foreground, filled=True, levels=1).split()[0].data],
                kdims=foreground.kdims,
                crs=foreground.crs)
        self.result = gv.project(foreground, projection=self.crs)
        return foreground
示例#2
0
    def contour(self, x=None, y=None, z=None, data=None, filled=False):
        from holoviews.operation import contours

        if 'projection' in self._plot_opts:
            import cartopy.crs as ccrs
            t = self._plot_opts['projection']
            if isinstance(t, ccrs.CRS) and not isinstance(t, ccrs.Projection):
                raise ValueError('invalid transform:'
                                 ' Spherical contouring is not supported - '
                                 ' consider using PlateCarree/RotatedPole.')

        opts = dict(plot=self._plot_opts,
                    style=self._style_opts,
                    norm=self._norm_opts)
        qmesh = self.quadmesh(x, y, z, data)

        if self.geo:
            # Apply projection before rasterizing
            import cartopy.crs as ccrs
            from geoviews import project
            projection = self._plot_opts.get('projection',
                                             ccrs.GOOGLE_MERCATOR)
            qmesh = project(qmesh, projection=projection)

        if filled:
            opts['style']['line_alpha'] = 0

        if opts['plot']['colorbar']:
            opts['plot']['show_legend'] = False
        levels = self.kwds.get('levels', 5)
        if isinstance(levels, int):
            opts['plot']['color_levels'] = levels
        return contours(qmesh, filled=filled, levels=levels).opts(**opts)
示例#3
0
def geoview_flat_plot(region_da, time_sel=0, level_sel=False, wide_chile=True):
    
    if type(level_sel) is int:
        da = region_da.isel(level=level_sel)
    else:
        da = region_da
    
    gv_ds = gv.Dataset(da.isel(time=time_sel))
    plot = gv_ds.to(gv.Image,  ['lon', 'lat'], 't', 'time').opts(cmap='viridis', 
                                                                colorbar=True)
    extras = []
    if wide_chile:
        easter_island_text = gv.Text(-104.360481, -24.104671, 'Easter Island').opts(color='white')
        easter_island_point = gv.Points([(-109.360481, -27.104671)]).opts(color='red')

        easter = easter_island_point * easter_island_text

        falkland_islands_text = gv.Text(-49.563412, -56.820557, 'Falklands').opts(color='white')
        falkland_islands_point = gv.Points([(-51.563412, -59.820557)]).opts(color='red')

        falkland = falkland_islands_point * falkland_islands_text
        
        extras.append(easter * falkland)
    
    plot = contours(plot, filled=True, overlaid=True)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        
        final_plot = plot * gf.coastline
        for extra in extras:
            final_plot *= extra
        gv.output(final_plot)
示例#4
0
def plot_qmesh_contours(t,
                        freqs,
                        tfr,
                        l=None,
                        filled=True,
                        overlaid=True,
                        img_args={},
                        contour_args={}):
    '''plot an interpolated QuadMesh as an Image overlaid with contours'''
    from holoviews.operation import contours
    ti, freqsi, tfri = interpolated_scalogram(t, freqs, tfr, 'cubic')
    img = hv.Image( (ti[0,:], freqsi[:,0], tfri), ["Time", "Frequency"] )\
            .opts(cmap="Viridis", width=400,show_grid=False)\
            .opts( **img_args )
    if l is None: l = estimate_levels(tfr)
    return contours(img, levels=l, filled=filled,
                    overlaid=overlaid).opts("Contours", **contour_args)
示例#5
0
    def extract_foreground(self, **kwargs):
        img = self.image
        bg, fg = self.bg_path_view(), self.fg_path_view()
        self._initialized = True

        if not len(bg) or not len(fg):
            return gv.Path([], img.kdims, crs=img.crs)

        if self.downsample != 1:
            kwargs = {'dynamic': False}
            h, w = img.interface.shape(img, gridded=True)
            kwargs['width'] = int(w*self.downsample)
            kwargs['height'] = int(h*self.downsample)
            img = regrid(img, **kwargs)

        foreground = extract_foreground(img, background=bg, foreground=fg,
                                        iterations=self.iterations)
        foreground = gv.Path([contours(foreground, filled=True, levels=1).split()[0].data],
                             kdims=foreground.kdims, crs=foreground.crs)
        self.result = gv.project(foreground, projection=self.crs)
        return foreground