def get_content(self):
        lang = get_active_locale()
        main_sector_name = self.emission_sector[0]
        main_sector_metadata = SECTORS[main_sector_name]

        cols = []

        edf = predict_emissions().dropna(axis=1, how='all')
        forecast = edf.pop('Forecast')
        edf = edf[main_sector_name]

        subsectors = main_sector_metadata['subsectors']
        colors = generate_color_scale(main_sector_metadata['color'],
                                      len(subsectors))

        graph = PredictionFigure(sector_name=main_sector_name,
                                 unit_name='kt',
                                 title=_('Total emissions'),
                                 smoothing=True,
                                 fill=True,
                                 stacked=True,
                                 legend=True,
                                 legend_x=0.8)

        for idx, (sector_name,
                  sector_metadata) in enumerate(subsectors.items()):
            df = pd.DataFrame(edf[sector_name])
            df['Forecast'] = forecast

            fig = self.make_sector_fig(df, sector_name, sector_metadata,
                                       colors[idx])
            sector_page = get_page_for_emission_sector(main_sector_name,
                                                       sector_name)
            card = GraphCard(id='emissions-%s-%s' %
                             (main_sector_name, sector_name),
                             graph=dict(figure=fig),
                             link_to_page=sector_page)
            cols.append(dbc.Col(card.render(), md=6))

            # Add the summed sector to the all emissions graph
            df = df.drop(columns=['Forecast'])
            s = df.sum(axis=1)
            s.name = 'Emissions'
            df = pd.DataFrame(s)
            df['Forecast'] = forecast
            graph.add_series(df=df,
                             trace_name=sector_metadata.get(
                                 'name_%s' % lang, sector_metadata['name']),
                             column_name='Emissions',
                             historical_color=colors[idx])

        self.total_emissions = edf.iloc[-1].sum()

        card = GraphCard(id='%s-emissions-total' % main_sector_name,
                         graph=dict(figure=graph.get_figure()))

        return html.Div([
            dbc.Row(dbc.Col(card.render())),
            dbc.Row(cols),
        ])
Beispiel #2
0
def make_sector_fig(df, name, metadata):
    fig = PredictionFigure(
        sector_name=name,
        unit_name='kt',
        title=metadata['name'],
        smoothing=True,
        # allow_nonconsecutive_years=True,
        fill=True,
        stacked=True,
    )
    if len(df.columns) == 2:
        fig.add_series(df=df, trace_name='Päästöt', column_name='')
    else:
        fig.legend = True
        fig.legend_x = 0.8
        column_names = list(df.columns)
        column_names.remove('Forecast')
        colors = generate_color_scale(metadata['color'], len(column_names))
        for idx, col_name in enumerate(column_names):
            subsector = metadata['subsectors'][col_name]
            fig.add_series(df=df,
                           trace_name=subsector['name'],
                           column_name=col_name,
                           historical_color=colors[idx])
    return fig.get_figure()
    def _refresh_emission_cards(self):
        card = self.get_card('parking-emission-reductions')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='kt (CO2e.)/a',
            fill=True,
            smoothing=True,
        )

        with override_variable(
                'residential_parking_fee_share_of_cars_impacted', 0):
            df0 = predict_cars_emissions()

        df1 = predict_cars_emissions()

        df1['Emissions'] -= df0['Emissions']
        self.yearly_emissions_impact = df1['Emissions'].iloc[-1]
        df_forecast = df1[df1.Forecast]

        fig.add_series(df=df_forecast,
                       column_name='Emissions',
                       trace_name=_('Emissions'))
        card.set_figure(fig)

        card = self.get_card('car-emission-factor')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='g/km',
        )
        fig.add_series(df=df1,
                       column_name='EmissionFactor',
                       trace_name=_('Emission factor'))
        card.set_figure(fig)
 def make_sector_fig(self, df, name, metadata, base_color):
     lang = get_active_locale()
     fig = PredictionFigure(
         sector_name=name,
         unit_name='kt',
         title=metadata.get('name_%s' % lang, metadata['name']),
         smoothing=True,
         # allow_nonconsecutive_years=True,
         fill=True,
         stacked=True,
     )
     if len(df.columns) == 2:
         fig.add_series(df=df,
                        trace_name=_('Emissions'),
                        column_name='',
                        historical_color=base_color)
     else:
         fig.legend = True
         fig.legend_x = 0.8
         column_names = list(df.columns)
         column_names.remove('Forecast')
         colors = generate_color_scale(base_color, len(column_names))
         for idx, col_name in enumerate(column_names):
             subsector = metadata['subsectors'][col_name]
             fig.add_series(df=df,
                            trace_name=subsector.get(
                                'name_%s' % lang, metadata['name']),
                            column_name=col_name,
                            historical_color=colors[idx])
     return fig.get_figure()
Beispiel #5
0
def render_page():
    cols = []
    edf = predict_emissions().dropna(axis=1, how='all')
    forecast = edf.pop('Forecast')
    graph = PredictionFigure(sector_name=None,
                             unit_name='kt',
                             title='Päästöt yhteensä',
                             smoothing=True,
                             fill=True,
                             stacked=True,
                             legend=True,
                             legend_x=0.8)
    for sector_name, sector_metadata in SECTORS.items():
        df = pd.DataFrame(edf[sector_name])
        df['Forecast'] = forecast

        fig = make_sector_fig(df, sector_name, sector_metadata)
        sector_page = get_page_for_emission_sector(sector_name, None)
        card = GraphCard(id='emissions-%s' % sector_name,
                         graph=dict(figure=fig),
                         link_to_page=sector_page)
        cols.append(dbc.Col(card.render(), md=6))

        # Add the summed sector to the all emissions graph
        df = df.drop(columns=['Forecast'])
        s = df.sum(axis=1)
        s.name = 'Emissions'
        df = pd.DataFrame(s)
        df['Forecast'] = forecast
        graph.add_series(df=df,
                         trace_name=sector_metadata['name'],
                         column_name='Emissions',
                         historical_color=sector_metadata['color'])

    target_year = get_variable('target_year')
    ref_year = get_variable('ghg_reductions_reference_year')
    perc_off = get_variable('ghg_reductions_percentage_in_target_year')

    last_hist_year = edf.loc[~forecast].index.max()
    last_hist = edf.loc[last_hist_year].sum()
    end_emissions = edf.loc[target_year].sum()
    ref_emissions = edf.loc[ref_year].sum()
    target_emissions = ref_emissions * (1 - perc_off / 100)

    target_year_emissions = edf.loc[target_year].sum()
    sticky = StickyBar(
        label='Päästövähennykset yhteensä',
        goal=last_hist - target_emissions,
        value=last_hist - end_emissions,
        unit='kt',
        below_goal_good=False,
    )

    card = GraphCard(id='emissions-total',
                     graph=dict(figure=graph.get_figure()))

    return html.Div(
        [dbc.Row(dbc.Col(card.render())),
         dbc.Row(cols),
         sticky.render()])
Beispiel #6
0
def generate_solar_power_stacked(df):
    pv_kwh_wp = get_variable('yearly_pv_energy_production_kwh_wp')
    df.SolarPowerNew = df.SolarPowerNew * pv_kwh_wp
    df.SolarPowerExisting = df.SolarPowerExisting * pv_kwh_wp
    df.loc[~df.Forecast, 'SolarPowerNew'] = np.nan

    graph = PredictionFigure(sector_name='ElectricityConsumption',
                             unit_name='GWh',
                             title='Aurinkopaneelien sähköntuotanto',
                             stacked=True,
                             fill=True,
                             color_scale=2)
    graph.add_series(df=df,
                     trace_name='Vanhat rakennukset',
                     column_name='SolarPowerExisting',
                     color_idx=0)
    graph.add_series(df=df,
                     trace_name='Uudet rakennukset',
                     column_name='SolarPowerNew',
                     color_idx=1)

    forecast_df = df[df.Forecast]
    hist_df = df[~df.Forecast]
    years_left = forecast_df.index.max() - hist_df.index.max()
    ekwpa = (forecast_df.SolarPowerExisting.iloc[-1] -
             hist_df.SolarPowerExisting.iloc[-1]) / years_left
    nkwpa = forecast_df.SolarPowerNew.iloc[-1] / years_left

    return graph.get_figure(), ekwpa / pv_kwh_wp, nkwpa / pv_kwh_wp
    def _refresh_parking_fee_cards(self):
        pcard = self.get_card('residential-parking-fee')
        self.set_variable('residential_parking_fee_increase',
                          pcard.get_slider_value())
        icard = self.get_card('cars-affected-by-residential-parking-fee')
        self.set_variable('residential_parking_fee_share_of_cars_impacted',
                          icard.get_slider_value())

        cd = CardDescription()
        df = predict_parking_fee_impact()

        last_hist_year = df[~df.Forecast].index.max()
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name=_('€/year'),
            smoothing=False,
            # y_min=df['Fees'].min(),
            y_max=df.loc[last_hist_year]['ResidentialFees'] *
            (1 + MAX_PARKING_FEE_INCREASE_PERC / 100))
        fig.add_series(df=df,
                       column_name='ResidentialFees',
                       trace_name='Asukaspysäköinnin hinta')
        pcard.set_figure(fig)

        pcard.set_description(
            cd.render("""
        Oletuksena on Wienin tutkimus maksullisen pysäköinnin vaikutuksesta, jonka mukaan pysäköintimaksun
        kaksinkertaistaminen vähentää pysäköintiä ja siten autoliikennettä siihen kohdistuvilla alueilla
        noin 8,8 %. Asukaspysäköintimaksujen korotus alkoi vuonna 2015 ja vuosimaksu nousee
        120 eurosta 360 euroon vuoteen 2021 mennessä. Asukaspysäköintitunnusten määrä on vuosina 2014–2019
        vähentynyt noin 600 kpl vaikka asukasluku on kasvanut kantakaupungissa."""
                      ))
        """{municipality_locative} lyhytaikainen pysäköinti on vähentynyt vuoden 2017 pysäköintimaksujen korotuksen
        jälkeen noin 10%."""

        fig = PredictionFigure(sector_name='Transportation',
                               unit_name='%',
                               smoothing=False,
                               y_max=100)
        df['ResidentialShareOfCarsImpacted'] *= 100
        cd.set_values(
            residential_share_target=df['ResidentialShareOfCarsImpacted'].
            iloc[-1],
            residential_share=df[~df.Forecast]
            ['ResidentialShareOfCarsImpacted'].iloc[-1],
        )
        fig.add_series(df=df,
                       column_name='ResidentialShareOfCarsImpacted',
                       trace_name='Osuus')
        icard.set_figure(fig)
        icard.set_description(
            cd.render("""
        Tarkastelussa on mukana vain keskustan asukaspysäköintivyöhykkeet.
        Asukaspysäköintilupia on myönnetty nyt n. {residential_share} % {municipality_genitive}
        liikennekäytössä olevalle henkilöautokannalle.
        Skenaariossa vuonna {target_year} asukaspysäköinnin piirissä on {residential_share_target} %
        auton omistajista.
        """))
Beispiel #8
0
def draw_district_heat_consumption_emissions(df):
    graph = PredictionFigure(
        sector_name='BuildingHeating',
        unit_name='kt',
        title='Kaukolämmön kulutuksen päästöt',
        smoothing=True,
        allow_nonconsecutive_years=True,
        fill=True,
    )
    graph.add_series(df=df, column_name='NetEmissions', trace_name='Päästöt')
    return graph.get_figure()
Beispiel #9
0
def draw_new_building_unit_heat_factor_graph(df):
    graph = PredictionFigure(
        sector_name='BuildingHeating',
        unit_name='kWh/k-m²',
        title='Uuden rakennuskannan ominaislämmönkulutus',
        color_scale=2,
    )
    graph.add_series(df=df,
                     column_name='NewBuildingHeatUsePerNetArea',
                     trace_name='Ominaislämmönkulutus',
                     color_idx=1)
    return graph.get_figure()
Beispiel #10
0
def draw_new_building_unit_heat_factor_graph(df):
    graph = PredictionFigure(
        sector_name='BuildingHeating',
        unit_name='kWh/k-m²',
        title=_('Future building stock heat efficiency'),
        color_scale=2,
    )
    graph.add_series(df=df,
                     column_name='NewBuildingHeatUsePerNetArea',
                     trace_name=_('Heat efficiency'),
                     color_idx=1)
    return graph.get_figure()
Beispiel #11
0
    def _refresh_mileage_cards(self):
        card = self.get_card('car-mileage-per-resident')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='km',
            color_scale=2,
            legend=True,
        )
        mdf = predict_road_mileage()
        pop = predict_population()

        cd = CardDescription()
        card.set_description(
            cd.render("""
        Henkilöautojen kilometrisuorite on saatu VTT:ltä ja se pitää sisällään henkilöautoliikenteen
        Helsingin aluerajojen sisäpuolella. Henkilöautojen käyttäjämääräksi on oletettu keskimäärin
        1,2 henkilöä autossa. Joukkoliikenteen matkustajakilometrit on saatu HSL:n tilastoista. Näiden
        lisäksi Helsingin katuverkossa liikkuu pitkän matkan busseja sekä turistibusseja, jotka muodostavat
        noin neljäsosan linja-autoliikenteestä Helsingissä. Kävelyn ja pyöräilyn oletukset henkilökilometreistä
        perustuvat HSL:n liikkumistutkimukseen matkamääristä ja keskimääräisistä pituuksista. Pyörällä
        oletuksena on keskipituus 3,7 km ja kävelymatkalla 1,2 km.
        """))

        fc = mdf.pop('Forecast')
        df = pd.DataFrame(fc)
        for vehicle, road in list(mdf.columns):
            if vehicle == 'Cars':
                df[road] = mdf[(vehicle, road)]
                df[road + 'PerResident'] = df[road] / pop['Population']
                df[road] /= 1000000

        fig.add_series(df=df,
                       column_name='UrbanPerResident',
                       trace_name='Katuajo',
                       color_idx=0)
        fig.add_series(df=df,
                       column_name='HighwaysPerResident',
                       trace_name='Maantieajo',
                       color_idx=1)
        card.set_figure(fig)

        card = self.get_card('car-mileage')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='M km',
            color_scale=2,
            stacked=True,
            fill=True,
            legend=True,
        )

        fig.add_series(df=df,
                       column_name='Urban',
                       trace_name='Katusuorite',
                       color_idx=0)
        fig.add_series(df=df,
                       column_name='Highways',
                       trace_name='Maantiesuorite',
                       color_idx=1)
        card.set_figure(fig)
Beispiel #12
0
def generate_district_heating_emission_factor_graph(df):
    graph = PredictionFigure(
        sector_name='BuildingHeating',
        unit_name='g/kWh',
        title='Kaukolämmön päästökerroin',
        smoothing=True,
        allow_nonconsecutive_years=True,
    )
    graph.add_series(
        df=df,
        column_name='Emission factor',
        trace_name='Päästökerroin',
    )

    return graph.get_figure()
Beispiel #13
0
def generate_district_heating_forecast_graph(df):
    graph = PredictionFigure(
        sector_name='BuildingHeating',
        unit_name='kt/vuosi',
        title='Kaukolämmön kulutuksen päästöt',
        smoothing=True,
        allow_nonconsecutive_years=True,
        fill=True,
    )
    graph.add_series(
        df=df,
        column_name='District heat consumption emissions',
        trace_name='Päästöt',
    )

    return graph.get_figure()
Beispiel #14
0
def generate_solar_power_graph(df, label, col, ymax, is_existing):
    graph = PredictionFigure(
        sector_name='ElectricityConsumption',
        unit_name='MWp',
        title='%s rakennuskannan aurinkopaneelien piikkiteho' % label,
        y_max=ymax,
        color_scale=2)
    if is_existing:
        color_idx = 0
    else:
        color_idx = 1

    graph.add_series(df=df,
                     trace_name='Piikkiteho',
                     column_name=col,
                     color_idx=color_idx)
    return graph.get_figure()
Beispiel #15
0
def draw_bev_chart(df):
    engines = {'electric', 'gasoline', 'diesel'}
    df = df.dropna()[[*engines, 'Forecast']].copy()
    graph = PredictionFigure(
        sector_name='Transportation',
        unit_name='%',
        title='Sähköautojen ajosuoriteosuus',
        legend=True,
        legend_x=0.6,
        y_max=100,
    )

    for col in engines:
        et = ENGINE_TYPES[col]
        df[col] *= 100
        graph.add_series(
            df=df, column_name=col, trace_name=et['name'], historical_color=et['color']
        )

    return graph.get_figure()
Beispiel #16
0
    def draw_bev_chart(self, df):
        engines = ['electric', 'PHEV (gasoline)', 'gasoline', 'diesel']
        df = df.dropna()[[*engines, 'Forecast']].copy()
        df.loc[df.index == df.index.min(), 'Forecast'] = False
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='%',
            legend=True,
            legend_x=0.8,
            y_max=100,
        )

        for col in engines:
            et = ENGINE_TYPES[col]
            df[col] *= 100
            fig.add_series(
                df=df, column_name=col, trace_name=et['name'], historical_color=et['color']
            )

        return fig
Beispiel #17
0
    def _refresh_trip_cards(self):
        df = predict_passenger_kms()

        card = self.get_card('number-of-passenger-kms')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='km',
        )
        fig.add_series(df,
                       column_name='KmsPerResident',
                       trace_name=_('passenger kms (p.c.)'))
        card.set_figure(fig)
        df.pop('KmsPerResident')

        total = df.sum(axis=1)

        fc = df.pop('Forecast')
        df = df.div(total, axis=0)
        df *= 100

        # df['Other'] += df.pop('Taxi')
        df['Rail'] = df.pop('Metro') + df.pop('Tram') + df.pop('Train')

        ccard = self.get_card('modal-share-car')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='%',
        )
        fig.add_series(df=df,
                       forecast=fc,
                       column_name='Car',
                       trace_name='Henkilöautot')
        ccard.set_figure(fig)
        df.pop('Car')

        mcard = self.get_card('modal-shares-rest')
        color_scale = len(df.columns)
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='%',
            legend=True,
            color_scale=color_scale,
        )
        last_hist_year = fc[~fc].index.max()
        columns = list(
            df.loc[last_hist_year].sort_values(ascending=False).index)
        for idx, col in enumerate(columns):
            name = MODE_TRANSLATIONS.get(col)
            if name is not None:
                name = name.get(get_active_locale())
            if name is None:
                name = col
            fig.add_series(df=df,
                           forecast=fc,
                           column_name=col,
                           trace_name=name,
                           color_idx=idx)

        mcard.set_figure(fig)
Beispiel #18
0
def draw_heat_consumption(df):
    df.loc[~df.Forecast, 'NewBuildingHeatUse'] = np.nan
    graph = PredictionFigure(
        title='Kaukolämmön kokonaiskulutus',
        unit_name='GWh',
        sector_name='BuildingHeating',
        smoothing=True,
        stacked=True,
        fill=True,
        color_scale=2,
    )

    graph.add_series(
        df=df,
        column_name='ExistingBuildingHeatUse',
        trace_name='Vanhat rakennukset',
        color_idx=0,
    )
    graph.add_series(df=df,
                     column_name='NewBuildingHeatUse',
                     trace_name='Uudet rakennukset',
                     color_idx=1)

    return graph.get_figure()
Beispiel #19
0
def draw_heat_consumption(df):
    df.loc[~df.Forecast, 'NewBuildingHeatUse'] = np.nan
    graph = PredictionFigure(
        title=_('District heat net consumption'),
        unit_name='GWh',
        sector_name='BuildingHeating',
        smoothing=True,
        stacked=True,
        fill=True,
        color_scale=2,
    )

    graph.add_series(
        df=df,
        column_name='ExistingBuildingHeatUse',
        trace_name=_('Existing buildings'),
        color_idx=0,
    )
    graph.add_series(df=df,
                     column_name='NewBuildingHeatUse',
                     trace_name=_('Future buildings'),
                     color_idx=1)

    return graph.get_figure()
Beispiel #20
0
def solar_power_callback(existing_building_perc, new_building_perc):
    # First see what the maximum solar production capacity is to set the
    # Y axis maximum.
    set_variable('solar_power_existing_buildings_percentage', 100)
    set_variable('solar_power_new_buildings_percentage', 100)
    kwp_max = predict_solar_power_production()

    # Then predict with the given percentages.
    set_variable('solar_power_existing_buildings_percentage',
                 existing_building_perc)
    set_variable('solar_power_new_buildings_percentage', new_building_perc)
    kwp_df = predict_solar_power_production()

    ymax = kwp_max.SolarPowerExisting.iloc[-1]
    fig_old = generate_solar_power_graph(kwp_df, "Vanhan",
                                         "SolarPowerExisting", ymax, True)
    # ymax = kwp_max.SolarPowerNew.iloc[-1]
    fig_new = generate_solar_power_graph(kwp_df, "Uuden", "SolarPowerNew",
                                         ymax, False)
    fig_tot, ekwpa, nkwpa = generate_solar_power_stacked(kwp_df)

    graph = PredictionFigure(sector_name='ElectricityConsumption',
                             unit_name='kt',
                             title='Aurinkopaneelien päästövaikutukset',
                             fill=True)
    ef_df = predict_electricity_emission_factor()
    kwp_df['NetEmissions'] = -kwp_df['SolarProduction'] * ef_df[
        'EmissionFactor'] / 1000
    graph.add_series(df=kwp_df,
                     column_name='NetEmissions',
                     trace_name='Päästövaikutukset')
    fig_emissions = graph.get_figure()

    s = kwp_df.SolarProduction

    cd = CardDescription()

    city_owned = get_variable('building_area_owned_by_org') / 100
    cd.set_values(existing_building_perc=existing_building_perc,
                  org_existing_building_kwp=1000 * ekwpa * city_owned,
                  others_existing_building_kwp=1000 * ekwpa * (1 - city_owned))

    existing_kwpa = cd.render("""
    Kun aurinkopaneeleita rakennetaan {existing_building_perc:noround} % kaikesta vanhan
    rakennuskannan kattopotentiaalista, {org_genitive} tulee rakentaa aurinkopaneeleita
    {org_existing_building_kwp} kWp vuodessa skenaarion toteutumiseksi. Muiden kuin {org_genitive}
    tulee rakentaa {others_existing_building_kwp} kWp aurinkopaneeleita vuodessa.
    """)

    cd.set_values(new_building_perc=new_building_perc,
                  org_new_building_kwp=1000 * nkwpa * city_owned,
                  others_new_building_kwp=1000 * nkwpa * (1 - city_owned))
    new_kwpa = cd.render("""
    Kun uuteen rakennuskantaan rakennetaan aurinkopaneeleja {new_building_perc:noround} %
    kaikesta kattopotentiaalista, {org_genitive} tulee rakentaa aurinkopaneeleja
    {org_new_building_kwp} kWp vuodessa skenaarion toteutumiseksi. Muiden kuin {org_genitive}
    tulee rakentaa {others_new_building_kwp} kWp aurinkopaneeleita vuodessa.
    """)

    forecast = s.iloc[-1] * get_variable('yearly_pv_energy_production_kwh_wp')

    sticky = StickyBar(
        label='Aurinkosähkön tuotanto',
        value=forecast,
        unit='GWh',
        current_page=page,
    )

    return [
        fig_old, fig_new, fig_tot, fig_emissions, existing_kwpa, new_kwpa,
        sticky.render()
    ]
Beispiel #21
0
def district_heating_consumption_callback(existing_building_perc,
                                          new_building_perc):
    set_variable('district_heating_existing_building_efficiency_change',
                 existing_building_perc / 10)
    set_variable('district_heating_new_building_efficiency_change',
                 new_building_perc / 10)

    df = predict_district_heat_consumption()
    geo_df = predict_geothermal_production()
    geo_df = geo_df[geo_df.Forecast]
    df['GeoEnergyProductionExisting'] = geo_df['GeoEnergyProductionExisting']
    df['GeoEnergyProductionNew'] = geo_df['GeoEnergyProductionNew']

    df['ExistingBuildingHeatUse'] -= df['GeoEnergyProductionExisting'].fillna(
        0)
    df['NewBuildingHeatUse'] -= df['GeoEnergyProductionNew'].fillna(0)

    first_forecast = df[df.Forecast].iloc[0]
    last_forecast = df[df.Forecast].iloc[-1]
    last_history = df[~df.Forecast].iloc[-1]

    cd = CardDescription()
    org_owned = get_variable('building_area_owned_by_org') / 100
    geo_production = last_forecast.GeoEnergyProductionExisting + last_forecast.GeoEnergyProductionNew
    cd.set_values(
        existing_renovation=get_variable(
            'district_heating_existing_building_efficiency_change'),
        new_improvement=get_variable(
            'district_heating_new_building_efficiency_change'),
        existing_next_year_reduction=(1 -
                                      (first_forecast.ExistingBuildingHeatUse -
                                       last_history.ExistingBuildingHeatUse)) *
        org_owned,
        new_area=last_forecast.NewBuildingNetArea,
        existing_area=last_forecast.ExistingBuildingNetArea,
        geo_production=geo_production,
        geo_percentage=(geo_production / last_forecast.TotalHeatConsumption) *
        100,
    )
    existing_desc = cd.render("""
        Skenaarion mukaan nykyistä rakennuskantaa remontoidaan siten, että rakennuksien
        energiatehokkuus paranee {existing_renovation:noround} % vuodessa. Ensi vuonna {org_genitive}
        omistamien rakennuksien lämmönkulutuksen pitää pudota {existing_next_year_reduction} GWh.
    """)
    new_desc = cd.render("""
        Uuden rakennuskannan energiatehokkuus paranee skenaariossa {new_improvement:noround} % vuodessa.
        Vuonna {target_year} nykyistä rakennuskantaa on {existing_area} milj. kem² ja uutta rakennuskantaa
        {new_area} milj. kem².
    """)
    geo_desc = cd.render("""
        Vanhassa ja uudessa rakennuskannassa korvataan kaukolämpöä paikallisesti tuotetulla
        maalämmöllä siten, että vuonna {target_year} kaukolämpöä korvataan {geo_production} GWh
        ({geo_percentage} % sen vuoden kaukolämmönkulutuksesta).
    """)

    fig1 = draw_existing_building_unit_heat_factor_graph(df)
    fig2 = draw_new_building_unit_heat_factor_graph(df)

    geo_fig = PredictionFigure(
        sector_name='BuildingHeating',
        unit_name='GWh',
        title='Maalämmöllä korvattu kaukolämpö',
        fill=True,
    )
    geo_fig.add_series(
        df=geo_df,
        column_name='GeoEnergyProduction',
        trace_name='Maalämpötuotanto',
    )

    fig3 = draw_heat_consumption(df)

    df = predict_district_heating_emissions()
    unit_emissions_card = make_unit_emissions_card(df)
    fig4 = draw_district_heat_consumption_emissions(df)
    sticky = make_bottom_bar(df)

    return [
        fig1,
        dbc.Col(existing_desc, style=dict(minHeight='8rem')), fig2,
        dbc.Col(new_desc, style=dict(minHeight='8rem')),
        geo_fig.get_figure(),
        dbc.Col(geo_desc, style=dict(minHeight='8rem')), fig3,
        unit_emissions_card, fig4, sticky
    ]
Beispiel #22
0
    def refresh_graph_cards(self):
        # First see what the maximum solar production capacity is to set the
        # Y axis maximum.
        set_variable('solar_power_existing_buildings_percentage', 100)
        set_variable('solar_power_new_buildings_percentage', 100)
        kwp_max_df = predict_solar_power_production()

        # Then predict with the given percentages.
        existing_card = self.get_card('existing-buildings')
        set_variable('solar_power_existing_buildings_percentage', existing_card.get_slider_value())

        future_card = self.get_card('new-buildings')
        set_variable('solar_power_new_buildings_percentage', future_card.get_slider_value())

        df = predict_solar_power_production()

        forecast_df = df[df.Forecast]
        hist_df = df[~df.Forecast]
        years_left = forecast_df.index.max() - hist_df.index.max()
        ekwpa = (forecast_df.SolarPowerExisting.iloc[-1] - hist_df.SolarPowerExisting.iloc[-1]) / years_left
        nkwpa = forecast_df.SolarPowerNew.iloc[-1] / years_left

        cd = CardDescription()
        city_owned = get_variable('building_area_owned_by_org') / 100
        cd.set_values(
            existing_building_perc=existing_card.get_slider_value(),
            org_existing_building_kwp=1000 * ekwpa * city_owned,
            others_existing_building_kwp=1000 * ekwpa * (1 - city_owned)
        )
        existing_card.set_description(cd.render("""
        Kun aurinkopaneeleita rakennetaan {existing_building_perc:noround} % kaikesta vanhan
        rakennuskannan kattopotentiaalista, {org_genitive} tulee rakentaa aurinkopaneeleita
        {org_existing_building_kwp} kWp vuodessa skenaarion toteutumiseksi. Muiden kuin {org_genitive}
        tulee rakentaa {others_existing_building_kwp} kWp aurinkopaneeleita vuodessa.
        """))

        cd.set_values(
            new_building_perc=future_card.get_slider_value(),
            org_new_building_kwp=1000 * nkwpa * city_owned,
            others_new_building_kwp=1000 * nkwpa * (1 - city_owned)
        )
        future_card.set_description(cd.render("""
        Kun uuteen rakennuskantaan rakennetaan aurinkopaneeleja {new_building_perc:noround} %
        kaikesta kattopotentiaalista, {org_genitive} tulee rakentaa aurinkopaneeleja
        {org_new_building_kwp} kWp vuodessa skenaarion toteutumiseksi. Muiden kuin {org_genitive}
        tulee rakentaa {others_new_building_kwp} kWp aurinkopaneeleita vuodessa.
        """))

        ymax = kwp_max_df.SolarPowerExisting.iloc[-1]
        fig = PredictionFigure(
            sector_name='ElectricityConsumption', unit_name='MWp',
            y_max=ymax, color_scale=2
        )
        fig.add_series(df=df, trace_name=_('Peak power'), column_name='SolarPowerExisting', color_idx=0)
        existing_card.set_figure(fig)

        fig = PredictionFigure(
            sector_name='ElectricityConsumption', unit_name='MWp',
            y_max=ymax, color_scale=2
        )
        fig.add_series(df=df, trace_name=_('Peak power'), column_name='SolarPowerNew', color_idx=1)
        future_card.set_figure(fig)

        pv_kwh_wp = get_variable('yearly_pv_energy_production_kwh_wp')
        df.SolarPowerNew = df.SolarPowerNew * pv_kwh_wp
        df.SolarPowerExisting = df.SolarPowerExisting * pv_kwh_wp
        df.loc[~df.Forecast, 'SolarPowerNew'] = np.nan

        card = self.get_card('production')
        fig = PredictionFigure(
            sector_name='ElectricityConsumption', unit_name='GWh',
            stacked=True, fill=True, color_scale=2
        )
        fig.add_series(df=df, trace_name=_('Existing buildings'), column_name='SolarPowerExisting', color_idx=0)
        fig.add_series(df=df, trace_name=_('Future buildings'), column_name='SolarPowerNew', color_idx=1)
        card.set_figure(fig)

        card = self.get_card('emission-impact')
        fig = PredictionFigure(
            sector_name='ElectricityConsumption', unit_name='kt',
            fill=True
        )
        ef_df = predict_electricity_emission_factor()
        df['NetEmissions'] = -df['SolarProduction'] * ef_df['EmissionFactor'] / 1000
        fig.add_series(df=df, column_name='NetEmissions', trace_name=_('Emissions'))
        card.set_figure(fig)

        s = df.SolarProduction
        self.solar_production_forecast = s.iloc[-1] * get_variable('yearly_pv_energy_production_kwh_wp')
Beispiel #23
0
    def refresh_graph_cards(self):
        ecard = self.get_card('renovated-per-year')
        self.set_variable('geothermal_existing_building_renovation',
                          ecard.get_slider_value() / 10)
        ncard = self.get_card('new-building-installation')
        self.set_variable('geothermal_new_building_installation_share',
                          ncard.get_slider_value())

        df = predict_geothermal_production()
        print(df)

        fig = PredictionFigure(
            sector_name='BuildingHeating',
            unit_name='milj. k-m²',
            smoothing=True,
            y_max=25,
        )
        fig.add_series(
            df=df,
            column_name='GeoBuildingNetAreaExisting',
            trace_name='Kerrosala',
        )
        ecard.set_figure(fig)

        org_owned = self.get_variable('building_area_owned_by_org') / 100
        cd = CardDescription()

        first_forecast = df[df.Forecast].iloc[0]
        last_forecast = df.iloc[-1]
        last_hist_year = df[~df.Forecast].index.max()
        last_forecast_year = df[df.Forecast].index.max()

        cd.set_values(
            existing_building_perc=self.get_variable(
                'geothermal_existing_building_renovation'),
            existing_building_area=last_forecast.GeoBuildingNetAreaExisting,
            boreholes_org=first_forecast.BoreholesPerYear * org_owned,
            boreholes_others=first_forecast.BoreholesPerYear * (1 - org_owned),
            borehole_area=last_forecast.BoreholeAreaNeeded,
            borehole_depth=self.get_variable('geothermal_borehole_depth'),
            new_building_perc=self.get_variable(
                'geothermal_new_building_installation_share'),
            new_building_area=last_forecast.GeoBuildingNetAreaNew,
            geothermal_production=last_forecast.GeoEnergyProduction,
            perc_dh=last_forecast.GeoEnergyProduction)
        ecard.set_description(
            cd.render("""
        Kun olemassaolevasta rakennuskannasta remontoidaan {existing_building_perc:noround} %
        joka vuosi ja vaihdetaan lämmitystavaksi maalämpö, vuonna {target_year} maalämmöllä
        lämmitetään {existing_building_area} milj. kerrosneliömetriä. Skenaarion toteutumiseksi
        {org_genitive} pitää rakentaa ensi vuonna {boreholes_org} maalämpökaivoa, kun oletetaan kaivon
        syvyydeksi {borehole_depth} m. Muiden pitää rakentaa ensi vuonna {boreholes_others} kaivoa.
        """))

        ncard.set_description(
            cd.render("""
        Kun uudesta rakennuskannasta {new_building_perc:noround} % rakennetaan maalämmöllä,
        vuonna {target_year} lämmitetään maalämmöllä {new_building_area} milj. kerrosneliömetriä.
        |p|Vanhan ja uuden rakennuskannan maalämpökaivot tarvitsevat silloin yhteensä {borehole_area} km²
        pinta-alaa.
        """))
        fig = PredictionFigure(
            sector_name='BuildingHeating',
            unit_name='milj. k-m²',
            smoothing=True,
            y_max=10,
        )
        fig.add_series(
            df=df,
            column_name='GeoBuildingNetAreaNew',
            trace_name='Kerrosala',
        )
        ncard.set_figure(fig)

        card = self.get_card('geothermal-production')
        fig = PredictionFigure(
            sector_name='BuildingHeating',
            unit_name='GWh',
            smoothing=True,
            fill=True,
            stacked=True,
            color_scale=2,
        )
        fig.add_series(
            df=df,
            column_name='GeoEnergyProductionExisting',
            trace_name='Vanha rakennuskanta',
            color_idx=0,
        )
        fig.add_series(
            df=df,
            column_name='GeoEnergyProductionNew',
            trace_name='Uusi rakennuskanta',
            color_idx=1,
        )
        card.set_figure(fig)
        card.set_description(
            cd.render("""
            Vuonna {target_year} maalämpöpumpuilla tuotetaan {geothermal_production} GWh lämpöä.
            Skenaariossa se käytetään korvaamaan kaukolämpöä.
        """))

        # District heat
        dhdf = predict_district_heating_emissions()
        card = self.get_card('district-heat-emission-factor')
        fig = PredictionFigure(
            sector_name='BuildingHeating',
            unit_name='g/kWh',
            smoothing=True,
        )
        fig.add_series(df=dhdf,
                       column_name='Emission factor',
                       trace_name=_('Emission factor'))
        card.set_figure(fig)
        last_dhdf_hist_year = dhdf[~dhdf.Forecast].index.max()
        dhef_target = dhdf.loc[last_forecast_year, 'Emission factor']
        dhef_hist = dhdf.loc[last_dhdf_hist_year, 'Emission factor']
        cd.set_values(dh_emission_factor_target=dhef_target,
                      dh_emission_factor_hist=dhef_hist,
                      perc_change=((dhef_target / dhef_hist) - 1) * 100)
        cd.set_variables(last_dhdf_hist_year=last_dhdf_hist_year, )
        card.set_description(
            cd.render("""
            Skenaariossa paikallisella maalämmöllä korvataan pelkästään kaukolämpöä.
            Vuonna {target_year} kaukolämmöntuotannon päästökerroin on {dh_emission_factor_target}
            g/km. Muutos vuoteen {last_dhdf_hist_year} on {perc_change} %.
        """))

        # Electricity
        edf = predict_electricity_emission_factor()
        card = self.get_card('electricity-emission-factor')
        fig = PredictionFigure(
            sector_name='ElectricityConsumption',
            unit_name='g/kWh',
            smoothing=True,
        )
        fig.add_series(
            df=edf,
            column_name='EmissionFactor',
            trace_name=_('Emission factor'),
        )
        card.set_figure(fig)
        cd.set_values(
            heat_pump_el=last_forecast.ElectricityUse,
            elef=edf.loc[last_forecast_year].EmissionFactor,
        )
        card.set_description(
            cd.render("""
            Vuonna {target_year} maalämpöpumput käyttävät sähköä {heat_pump_el} GWh.
            Sähkönkulutuksesta aiheutuvat päästöt määräytyvät sähkönhankinnan päästökertoimen
            mukaan ({elef} g/kWh vuonna {target_year}).
        """))

        card = self.get_card('emissions')
        fig = PredictionFigure(
            sector_name='BuildingHeating',
            unit_name='kt',
            smoothing=True,
            fill=True,
        )
        fig.add_series(
            df=df,
            column_name='NetEmissions',
            trace_name=_('Emissions'),
        )
        card.set_figure(fig)
Beispiel #24
0
    def refresh_graph_cards(self):
        card = self.get_card('ev-parking-fee-discount')
        self.set_variable('parking_subsidy_for_evs', card.get_slider_value())

        df = predict_parking_fee_impact()
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name=_('€/year'),
            y_max=1000,
        )
        fig.add_series(df=df,
                       column_name='ParkingSubsidyForEVs',
                       trace_name=_('Yearly subsidy'))
        card.set_figure(fig)
        cd = CardDescription()
        cd.set_values(
            parking_subsidy_for_evs=get_variable('parking_subsidy_for_evs'))
        card.set_description(
            cd.render("""
            Skenaariossa täyssähköautoille myönnetään pysäköintietuuksia
            jatkossa yhteensä {parking_subsidy_for_evs} €/vuosi.
        """))
        card.set_description(cd.render("""
            In this scenario, BEVs will be given extra parking subsidies
            in total {parking_subsidy_for_evs} € per year.
        """),
                             lang='en')

        card = self.get_card('share-of-ev-charging-stations-built')
        self.set_variable('share_of_ev_charging_station_demand_built',
                          card.get_slider_value())

        df = predict_ev_charging_station_demand()
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name=_('charging stations'),
            color_scale=2,
        )
        fig.add_series(df=df,
                       column_name='Built',
                       trace_name=_('Built'),
                       color_idx=0)
        fig.add_series(df=df,
                       column_name='Demand',
                       trace_name=_('Demand'),
                       color_idx=1)
        card.set_figure(fig)

        cd.set_values(
            stations_per_bev=int(
                get_variable('number_of_charging_stations_per_bev') * 100),
            share_stations=get_variable(
                'share_of_ev_charging_station_demand_built'),
            built=df.iloc[-1].Built,
            demand=df.iloc[-1].Demand,
        )
        card.set_description(
            cd.render("""
            Täyssähköautoihin siirtyminen on nopeinta, kun julkisia latauspisteitä
            rakennetaan {stations_per_bev:noround} kpl jokaista 100 sähköautoa kohti. Skenaariossa
            tästä määrästä rakennetaan {share_stations} %. Vuonna {target_year} olisi
            tarve {demand} latauspisteelle ja rakennettuna on {built} latauspistettä.
        """))
        card.set_description(cd.render("""
            Moving to BEVs will happen the fastest when public charging stations are being
            built so that there will be {stations_per_bev:noround} stations for each 
            100 electric vehicles. In this scenario, the city will build {share_stations} %.
            In the year {target_year} there would be demand for {demand} stations and
            there will be {built} stations built.
        """),
                             lang='en')

        card = self.get_card('yearly-fleet-turnover')
        df = predict_cars_in_use()
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='%',
            smoothing=True,
        )
        df['YearlyTurnover'] *= 100
        fig.add_series(df=df,
                       column_name='YearlyTurnover',
                       trace_name=_('Turnover'))
        card.set_figure(fig)
        cd.set_values(mean_yearly_turnover=df[~df.Forecast]
                      ['YearlyTurnover'].tail(8).mean())
        card.set_description(
            cd.render("""
            Viime vuosina {municipality_locative} henkilöautokannasta uusittiin noin
            {mean_yearly_turnover} % vuodessa. Laskentamallissa oletataan, että
            uusiutumisnopeus ei juuri muutu.
        """))

        card = self.get_card('cars-per-resident')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name=_('cars/1,000 res.'),
            smoothing=True,
        )
        df['CarsPerResident'] *= 1000
        fig.add_series(df=df,
                       column_name='CarsPerResident',
                       trace_name=_('Cars'))
        card.set_figure(fig)
        cd.set_values(
            cars_in_use=df[~df.Forecast]['NumberOfCars'].iloc[-1],
            cars_in_use_year=df[~df.Forecast].index.max(),
        )
        card.set_description(
            cd.render("""
            Laskentamallissa tarkastellaan ainoastaan liikennekäyttöön rekisteröityjä
            henkilöautoja. Vuonna {cars_in_use_year} {municipality_locative} oli liikennekäytössä
            {cars_in_use} henkilöautoa.
        """))

        card = self.get_card('newly-registered-evs')
        df = predict_newly_registered_cars()
        fc = df.pop('Forecast')
        total = df.sum(axis=1)
        df = df.div(total, axis=0)
        df *= 100
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='%',
            smoothing=True,
            color_scale=4,
            legend=True,
        )
        for engine_type in ('BEV', 'PHEV', 'gasoline', 'diesel', 'other'):
            et = ENGINE_TYPES[engine_type]
            fig.add_series(df=df,
                           forecast=fc,
                           column_name=engine_type,
                           trace_name=et['name'],
                           historical_color=et['color'])
        card.set_figure(fig)
        cd.set_values(
            bev_share=df[~fc]['BEV'].iloc[-1],
            phev_share=df[~fc]['PHEV'].iloc[-1],
            hist_year=df[~fc].index.max(),
        )
        card.set_description(
            cd.render("""
            Vuonna {hist_year} {municipality_genitive} ensirekisteröidyistä
            henkilöautoista {bev_share} % oli täyssähköautoja (BEV) ja
            {phev_share} % ladattavia hybridiautoja (PHEV).
        """))

        card = self.get_card('car-fleet')
        df = predict_cars_in_use_by_engine_type()
        df = df.sum(axis=1, level='EngineType')
        df['Forecast'] = True
        fc = df.pop('Forecast')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name=_('cars'),
            fill=True,
            stacked=True,
            legend=True,
        )
        for engine_type in ('BEV', 'PHEV', 'gasoline', 'diesel', 'other'):
            fig.add_series(df=df,
                           forecast=fc,
                           column_name=engine_type,
                           trace_name=_(engine_type),
                           forecast_color=ENGINE_TYPE_COLORS[engine_type])
        card.set_figure(fig)

        df = predict_cars_emissions()
        with override_variable('share_of_ev_charging_station_demand_built', 0):
            with override_variable('parking_subsidy_for_evs', 0):
                df0 = predict_cars_emissions()

        card = self.get_card('emission-factor')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='g/km',
            color_scale=2,
            legend=True,
            legend_x=0.6,
        )
        fig.add_series(df=df,
                       column_name='EmissionFactor',
                       trace_name=_('Emission factor with actions'),
                       color_idx=0)
        fig.add_series(df=df0,
                       column_name='EmissionFactor',
                       trace_name=_('Emission factor without actions'),
                       color_idx=1)
        card.set_figure(fig)

        df.Mileage /= 1000000
        card = self.get_card('mileage')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name=_('M km'),
            fill=True,
        )
        fig.add_series(
            df=df,
            column_name='Mileage',
            trace_name=_('Vehicle mileage'),
        )
        card.set_figure(fig)

        card = self.get_card('emission-impact')

        df['Emissions'] -= df0['Emissions']
        df = df[df.Forecast]
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name=_('kt/a'),
            fill=True,
        )
        fig.add_series(df=df,
                       column_name='Emissions',
                       trace_name=_('Reductions'))
        self.net_emissions_impact = df['Emissions'].sum()
        self.yearly_emissions_impact = df['Emissions'].iloc[-1]
        card.set_figure(fig)
Beispiel #25
0
    def refresh_graph_cards(self):
        df = predict_cars_emissions()
        df['Mileage'] /= 1000000

        fig = self.draw_bev_chart(df)
        bev_card = self.get_card('bev-percentage')
        bev_card.set_figure(fig)

        mpr_card = self.get_card('mileage-per-resident')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='km/as.',
        )
        fig.add_series(
            df=df, column_name='PerResident', trace_name=_('Vehicle mileage/res.'),
        )
        mpr_card.set_figure(fig)

        card = self.get_card('emission-factor')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='g/km',
        )
        fig.add_series(
            df=df, column_name='EmissionFactor', trace_name=_('Emission factor'),
        )
        card.set_figure(fig)

        card = self.get_card('total-mileage')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='milj. km',
            fill=True,
        )
        fig.add_series(
            df=df, column_name='Mileage', trace_name=_('Vehicle mileage'),
        )
        card.set_figure(fig)

        card = self.get_card('emissions')
        fig = PredictionFigure(
            sector_name='Transportation',
            unit_name='kt (CO₂e.)',
            fill=True,
        )
        fig.add_series(
            df=df, column_name='Emissions', trace_name=_('Emissions'),
        )
        card.set_figure(fig)

        """
        graph = PredictionFigure(
            sector_name='Transportation',
            unit_name='%',
            title='Biopolttoaineiden osuus myydyissä polttoaineissa',
        )
        graph.add_series(
            df=df, column_name='electric', trace_name='Bion osuus'
        )
        biofuel_chart = graph.get_figure()
        """

        cd = CardDescription()
        last_forecast = df[df.Forecast].iloc[-1]
        last_history = df[~df.Forecast].iloc[-1]
        self.last_emissions = df.iloc[-1].loc['Emissions']

        mileage_change = ((last_forecast.PerResident / last_history.PerResident) - 1) * 100
        cd.set_values(
            bev_percentage=last_forecast.electric * 100,
            phev_percentage=last_forecast['PHEV (gasoline)'] * 100,
            bev_mileage=last_forecast.Mileage * last_forecast.electric,
            phev_mileage=last_forecast.Mileage * last_forecast['PHEV (gasoline)'],
            per_resident_adjustment=mileage_change,
            target_population=last_forecast.Population,
            urban_mileage=last_forecast.UrbanPerResident,
            highway_mileage=last_forecast.HighwaysPerResident,
        )

        bev_card.set_description(cd.render("""
            Skenaariossa polttomoottorihenkilöautot korvautuvat sähköautoilla siten,
            että vuonna {target_year} {municipality_genitive} kaduilla ja teillä
            ajetaan täyssähköautoilla {bev_percentage} % kaikista ajokilometreistä
            ({bev_mileage} milj. km) ja ladattavilla hybridisähköautoilla {phev_percentage}
            % ajokilometreistä ({phev_mileage} milj. km).
        """))

        bev_card.set_description(cd.render("""
            In this scenario, ICE cars are being replaced with electric vehicles so
            that in the year {target_year} in the streets and highways of {municipality},
            BEVs account for {bev_percentage} % of all car mileage
            ({bev_mileage} Mkm) and PHEVs account for {phev_percentage} %
            of all car mileage ({phev_mileage} M km).
        """), lang='en')

        mpr_card.set_description(cd.render("""
            Vuonna {target_year} {municipality_locative} asuu {target_population} ihmistä.
            Skenaariossa ajokilometrit asukasta kohti muuttuvat vuoteen {target_year} mennessä
            {per_resident_adjustment} %. Yksi asukas ajaa keskimäärin {urban_mileage} km kaduilla
            ja {highway_mileage} km maanteillä vuodessa.
        """))

        mpr_card.set_description(cd.render("""
            In the year {target_year} City of {municipality} will have {target_population} residents.
            In this scenario, car mileage per resident will change until {target_year} by
            {per_resident_adjustment} %. One resident will drive on average {urban_mileage} km
            on the streets and {highway_mileage} km on the highways per year.
        """), lang='en')
Beispiel #26
0
def cars_callback(bev_percentage, mileage_adj):
    set_variable('cars_bev_percentage', bev_percentage)
    set_variable('cars_mileage_per_resident_adjustment', mileage_adj)

    df = predict_cars_emissions()
    df['Mileage'] /= 1000000

    bev_chart = draw_bev_chart(df)
    """
    graph = PredictionFigure(
        sector_name='Transportation',
        unit_name='%',
        title='Biopolttoaineiden osuus myydyissä polttoaineissa',
    )
    graph.add_series(
        df=df, column_name='electric', trace_name='Bion osuus'
    )
    biofuel_chart = graph.get_figure()
    """

    graph = PredictionFigure(
        sector_name='Transportation',
        unit_name='km/as.',
        title='Ajokilometrit asukasta kohti',
    )
    graph.add_series(
        df=df, column_name='PerResident', trace_name='Suorite/as.',
    )
    per_resident_chart = graph.get_figure()

    # Total mileage
    graph = PredictionFigure(
        sector_name='Transportation',
        unit_name='milj. km',
        title='%s ajetut henkilöautokilometrit' % get_variable('municipality_locative'),
        fill=True,
    )
    graph.add_series(
        df=df, column_name='Mileage', trace_name='Ajosuorite',
    )
    mileage_chart = graph.get_figure()

    # Total emissions
    graph = PredictionFigure(
        sector_name='Transportation',
        unit_name='g/km',
        title='Henkilöautojen päästökerroin',
    )
    graph.add_series(
        df=df, column_name='EmissionFactor', trace_name='Päästökerroin',
    )
    emission_factor_chart = graph.get_figure()

    # Total emissions
    graph = PredictionFigure(
        sector_name='Transportation',
        unit_name='kt (CO₂e.)',
        title='Henkilöautoilun päästöt',
        fill=True,
    )
    graph.add_series(
        df=df, column_name='Emissions', trace_name='Päästöt',
    )
    emissions_chart = graph.get_figure()

    cd = CardDescription()
    first_forecast = df[df.Forecast].iloc[0]
    last_forecast = df[df.Forecast].iloc[-1]
    last_history = df[~df.Forecast].iloc[-1]

    cd.set_values(
        bev_percentage=get_variable('cars_bev_percentage'),
        bev_mileage=last_forecast.Mileage * last_forecast.electric,
        per_resident_adjustment=get_variable('cars_mileage_per_resident_adjustment'),
        target_population=last_forecast.Population,
    )
    bev_desc = cd.render("""
        Skenaariossa polttomoottorihenkilöautot korvautuvat sähköautoilla siten,
        että vuonna {target_year} {municipality_genitive} kaduilla ja teillä
        ajetaan sähköautoilla {bev_percentage:noround} % kaikista ajokilometreistä
        ({bev_mileage} milj. km).
    """)
    pr_desc = cd.render("""
        Vuonna {target_year} {municipality_locative} asuu {target_population} ihmistä.
        Skenaariossa ajokilometrit asukasta kohti muuttuvat vuoteen {target_year} mennessä
        {per_resident_adjustment:noround} %.
    """)

    sticky = make_bottom_bar(df)

    return [
        bev_chart, dbc.Col(bev_desc), emission_factor_chart,
        per_resident_chart, dbc.Col(pr_desc), mileage_chart,
        emissions_chart, sticky
    ]
Beispiel #27
0
def electricity_consumption_callback(value):
    set_variable('electricity_consumption_per_capita_adjustment', value / 10)

    df = predict_electricity_consumption_emissions()

    graph = PredictionFigure(sector_name='ElectricityConsumption',
                             title=_('Electricity consumption per resident'),
                             unit_name='kWh/as.')
    graph.add_series(df=df,
                     trace_name=_('Consumption/res.'),
                     column_name='ElectricityConsumptionPerCapita')
    per_capita_fig = graph.get_figure()

    graph = PredictionFigure(
        sector_name='ElectricityConsumption',
        title=_('Electricity consumption'),
        unit_name='GWh',
        fill=True,
    )
    graph.add_series(df=df,
                     trace_name=_('Electricity consumption'),
                     column_name='NetConsumption')
    consumption_fig = graph.get_figure()

    graph = PredictionFigure(
        sector_name='ElectricityConsumption',
        title=_('Electricity production emission factor'),
        unit_name='g/kWh',
        smoothing=True,
    )
    graph.add_series(df=df,
                     trace_name=_('Emission factor'),
                     column_name='EmissionFactor')
    factor_fig = graph.get_figure()

    graph = PredictionFigure(
        sector_name='ElectricityConsumption',
        title=_('Electricity consumption emissions'),
        unit_name='kt',
        smoothing=True,
        fill=True,
    )
    graph.add_series(df=df, trace_name='Päästöt', column_name='NetEmissions')
    emission_fig = graph.get_figure()

    graph = PredictionFigure(
        sector_name='ElectricityConsumption',
        title=_('Local PV production'),
        unit_name='GWh',
        smoothing=True,
        fill=True,
    )
    graph.add_series(df=df,
                     trace_name='Tuotanto',
                     column_name='SolarProduction')
    solar_fig = graph.get_figure()

    first_forecast = df[df.Forecast].iloc[0]
    last_forecast = df[df.Forecast].iloc[-1]
    last_history = df[~df.Forecast].iloc[-1]
    last_history_year = df[~df.Forecast].index.max()

    cd = CardDescription()
    cd.set_values(
        per_resident_adj=get_variable(
            'electricity_consumption_per_capita_adjustment'),
        per_resident_change=(
            (last_forecast.ElectricityConsumptionPerCapita /
             last_history.ElectricityConsumptionPerCapita) - 1) * 100,
        last_history_year=last_history.name,
        solar_production_target=last_forecast.SolarProduction,
        solar_production_perc=(last_forecast.SolarProduction * 100) /
        last_forecast.ElectricityConsumption,
        solar_production_hist=last_history.SolarProduction,
    )
    per_resident_desc = cd.render("""
        Skenaariossa asukaskohtainen sähkönkulutus pienenee {per_resident_adj:noround} % vuodessa.
        Vuonna {target_year} asukaskohtainen kulutus on muuttunut {per_resident_change} % nykyhetkestä.
    """)
    solar_desc = cd.render("""
        Vuonna {target_year} {municipality_locative} sijaitsevilla aurinkopaneeleilla
        tuotetaan {solar_production_target} GWh, joka on {solar_production_perc} %
        kaikesta vuoden {target_year} kulutussähköstä.
    """)

    bar = StickyBar(label=_('Electicity consumption emissions'),
                    value=last_forecast.NetEmissions,
                    unit='kt',
                    current_page=page)

    return [
        per_capita_fig,
        dbc.Col(per_resident_desc, style=dict(minHeight='6rem')), solar_fig,
        dbc.Col(solar_desc, style=dict(minHeight='6rem')), consumption_fig,
        factor_fig, emission_fig,
        bar.render()
    ]