Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_data(self):
"""get_data() -> (xdata, ydata)
Implements AbstractDataSource. Because this class uses structured
(gridded) data, this method returns the pair of data axes, instead of,
for example, a full mesh-grid. This behavious differs from
other data sources.
"""
if self._xdata is not None:
xdata = self._xdata
else:
xdata = ArrayDataSource(array([]))
if self._ydata is not None:
ydata = self._ydata
else:
ydata = ArrayDataSource(array([]))
return xdata, ydata
def _plot_interpolated(self, pid, po, reg, series_id=0):
iso = po.name
p_uys, p_ues = self.set_interpolated_values(iso, reg, po.fit)
ymi, yma = 0, 0
if len(p_uys):
ymi, yma = self._calc_limits(p_uys, p_ues)
graph = self.graph
# display the predicted values
s, p = graph.new_series(self.xs,
p_uys,
isotope=iso,
yerror=ArrayDataSource(p_ues),
fit=False,
add_tools=False,
add_inspector=False,
type='scatter',
marker=po.marker,
marker_size=po.marker_size,
plotid=pid,
bind_id=-1)
series = len(p.plots) - 1
graph.set_series_label('Unknowns-predicted{}'.format(series_id), plotid=pid,
series=series)
self._add_error_bars(s, p_ues, 'y', self.options.nsigma, True)
return ymi, yma
xtitle = '39Ar/40Ar'
ytitle = '36Ar/40Ar'
# for axis in (plot.x_axis, plot.y_axis):
# axis.title_font = 'courier 15'
graph.set_x_title(xtitle, plotid=pid)
graph.set_y_title(ytitle, plotid=pid)
p = graph.plots[pid]
p.y_axis.title_spacing = 50
graph.set_grid_traits(visible=False)
graph.set_grid_traits(visible=False, grid='y')
scatter, _p = graph.new_series(xs, ys,
xerror=ArrayDataSource(data=xerrs),
yerror=ArrayDataSource(data=yerrs),
type='scatter',
marker='circle',
bind_id=self.group_id,
# selection_marker_size=5,
# selection_color='green',
marker_size=2)
# self._scatter = scatter
graph.set_series_label('data{}'.format(self.group_id))
eo = ErrorEllipseOverlay(component=scatter,
reg=reg,
fill=self.options.fill_ellipses)
scatter.overlays.append(eo)
# mi, ma = graph.get_x_limits()
if efit in ['preceding', 'bracketing interpolate', 'bracketing average']:
reg = InterpolationRegressor(xs=r_xs, ys=r_ys, yserr=r_es, kind=efit)
kw['add_tools'] = False
scatter, _p = graph.new_series(r_xs, r_ys, yerror=r_es, type='scatter', fit=False,
**kw)
def update_meta_func(obj, b, c, d):
self.update_interpolation_regressor(po.name, reg, obj, refs)
self._add_error_bars(scatter, r_es, 'y', self.options.nsigma, True)
ffit = po.fit
else:
ffit = '{}_{}'.format(po.fit, po.error_type)
_, scatter, l = graph.new_series(r_xs, r_ys,
yerror=ArrayDataSource(data=r_es),
fit=ffit,
bind_id=hash(tuple(refs)),
**kw)
if hasattr(l, 'regressor'):
reg = l.regressor
self._add_error_bars(scatter, r_es, 'y', self.options.nsigma, True)
def af(i, x, y, analysis):
return ('Run Date: {}'.format(analysis.rundate.strftime('%m-%d-%Y %H:%M')),
'Rel. Time: {:0.4f}'.format(x))
self._add_scatter_inspector(scatter,
update_meta_func=update_meta_func,
add_selection=True,
additional_info=af,
items=refs)
def get_data_sources(x=None, y=None):
y = np.asarray(y)
if x is None:
x = np.arange(len(y))
else:
x = np.asarray(x)
y_source = ArrayDataSource(y)
x_source = ArrayDataSource(x)
return x_source, y_source
def _plot_unknowns_current(self, pid, po):
ymi, yma = 0, 0
if self.analyses and self.show_current:
graph = self.graph
n = [ai.record_id for ai in self.sorted_analyses]
ys, ye = self.current_data(po)
ymi, yma = self._calc_limits(ys, ye)
scatter, plot = graph.new_series(x=self.xs,
y=ys, yerror=ye, type='scatter',
display_index=ArrayDataSource(data=n),
fit=False,
plotid=pid,
bind_id=-2,
add_tools=False,
add_inspector=False,
marker=po.marker,
marker_size=po.marker_size)
def af(i, x, y, analysis):
v, e = self._get_interpolated_value(po, analysis)
return (u'Interpolated: {}{}{}'.format(floatfmt(v), PLUSMINUS, floatfmt(e)),
'Run Date: {}'.format(analysis.rundate.strftime('%m-%d-%Y %H:%M')),
'Rel. Time: {:0.4f}'.format(x))
self._add_error_bars(scatter, ye, 'y', self.options.nsigma, True)
self._add_scatter_inspector(scatter,
def _create_data_sources(data, index_sort="none"):
"""
Returns datasources for index and value based on the inputs. Assumes that
the index data is unsorted unless otherwise specified.
"""
if (type(data) == ndarray) or (len(data) == 2):
index, value = data
if type(index) in (list, tuple, ndarray):
index = ArrayDataSource(array(index), sort_order=index_sort)
elif not isinstance(index, AbstractDataSource):
raise RuntimeError("Need an array or list of values or a DataSource, got %s instead." % type(index))
if type(value) in (list, tuple, ndarray):
value = ArrayDataSource(array(value))
elif not isinstance(value, AbstractDataSource):
raise RuntimeError("Need an array or list of values or a DataSource, got %s instead." % type(index))
return index, value
else:
raise RuntimeError("Unable to create datasources.")
def _create_data_sources(data, index_sort="none"):
"""
Returns datasources for index and value based on the inputs. Assumes that
the index data is unsorted unless otherwise specified.
"""
if (type(data) == ndarray) or (len(data) == 2):
index, value = data
if type(index) in (list, tuple, ndarray):
index = ArrayDataSource(array(index), sort_order=index_sort)
elif not isinstance(index, AbstractDataSource):
raise RuntimeError("Need an array or list of values or a DataSource, got %s instead." % type(index))
if type(value) in (list, tuple, ndarray):
value = ArrayDataSource(array(value))
elif not isinstance(value, AbstractDataSource):
raise RuntimeError("Need an array or list of values or a DataSource, got %s instead." % type(index))
return index, value
else:
raise RuntimeError("Unable to create datasources.")
def get_candle_plot():
means = np.array([0.2, 0.8, 0.5])
stds = np.array([1.0, 0.3, 0.5])
data = scipy.stats.norm(loc=means, scale=stds).rvs((100, 3))
x = ArrayDataSource(np.arange(3))
center = ArrayDataSource(data.mean(0))
bar_min = ArrayDataSource(data.mean(0)-data.std(0))
bar_max = ArrayDataSource(data.mean(0)+data.std(0))
stem_min = ArrayDataSource(data.min(0))
stem_max = ArrayDataSource(data.max(0))
x_range = DataRange1D(low=-1, high=3)
y_range = DataRange1D(tight_bounds=False)
y_range.add(center, bar_min, bar_max, stem_min, stem_max)
candle_plot = CandlePlot(
index=x,
index_mapper=LinearMapper(range=x_range),
value_mapper=LinearMapper(range=y_range),
center_values=center,
bar_min=bar_min,
bar_max=bar_max,
min_values=stem_min,
max_values=stem_max,
center_color='yellow',