Example #1
0
def population_callback(value):
    set_variable('population_forecast_correction', value)
    pop_df = get_adjusted_population_forecast()
    target_year = get_variable('target_year')
    pop_in_target_year = pop_df.loc[target_year].Population
    last_hist = pop_df[~pop_df.Forecast].iloc[-1]
    fig = generate_population_forecast_graph(pop_df)
    cd = CardDescription()
    cd.set_values(
        pop_in_target_year=pop_in_target_year,
        pop_adj=get_variable('population_forecast_correction'),
        pop_diff=(1 - last_hist.Population / pop_in_target_year) * 100,
    )
    cd.set_variables(last_year=last_hist.name)
    pop_desc = cd.render("""
        {municipality_genitive} väkiluku vuonna {target_year} on {pop_in_target_year}.
        Muutos viralliseen väestöennusteeseen on {pop_adj:noround} %.
        Väkiluvun muutos vuoteen {last_year} verrattuna on {pop_diff} %.
    """)

    bar = StickyBar(
        label="Väkiluku %s" % get_variable('municipality_locative'),
        value=pop_in_target_year,
        unit='asukasta',
    )

    # return fig, pop_in_target_year.round()
    return [fig, dbc.Col(pop_desc), bar.render()]
Example #2
0
def population_callback(value):
    set_variable('population_forecast_correction', value)
    pop_df = predict_population()
    target_year = get_variable('target_year')
    pop_in_target_year = pop_df.loc[target_year].Population
    last_hist = pop_df[~pop_df.Forecast].iloc[-1]
    fig = generate_population_forecast_graph(pop_df)
    cd = CardDescription()
    cd.set_values(
        pop_in_target_year=pop_in_target_year,
        pop_adj=get_variable('population_forecast_correction'),
        pop_diff=(1 - last_hist.Population / pop_in_target_year) * 100,
    )
    cd.set_variables(last_year=last_hist.name)
    pop_desc = cd.render("""
        The population of {municipality} in the year {target_year} will be {pop_in_target_year}.
        The difference compared to the official population forecast is {pop_adj:noround} %.
        Population change compared to {last_year} is {pop_diff} %.
    """)
    # pop_desc = cd.render("""
    #    {municipality_genitive} väkiluku vuonna {target_year} on {pop_in_target_year}.
    #    Muutos viralliseen väestöennusteeseen on {pop_adj:noround} %.
    #    Väkiluvun muutos vuoteen {last_year} verrattuna on {pop_diff} %.
    #""")

    bar = StickyBar(
        label=gettext('Population in %(municipality)s') %
        dict(municipality=get_variable('municipality_name')),
        value=pop_in_target_year,
        unit=gettext('residents'),
    )

    # return fig, pop_in_target_year.round()
    return [fig, dbc.Col(pop_desc), bar.render()]
Example #3
0
    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.
        """))
Example #4
0
 def generate_card_description(self, production_stats, production_fuels):
     df = production_stats.iloc[-1]
     cd = CardDescription()
     cd.set_values(
         generated_heat=df.loc['Production with heat pumps'],
         cop=get_variable('district_heating_heat_pump_cop'),
         el_use=df.loc['Heat pump electricity consumption'],
     )
     return cd.render("""
     Vuonna {target_year} {municipality_locative} tuotetaan lämpöpumpuilla
     {generated_heat} GWh lämpöä. Lämpöpumppujen COP-luku on keskimäärin {cop:noround},
     jolloin lämpöpumput tarvitsevat {el_use} GWh sähköä.
     """)
Example #5
0
 def generate_card_description(self, production_stats, production_fuels):
     target_year = production_fuels.iloc[-1]
     fuel_df = prepare_fuel_classification_dataset()
     ef = fuel_df[fuel_df.name == self.name].co2e_emission_factor.iloc[0]
     cd = CardDescription()
     cd.set_values(
         generated_heat=target_year.loc[self.name],
         ef=ef,
     )
     return cd.render("""
     Maakaasua polttamalla tuotetaan {generated_heat} GWh lämpöä.
     Maakaasun päästökerroin on {ef} t/TJ.
     """)
Example #6
0
 def generate_card_description(self, production_stats, production_fuels):
     target_year = production_fuels.iloc[-1]
     fuel_df = prepare_fuel_classification_dataset()
     bio_ef = fuel_df[fuel_df.name ==
                      self.name].co2e_emission_factor.iloc[0]
     bio_ef_perc = get_variable('bio_emission_factor')
     cd = CardDescription()
     cd.set_values(
         generated_heat=target_year.loc[self.name],
         bio_ef=bio_ef * bio_ef_perc / 100,
         bio_ef_perc=bio_ef_perc,
         bio_ef_real=bio_ef,
     )
     return cd.render("""
     Biomassaa polttamalla tuotetaan {generated_heat} GWh lämpöä.
     Biomassalle käytetään laskennallista päästökerrointa {bio_ef} t/TJ,
     joka on {bio_ef_perc:noround}\u00a0% biomassan fysikaalisesta
     päästökertoimesta ({bio_ef_real} t/TJ).
     """)
Example #7
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()
    ]
Example #8
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
    ]
Example #9
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)
Example #10
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)
Example #11
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')
Example #12
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')
Example #13
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()
    ]
Example #14
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
    ]