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_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_get_color(self): """Should return colors with modifications""" color = plotting.get_color(0, 0.5, False) self.assertEqual(len(color), 4) color = plotting.get_color(4) self.assertTrue(color.startswith('rgba(')) color = plotting.get_color(1235, 0.5) self.assertTrue(color.startswith('rgba('))
def test_get_color(self): """Should return colors with modifications""" color = plotting.get_color(0, 0.5, False) self.assertEqual(len(color), 4) color = plotting.get_color(4) self.assertTrue(color.startswith('rgba(')) color = plotting.get_color(1235, 0.5) self.assertTrue(color.startswith('rgba('))
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(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_get_color(self): """ :return: """ color = plotting.get_color(0, 0.5, False) self.assertEqual(len(color), 4) color = plotting.get_color(4) self.assertTrue(color.startswith('rgba(')) color = plotting.get_color(1235, 0.5) self.assertTrue(color.startswith('rgba('))
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_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_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 create_density_trace(dist, color_index=0, name=None): x = mstats.distributions.adaptive_range(dist, 5) y = dist.probabilities_at(x) return go.Scatter(x=x, y=y, name=name, fill='tozeroy', mode='lines', line=dict(color=plotting.get_color(color_index)))
def calculate_median(values, uncertainties, color_index=0, plot_name=None): """ :param values: :param uncertainties: :param color_index: :param plot_name: :return: """ try: values = values.values except: pass try: uncertainties = uncertainties.values except: pass measurements = [ (val, unc) for val, unc in zip(values, uncertainties) if not np.isnan(val) and not np.isnan(unc) ] values, uncertainties = zip(*measurements) measurements = mstats.values.join(values, uncertainties) dist = mstats.create_distribution(measurements) pop = mdist.population(dist) median = mstats.ValueUncertainty( mdist.percentile(pop), mdist.weighted_median_average_deviation(pop) ) x = mdist.adaptive_range(dist, 4) y = dist.probabilities_at(x) trace = go.Scatter( x=x, y=y, name=plot_name, fill='tozeroy', mode='lines', line=dict( color=plotting.get_color(color_index) ) ) return dict( measurements=measurements, median=median, trace=trace )
def plot_comparison(data_frame, title, comparison_column, comparison_label): data_frame = data_frame.sort_values(by='trial_label') traces = [] for method in data_frame['boarding_method'].unique(): df_method = data_frame[data_frame['boarding_method'] == method] delays = [] times = [] for delay in sorted(df_method[comparison_column].unique()): x = df_method[df_method[comparison_column] == delay] times.append(np.median(x['elapsed'])) delays.append(delay) if method == 'r': c = 'rgba(204, 204, 204, 0.8)' elif method == 'b': c = plotting.get_color(0, 0.8) else: c = plotting.get_color(1, 0.8) traces.append(go.Scatter( x=times, y=delays, name=method, mode='lines+markers', marker=dict( color=c ) )) project.display.plotly( data=traces, layout=plotting.create_layout( title=title, x_label='Boarding Time (s)', y_label=comparison_label ), scale=0.75 )
def plot_collection( data_frame, title, color_column='boarding_method', color_values=None ): data_frame = data_frame.sort_values(by='trial_label') times = data_frame['elapsed'] labels = data_frame['trial_label'] colors = [] if color_values is None: color_values = dict( r='rgba(204, 204, 204, 0.8)', b=plotting.get_color(0, 0.8), default=plotting.get_color(1, 0.8) ) for index, row in data_frame.iterrows(): method = row[color_column] colors.append( color_values.get(method, color_values.get('default')) ) project.display.plotly( data=go.Bar( y=times, x=labels, marker=dict(color=colors), ), layout=plotting.create_layout( title=title, y_label='Boarding Time (s)', x_label='Trial', y_bounds=[times.min() - 10, times.max() + 10] ), scale=0.75 )
def create_density_trace(dist, color_index=0, name=None): x = mstats.distributions.adaptive_range(dist, 5) y = dist.probabilities_at(x) return go.Scatter( x=x, y=y, name=name, fill='tozeroy', mode='lines', line=dict( color=plotting.get_color(color_index) ) )
def comparison_plot(x_name, y_name, color_name, layout): traces = [] for entry in df[color_name].unique(): sub_df = df[df[color_name] == entry] traces.append( go.Scatter(x=sub_df[x_name], y=sub_df[y_name], text=sub_df.uid, mode='markers', marker={ 'size': 10, 'color': plotting.get_color(len(traces), 0.75) }, name='{} == {}'.format(color_name, entry))) cd.display.plotly(data=traces, layout=layout)
def comparison_plot(x_name, y_name, color_name, layout): traces = [] for entry in df[color_name].unique(): sub_df = df[df[color_name] == entry] traces.append(go.Scatter( x=sub_df[x_name], y=sub_df[y_name], text=sub_df.uid, mode='markers', marker={ 'size': 10, 'color': plotting.get_color(len(traces), 0.75) }, name='{} == {}'.format(color_name, entry) )) cd.display.plotly(data=traces, layout=layout)
def calculate_median(values, uncertainties, color_index=0, plot_name=None): """ :param values: :param uncertainties: :param color_index: :param plot_name: :return: """ try: values = values.values except: pass try: uncertainties = uncertainties.values except: pass measurements = [(val, unc) for val, unc in zip(values, uncertainties) if not np.isnan(val) and not np.isnan(unc)] values, uncertainties = zip(*measurements) measurements = mstats.values.join(values, uncertainties) dist = mstats.create_distribution(measurements) pop = mdist.population(dist) median = mstats.ValueUncertainty( mdist.percentile(pop), mdist.weighted_median_average_deviation(pop)) x = mdist.adaptive_range(dist, 4) y = dist.probabilities_at(x) trace = go.Scatter(x=x, y=y, name=plot_name, fill='tozeroy', mode='lines', line=dict(color=plotting.get_color(color_index))) return dict(measurements=measurements, median=median, trace=trace)
name=cd.shared.trackway_name ) template = """ <div style="margin:0.5em;display:flex;flex-direction:column;"> <div style="width:50px;height:40px;background-color:{color};"> </div> <div style="width:100%;text-align:center">G{index}</div> </div> """ swatches = [] for i in range(8): swatches.append(template.format( index=i, color=plotting.get_color(i) )) cd.display.html( """ <div style="display:flex;align-items:middle;justify-content:center;"> {swatches} </div> """.format( swatches=''.join(swatches) ) ) cd.display.markdown( """ The following table outlines the simulation trials run on the {{ name }}
) traces = [] for i in range(len(columns_progress)): column_progress = columns_progress[i] if i == 0: name = 'Window' elif i == (len(columns_progress) - 1): name = 'Aisle' else: name = 'Middle' traces.append(go.Scatter( x=np.arange(0, len(column_progress), 1), y=column_progress, mode='markers', marker={'color': plotting.get_color(i, 0.7)}, name=name )) cd.display.plotly( data=traces, layout=plotting.create_layout( title='Progress By "Column"', x_label='Time (s)', y_label='Progress (%)' ) )
distribution_trace = go.Scatter( x=dist_data['values']['x'], y=dist_data['values']['y'], name='Distribution', mode='lines', fill='tozeroy' ) segment_trace = go.Scatter( x=dist_data['segment']['x'], y=dist_data['segment']['y'], mode='lines', name='Region', line=go.Line( color=plotting.get_color(1, 1.0), width=4 ) ) gaussian_trace = go.Scatter( x=dist_data['gauss']['x'], y=dist_data['gauss']['y'], mode='lines', name='Region Fit', line=go.Line( color='rgba(0, 0, 0, 0.75)', dash='dash', width=3 ) )
from tracksim import paths from tracksim import reader paths.override('results', '../simulation/results') data = reader.groups() entries = [] for t in data['trials']: parts = t['id'].replace('_', '-').split('-') entries.append(dict( gait_id=parts[0], label='{}-{}'.format(*parts[:2]), rmsd=t['couplings']['rmsd'], swing=t['couplings']['swing'], color=plotting.get_color(int(parts[0][-1])), coupling_length=t['couplings']['value']['value'], uncertainty=t['couplings']['value']['uncertainty'] )) df = pd.DataFrame(entries).sort_values(by=['coupling_length', 'gait_id']) df['order'] = np.arange(0, df.shape[0], 1) cd.shared.df = df cd.display.table(df)
""" ## Maximum Spreads It would be easy to assume that there is a correlation between high width spreads and high length spreads. However, plotting them against each other reveals a very weak correlation. """ ) cd.display.plotly( data=go.Scatter( x=trackways_df['length_spread'], y=trackways_df['width_spread'], mode='markers', marker=dict( color=plotting.get_color(2) ), text=trackways_df['trackway'] ), layout=plotting.create_layout( {'hovermode': 'closest'}, title='Width versus Length Spreads Per Trackway', x_label='Length Spreads (%)', y_label='Width Spreads (%)' ) ) cd.display.markdown( """ Looking at maximum spreads, we get a median value of {{ median }}%, which is larger than either the length or the width values.
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)
normalized = [100.0 * (v / median - 1.0) for v in d.measurements] normalized_values += normalized x_values = list(np.arange(1, len(normalized), 1)) y_values, y_uncertainties = mstats.values.unzip(normalized) traces.append(go.Bar( x=x_values, y=y_values, error_y=dict( type='data', array=y_uncertainties, visible=True ), name=key.split('-')[0], marker=dict( color=plotting.get_color(len(traces), 0.5) ) )) d = mstats.create_distribution(normalized_values) mad = mstats.distributions.weighted_median_average_deviation(d, count=2048) result = mstats.ValueUncertainty(0, mad) project.display.text( """ Finally, the overall width and height measurements were analyzed in the same fashion as the above results. The result is that they exhibit the same low and reasonable ±3% variance as the digit length measurements. """ )
def create_scatter( data_frame: pd.DataFrame, value_column: typing.Union[str, list], uncertainty_column: typing.Union[str, list] = None, x_column: typing.Union[str, list] = None, sort_by: typing.Union[str, list] = 'separation' ): """ Create a scatter plot for each row in the specified data frame where the x, y and y uncertainty values are defined by column names or a Series/list where the elements match the order of the entries in the data frame. :param data_frame: :param value_column: :param uncertainty_column: :param x_column: :param sort_by: :return: """ traces = [] data_frame = data_frame.copy() # type: pd.DataFrame ids = data_frame.id.tolist() for index, gait_id in enumerate(sorted(data_frame.gait_id.unique())): df_slice = data_frame[data_frame.gait_id == gait_id] if sort_by: df_slice = df_slice.sort_values(by=sort_by) if isinstance(uncertainty_column, str): uncertainties = df_slice[uncertainty_column] elif uncertainty_column is None: uncertainties = None else: uncertainties = [ uncertainty_column[ids.index(tid)] for tid in df_slice.id ] if isinstance(value_column, str): values = df_slice[value_column] else: values = [ value_column[ids.index(tid)] for tid in df_slice.id ] if x_column is None: x = df_slice.order elif isinstance(x_column, str): x = df_slice[x_column] else: x = [ x_column[ids.index(tid)] for tid in df_slice.id ] if uncertainty_column: error_y = { 'type': 'data', 'visible': True, 'array': uncertainties } else: error_y = { 'visible': False } traces.append(go.Scatter( x=x, y=values, error_y=error_y, mode='markers', marker={ 'size': 6, 'color': plotting.get_color(index) }, text=df_slice.short_id, name=gait_id )) return traces
short_id = '{}-{} ({}%)'.format(gait_id, separation, duty_cycle) t['short_id'] = short_id df.append( dict(id=t['id'], short_id=short_id, duty_cycle=duty_cycle, gait_id=gait_id, gait_index=int(gait_id[1]), gait_name=gait_name, separation=separation, coupling_length=t['couplings']['value']['value'], uncertainty=t['couplings']['value']['uncertainty'], start_time=t['times']['cycles'][0], end_time=t['times']['cycles'][-1], color=plotting.get_color(int(gait_id[1])))) def redundant_filter(row): """ :param row: :return: """ if row.gait_index in [0, 4] and row.duty_cycle > 50: # Remove trots and paces with DC > 50% because they are duplicates return False if row.duty_cycle > 60 and row.gait_index in [1, 2, 5, 6]: # Remove with DC > 0.5 because they are duplicates
name=cd.shared.trackway_name ) template = """ <div style="margin:0.5em;display:flex;flex-direction:column;"> <div style="width:50px;height:40px;background-color:{color};"> </div> <div style="width:100%;text-align:center">G{index}</div> </div> """ swatches = [] for i in range(8): swatches.append(template.format( index=i, color=plotting.get_color(i) )) cd.display.html( """ <div style="display:flex;align-items:middle;justify-content:center;"> {swatches} </div> """.format( swatches=''.join(swatches) ) ) cd.display.markdown( """ The following table outlines the simulation trials run on the {{ name }}
short_id = '{}-{} ({}%)'.format(gait_id, separation, duty_cycle) t['short_id'] = short_id df.append(dict( id=t['id'], short_id=short_id, duty_cycle=duty_cycle, gait_id=gait_id, gait_index=int(gait_id[1]), gait_name=gait_name, separation=separation, coupling_length=t['couplings']['value']['value'], uncertainty=t['couplings']['value']['uncertainty'], start_time=t['times']['cycles'][0], end_time=t['times']['cycles'][-1], color=plotting.get_color(int(gait_id[1])) )) def redundant_filter(row): """ :param row: :return: """ if row.gait_index in [0, 4] and row.duty_cycle > 50: # Remove trots and paces with DC > 50% because they are duplicates return False if row.duty_cycle > 60 and row.gait_index in [1, 2, 5, 6]:
import numpy as np import cauldron as cd from cauldron import plotting import pandas as pd from tracksim import paths from tracksim import reader paths.override('results', '../simulation/results') data = reader.groups() entries = [] for t in data['trials']: parts = t['id'].replace('_', '-').split('-') entries.append( dict(gait_id=parts[0], label='{}-{}'.format(*parts[:2]), rmsd=t['couplings']['rmsd'], swing=t['couplings']['swing'], color=plotting.get_color(int(parts[0][-1])), coupling_length=t['couplings']['value']['value'], uncertainty=t['couplings']['value']['uncertainty'])) df = pd.DataFrame(entries).sort_values(by=['coupling_length', 'gait_id']) df['order'] = np.arange(0, df.shape[0], 1) cd.shared.df = df cd.display.table(df)
of different simulation trials. The per-gait color scheme shown below will be used when plotting per-trial results for comparison. """, name=cd.shared.trackway_name) template = """ <div style="margin:0.5em;display:flex;flex-direction:column;"> <div style="width:50px;height:40px;background-color:{color};"> </div> <div style="width:100%;text-align:center">G{index}</div> </div> """ swatches = [] for i in range(8): swatches.append(template.format(index=i, color=plotting.get_color(i))) cd.display.html(""" <div style="display:flex;align-items:middle;justify-content:center;"> {swatches} </div> """.format(swatches=''.join(swatches))) cd.display.markdown(""" The following table outlines the simulation trials run on the {{ name }} trackway. Gaits are uniquely identified in terms of their gait identifier, separation and duty cycle values. The table has been sorted by median coupling lengths for each trial. """, name=cd.shared.trackway_name)
for key in ['Width-Box', 'Height-Box']: d = mstats.create_distribution(measurements=df[key].tolist(), uncertainties=5) median = mstats.distributions.percentile(d) normalized = [100.0 * (v / median - 1.0) for v in d.measurements] normalized_values += normalized x_values = list(np.arange(1, len(normalized), 1)) y_values, y_uncertainties = mstats.values.unzip(normalized) traces.append( go.Bar(x=x_values, y=y_values, error_y=dict(type='data', array=y_uncertainties, visible=True), name=key.split('-')[0], marker=dict(color=plotting.get_color(len(traces), 0.5)))) d = mstats.create_distribution(normalized_values) mad = mstats.distributions.weighted_median_average_deviation(d, count=2048) result = mstats.ValueUncertainty(0, mad) project.display.text(""" Finally, the overall width and height measurements were analyzed in the same fashion as the above results. The result is that they exhibit the same low and reasonable ±3% variance as the digit length measurements. """) project.display.plotly(data=traces, layout=plotting.create_layout( title='Size Measurements Deviations ({}%)'.format( result.html_label.split(' ', 1)[-1]),
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 df = cd.shared.data plot_collection = cd.shared.plot_collection df = df[df.collection == 'twogis'].copy() labels = [] for index, row in df.iterrows(): labels.append('{}G {}'.format(row.group_count, row.trial_label)) df['trial_label'] = labels plot_collection( df[df.collection == 'twogis'], title='Seating & Interchange Delay Trials', color_column='group_count', color_values={ 1: plotting.get_color(0), 2: plotting.get_color(1), 3: plotting.get_color(2), 4: plotting.get_color(3), 5: plotting.get_color(4), 6: plotting.get_color(5), 8: plotting.get_color(6), 10: plotting.get_color(7), 'default': plotting.get_color(8) } )