Пример #1
0
def predict_electricity_emission_factor(variables, datasets):
    """
    df = datasets['ghg_emissions']
    df = df[df.Kaupunki == variables['municipality_name']].drop(columns='Kaupunki')
    df = df[df.Sektori1 == 'Sähkö']
    df['EmissionFactor'] = df['Päästöt'] / df['Energiankulutus'] * 1000
    print(df.groupby('Vuosi')[['Päästöt', 'Energiankulutus']].sum())
    s = df.groupby('Vuosi')['EmissionFactor'].mean()
    print(s)
    df = pd.DataFrame(s)
    """

    PAST_VALUES = [
        214.60, 261.20, 285.80, 349.80, 298.30, 205.00, 307.90, 278.50, 214.40,
        229.10, 269.80, 226.90, 166.90, 199.90, 173.10, 134.90, 146.00, 131.40
    ]
    START_YEAR = 2000

    df = pd.DataFrame(PAST_VALUES,
                      index=range(START_YEAR, START_YEAR + len(PAST_VALUES)),
                      columns=['EmissionFactor'])

    df['Forecast'] = False
    start_year = find_consecutive_start(df.index)
    df = df.reindex(pd.Index(range(start_year, variables['target_year'] + 1)))
    df.Forecast = df.Forecast.fillna(True)
    df.loc[2030, 'EmissionFactor'] = 70  # g CO2e/kWh
    df.loc[2035, 'EmissionFactor'] = 45  # g CO2e/kWh

    df['EmissionFactor'] = df['EmissionFactor'].interpolate()

    return df
Пример #2
0
    def get_traces_for_series(self, series: PredictionFigureSeries, index: int,
                              has_multiple_series: bool):
        df = series.df

        trace_attrs = {}
        if self.stacked or self.fill:
            if self.stacked and index > 0:
                trace_attrs['fill'] = 'tonexty'
            else:
                trace_attrs['fill'] = 'tozeroy'

        if self.fill:
            trace_attrs['mode'] = 'none'
        else:
            trace_attrs['mode'] = 'lines'

        if self.allow_nonconsecutive_years:
            start_year = df.index.min()
        else:
            start_year = find_consecutive_start(df.index)

        y_column = series.column_name
        hist_series = df.loc[~df.Forecast & (df.index >= start_year),
                             y_column].dropna()

        hovertemplate = '%{x}: %{y}'
        if self.unit_name:
            hovertemplate += ' %s' % self.unit_name

        traces = []
        line_attrs = dict(width=4)
        if self.smoothing:
            line_attrs.update(dict(smoothing=1, shape='spline'))

        if len(hist_series):
            color = series.get_color(forecast=False)

            if self.stacked:
                trace_attrs['stackgroup'] = 'history'
            if self.fill:
                trace_attrs['fillcolor'] = color

            hist_trace = dict(type='scatter',
                              x=hist_series.index.astype(str),
                              y=hist_series,
                              name=series.trace_name,
                              hovertemplate=hovertemplate,
                              line=dict(
                                  color=color,
                                  **line_attrs,
                              ),
                              **trace_attrs)

            traces.append(hist_trace)
            last_hist_year = hist_series.index.max()
            forecast_series = df.loc[df.Forecast |
                                     (df.index == last_hist_year), y_column]
        else:
            forecast_series = df.loc[df.Forecast, y_column]

        forecast_series = forecast_series.dropna()
        if len(forecast_series):
            color = series.get_color(forecast=True)

            if self.stacked:
                trace_attrs['stackgroup'] = 'forecast'
            if self.fill:
                trace_attrs['fillcolor'] = color
            else:
                line_attrs['dash'] = 'dash'

            forecast_trace = dict(type='scatter',
                                  x=forecast_series.index.astype(str),
                                  y=forecast_series,
                                  name='%s (enn.)' % series.trace_name,
                                  hovertemplate=hovertemplate,
                                  line=dict(
                                      color=color,
                                      **line_attrs,
                                  ),
                                  showlegend=False,
                                  **trace_attrs)
            traces.insert(0, forecast_trace)

        return traces
Пример #3
0
def predict_geothermal_production(variables, datasets):
    target_year = variables['target_year']
    yearly_renovation = variables['geothermal_existing_building_renovation'] / 100
    new_building_geothermal_percentage = variables['geothermal_new_building_installation_share'] / 100

    old_heat_use_df = generate_heat_use_per_net_area_forecast_existing_buildings()
    new_heat_use_df = generate_heat_use_per_net_area_forecast_new_buildings()
    building_df = generate_building_floor_area_forecast()
    hist_geo = get_historical_production()

    DH_PERCENTAGE = 0.85

    df = building_df.copy()
    hist_df = df[~df.Forecast]
    last_historical_year = hist_geo.index.max()

    last_area = df.loc[last_historical_year]
    dh_area = last_area.sum() * DH_PERCENTAGE

    dh_left = dh_area.copy()
    geo = pd.Series()
    for year in range(last_historical_year + 1, target_year + 1):
        dh_left *= (1 - yearly_renovation)
        geo.loc[year] = float(dh_area - dh_left)

    df = pd.DataFrame()
    df['GeoBuildingNetAreaExisting'] = geo
    s = df['GeoBuildingNetAreaExisting'] * old_heat_use_df['HeatUsePerNetArea'] / 1000000  # kWh -> GWh
    df['GeoEnergyProductionExisting'] = s

    bdf = building_df.loc[building_df.index >= last_historical_year]
    bdf = bdf.drop(columns='Forecast').sum(axis=1)
    bdf = bdf.diff().dropna()

    df['GeoBuildingNetAreaNew'] = (bdf * new_building_geothermal_percentage).cumsum()
    df['GeoEnergyProductionNew'] = df['GeoBuildingNetAreaNew'] * new_heat_use_df / 1000000  # kWh -> GWh

    df['GeoBuildingNetAreaNew'] /= 1000000
    df['GeoBuildingNetAreaExisting'] /= 1000000

    ep = df['GeoEnergyProductionExisting']
    ep = hist_geo.append(ep).sort_index()
    start_year = find_consecutive_start(hist_geo.index)
    df = df.reindex(range(start_year, df.index.max() + 1))
    df['GeoEnergyProductionExisting'] = ep
    df['GeoEnergyProduction'] = df['GeoEnergyProductionNew'].fillna(0) + df['GeoEnergyProductionExisting']

    df['ElectricityUse'] = df['GeoEnergyProduction'] / variables['geothermal_heat_pump_cop']
    edf = predict_electricity_emission_factor()
    df['Emissions'] = df['ElectricityUse'] * edf['EmissionFactor'] / 1000
    dhdf, _ = calc_district_heating_unit_emissions_forecast()
    df['EmissionReductions'] = df['GeoEnergyProduction'] * dhdf['Emission factor'] / 1000
    df['NetEmissions'] = df['Emissions'] - df['EmissionReductions']

    production_per_hole = get_borehole_production(variables['geothermal_borehole_depth'])

    boreholes = df['GeoEnergyProduction'] * 1000000 / production_per_hole
    boreholes[last_historical_year] = 0
    boreholes = boreholes.sort_index()
    df['BoreholesPerYear'] = boreholes.diff().fillna(0)
    # assume grid formation
    df['BoreholeAreaNeeded'] = (boreholes * 25**2) / 1000000  # m2 -> km2

    df['Forecast'] = False
    df.loc[df.index > last_historical_year, 'Forecast'] = True

    return df