def get_segment_traces(group, segment):
    color = display.COLORS[group.index % len(display.COLORS)]
    return plotting.make_segment_traces(
        pes_tracks,
        segment,
        color=color,
        name='Gauge #{}'.format(group.index + 1),
        show_legend=(group.segments.index(segment) < 1),
        legend_group='gauge-group-{}'.format(group.index))
Пример #2
0
def compute_unweighted(
        tracks: pd.DataFrame,
        tolerance_fraction: float
) -> dict:
    """ """

    pes_tracks = tracks[tracks['pes'] == 1].copy()  # type: pd.DataFrame
    tolerance = 0.5 * tolerance_fraction * np.median(pes_tracks['width'].values)
    pes_tracks['tolerance'] = tolerance

    scatter_trace = plotting.create_scatter(
        pes_tracks['curvePosition'],
        pes_tracks['simpleGauge'],
        color='rgba(200, 200, 200, 1)',
        name='Gauges'
    )

    segments = forward_windowing.compute(
        pes_tracks['simpleGauge'].tolist(),
        pes_tracks['tolerance'].tolist(),
        weighted=False
    )

    segment_traces = [
        trace
        for s in segments
        for trace in plotting.make_segment_traces(pes_tracks, s)
    ]

    return dict(
        segments=segments,
        data=[scatter_trace] + segment_traces,
        layout=go.Layout(
            xaxis={'title': 'Trackway Position (m)'},
            yaxis={'title': 'Gauge (m)'}
        )
    )
Пример #3
0
layout = go.Layout(
    title='{} Pes Gauge Values Along Trackway'.format(trackway_name),
    xaxis={'title': 'Trackway Position (m)'},
    yaxis={'title': 'Gauge (m)'})

scatter_trace = plotting.create_scatter(pes_tracks['curvePosition'],
                                        pes_tracks['simpleGauge'],
                                        pes_tracks['simpleGaugeUnc'],
                                        color='rgba(200, 200, 200, 1)',
                                        name='Gauges')

segments = forward_windowing.compute(pes_tracks['simpleGauge'].tolist(),
                                     pes_tracks['simpleGaugeUnc'].tolist())
segment_traces = [
    trace for s in segments
    for trace in plotting.make_segment_traces(pes_tracks, s)
]

cd.display.markdown("""
    ## Segmentation with Uncertainties

    The first, and most crucial, change to make to the analysis is to introduce
    uncertainties into the clustering process. Their introduction allows us to
    segment using statistical significance instead of an arbitrary assigned
    tolerance.
    """)

cd.display.plotly(data=[scatter_trace] + segment_traces, layout=layout)

cd.display.markdown("""
    The result of uncertainty-based clustering differs substantially from
    tracks['simpleGauge'],
    tracks['simpleGaugeUnc'],
    color='rgba(200, 200, 200, 1)',
    name='Gauges'
)

forward_segments = forward_windowing.compute(
    tracks['simpleGauge'].tolist(),
    tracks['simpleGaugeUnc'].tolist()
)

cd.display.plotly(
    data=[scatter_trace] + [
        trace
        for s in forward_segments
        for trace in plotting.make_segment_traces(tracks, s)
    ],
    layout=layout
)

layout = go.Layout(
    title='Precision-Window Gauge Clustering',
    xaxis={'title': 'Trackway Position (m)'},
    yaxis={'title': 'Gauge (m)'}
)

scatter_trace = plotting.create_scatter(
    tracks['curvePosition'],
    tracks['simpleGauge'],
    tracks['simpleGaugeUnc'],
    color='rgba(200, 200, 200, 1)',