コード例 #1
0
def test_timeseries_plots_xy(report_with_raw_xy):
    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        report_with_raw_xy)
    assert isinstance(ts_spec, str)
    assert isinstance(scatter_spec, str)
    assert isinstance(ts_prob_spec, str)
    assert inc_dist
コード例 #2
0
def test_timeseries_plots_only_x_axis_data(report_with_raw_xy):
    pfxobs = report_with_raw_xy.raw_report.processed_forecasts_observations
    only_x = report_with_raw_xy.replace(
        raw_report=report_with_raw_xy.raw_report.replace(
            processed_forecasts_observations=tuple(
                pair for pair in pfxobs
                if pair.original.forecast.axis == 'x')))

    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        only_x)
    ts_spec_dict = json.loads(ts_spec)
    obs_names = sorted(
        list(
            set(
                figures._legend_text(fxobs.original.observation.name)
                if hasattr(fxobs.original, 'observation') else figures.
                _legend_text(fxobs.original.aggregate.name)
                for fxobs in pfxobs)))
    # assert that only observations appear on the timeseries plot
    assert len(ts_spec_dict['data']) == len(obs_names)
    assert [p['name'] for p in ts_spec_dict['data']] == obs_names

    assert isinstance(ts_spec, str)
    assert scatter_spec is None
    assert isinstance(ts_prob_spec, str)
    assert not inc_dist
コード例 #3
0
def test_timeseries_plots_event_data(event_report_with_raw):
    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        event_report_with_raw)
    assert isinstance(ts_spec, str)
    assert isinstance(scatter_spec, str)
    assert ts_prob_spec is None
    assert not inc_dist
コード例 #4
0
def test_timeseries_plots_missing_prob_fx_data(report_with_raw_xy,
                                               report_with_raw,
                                               replace_pfxobs_attrs):
    non_cdf = report_with_raw.raw_report.processed_forecasts_observations
    missing_values = replace_pfxobs_attrs(report_with_raw_xy,
                                          forecast_values=None)
    raw = missing_values.raw_report
    missing_values = missing_values.replace(raw_report=raw.replace(
        processed_forecasts_observations=(
            raw.processed_forecasts_observations + non_cdf)))

    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        missing_values)
    ts_spec_dict = json.loads(ts_spec)
    assert len(ts_spec_dict['data'])

    # assert that only non-probabilistic forecasts and observations were
    # plotted in absence of data for probabilistic forecasts.
    plotted_names = [p['name'] for p in ts_spec_dict['data']]
    should_plot = [fxobs.original.forecast.name for fxobs in non_cdf]
    should_plot += [
        fxobs.original.observation.name if hasattr(
            fxobs.original, 'observation') else fxobs.original.aggregate.name
        for fxobs in non_cdf
    ]
    should_plot = list(map(figures._legend_text, should_plot))
    for name in plotted_names:
        assert name in should_plot

    assert isinstance(ts_spec, str)
    assert isinstance(scatter_spec, str)
    assert ts_prob_spec is None
    assert inc_dist
コード例 #5
0
def test_timeseries_plots_missing_obs_data(report_with_raw,
                                           replace_pfxobs_attrs):
    missing_obs = replace_pfxobs_attrs(report_with_raw,
                                       observation_values=None)
    _, scat_plot, _, _ = figures.timeseries_plots(missing_obs)
    # assert scatterplots are not created when obs data is missing
    assert scat_plot is None
コード例 #6
0
def test_probabilistic_plotting_asymmetric_cv(
        report_with_raw_xy_asymmetric_cv):
    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        report_with_raw_xy_asymmetric_cv)
    assert isinstance(ts_spec, str)
    assert isinstance(scatter_spec, str)
    assert isinstance(ts_prob_spec, str)
    assert inc_dist
コード例 #7
0
def _get_render_kwargs(report, dash_url, with_timeseries):
    """Creates a dictionary of key word template arguments for a jinja2
    report template.

    Parameters
    ----------
    report: :py:class:`solarforecastarbiter.datamodel.Report`
    dash_url: str
        URL of the Solar Forecast arbiter dashboard to use when building links.
    with_timeseries: bool
        Whether or not to include timeseries plots. If an error occurs when
        trying to generate timeseries plots, the `timeseries_spec`,
        `scatter_spec`, and `timeseries_prob_spec` arguments will not be
        defined.

    Returns
    -------
    kwargs: dict
        Dictionary of template variables to unpack as key word arguments when
        rendering.
    """
    kwargs = dict(
        human_categories=datamodel.ALLOWED_CATEGORIES,
        human_metrics=datamodel.ALLOWED_METRICS,
        report=report,
        category_blurbs=datamodel.CATEGORY_BLURBS,
        dash_url=dash_url,
        metrics_json=build_metrics_json(report),
    )
    report_plots = getattr(report.raw_report, 'plots', None)
    # get plotting library versions used when plots were generated.
    # if plot generation failed, fallback to the curent version
    plot_bokeh = getattr(report_plots, 'bokeh_version', None)
    kwargs['bokeh_version'] = plot_bokeh if plot_bokeh else bokeh_version

    plot_plotly = getattr(report_plots, 'plotly_version', None)
    kwargs['plotly_version'] = plot_plotly if plot_plotly else plotly_version

    if with_timeseries:
        try:
            timeseries_specs = plotly_figures.timeseries_plots(report)
        except Exception:
            logger.exception(
                'Failed to make Plotly items for timeseries and scatterplot')
        else:
            if timeseries_specs[0] is not None:
                kwargs['timeseries_spec'] = timeseries_specs[0]

            if timeseries_specs[1] is not None:
                kwargs['scatter_spec'] = timeseries_specs[1]

            if timeseries_specs[2] is not None:
                kwargs['timeseries_prob_spec'] = timeseries_specs[2]

            kwargs['includes_distribution'] = timeseries_specs[3]

    return kwargs
コード例 #8
0
def test_timeseries_plots_event_data_no_obs(event_report_with_raw,
                                            replace_pfxobs_attrs):
    event_report = replace_pfxobs_attrs(event_report_with_raw,
                                        observation_values=None)

    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        event_report)
    # assert forecast is plotted, but histogram is skipped without observation
    # data.
    assert isinstance(ts_spec, str)
    assert scatter_spec is None
    assert ts_prob_spec is None
    assert not inc_dist
コード例 #9
0
def test_timeseries_plots_missing_fx_data(report_with_raw, report_with_raw_xy,
                                          replace_pfxobs_attrs):
    missing_values = replace_pfxobs_attrs(report_with_raw,
                                          forecast_values=None)

    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        missing_values)

    # assert that all plotting is skipped if forecasts are not included.
    assert ts_spec is None
    assert scatter_spec is None
    assert ts_prob_spec is None
    assert not inc_dist
コード例 #10
0
def test_timeseries_plots_only_x_axis_data_no_obs(report_with_raw_xy,
                                                  replace_pfxobs_attrs):
    pfxobs = report_with_raw_xy.raw_report.processed_forecasts_observations
    only_x = report_with_raw_xy.replace(
        raw_report=report_with_raw_xy.raw_report.replace(
            processed_forecasts_observations=tuple(
                pair for pair in pfxobs
                if pair.original.forecast.axis == 'x')))

    only_x = replace_pfxobs_attrs(only_x, observation_values=None)
    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        only_x)
    # assert that only the probability/time plot exists, since we only had
    # forecast data with axis=x
    assert ts_spec is None
    assert scatter_spec is None
    assert isinstance(ts_prob_spec, str)
    assert not inc_dist
コード例 #11
0
def test_timeseries_plots_missing_some_fx_data(report_with_raw,
                                               report_with_raw_xy,
                                               replace_pfxobs_attrs):
    pfxobs = report_with_raw.raw_report.processed_forecasts_observations
    missing_values = report_with_raw.replace(
        raw_report=report_with_raw.raw_report.replace(
            processed_forecasts_observations=(pfxobs[0], pfxobs[1],
                                              pfxobs[2].replace(
                                                  forecast_values=None))))

    ts_spec, scatter_spec, ts_prob_spec, inc_dist = figures.timeseries_plots(
        missing_values)

    ts_spec_dict = json.loads(ts_spec)
    missing_fx = pfxobs[-1].original.forecast

    # assert missing forecast does not exist in the data/legend when it's name
    # is still available as metadata.
    assert missing_fx.name not in [k['name'] for k in ts_spec_dict['data']]
    assert isinstance(ts_spec, str)
    assert isinstance(scatter_spec, str)
    assert ts_prob_spec is None
    assert not inc_dist