Ejemplo n.º 1
0
def plot_timeseries(
        model, array='all', timesteps_zoom=None, rangeslider=False,
        subset={}, sum_dims='locs',
        squeeze=True, **kwargs):
    """
    Parameters
    ----------
    array : str or list; default = 'all'
        options: 'all', 'results', 'inputs', the name/list of any energy carrier(s)
        (e.g. 'power'), the name/list of any input/output DataArray(s).

        User can specify 'all' for all input/results timeseries plots, 'inputs'
        for just input timeseries, 'results' for just results timeseries, or the
        name of any data array to plot (in either inputs or results).
        In all but the last case, arrays can be picked from dropdown in visualisation.
        In the last case, output can be saved to SVG and a rangeslider can be used.

    timesteps_zoom : int, optional
        Number of timesteps to show initially on the x-axis (if not
        given, the full time range is shown by default).
    rangeslider : bool, optional
        If True, displays a range slider underneath the plot for navigating
        (helpful primarily in interactive use).
    subset : dict, optional
        Dictionary by which data is subset (uses xarray `loc` indexing). Keys
        any of ['timeseries', 'locs', 'techs', 'carriers', 'costs'].
    sum_dims : str, optional
        List of dimension names to sum plot variable over.
    squeeze : bool, optional
        Whether to squeeze out dimensions of length = 1.

    """

    dataset = model._model_data.copy()

    timesteps = pd.to_datetime(model._model_data.timesteps.values)

    layout = dict(
        barmode='relative', xaxis={}, autosize=True,
        legend=(dict(traceorder='reversed', xanchor='left')), hovermode='x'
    )
    # Clustered data does not get plotted on a datetime axis
    if 'clusters' in dataset.dims:
        layout.update(get_clustered_layout(dataset))

    relevant_vars = _get_relevant_vars(model, dataset, array)

    data, layout = get_data_layout(
        _get_var_data, _get_var_layout, relevant_vars,
        layout, model, dataset,
        subset, sum_dims, squeeze,
    )

    if rangeslider:
        layout['xaxis']['rangeslider'] = {}

    if timesteps_zoom:
        layout['xaxis']['range'] = [timesteps[0], timesteps[timesteps_zoom]]

    return data, layout
Ejemplo n.º 2
0
def _get_var_layout(var, dataset):
    """
    Variable-specific layout. Increases axis verbosity for some known variables.
    `visible` used in dropdown, not if only one array is shown.

    """
    args = {}
    if var in dataset.carriers.values:
        title = 'Carrier flow: {}'.format(var)
        y_axis_title = 'Energy produced(+) / consumed(-)'
    elif var == 'resource':
        title = 'Available resource'
        y_axis_title = 'Energy (per unit of area)'
    elif var == 'resource_con':
        title = 'Consumed resource'
        y_axis_title = 'Energy'
    elif var == 'cost_var':
        title = 'Variable costs'
        y_axis_title = 'Cost'
    elif var == 'storage_inter_cluster':
        title = 'Storage at start of each day in unclustered timeseries'
        y_axis_title = 'Stored energy'
        args.update({'xaxis': {'type': 'date'}})
    else:
        title = y_axis_title = '{}'.format(var).capitalize()

    if 'clusters' in dataset.dims and var != 'storage_inter_cluster':
        args.update(get_clustered_layout(dataset))

    args.update({'yaxis': dict(title=y_axis_title), 'title': title})

    return args