How to use the calliope.core.util.dataset.split_loc_techs function in calliope

To help you get started, we’ve selected a few calliope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github calliope-project / calliope / calliope / analysis / postprocess.py View on Github external
----------
    results : xarray.Dataset
        Model results
    model_data : xarray.Dataset
        Model input data
    total : bool, optional
        If False (default) returns per-technology levelised cost, if True,
        returns overall system-wide levelised cost.

    """
    cost = results['cost']
    # Here we scale production by timestep weight
    carrier_prod = results['carrier_prod'] * model_data.timestep_weights

    if total:
        cost = split_loc_techs(cost).sum(dim=['locs', 'techs'])
        supply_only_carrier_prod = carrier_prod.sel(
            loc_tech_carriers_prod=list(model_data.loc_tech_carriers_supply_conversion_all.values)
        )
        carrier_prod = split_loc_techs(supply_only_carrier_prod).sum(dim=['timesteps', 'locs', 'techs'])
    else:
        cost = split_loc_techs(cost).sum(dim=['locs'])
        carrier_prod = split_loc_techs(carrier_prod).sum(['timesteps', 'locs'])

    levelised_cost = []

    for carrier in carrier_prod['carriers'].values:
        levelised_cost.append(cost / carrier_prod.loc[dict(carriers=carrier)])

    return xr.concat(levelised_cost, dim='carriers')
github calliope-project / calliope / calliope / core / time / masks.py View on Github external
if kwargs is not None:
        subset.update({k: v for k, v in kwargs.items()})

    unusable_dims = (
        set(subset.keys())
        .difference(["techs", "locs"])
        .difference(data[var].dims)
    )
    if unusable_dims:
        raise exceptions.ModelError(
            'Attempting to mask time based on  technology {}, '
            'but dimension(s) {} do not exist for parameter {}'.format(
                tech, unusable_dims, var.name)
        )

    arr = split_loc_techs(data[var].copy()).loc[subset]
    arr = arr.mean(dim=[i for i in arr.dims if i is not 'timesteps']).to_pandas()
    return arr
github calliope-project / calliope / calliope / analysis / postprocess.py View on Github external
model duration, for the given results, indexed by techs and carriers.

    The weight of timesteps is considered when computing capacity factors,
    such that higher-weighted timesteps have a stronger influence
    on the resulting system-wide time-averaged capacity factor.

    """
    # In operate mode, energy_cap is an input parameter
    if 'energy_cap' not in results.keys():
        energy_cap = model_data.energy_cap
    else:
        energy_cap = results.energy_cap

    prod_sum = (
        # Aggregated/clustered days are represented `timestep_weights` times
        split_loc_techs(results['carrier_prod']) * model_data.timestep_weights
    ).sum(dim='timesteps').sum(dim='locs')
    cap_sum = split_loc_techs(energy_cap).sum(dim='locs')
    time_sum = (model_data.timestep_resolution * model_data.timestep_weights).sum()

    capacity_factors = prod_sum / (cap_sum * time_sum)

    return capacity_factors
github calliope-project / calliope / calliope / core / io.py View on Github external
# a MILP model which optimises to within the MIP gap, but does not fully
    # converge on the LP relaxation, may return as 'feasible', not 'optimal'
    if ('termination_condition' not in model_data.attrs or
            model_data.attrs['termination_condition'] in ['optimal', 'feasible']):
        data_vars = model_data.data_vars
    else:
        data_vars = model_data.filter_by_attrs(is_result=0).data_vars
        exceptions.warn(
            'Model termination condition was not optimal, saving inputs only.'
        )

    for var in data_vars:
        in_out = 'results' if model_data[var].attrs['is_result'] else 'inputs'
        out_path = os.path.join(path, '{}_{}.csv'.format(in_out, var))
        series = split_loc_techs(model_data[var], return_as='Series')
        if dropna:
            series = series.dropna()
        series.to_csv(out_path, header=True)
github calliope-project / calliope / calliope / analysis / postprocess.py View on Github external
Model input data
    total : bool, optional
        If False (default) returns per-technology levelised cost, if True,
        returns overall system-wide levelised cost.

    """
    cost = results['cost']
    # Here we scale production by timestep weight
    carrier_prod = results['carrier_prod'] * model_data.timestep_weights

    if total:
        cost = split_loc_techs(cost).sum(dim=['locs', 'techs'])
        supply_only_carrier_prod = carrier_prod.sel(
            loc_tech_carriers_prod=list(model_data.loc_tech_carriers_supply_conversion_all.values)
        )
        carrier_prod = split_loc_techs(supply_only_carrier_prod).sum(dim=['timesteps', 'locs', 'techs'])
    else:
        cost = split_loc_techs(cost).sum(dim=['locs'])
        carrier_prod = split_loc_techs(carrier_prod).sum(['timesteps', 'locs'])

    levelised_cost = []

    for carrier in carrier_prod['carriers'].values:
        levelised_cost.append(cost / carrier_prod.loc[dict(carriers=carrier)])

    return xr.concat(levelised_cost, dim='carriers')
github calliope-project / calliope / calliope / analysis / postprocess.py View on Github external
The weight of timesteps is considered when computing capacity factors,
    such that higher-weighted timesteps have a stronger influence
    on the resulting system-wide time-averaged capacity factor.

    """
    # In operate mode, energy_cap is an input parameter
    if 'energy_cap' not in results.keys():
        energy_cap = model_data.energy_cap
    else:
        energy_cap = results.energy_cap

    prod_sum = (
        # Aggregated/clustered days are represented `timestep_weights` times
        split_loc_techs(results['carrier_prod']) * model_data.timestep_weights
    ).sum(dim='timesteps').sum(dim='locs')
    cap_sum = split_loc_techs(energy_cap).sum(dim='locs')
    time_sum = (model_data.timestep_resolution * model_data.timestep_weights).sum()

    capacity_factors = prod_sum / (cap_sum * time_sum)

    return capacity_factors