コード例 #1
0
    def corrConvergencePlot(self, simId, scenario, resultName):
        df = self.getCorrByTrials(simId, scenario, resultName)
        params = list(df['paramName'].unique())
        traces = []

        count = max(df['count'])

        # create a trace for each parameter
        for paramName in params:
            paramData = df.query('paramName == "%s"' % paramName)
            trace = go.Scatter(x=list(paramData['count']),
                               y=list(paramData['spearman']),
                               name=paramName,
                               mode='lines')
            traces.append(trace)

        # Round up to nearest integral value of CORR_STEP
        endX = count + (CORR_STEP - count % CORR_STEP)

        # I cannot center a narrower plot for reasons I don't understand
        layout = updateStyle('Plot',
                             width=None,
                             title='Correlation Convergence for %s' %
                             resultName,
                             xaxis=dict(range=[CORR_STEP, endX]))
        # margin=updateStyle('PlotMargin', l=40)

        figure = dict(data=traces, layout=layout)
        return figure
コード例 #2
0
    def tornadoPlot(self, simId, scenario, resultName, tornadoType,
                    sliderValue, selectedData):
        corrDF = self.getCorrDF(simId, scenario, resultName)

        if tornadoType == 'normalized':
            squared = corrDF.spearman**2
            corrDF['normalized'] = squared / squared.sum()
            corrDF['sign'] = 1
            corrDF.ix[(corrDF.spearman < 0), 'sign'] = -1
            corrDF[
                'value'] = corrDF.normalized * corrDF.sign  # normalized squares with signs restored
            plotColumn = 'value'
            title = 'Normalized rank correlation'
        else:
            plotColumn = 'spearman'
            title = 'Rank correlation'

        title += ' of {} for scenario {}'.format(resultName, scenario)

        varCount = min(
            20, len(corrDF)
        )  # if sliderValue is None else len(corrDF[corrDF['abs'] >= sliderValue]))
        varNames = list(reversed(corrDF.index[:varCount]))
        values = list(reversed(corrDF[plotColumn][:varCount]))

        plotData = go.Bar(
            orientation='h',
            x=values,
            y=varNames,
            width=0.6,
            marker=dict(
                color=getColor('TornadoPlotBar'),
                line=dict(color=getColor('TornadoPlotLine'), width=0),
            ),
            textposition='none',
            name='Rank correlation',
            hoverinfo='skip',  # prevents hover events
        )

        layout = updateStyle('Plot',
                             title=title,
                             margin=updateStyle('PlotMargin', l=300),
                             xaxis=dict(range=[-1, 1]),
                             dragmode='select')

        figure = dict(data=[plotData], layout=layout)
        return figure
コード例 #3
0
    def showDistribution(project, simId, scenario, outputName, sliderInfo,
                         distOptions, selectedData):
        _logger.debug('showDistribution(%s, %s, %s, %s, %s)' %
                      (project, simId, scenario, outputName, selectedData))

        # Clear selectedData if context changes
        context = (project, simId, scenario, outputName)
        if not data.histogramContext or context != data.histogramContext:
            _logger.debug('showDistribution: clearing context')
            selectedData = sliderInfo = None
            data.histogramContext = context

        # if called before values are known, return an empty plot
        if not (project and scenario and outputName) or simId is None:
            plotData = {'x': []}
            title = 'Please select a model output to plot'
            annotations = None
        else:
            plotData, title, annotations = data.distPlot(
                simId, scenario, outputName, sliderInfo, distOptions,
                selectedData)
        # TBD: generalize this
        if Oct16:
            if outputName == 'percent-change':
                xtitle = 'Change from baseline fuel'
                xticksuffix = '%'
            else:
                # latex formatting is broken, but HTML works fine
                # xtitle = '$g CO_2 MJ^{-1}$' if Oct16 else ''
                xtitle = 'g CO<sub>2</sub> MJ<sup>-1</sup>'
                xticksuffix = None
        else:
            xtitle = data.db.getOutputUnits(outputName)
            xticksuffix = ''

        layout = updateStyle('Plot',
                             title=title,
                             yaxis={
                                 'title': 'Probability density',
                                 'tickvals': []
                             },
                             xaxis={
                                 'title': xtitle,
                                 'ticksuffix': xticksuffix,
                             },
                             margin=getStyle('PlotMarginWithXTitle'),
                             dragmode='select',
                             showLegend=True,
                             legend=dict(x=0.0,
                                         y=1.0,
                                         bgcolor=getColor('PlotBg')))

        if annotations:
            layout['annotations'] = annotations

        figure = dict(data=plotData, layout=layout)
        return figure
コード例 #4
0
 def tornadoSectionLayout(self):
     layout = [
         html.P([
             html.Span(
                 'Adjust the number of variables to show by setting the correlation cut-off'
             ),
             html.Span(id='corr-cutoff-text')
         ],
                style=updateStyle(
                    'HelpText', display='none')),  # getStyle('HelpText')),
         html.Div([
             html.Div(
                 [
                     dcc.Slider(id='tornado-slider',
                                disabled=True,
                                min=0,
                                max=0.4,
                                step=0.01,
                                marks={
                                    value: sliderLabel(value)
                                    for value in np.arange(0, 0.4, 0.1)
                                },
                                updatemode='drag',
                                value=0.01),
                 ],
                 style={
                     'width': 300,
                     # 'display': 'inline-block'
                     'display': 'none'
                 }),
         ]),
         html.Div(dcc.Graph(id='tornado'), style={'margin-top':
                                                  74}),  # 20}),
         dcc.RadioItems(id='tornado-type-chooser',
                        options=[{
                            'label': 'Rank correlation',
                            'value': 'spearman'
                        }, {
                            'label': 'Normalized',
                            'value': 'normalized'
                        }],
                        value='normalized',
                        labelStyle={
                            'display': 'inline-block',
                            'margin': '6px'
                        })
     ]
     return layout
コード例 #5
0
    def layout(self):
        layout = html.Div(
            [
                dataStore(id='paraCoords-vars'),
                dataStore(id='dist-selected'),
                html.H1('Monte Carlo Simulation Explorer', className='title'),
                html.Table(
                    [
                        html.Tr([
                            html.Th('Project'),
                            html.Th('Simulation'),
                            html.Th('Scenario'),
                            html.Th('Model Output'),
                        ]),
                        html.Tr([
                            html.Td(self.projectChooser()),
                            html.Td(self.simChooser()),
                            html.Td(self.scenarioChooser()),
                            html.Td(self.outputChooser())
                        ])
                    ],
                    style={
                        'width': '100%',
                        'border': '1px solid black',
                        'table-layout': 'fixed',
                        'background-color': getColor('ChooserBgColor')
                    }),
                html.Div(
                    [
                        # distribution cluster and tornado chart
                        html.Div([
                            html.Div(self.distributionSectionLayout(),
                                     className='cell twocol'),
                            html.Div(self.tornadoSectionLayout(),
                                     className='cell twocol')
                        ],
                                 className='row'),

                        # parallel coordinates section
                        html.Div([
                            html.Div([
                                html.P([
                                    'Brush vertically over ranges to filter; click outside the selected range to reset. ',
                                    'Drag variable names below to reorder. Slider sets the number of vars to plot'
                                ],
                                       style=getStyle('HelpText')),
                                html.Div(
                                    [
                                        dcc.Slider(
                                            id='paraCoords-slider',
                                            min=1,
                                            max=10,
                                            step=1,
                                            marks={
                                                value:
                                                sliderLabel(value)
                                                for value in range(1, 11, 1)
                                            },
                                            updatemode='drag',
                                            value=6),
                                    ],
                                    style={
                                        'margin-bottom': 30,
                                        'margin-left': 'auto',
                                        'margin-right': 'auto',
                                        'width': 400
                                    }),
                                html.Div(dcc.Graph(id='paraCoords')),
                            ],
                                     className='cell onecol')
                        ],
                                 className='row'),

                        # Correlation convergence section
                        html.Div([
                            html.Div([
                                html.Span('Correlation convergence',
                                          style=getStyle('Label')),
                                html.Div('', style={'height': 15}),
                                html.Div(dcc.Graph(id='corr-convergence')),
                            ],
                                     className='cell onecol')
                        ],
                                 className='row'),

                        # Scatterplot section
                        html.Div([
                            html.Div([
                                html.Div([
                                    html.Div(style={'height': 15}),
                                    html.Span(
                                        'Model Inputs (random variables)',
                                        style=getStyle('Label')),
                                    html.Div(style={'height': 15}),
                                    self.inputChooser(multi=True)
                                ],
                                         style=updateStyle('Chooser',
                                                           width=900)),
                                html.Div(style={'height': 15}),
                                html.Div([
                                    html.Span('Model Outputs',
                                              style=getStyle('Label')),
                                    self.multiOutputChooser()
                                ],
                                         style=updateStyle('Chooser',
                                                           width=900)),
                                html.Div([
                                    html.Button('Create scatterplot',
                                                id='scatterplot-button',
                                                style=getStyle('Button'))
                                ],
                                         style={'margin': 5}),
                                html.Div([dcc.Graph(id='scatter-matrix')],
                                         style=updateStyle('AutoMargins'))
                            ],
                                     className='cell onecol')
                        ],
                                 className='row'),
                    ],
                    className='table',
                    style={
                        'width': 1200,
                        'margin-left': 'auto',
                        'margin-right': 'auto'
                    }),
            ],
            style=getStyle('Page'))

        return layout