示例#1
0
 def changed_layout(self, change):
     self.selected_nodes = []
     if self.graph is None:
         self.output_graph = None
         self.display_datashader_vis(self.output_graph)
     elif len(self.graph) == 0:
         self.output_graph = None
         self.display_datashader_vis("Cannot display blank graph.")
     elif isinstance(self.graph, nx.classes.graph.Graph):
         original = hv.Graph.from_networkx(
             self.graph, self._nx_layout, **self.graph_layout_params
         )
         self.output_graph = bundle_graph(original)
         self.tap_selection_stream = streams.Tap(source=self.output_graph)
         self.tap_selection_stream.add_subscriber(self.tap_stream_subscriber)
         self.box_selection_stream = streams.BoundsXY(source=self.output_graph)
         self.box_selection_stream.add_subscriber(self.box_stream_subscriber)
         self.final_graph = self.set_options(self.output_graph)
         self.display_datashader_vis(self.final_graph)
     else:
         self.output_graph = self.strip_and_produce_rdf_graph(self.graph)
         self.tap_selection_stream = streams.Tap(source=self.output_graph)
         self.tap_selection_stream.add_subscriber(self.tap_stream_subscriber)
         self.box_selection_stream = streams.BoundsXY(source=self.output_graph)
         self.box_selection_stream.add_subscriber(self.box_stream_subscriber)
         self.final_graph = self.set_options(self.output_graph)
         self.display_datashader_vis(self.final_graph)
示例#2
0
    def __init__(self, data, initial_params={}):
        super().__init__()
        if not isinstance(data, xr.core.dataarray.DataWithCoords):
            raise ValueError("Input should be an xarray data object, not %s" %
                             type(data))
        self.set_data(data)
        self.initial_params = initial_params
        self.control = Control(self.data)
        self.plot_button = pn.widgets.Button(name='Plot',
                                             width=200,
                                             disabled=True)
        self.index_selectors = []
        self.graph = pn.Spacer(name='Graph')
        self.taps_graph = hv.Points([])
        self.series_graph = pn.Row(pn.Spacer(name='Series Graph'))
        self.clear_series_button = pn.widgets.Button(name='Clear',
                                                     width=200,
                                                     disabled=True)
        self.output = pn.Row(self.graph, pn.Column(name='Index_selectors'))

        self._register(self.plot_button, 'plot_clicked', 'clicks')
        self.connect('plot_clicked', self.create_graph)

        self._register(self.control.coord_setter.coord_selector, 'set_coords')
        self.connect("set_coords", self.set_coords)

        self._register(self.clear_series_button, 'clear_series', 'clicks')
        self.connect('clear_series', self.clear_series)

        self.control.displayer.connect('variable_selected',
                                       self.check_is_plottable)
        self.control.displayer.connect('variable_selected',
                                       self._link_aggregation_selectors)
        self.control.fields.connect('x', self._link_aggregation_selectors)
        self.control.fields.connect('y', self._link_aggregation_selectors)

        self.panel = pn.Column(self.control.panel,
                               pn.Row(self.plot_button,
                                      self.clear_series_button),
                               self.output,
                               self.series_graph,
                               width_policy='max')

        # To auto-select in case of single variable
        if len(list(self.data.variables)) == 1:
            self.control.displayer.select.value = list(self.data.variables)

        self.control.setup_initial_values(self.initial_params)
        self.taps = []
        self.tap_stream = streams.Tap(transient=True)
        colors = [
            '#60fffc', '#6da252', '#ff60d4', '#ff9400', '#f4e322', '#229cf4',
            '#af9862', '#629baf', '#7eed5a', '#e29ec8', '#ff4300'
        ]
        self.color_pool = cycle(colors)
        self.clear_points = hv.streams.Stream.define(
            'Clear_points', clear=False)(transient=True)
示例#3
0
 def changed_layout(self, change):
     if self.graph is None:
         self.output_graph = None
         self.display_datashader_vis(self.output_graph)
     elif len(self.graph) == 0:
         self.output_graph = None
         self.display_datashader_vis("Cannot display blank graph.")
     else:
         self.output_graph = self.strip_and_produce_rdf_graph(self.graph)
         self.tap_selection_stream = streams.Tap(source=self.output_graph)
         self.tap_selection_stream.add_subscriber(
             self.tap_stream_subscriber)
         self.box_selection_stream = streams.BoundsXY(
             source=self.output_graph)
         self.box_selection_stream.add_subscriber(
             self.box_stream_subscriber)
         self.final_graph = self.set_options(self.output_graph)
         self.display_datashader_vis(self.final_graph)
示例#4
0
 def point_chooser(self, **kwargs):
     '''
     Visual tool for choosing points in the mask.
     :param kwargs: array, if you want to pre select pixels,
                    initialize_mask, True if you want to initialize mask.
                                     True also Overrides array.
                                     False does nothing and overrides
                                     nothing
                    initialize_value, what value you want to use in
                                     initialisation. Used if initialize_mask
                                     is True. Fallback value is 0.
     :return: hv.Object
     '''
     self.__do_mask_changes(**kwargs)
     tap = streams.Tap(rename={
         'x': 'first_coord',
         'y': 'second_coord'
     },
                       transient=True)
     ds_attrs = self._make_dataset_opts()
     dataset3d = hv.Dataset(**ds_attrs)
     mask_dims = self._obj.M.dims.copy()
     mask_dims.reverse()
     layout = dataset3d.to(hv.Image,
                           mask_dims,
                           'Value',
                           self._obj.M.no_mask_dims) * \
              decimate(
                  hv.DynamicMap(
                      lambda first_coord, second_coord:
                      hv.Points(self._record_taps(first_coord,
                                                  second_coord),
                                kdims=mask_dims),
                      streams=[tap]
                  )
              )
     return layout
    "Some time varying function"
    return np.exp(np.sin(xs + np.pi / time))


def integral(limit_a, limit_b, y, time):
    limit_a = -3 if limit_a is None else np.clip(limit_a, -3, 3)
    limit_b = 3 if limit_b is None else np.clip(limit_b, -3, 3)
    curve = hv.Curve((xs, function(xs, time)))
    area = hv.Area((xs, function(xs, time)))[limit_a:limit_b]
    summed = area.dimension_values('y').sum() * 0.015  # Numeric approximation
    return (area * curve * hv.VLine(limit_a) * hv.VLine(limit_b) *
            hv.Text(limit_b - 0.8, 2.0, '%.2f' % summed))


integral_streams = [
    streams.Stream.define('Time', time=1.0)(),
    streams.PointerX().rename(x='limit_b'),
    streams.Tap().rename(x='limit_a')
]

integral_dmap = hv.DynamicMap(integral, streams=integral_streams)

integral_dmap.opts(opts.Area(color='#fff8dc', line_width=2),
                   opts.Curve(color='black'), opts.VLine(color='red'))

image.dimensions()

dim('charge').min().apply(image)

dim('charge').max().apply(image)
示例#6
0
# get path to job's hdf5 files
h5_path = os.path.join(job.ws, "diags", "hdf5")

# open the full time series and see iteration numbers
time_series = OpenPMDTimeSeries(h5_path, check_all_files=True)

energy = hv.Dimension('energy', label='E', unit='MeV')
count = hv.Dimension('frequency', label='dQ/dE', unit='pC/MeV')

integral_streams = [
    streams.Stream.define(
        'Iteration',
        iteration=param.Integer(default=4600,
                                doc='Time step in the simulation'))(),
    streams.PointerX(rename={'x': 'limit_b'}),
    streams.Tap(rename={'x': 'limit_a'})
]

e_max = 25  # MeV


def integrated_charge(limit_a, limit_b, y, iteration):
    # compute 1D histogram
    energy_hist, bin_edges, nbins = particle_energy_histogram(
        tseries=time_series,
        it=iteration,
        cutoff=np.inf,  # no cutoff
        energy_max=e_max,
    )

    histogram = hv.Histogram((bin_edges, energy_hist),