def plot_smoothed(size): trial = cd.shared.trial steps_per_cycle = trial['settings']['steps_per_cycle'] time = trial['times']['cycles'] couplings = trial['couplings']['lengths'] couplings = mstats.values.from_serialized(couplings) couplings = mstats.values.windowed_smooth(couplings, size, 256) values, uncertainties = mstats.values.unzip(couplings) plot = plotting.make_line_data( x=time, y=values, y_unc=uncertainties, color=plotting.get_color(0, 0.8), fill_color=plotting.get_color(0, 0.2) ) coverage = 100 * (2 * size + 1) / steps_per_cycle cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Smoothed Coupling Lengths (Cycle Coverage {}%)'.format( coverage ), x_label='Cycle (#)', y_label='Coupling Length (m)' ) ) couplings = trial['couplings']['lengths'] couplings = mstats.values.from_serialized(couplings) couplings = mstats.values.box_smooth(couplings, 2 * size + 1, 256) values, uncertainties = mstats.values.unzip(couplings) plot = plotting.make_line_data( x=time, y=values, y_unc=uncertainties, color=plotting.get_color(1, 0.8), fill_color=plotting.get_color(1, 0.2) ) coverage = 100 * (2 * size + 1) / steps_per_cycle cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Box Smoothed Coupling Lengths (Cycle Coverage {}%)'.format( coverage ), x_label='Cycle (#)', y_label='Coupling Length (m)' ) )
def plot_smoothed(size): trial = cd.shared.trial steps_per_cycle = trial['settings']['steps_per_cycle'] time = trial['times']['cycles'] couplings = trial['couplings']['lengths'] couplings = mstats.values.from_serialized(couplings) couplings = mstats.values.windowed_smooth(couplings, size, 256) values, uncertainties = mstats.values.unzip(couplings) plot = plotting.make_line_data(x=time, y=values, y_unc=uncertainties, color=plotting.get_color(0, 0.8), fill_color=plotting.get_color(0, 0.2)) coverage = 100 * (2 * size + 1) / steps_per_cycle cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Smoothed Coupling Lengths (Cycle Coverage {}%)'.format( coverage), x_label='Cycle (#)', y_label='Coupling Length (m)')) couplings = trial['couplings']['lengths'] couplings = mstats.values.from_serialized(couplings) couplings = mstats.values.box_smooth(couplings, 2 * size + 1, 256) values, uncertainties = mstats.values.unzip(couplings) plot = plotting.make_line_data(x=time, y=values, y_unc=uncertainties, color=plotting.get_color(1, 0.8), fill_color=plotting.get_color(1, 0.2)) coverage = 100 * (2 * size + 1) / steps_per_cycle cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Box Smoothed Coupling Lengths (Cycle Coverage {}%)'.format( coverage), x_label='Cycle (#)', y_label='Coupling Length (m)'))
def test_make_line_data_defaults(self): """Should make line data using default values""" data = plotting.make_line_data(x=[1, 2, 3, 4], y=[1, 2, 3, 4], y_unc=[0.1, 0.1, 0.1, 0.1]) self.assertIsInstance(data, dict) self.assertIn('data', data) self.assertIn('layout', data)
def test_make_line_data_explicit_size(self): """Should make markers invisible by setting the size to zero.""" data = plotting.make_line_data(x=[1, 2, 3, 4], y=[1, 2, 3, 4], y_unc=[0.1, 0.1, 0.1, 0.1], marker_properties=0) self.assertIsInstance(data, dict) self.assertIn('data', data) self.assertIn('layout', data)
def test_make_line_data_explicit_width(self): """Should make line using the line properties as the line width.""" data = plotting.make_line_data(x=[1, 2, 3, 4], y=[1, 2, 3, 4], y_unc=[0.1, 0.1, 0.1, 0.1], line_properties=3) self.assertIsInstance(data, dict) self.assertIn('data', data) self.assertIn('layout', data)
def plot_couplings(df_row, trial): """ :param df_row: :param trial: :return: """ data = trial['couplings']['lengths'] median = mstats.ValueUncertainty(**trial['couplings']['value']) couplings = mstats.values.from_serialized( [v['value'] for v in data] ) min_value = mstats.values.minimum(couplings) max_value = mstats.values.maximum(couplings) y, unc = mstats.values.unzip(couplings) plot = plotting.make_line_data( x=[v['time'] for v in data], y=y, y_unc=unc, color=plotting.get_color(int(trial['id'][1]), 0.8), fill_color=plotting.get_color(int(trial['id'][1]), 0.3) ) cd.display.plotly( data=plot['data'], layout=plotting.create_layout( dict( showlegend=False ), title='{} Coupling Length'.format(trial['short_id']), x_label='Cycle (#)', y_label='Coupling Length (m)', y_bounds=[median.value - 0.5, median.value + 0.5] ) ) delta = abs(min_value - max_value) deviation = abs(min_value.value - max_value.value) / delta.uncertainty cd.display.markdown( """ Reference Statistics: * _Minimum:_ __{{ min }} m__ * _Median:_ __{{ median }} m__ * _Max:_ __{{ max }} m__ * _Deviations:_ __{{ deviation }}__ """, min=min_value.html_label, median=median.html_label, max=max_value.html_label, deviation=0.01 * round(100 * deviation) )
def test_make_line_data_defaults(self): """Should make line data using default values""" data = plotting.make_line_data( x=[1, 2, 3, 4], y=[1, 2, 3, 4], y_unc=[0.1, 0.1, 0.1, 0.1] ) self.assertIsInstance(data, dict) self.assertIn('data', data) self.assertIn('layout', data)
def plot_couplings(*args, **kwargs): """ :param kwargs: :param args: :return: """ title = kwargs.get('title', 'Coupling Lengths') traces = [] for entry in args: trial = entry['trial'] times = entry.get('times', trial['times']['cycles']) lengths = entry.get('lengths', trial['couplings']['lengths']) index = entry['index'] if 'index' in entry else trial['group_index'] if 'color' in entry: color = entry['color'] elif index is None: color = plotting.get_gray_color(100, 0.8) else: color = plotting.get_color(index, 0.8) if 'fill_color' in entry: fill_color = entry['fill_color'] elif index is None: fill_color = plotting.get_gray_color(100, 0.1) else: fill_color = plotting.get_color(index, 0.1) plot = plotting.make_line_data( x=times, y=[v['value'] for v in lengths], y_unc=[v['uncertainty'] for v in lengths], color=color, fill_color=fill_color, name=entry.get('name', trial['id']) ) traces += plot['data'] layout = dict( showlegend = len(traces) > 0 ) cd.display.plotly( data=traces, layout=plotting.create_layout( layout, title=title, x_label='Cycle (#)', y_label='Coupling Length (m)' ) )
def test_make_line_data_explicit_size(self): """Should make markers invisible by setting the size to zero.""" data = plotting.make_line_data( x=[1, 2, 3, 4], y=[1, 2, 3, 4], y_unc=[0.1, 0.1, 0.1, 0.1], marker_properties=0 ) self.assertIsInstance(data, dict) self.assertIn('data', data) self.assertIn('layout', data)
def test_make_line_data_explicit_width(self): """Should make line using the line properties as the line width.""" data = plotting.make_line_data( x=[1, 2, 3, 4], y=[1, 2, 3, 4], y_unc=[0.1, 0.1, 0.1, 0.1], line_properties=3 ) self.assertIsInstance(data, dict) self.assertIn('data', data) self.assertIn('layout', data)
def test_make_line_data(self): """Should make line data according to arguments""" data = plotting.make_line_data(x=[1, 2, 3, 4], y=[1, 2, 3, 4], y_unc=[0.1, 0.1, 0.1, 0.1], name='TEST', color=plotting.get_color(4), fill_color=plotting.get_color(5, 0.2), line_properties={}, marker_properties={}) self.assertIsInstance(data, dict) self.assertIn('data', data) self.assertIn('layout', data)
def plot_groupings(boarding_method, title): group_counts = [1, 2, 3, 4, 5, 6, 8, 10] elapsed = [] elapsed_uncertainties = [] for gc in group_counts: df_slice = df[ (df['boarding_method'] == boarding_method) & (df['group_count'] == gc) ] elapsed.append( np.median(df_slice['elapsed']) ) elapsed_uncertainties.append( np.median(np.abs( df_slice['elapsed'] - elapsed[-1] )) ) if boarding_method == 'r': c = 'rgba(150, 150, 150, 0.8)' fc = 'rgba(150, 150, 150, 0.2)' elif boarding_method == 'b': c = plotting.get_color(0, 0.8) fc = plotting.get_color(0, 0.2) else: c = plotting.get_color(1, 0.8) fc = plotting.get_color(1, 0.2) definition = dict( x=group_counts, y=elapsed, y_unc=elapsed_uncertainties, name=boarding_method.upper(), color=c, fill_color=fc ) plot = plotting.make_line_data(**definition) project.display.plotly( data=plot['data'], layout=plotting.create_layout( plot['layout'], title=title, x_label='Group Count (#)', y_label='Boarding Time (s)', ), scale=0.75 ) return plot['data']
def test_make_line_data(self): """Should make line data according to arguments""" data = plotting.make_line_data( x=[1, 2, 3, 4], y=[1, 2, 3, 4], y_unc=[0.1, 0.1, 0.1, 0.1], name='TEST', color=plotting.get_color(4), fill_color=plotting.get_color(5, 0.2), line_properties={}, marker_properties={} ) self.assertIsInstance(data, dict) self.assertIn('data', data) self.assertIn('layout', data)
def plot_couplings(*args, **kwargs): """ :param kwargs: :param args: :return: """ title = kwargs.get('title', 'Coupling Lengths') traces = [] for entry in args: trial = entry['trial'] times = entry.get('times', trial['times']['cycles']) lengths = entry.get('lengths', trial['couplings']['lengths']) index = entry['index'] if 'index' in entry else trial['group_index'] if 'color' in entry: color = entry['color'] elif index is None: color = plotting.get_gray_color(100, 0.8) else: color = plotting.get_color(index, 0.8) if 'fill_color' in entry: fill_color = entry['fill_color'] elif index is None: fill_color = plotting.get_gray_color(100, 0.1) else: fill_color = plotting.get_color(index, 0.1) plot = plotting.make_line_data( x=times, y=[v['value'] for v in lengths], y_unc=[v['uncertainty'] for v in lengths], color=color, fill_color=fill_color, name=entry.get('name', trial['id'])) traces += plot['data'] layout = dict(showlegend=len(traces) > 0) cd.display.plotly(data=traces, layout=plotting.create_layout( layout, title=title, x_label='Cycle (#)', y_label='Coupling Length (m)'))
def plot_couplings(df_row, trial): """ :param df_row: :param trial: :return: """ data = trial['couplings']['lengths'] median = mstats.ValueUncertainty(**trial['couplings']['value']) couplings = mstats.values.from_serialized([v['value'] for v in data]) min_value = mstats.values.minimum(couplings) max_value = mstats.values.maximum(couplings) y, unc = mstats.values.unzip(couplings) plot = plotting.make_line_data( x=[v['time'] for v in data], y=y, y_unc=unc, color=plotting.get_color(int(trial['id'][1]), 0.8), fill_color=plotting.get_color(int(trial['id'][1]), 0.3)) cd.display.plotly(data=plot['data'], layout=plotting.create_layout( dict(showlegend=False), title='{} Coupling Length'.format(trial['short_id']), x_label='Cycle (#)', y_label='Coupling Length (m)', y_bounds=[median.value - 0.5, median.value + 0.5])) delta = abs(min_value - max_value) deviation = abs(min_value.value - max_value.value) / delta.uncertainty cd.display.markdown(""" Reference Statistics: * _Minimum:_ __{{ min }} m__ * _Median:_ __{{ median }} m__ * _Max:_ __{{ max }} m__ * _Deviations:_ __{{ deviation }}__ """, min=min_value.html_label, median=median.html_label, max=max_value.html_label, deviation=0.01 * round(100 * deviation))
import cauldron as cd from cauldron import plotting trials = cd.shared.trials traces = [] for t in trials: values = [x['value'] for x in t['couplings']['lengths']] uncertainties = [x['uncertainty'] for x in t['couplings']['lengths']] plot = plotting.make_line_data( x=t['times']['cycles'], y=values, y_unc=uncertainties, name=t['settings']['id'], color=plotting.get_color(trials.index(t), 0.8), fill_color=plotting.get_color(trials.index(t), 0.2) ) traces += plot['data'] cd.display.plotly( data=traces, layout=plotting.create_layout( title='Coupling Length Comparison', x_label='Cycle (#)', y_label='Coupling Length (m)' ), scale=0.8 )
import cauldron as cd from cauldron import plotting trial = cd.shared.trial time = trial['times']['cycles'] couplings = trial['couplings']['lengths'] plot = plotting.make_line_data( x=time, y=[x['value'] for x in couplings], y_unc=[x['uncertainty'] for x in couplings], ) cd.display.plotly(data=plot['data'], layout=plotting.create_layout(title='Coupling Lengths', x_label='Cycle (#)', y_label='Coupling Length (m)'))
import cauldron as cd from cauldron import plotting trials = cd.shared.trials traces = [] for t in trials: values = [x['value'] for x in t['couplings']['lengths']] uncertainties = [x['uncertainty'] for x in t['couplings']['lengths']] plot = plotting.make_line_data( x=t['times']['cycles'], y=values, y_unc=uncertainties, name=t['settings']['id'], color=plotting.get_color(trials.index(t), 0.8), fill_color=plotting.get_color(trials.index(t), 0.2)) traces += plot['data'] cd.display.plotly(data=traces, layout=plotting.create_layout( title='Coupling Length Comparison', x_label='Cycle (#)', y_label='Coupling Length (m)'), scale=0.8)
import cauldron as cd from cauldron import plotting trial = cd.shared.trial time = trial['times']['cycles'] couplings = trial['couplings']['lengths'] plot = plotting.make_line_data( x=time, y=[x['value'] for x in couplings], y_unc=[x['uncertainty'] for x in couplings], ) cd.display.plotly( data=plot['data'], layout=plotting.create_layout( title='Coupling Lengths', x_label='Cycle (#)', y_label='Coupling Length (m)' ) )