Ejemplo n.º 1
0
def test_assign_lp_no_techs():
    """Testing
    """
    lp_stock_obj = load_profile.LoadProfileStock("test_stock")

    # Shape
    _a = np.zeros((365, 24))
    _b = np.array(range(365))
    shape_yh = _a + _b[:, np.newaxis]
    shape_yh = shape_yh / float(np.sum(range(365)) * 24)

    lp_stock_obj.add_lp(unique_identifier="A123",
                        technologies=['placeholder_tech'],
                        enduses=['test_enduse'],
                        shape_yd=np.full((365, 24), 1 / 365),
                        shape_yh=shape_yh,
                        sectors=['test_sector'],
                        model_yeardays=list(range(365)),
                        shape_y_dh=False)

    fuel_y = np.zeros((3))
    fuel_y[2] = 100
    fuel_yh = enduse_func.assign_lp_no_techs(enduse="test_enduse",
                                             sector="test_sector",
                                             load_profiles=lp_stock_obj,
                                             fuel_y=fuel_y,
                                             make_all_flat=False)

    assert np.sum(fuel_yh) == 100
Ejemplo n.º 2
0
def test_LoadProfileStock():
    """testing
    """

    result_obj = load_profile.LoadProfileStock("test_stock")

    expected = "test_stock"

    assert result_obj.name == expected
    model_yeardays = list(range(365))
    # -----
    result_obj.add_lp(unique_identifier="A123",
                      technologies=['placeholder_tech'],
                      enduses=['cooking'],
                      shape_y_dh=np.zeros((365)),
                      shape_yd=np.zeros((365)),
                      shape_yh=np.zeros((365, 24)),
                      sectors=[False],
                      model_yeardays=model_yeardays)

    result = result_obj.stock_enduses

    result2 = load_profile.get_stock_enduses(result_obj.load_profiles)

    assert result == ['cooking']
    assert result2 == ['cooking']

    # ---
    # -----
    result_obj.add_lp(unique_identifier="A123",
                      technologies=['placeholder_tech'],
                      enduses=['cooking'],
                      shape_y_dh=np.zeros((365)),
                      shape_yd=np.zeros((365)),
                      shape_yh=np.zeros((365, 24)),
                      sectors=['sectorA'],
                      model_yeardays=model_yeardays)

    result = result_obj.stock_enduses
    assert result == ['cooking']

    # test get_lp()
    np.testing.assert_array_equal(
        np.zeros((365, 24)),
        result_obj.get_lp('cooking', 'sectorA', 'placeholder_tech',
                          'shape_yh'))
Ejemplo n.º 3
0
def test_calc_fuel_tech_yh():
    """Testing
    """
    fueltypes = {'gas': 0, 'heat': 1}

    technologies = {'techA': read_data.TechnologyData()}
    technologies['techA'].fueltype_str = 'gas'
    technologies['techA'].eff_achieved = 1.0
    technologies['techA'].diff_method = 'linear'
    technologies['techA'].eff_by = 0.5
    technologies['techA'].eff_ey = 0.5
    technologies['techA'].year_eff_ey = 2020
    '''tech_stock = technological_stock.TechStock(
        name="name",
        technologies=technologies,
        base_yr=2015,
        curr_yr=2020,
        fueltypes=fueltypes,
        temp_by=np.ones((365, 24)) + 10,
        temp_cy=np.ones((365, 24)) + 10,
        t_base_heating_by=15.5,
        potential_enduses=['heating'],
        t_base_heating_cy=15.5,
        enduse_technologies={'heating': ['techA']})'''

    lp_stock_obj = load_profile.LoadProfileStock("test_stock")

    _a = np.zeros((365, 24))
    _b = np.array(range(365))
    shape_yh = _a + _b[:, np.newaxis]
    shape_yh = shape_yh / float(np.sum(range(365)) * 24)
    model_yeardays = list(range(365))

    lp_stock_obj.add_lp(unique_identifier="A123",
                        technologies=['techA'],
                        enduses=['heating'],
                        shape_yd=np.full((365, 24), 1 / 365),
                        shape_yh=shape_yh,
                        sectors=['sectorA'],
                        shape_y_dh=np.full((365), 1 / 365),
                        model_yeardays=model_yeardays)

    fuel = 200
    results = enduse_func.calc_fuel_tech_yh(enduse='heating',
                                            sector='sectorA',
                                            enduse_techs=['techA'],
                                            fuel_tech_y={'techA': fuel},
                                            load_profiles=lp_stock_obj,
                                            fueltypes_nr=2,
                                            fueltypes=fueltypes,
                                            mode_constrained=False)

    assert results[1][3][0] == 3.0 / float(np.sum(range(365)) * 24) * 200

    # ---
    results = enduse_func.calc_fuel_tech_yh(enduse='heating',
                                            sector='sectorA',
                                            enduse_techs=['techA'],
                                            fuel_tech_y={'techA': fuel},
                                            load_profiles=lp_stock_obj,
                                            fueltypes_nr=2,
                                            fueltypes=fueltypes,
                                            mode_constrained=True)

    assert results['techA'][3][0] == 3.0 / float(np.sum(range(365)) * 24) * 200
Ejemplo n.º 4
0
    def __init__(
            self,
            name,
            assumptions,
            technologies,
            enduses,
            temp_by,
            temp_cy,
            tech_lp,
            sectors,
            crit_temp_min_max
        ):
        """Constructor of weather region
        """
        self.name = name

        fueltypes = lookup_tables.basic_lookups()['fueltypes']

        # Base temperatures of current year
        rs_t_base_heating_cy = assumptions.non_regional_vars['rs_t_base_heating'][assumptions.curr_yr]
        ss_t_base_heating_cy = assumptions.non_regional_vars['ss_t_base_heating'][assumptions.curr_yr]
        ss_t_base_cooling_cy = assumptions.non_regional_vars['ss_t_base_cooling'][assumptions.curr_yr]
        is_t_base_heating_cy = assumptions.non_regional_vars['is_t_base_heating'][assumptions.curr_yr]

        # ==================================================================
        # Technology stocks
        # ==================================================================
        rs_tech_stock = technological_stock.TechStock(
            'rs_tech_stock',
            technologies,
            assumptions.base_yr,
            assumptions.curr_yr,
            fueltypes,
            temp_by,
            temp_cy,
            assumptions.t_bases.rs_t_heating,
            enduses['residential'],
            rs_t_base_heating_cy,
            assumptions.specified_tech_enduse_by)

        ss_tech_stock = technological_stock.TechStock(
            'ss_tech_stock',
            technologies,
            assumptions.base_yr,
            assumptions.curr_yr,
            fueltypes,
            temp_by,
            temp_cy,
            assumptions.t_bases.ss_t_heating,
            enduses['service'],
            ss_t_base_heating_cy,
            assumptions.specified_tech_enduse_by)

        is_tech_stock = technological_stock.TechStock(
            'is_tech_stock',
            technologies,
            assumptions.base_yr,
            assumptions.curr_yr,
            fueltypes,
            temp_by,
            temp_cy,
            assumptions.t_bases.is_t_heating,
            enduses['industry'],
            ss_t_base_heating_cy,
            assumptions.specified_tech_enduse_by)

        self.tech_stock = {
            'residential': rs_tech_stock,
            'service': ss_tech_stock,
            'industry': is_tech_stock}

        # ==================================================================
        # Load profiles
        # ==================================================================
        flat_shape_yd, _, flat_shape_y_dh = generic_shapes.flat_shape()

        # ==================================================================
        # Residential submodel load profiles
        # ==================================================================
        load_profiles = load_profile.LoadProfileStock("load_profiles")
        dummy_sector = None

        # --------Calculate HDD/CDD of used weather year
        self.rs_hdd_by, _ = hdd_cdd.calc_reg_hdd(
            temp_by, assumptions.t_bases.rs_t_heating, assumptions.model_yeardays, crit_temp_min_max)
        self.rs_hdd_cy, rs_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd(
            temp_cy, rs_t_base_heating_cy, assumptions.model_yeardays, crit_temp_min_max)

        # --------Calculate HDD/CDD of base year weather year
        #self.rs_cdd_by, _ = hdd_cdd.calc_reg_cdd(
        #    temp_by, assumptions.t_bases.rs_t_cooling_by, assumptions.model_yeardays)
        #self.rs_cdd_cy, rs_fuel_shape_cooling_yd = hdd_cdd.calc_reg_cdd(
        #    temp_cy, rs_t_base_cooling_cy, assumptions.model_yeardays)

        # -------Calculate climate change correction factors
        try:
            f_heat_rs_y = np.nan_to_num(
                1.0 / float(np.sum(self.rs_hdd_by))) * np.sum(self.rs_hdd_cy)
            #self.f_cooling_rs_y = np.nan_to_num(
            #    1.0 / float(np.sum(self.rs_cdd_by))) * np.sum(self.rs_cdd_cy)
            f_cooling_rs_y = 1
        except ZeroDivisionError:
            f_heat_rs_y = 1
            f_cooling_rs_y = 1

        # Calculate rs peak day
        rs_peak_day = enduse_func.get_peak_day(self.rs_hdd_cy)

        # ========
        # Enduse specific profiles
        # ========
        # -- Apply enduse sepcific shapes for enduses with not technologies with own defined shapes
        for enduse in enduses['residential']:

            # Enduses where technology specific load profiles are defined for yh
            if enduse in ['rs_space_heating']:
                pass
            else:
                # Get all technologies of enduse
                tech_list = helpers.get_nested_dict_key(
                    assumptions.fuel_tech_p_by[enduse][dummy_sector])

                # Remove heat pumps from rs_water_heating
                tech_list = basic_functions.remove_element_from_list(tech_list, 'heat_pumps_electricity')

                shape_y_dh = insert_peak_dh_shape(
                    peak_day=rs_peak_day,
                    shape_y_dh=tech_lp['rs_shapes_dh'][enduse]['shape_non_peak_y_dh'],
                    shape_peak_dh=tech_lp['rs_shapes_dh'][enduse]['shape_peak_dh'])

                load_profiles.add_lp(
                    unique_identifier=uuid.uuid4(),
                    technologies=tech_list,
                    enduses=[enduse],
                    shape_yd=tech_lp['rs_shapes_yd'][enduse]['shape_non_peak_yd'],
                    shape_y_dh=shape_y_dh,
                    sectors=[dummy_sector],
                    model_yeardays=assumptions.model_yeardays)

        # ==========
        # Technology specific profiles for residential heating
        # ===========
        # ------Heating boiler
        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['heating_const'],
            enduses=['rs_space_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_y_dh=tech_lp['rs_profile_boilers_y_dh'],
            sectors=[dummy_sector],
            model_yeardays=assumptions.model_yeardays)

        # ------Heating CHP
        rs_profile_chp_y_dh = insert_peak_dh_shape(
            peak_day=rs_peak_day,
            shape_y_dh=tech_lp['rs_profile_chp_y_dh'],
            shape_peak_dh=tech_lp['rs_lp_heating_CHP_dh']['peakday'])

        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['tech_CHP'],
            enduses=['rs_space_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_y_dh=rs_profile_chp_y_dh,
            sectors=[dummy_sector],
            model_yeardays=assumptions.model_yeardays)

        # ------Electric heating, storage heating (primary)
        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['storage_heating_electricity'],
            enduses=['rs_space_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_y_dh=tech_lp['rs_profile_storage_heater_y_dh'],
            sectors=[dummy_sector],
            model_yeardays=assumptions.model_yeardays)

        # ------Electric heating secondary (direct elec heating)
        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['secondary_heating_electricity'],
            enduses=['rs_space_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_y_dh=tech_lp['rs_profile_elec_heater_y_dh'],
            sectors=[dummy_sector],
            model_yeardays=assumptions.model_yeardays)

        # ------Heat pump heating
        rs_profile_hp_y_dh = insert_peak_dh_shape(
            peak_day=rs_peak_day,
            shape_y_dh=tech_lp['rs_profile_hp_y_dh'],
            shape_peak_dh=tech_lp['rs_lp_heating_hp_dh']['peakday'])

        rs_fuel_shape_hp_yh, rs_hp_shape_yd = get_fuel_shape_heating_hp_yh(
            tech_lp_y_dh=rs_profile_hp_y_dh,
            tech_stock=rs_tech_stock,
            rs_hdd_cy=self.rs_hdd_cy,
            model_yeardays=assumptions.model_yeardays)

        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['heating_non_const'],
            enduses=['rs_space_heating', 'rs_water_heating'],
            shape_y_dh=rs_profile_hp_y_dh,
            shape_yd=rs_hp_shape_yd,
            shape_yh=rs_fuel_shape_hp_yh,
            sectors=[dummy_sector],
            model_yeardays=assumptions.model_yeardays)

        # ------District_heating_electricity. Assumption made that same curve as CHP
        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['tech_district_heating'],
            enduses=['rs_space_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_y_dh=rs_profile_hp_y_dh,
            sectors=[dummy_sector],
            model_yeardays=assumptions.model_yeardays)

        # ==================================================================
        # Service Submodel load profiles
        # ==================================================================
        # --------HDD/CDD
        # current weather_yr
        self.ss_hdd_by, _ = hdd_cdd.calc_reg_hdd(
            temp_by, assumptions.t_bases.ss_t_heating, assumptions.model_yeardays, crit_temp_min_max)

        ss_hdd_cy, ss_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd(
            temp_cy, ss_t_base_heating_cy, assumptions.model_yeardays, crit_temp_min_max)

        self.ss_cdd_by, _ = hdd_cdd.calc_reg_cdd(
            temp_by, assumptions.t_bases.ss_t_cooling, assumptions.model_yeardays, crit_temp_min_max)

        ss_cdd_cy, ss_lp_cooling_yd = hdd_cdd.calc_reg_cdd(
            temp_cy, ss_t_base_cooling_cy, assumptions.model_yeardays, crit_temp_min_max)

        try:
            f_heat_ss_y = np.nan_to_num(
                1.0 / float(np.sum(self.ss_hdd_by))) * np.sum(ss_hdd_cy)
            f_cooling_ss_y = np.nan_to_num(
                1.0 / float(np.sum(self.ss_cdd_by))) * np.sum(ss_cdd_cy)
        except ZeroDivisionError:
            f_heat_ss_y = 1
            f_cooling_ss_y = 1

        # ========
        # Enduse specific profiles
        # ========
        # - Assign to each enduse the carbon fuel trust dataset
        for enduse in enduses['service']:

            # Skip temperature dependent end uses (regional) because load profile in regional load profile stock
            if enduse in assumptions.enduse_space_heating or enduse in assumptions.ss_enduse_space_cooling:
                pass
            else:
                for sector in sectors['service']:

                    # Get technologies with assigned fuel shares
                    tech_list = helpers.get_nested_dict_key(
                        assumptions.fuel_tech_p_by[enduse][sector])

                    # Apply correction factor for weekend_effect
                    shape_non_peak_yd_weighted = load_profile.abs_to_rel(
                        tech_lp['ss_shapes_yd'][enduse][sector]['shape_non_peak_yd'] * assumptions.ss_weekend_f)

                    load_profiles.add_lp(
                        unique_identifier=uuid.uuid4(),
                        technologies=tech_list,
                        enduses=[enduse],
                        shape_yd=shape_non_peak_yd_weighted,
                        shape_y_dh=tech_lp['ss_shapes_dh'][enduse][sector]['shape_non_peak_y_dh'],
                        model_yeardays=assumptions.model_yeardays,
                        sectors=[sector])

        # Apply correction factor for weekend_effect for space heating
        ss_fuel_shape_heating_yd_weighted = load_profile.abs_to_rel(
            ss_fuel_shape_heating_yd * assumptions.ss_weekend_f)

        # ========
        # Technology specific profiles
        # ========

        # Flatten list of all potential technologies
        ss_space_heating_tech_lists = list(assumptions.tech_list.values())
        all_techs_ss_space_heating = [item for sublist in ss_space_heating_tech_lists for item in sublist]


        # -----Heat pump (RESIDENTIAL HEAT PUMP PROFILE FOR SERVICE SECTOR)
        all_techs_ss_space_heating = basic_functions.remove_element_from_list(
            all_techs_ss_space_heating, 'heat_pumps_electricity')

        ss_fuel_shape_hp_yh, ss_hp_shape_yd = get_fuel_shape_heating_hp_yh(
            tech_lp_y_dh=rs_profile_hp_y_dh,
            tech_stock=rs_tech_stock,
            rs_hdd_cy=ss_hdd_cy,
            model_yeardays=assumptions.model_yeardays)

        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['heating_non_const'],
            enduses=['ss_space_heating', 'ss_water_heating'],
            sectors=sectors['service'],
            shape_y_dh=rs_profile_hp_y_dh,
            shape_yd=ss_hp_shape_yd,
            shape_yh=ss_fuel_shape_hp_yh,
            model_yeardays=assumptions.model_yeardays)

        # ---secondary_heater_electricity Info: The residential direct heating load profile is used
        all_techs_ss_space_heating = basic_functions.remove_element_from_list(
            all_techs_ss_space_heating, 'secondary_heater_electricity')

        # Get aggregated electricity load profile
        #ALTERNATIVE :tech_lp['ss_all_tech_shapes_dh']['ss_other_electricity']['shape_non_peak_y_dh']
        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['secondary_heating_electricity'],
            enduses=['ss_space_heating'],
            sectors=sectors['service'],
            shape_yd=ss_fuel_shape_heating_yd_weighted,
            shape_y_dh=tech_lp['rs_profile_elec_heater_y_dh'],
            model_yeardays=assumptions.model_yeardays)
            # ELEC CURVE ss_fuel_shape_electricity # DIRECT HEATING ss_profile_elec_heater_yh

        # ---Heating technologies (all other)
        # (the heating shape follows the gas shape of aggregated sectors)
        # meaning that for all technologies, the load profile is the same
        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=all_techs_ss_space_heating,
            enduses=['ss_space_heating'],
            sectors=sectors['service'],
            shape_yd=ss_fuel_shape_heating_yd_weighted,
            shape_y_dh=tech_lp['ss_all_tech_shapes_dh']['ss_space_heating']['shape_non_peak_y_dh'],
            model_yeardays=assumptions.model_yeardays)

        # --Add cooling technologies for service sector
        coolings_techs = assumptions.tech_list['cooling_const']

        for cooling_enduse in assumptions.ss_enduse_space_cooling:
            for sector in sectors['service']:

                # Apply correction factor for weekend_effect 'cdd_weekend_cfactors'
                ss_lp_cooling_yd_weighted = load_profile.abs_to_rel(
                    ss_lp_cooling_yd * assumptions.cdd_weekend_cfactors)

                load_profiles.add_lp(
                    unique_identifier=uuid.uuid4(),
                    technologies=coolings_techs,
                    enduses=[cooling_enduse],
                    sectors=[sector],
                    shape_yd=ss_lp_cooling_yd_weighted,
                    shape_y_dh=tech_lp['ss_profile_cooling_y_dh'],
                    model_yeardays=assumptions.model_yeardays)

        # ==================================================================
        # Industry submodel load profiles
        # ==================================================================

        # --------HDD/CDD
        # Current weather_yr
        self.is_hdd_by, _ = hdd_cdd.calc_reg_hdd(
            temp_by, assumptions.t_bases.is_t_heating, assumptions.model_yeardays, crit_temp_min_max)

        #is_cdd_by, _ = hdd_cdd.calc_reg_cdd(
        #    temp_by, assumptions.t_bases.is_t_cooling, assumptions.model_yeardays)

        # Take same base temperature as for service sector
        is_hdd_cy, is_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd(
            temp_cy, is_t_base_heating_cy, assumptions.model_yeardays, crit_temp_min_max)
        #is_cdd_cy, _ = hdd_cdd.calc_reg_cdd(
        #    temp_cy, ss_t_base_cooling_cy, assumptions.model_yeardays)

        try:
            f_heat_is_y = np.nan_to_num(1.0 / float(np.sum(self.is_hdd_by))) * np.sum(is_hdd_cy)
            #self.f_cooling_is_y = np.nan_to_num(1.0 / float(np.sum(is_cdd_by))) * np.sum(is_cdd_cy)
            f_cooling_is_y = 1
        except ZeroDivisionError:
            f_heat_is_y = 1
            f_cooling_is_y = 1

        # ========
        # Technology specific profiles
        # ========

        # --Heating technologies

        # Flatten list of all potential heating technologies
        is_space_heating_tech_lists = list(assumptions.tech_list.values())
        all_techs_is_space_heating = [item for sublist in is_space_heating_tech_lists for item in sublist]

        # Apply correction factor for weekend_effect for space heating load profile
        is_fuel_shape_heating_yd_weighted = load_profile.abs_to_rel(
            is_fuel_shape_heating_yd * assumptions.is_weekend_f)

        # - Direct electric heating
        # Remove tech from all space heating techs
        all_techs_is_space_heating = basic_functions.remove_element_from_list(
            all_techs_is_space_heating, 'secondary_heater_electricity')

        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=assumptions.tech_list['secondary_heating_electricity'],
            enduses=['is_space_heating'],
            sectors=sectors['industry'],
            shape_yd=is_fuel_shape_heating_yd_weighted,
            shape_y_dh=tech_lp['rs_profile_elec_heater_y_dh'],
            model_yeardays=assumptions.model_yeardays)

        # Add flat load profiles for non-electric heating technologies
        load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=all_techs_is_space_heating,
            enduses=['is_space_heating'],
            sectors=sectors['industry'],
            shape_yd=is_fuel_shape_heating_yd_weighted,
            shape_y_dh=flat_shape_y_dh,
            model_yeardays=assumptions.model_yeardays)

        # Apply correction factor for weekend_effect to flat load profile for industry
        flat_shape_yd = flat_shape_yd * assumptions.is_weekend_f
        flat_shape_yd_weighted = load_profile.abs_to_rel(flat_shape_yd)

        # ========
        # Enduse specific profiles
        # ========
        for enduse in enduses['industry']:
            if enduse == "is_space_heating":
                pass # Do not create non regional stock because temp dependent
            else:
                for sector in sectors['industry']:

                    tech_list = helpers.get_nested_dict_key(
                        assumptions.fuel_tech_p_by[enduse][sector])

                    load_profiles.add_lp(
                        unique_identifier=uuid.uuid4(),
                        technologies=tech_list,
                        enduses=[enduse],
                        shape_yd=flat_shape_yd_weighted,
                        shape_y_dh=flat_shape_y_dh,
                        model_yeardays=assumptions.model_yeardays,
                        sectors=[sector])

        # ---------------
        # Load profiles
        # ---------------
        self.load_profiles = load_profiles

        self.f_heat = {
            'residential': f_heat_rs_y,
            'service': f_heat_ss_y,
            'industry': f_heat_is_y}

        self.f_colling = {
            'residential': f_cooling_rs_y,
            'service': f_cooling_ss_y,
            'industry': f_cooling_is_y}
Ejemplo n.º 5
0
    def create_load_profile_stock(cls, data):
        """Assign load profiles which are the same for all regions
        ``non_regional_load_profiles``

        Parameters
        ----------
        data : dict
            Data container

        Returns
        -------
        non_regional_profile_stock : object
            Load profile stock with non regional dependent load profiles
        """
        non_regional_profile_stock = load_profile.LoadProfileStock(
            "non_regional_load_profiles")

        # Lighting (residential)
        non_regional_profile_stock.add_load_profile(
            unique_identifier=uuid.uuid4(),
            technologies=data['assumptions']['technology_list']['rs_lighting'],
            enduses=['rs_lighting'],
            shape_yd=data['rs_shapes_yd']['rs_lighting']['shape_non_peak_yd'],
            shape_yh=data['rs_shapes_dh']['rs_lighting']['shape_non_peak_y_dh']
            * data['rs_shapes_yd']['rs_lighting']['shape_non_peak_yd']
            [:, np.newaxis],
            enduse_peak_yd_factor=data['rs_shapes_yd']['rs_lighting']
            ['shape_peak_yd_factor'],
            shape_peak_dh=data['rs_shapes_dh']['rs_lighting']['shape_peak_dh'])

        # rs_cold (residential refrigeration)
        non_regional_profile_stock.add_load_profile(
            unique_identifier=uuid.uuid4(),
            technologies=data['assumptions']['technology_list']['rs_cold'],
            enduses=['rs_cold'],
            shape_yd=data['rs_shapes_yd']['rs_cold']['shape_non_peak_yd'],
            shape_yh=data['rs_shapes_dh']['rs_cold']['shape_non_peak_y_dh'] *
            data['rs_shapes_yd']['rs_cold']['shape_non_peak_yd'][:,
                                                                 np.newaxis],
            enduse_peak_yd_factor=data['rs_shapes_yd']['rs_cold']
            ['shape_peak_yd_factor'],
            shape_peak_dh=data['rs_shapes_dh']['rs_cold']['shape_peak_dh'])

        # rs_cooking
        non_regional_profile_stock.add_load_profile(
            unique_identifier=uuid.uuid4(),
            technologies=data['assumptions']['technology_list']['rs_cooking'],
            enduses=['rs_cooking'],
            shape_yd=data['rs_shapes_yd']['rs_cooking']['shape_non_peak_yd'],
            shape_yh=data['rs_shapes_dh']['rs_cooking']['shape_non_peak_y_dh']
            * data['rs_shapes_yd']['rs_cooking']['shape_non_peak_yd']
            [:, np.newaxis],
            enduse_peak_yd_factor=data['rs_shapes_yd']['rs_cooking']
            ['shape_peak_yd_factor'],
            shape_peak_dh=data['rs_shapes_dh']['rs_cooking']['shape_peak_dh'])

        # rs_wet
        non_regional_profile_stock.add_load_profile(
            unique_identifier=uuid.uuid4(),
            technologies=data['assumptions']['technology_list']['rs_wet'],
            enduses=['rs_wet'],
            shape_yd=data['rs_shapes_yd']['rs_wet']['shape_non_peak_yd'],
            shape_yh=data['rs_shapes_dh']['rs_wet']['shape_non_peak_y_dh'] *
            data['rs_shapes_yd']['rs_wet']['shape_non_peak_yd'][:, np.newaxis],
            enduse_peak_yd_factor=data['rs_shapes_yd']['rs_wet']
            ['shape_peak_yd_factor'],
            shape_peak_dh=data['rs_shapes_dh']['rs_wet']['shape_peak_dh'])

        # -- dummy rs technologies (apply enduse sepcific shape)
        for enduse in data['assumptions']['rs_dummy_enduses']:
            tech_list = helpers.get_nested_dict_key(
                data['assumptions']['rs_fuel_tech_p_by'][enduse])
            non_regional_profile_stock.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=tech_list,
                enduses=[enduse],
                shape_yd=data['rs_shapes_yd'][enduse]['shape_non_peak_yd'],
                shape_yh=data['rs_shapes_dh'][enduse]['shape_non_peak_y_dh'] *
                data['rs_shapes_yd'][enduse]['shape_non_peak_yd'][:,
                                                                  np.newaxis],
                enduse_peak_yd_factor=data['rs_shapes_yd'][enduse]
                ['shape_peak_yd_factor'],
                shape_peak_dh=data['rs_shapes_dh'][enduse]['shape_peak_dh'])

        # - dummy ss technologies
        for enduse in data['assumptions']['ss_dummy_enduses']:
            tech_list = helpers.get_nested_dict_key(
                data['assumptions']['ss_fuel_tech_p_by'][enduse])
            for sector in data['ss_sectors']:
                non_regional_profile_stock.add_load_profile(
                    unique_identifier=uuid.uuid4(),
                    technologies=tech_list,
                    enduses=[enduse],
                    sectors=[sector],
                    shape_yd=data['ss_shapes_yd'][sector][enduse]
                    ['shape_non_peak_yd'],
                    shape_yh=data['ss_shapes_dh'][sector][enduse]
                    ['shape_non_peak_y_dh'] * data['ss_shapes_yd'][sector]
                    [enduse]['shape_non_peak_yd'][:, np.newaxis],
                    enduse_peak_yd_factor=data['ss_shapes_yd'][sector][enduse]
                    ['shape_peak_yd_factor'],
                    shape_peak_dh=data['ss_shapes_dh'][sector][enduse]
                    ['shape_peak_dh'])

        # dummy is - Flat load profile
        shape_peak_dh, _, shape_peak_yd_factor, shape_non_peak_yd, shape_non_peak_yh = generic_shapes.generic_flat_shape(
        )

        for enduse in data['assumptions']['is_dummy_enduses']:
            tech_list = helpers.get_nested_dict_key(
                data['assumptions']['is_fuel_tech_p_by'][enduse])
            for sector in data['is_sectors']:
                non_regional_profile_stock.add_load_profile(
                    unique_identifier=uuid.uuid4(),
                    technologies=tech_list,
                    enduses=[enduse],
                    sectors=[sector],
                    shape_yd=shape_non_peak_yd,
                    shape_yh=shape_non_peak_yh,
                    enduse_peak_yd_factor=shape_peak_yd_factor,
                    shape_peak_dh=shape_peak_dh)

        return non_regional_profile_stock
Ejemplo n.º 6
0
    def __init__(self, weather_region_name, data, modeltype):
        """Constructor
        """
        self.weather_region_name = weather_region_name

        # Temperatures
        temp_by = data['temperature_data'][weather_region_name][
            data['sim_param']['base_yr']]
        temp_cy = data['temperature_data'][weather_region_name][
            data['sim_param']['curr_yr']]

        rs_t_base_heating_cy = hdd_cdd.sigm_temp(data['sim_param'],
                                                 data['assumptions'],
                                                 'rs_t_base_heating')
        rs_t_base_cooling_cy = hdd_cdd.sigm_temp(data['sim_param'],
                                                 data['assumptions'],
                                                 'rs_t_base_cooling')
        rs_t_base_heating_by = hdd_cdd.sigm_temp(data['sim_param'],
                                                 data['assumptions'],
                                                 'rs_t_base_heating')
        rs_t_base_cooling_by = hdd_cdd.sigm_temp(data['sim_param'],
                                                 data['assumptions'],
                                                 'rs_t_base_cooling')
        ss_t_base_heating_cy = hdd_cdd.sigm_temp(data['sim_param'],
                                                 data['assumptions'],
                                                 'ss_t_base_heating')
        ss_t_base_cooling_cy = hdd_cdd.sigm_temp(data['sim_param'],
                                                 data['assumptions'],
                                                 'ss_t_base_cooling')
        ss_t_base_heating_by = hdd_cdd.sigm_temp(data['sim_param'],
                                                 data['assumptions'],
                                                 'ss_t_base_heating')
        ss_t_base_cooling_by = hdd_cdd.sigm_temp(data['sim_param'],
                                                 data['assumptions'],
                                                 'ss_t_base_cooling')

        # -------------------
        # Technology stock
        # -------------------
        if modeltype == 'is_submodel':
            self.is_tech_stock = technological_stock.TechStock(
                'is_tech_stock', data, temp_by, temp_cy,
                data['assumptions']['ss_t_base_heating']['base_yr'],
                data['is_all_enduses'], ss_t_base_heating_cy,
                data['assumptions']['is_specified_tech_enduse_by'])
        elif modeltype == 'rs_submodel':
            self.rs_tech_stock = technological_stock.TechStock(
                'rs_tech_stock', data, temp_by, temp_cy,
                data['assumptions']['rs_t_base_heating']['base_yr'],
                data['rs_all_enduses'], rs_t_base_heating_cy,
                data['assumptions']['rs_specified_tech_enduse_by'])
        elif modeltype == 'ss_submodel':
            self.ss_tech_stock = technological_stock.TechStock(
                'ss_tech_stock', data, temp_by, temp_cy,
                data['assumptions']['ss_t_base_heating']['base_yr'],
                data['ss_all_enduses'], ss_t_base_heating_cy,
                data['assumptions']['ss_specified_tech_enduse_by'])

        # -------------------
        # Load profiles
        # -------------------
        if modeltype == 'rs_submodel':

            # --------Profiles
            self.rs_load_profiles = load_profile.LoadProfileStock(
                "rs_load_profiles")

            # --------HDD/CDD
            rs_hdd_by, _ = hdd_cdd.get_reg_hdd(temp_by, rs_t_base_heating_by)
            rs_cdd_by, _ = hdd_cdd.get_reg_cdd(temp_by, rs_t_base_cooling_by)
            rs_hdd_cy, rs_fuel_shape_heating_yd = hdd_cdd.get_reg_hdd(
                temp_cy, rs_t_base_heating_cy)
            rs_cdd_cy, _ = hdd_cdd.get_reg_cdd(temp_cy, rs_t_base_cooling_cy)

            # Climate change correction factors
            # (Assumption: Demand for heat correlates directly with fuel)
            try:
                self.rs_heating_factor_y = np.nan_to_num(
                    1.0 / float(np.sum(rs_hdd_by))) * np.sum(rs_hdd_cy)
                self.rs_cooling_factor_y = np.nan_to_num(
                    1.0 / float(np.sum(rs_cdd_by))) * np.sum(rs_cdd_cy)
            except ZeroDivisionError:
                self.rs_heating_factor_y = 1
                self.rs_cooling_factor_y = 1

            # yd peak factors for heating and cooling
            rs_peak_yd_heating_factor = self.get_shape_peak_yd_factor(
                rs_hdd_cy)
            #rs_peak_yd_cooling_factor = self.get_shape_peak_yd_factor(rs_cdd_cy)

            # --Specific heating technologies for residential sector
            rs_profile_storage_heater_yh, _ = self.get_shape_heating_boilers_yh(
                data, rs_fuel_shape_heating_yd,
                'rs_profile_heating_storage_dh')
            rs_profile_elec_heater_yh, _ = self.get_shape_heating_boilers_yh(
                data, rs_fuel_shape_heating_yd,
                'rs_profile_heating_second_heating_dh')
            # boiler, non-peak
            rs_profile_boilers_yh, rs_profile_boilers_y_dh = self.get_shape_heating_boilers_yh(
                data, rs_fuel_shape_heating_yd, 'rs_shapes_heating_boilers_dh')
            # heat pumps, non-peak
            rs_fuel_shape_hp_yh, rs_fuel_shape_hp_y_dh = self.get_fuel_shape_heating_hp_yh(
                data, self.rs_tech_stock, rs_hdd_cy,
                'rs_shapes_heating_heat_pump_dh')

            rs_fuel_shape_hybrid_tech_yh = self.get_shape_heating_hybrid_yh(
                self.rs_tech_stock, 'rs_space_heating',
                rs_profile_boilers_y_dh, rs_fuel_shape_hp_y_dh,
                rs_fuel_shape_heating_yd, 'hybrid_gas_electricity')

            # Cooling residential
            #rs_fuel_shape_cooling_yh = self.get_shape_cooling_yh(
            # data, rs_fuel_shape_cooling_yd, 'rs_shapes_cooling_dh')

            # Heating boiler
            self.rs_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_const'],
                enduses=['rs_space_heating', 'rs_water_heating'],
                shape_yd=rs_fuel_shape_heating_yd,
                shape_yh=rs_profile_boilers_yh,
                enduse_peak_yd_factor=rs_peak_yd_heating_factor,
                shape_peak_dh=data['rs_shapes_heating_boilers_dh']['peakday'])

            # Electric heating, primary...(storage)
            self.rs_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['primary_heating_electricity'],
                enduses=['rs_space_heating'],
                shape_yd=rs_fuel_shape_heating_yd,
                shape_yh=rs_profile_storage_heater_yh,
                enduse_peak_yd_factor=rs_peak_yd_heating_factor,
                shape_peak_dh=data['rs_profile_heating_storage_dh']['peakday'])

            # Electric heating, secondary...
            self.rs_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['secondary_heating_electricity'],
                enduses=['rs_space_heating', 'rs_water_heating'],
                shape_yd=rs_fuel_shape_heating_yd,
                shape_yh=rs_profile_elec_heater_yh,
                enduse_peak_yd_factor=rs_peak_yd_heating_factor,
                shape_peak_dh=data['rs_profile_heating_second_heating_dh']
                ['peakday'])

            # Hybrid heating
            self.rs_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_hybrid'],
                enduses=['rs_space_heating', 'rs_water_heating'],
                shape_yd=rs_fuel_shape_heating_yd,
                shape_yh=rs_fuel_shape_hybrid_tech_yh,
                enduse_peak_yd_factor=rs_peak_yd_heating_factor)

            # Heat pump heating
            self.rs_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_temp_dep'],
                enduses=['rs_space_heating', 'rs_water_heating'],
                shape_yd=rs_fuel_shape_heating_yd,
                shape_yh=rs_fuel_shape_hp_yh,
                enduse_peak_yd_factor=rs_peak_yd_heating_factor,
                shape_peak_dh=data['rs_shapes_heating_heat_pump_dh']
                ['peakday'])

        elif modeltype == 'ss_submodel':

            # --------Profiles
            self.ss_load_profiles = load_profile.LoadProfileStock(
                "ss_load_profiles")

            # --------HDD/CDD
            ss_hdd_by, _ = hdd_cdd.get_reg_hdd(temp_by, ss_t_base_heating_by)
            ss_cdd_by, _ = hdd_cdd.get_reg_cdd(temp_by, ss_t_base_cooling_by)

            ss_hdd_cy, ss_fuel_shape_heating_yd = hdd_cdd.get_reg_hdd(
                temp_cy, rs_t_base_heating_cy)
            ss_cdd_cy, _ = hdd_cdd.get_reg_cdd(temp_cy, ss_t_base_cooling_cy)

            try:
                self.ss_heating_factor_y = np.nan_to_num(
                    1.0 / float(np.sum(ss_hdd_by))) * np.sum(ss_hdd_cy)
                self.ss_cooling_factor_y = np.nan_to_num(
                    1.0 / float(np.sum(ss_cdd_by))) * np.sum(ss_cdd_cy)
            except ZeroDivisionError:
                self.ss_heating_factor_y = 1
                self.ss_cooling_factor_y = 1

            ss_peak_yd_heating_factor = self.get_shape_peak_yd_factor(
                ss_hdd_cy)
            #ss_peak_yd_cooling_factor = self.get_shape_peak_yd_factor(ss_cdd_cy)

            # --Heating technologies for service sector
            # (the heating shape follows the gas shape of aggregated sectors)
            ss_fuel_shape_any_tech, ss_fuel_shape = self.ss_get_sector_enduse_shape(
                data, ss_fuel_shape_heating_yd, 'ss_space_heating')

            # Cooling service
            #ss_fuel_shape_cooling_yh = self.get_shape_cooling_yh(data, ss_fuel_shape_cooling_yd, 'ss_shapes_cooling_dh') # Service cooling
            #ss_fuel_shape_cooling_yh = self.get_shape_cooling_yh(data, ss_fuel_shape_heating_yd, 'ss_shapes_cooling_dh') # Service cooling #USE HEAT YD BUT COOLING SHAPE
            #ss_fuel_shape_cooling_yh = self.get_shape_cooling_yh(data, load_profile.absolute_to_relative(ss_hdd_cy + ss_cdd_cy), 'ss_shapes_cooling_dh') # hdd & cdd

            # Hybrid
            ss_profile_hybrid_gas_elec_yh = self.get_shape_heating_hybrid_yh(
                self.ss_tech_stock, 'ss_space_heating', ss_fuel_shape,
                ss_fuel_shape, ss_fuel_shape_heating_yd,
                'hybrid_gas_electricity')

            self.ss_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_const'],
                enduses=['ss_space_heating', 'ss_water_heating'],
                sectors=data['ss_sectors'],
                shape_yd=ss_fuel_shape_heating_yd,
                shape_yh=ss_fuel_shape_any_tech,
                enduse_peak_yd_factor=ss_peak_yd_heating_factor,
                shape_peak_dh=data['ss_shapes_dh'])

            self.ss_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['primary_heating_electricity'],
                enduses=['ss_space_heating'],
                sectors=data['ss_sectors'],
                shape_yd=ss_fuel_shape_heating_yd,
                shape_yh=ss_fuel_shape_any_tech,
                enduse_peak_yd_factor=ss_peak_yd_heating_factor,
                shape_peak_dh=data['rs_profile_heating_storage_dh']['peakday'])

            self.ss_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['secondary_heating_electricity'],
                enduses=['rs_space_heating', 'rs_water_heating'],
                sectors=data['ss_sectors'],
                shape_yd=ss_fuel_shape_heating_yd,
                shape_yh=ss_fuel_shape_any_tech,
                enduse_peak_yd_factor=ss_peak_yd_heating_factor)

            self.ss_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_hybrid'],
                enduses=['ss_space_heating', 'ss_water_heating'],
                sectors=data['ss_sectors'],
                shape_yd=ss_fuel_shape_heating_yd,
                shape_yh=ss_profile_hybrid_gas_elec_yh,
                enduse_peak_yd_factor=ss_peak_yd_heating_factor,
            )

            self.ss_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_temp_dep'],
                enduses=['ss_space_heating', 'ss_water_heating'],
                sectors=data['ss_sectors'],
                shape_yd=ss_fuel_shape_heating_yd,
                shape_yh=ss_fuel_shape_any_tech,
                enduse_peak_yd_factor=ss_peak_yd_heating_factor)

        elif modeltype == 'is_submodel':

            # --------Profiles
            self.is_load_profiles = load_profile.LoadProfileStock(
                "is_load_profiles")

            # --------HDD/CDD
            is_hdd_by, _ = hdd_cdd.get_reg_hdd(temp_by, ss_t_base_heating_by)
            is_cdd_by, _ = hdd_cdd.get_reg_cdd(temp_by, ss_t_base_cooling_by)

            # Take same base temperature as for service sector
            is_hdd_cy, is_fuel_shape_heating_yd = hdd_cdd.get_reg_hdd(
                temp_cy, ss_t_base_heating_cy)
            is_cdd_cy, _ = hdd_cdd.get_reg_cdd(temp_cy, ss_t_base_cooling_cy)

            try:
                self.is_heating_factor_y = np.nan_to_num(
                    1.0 / float(np.sum(is_hdd_by))) * np.sum(is_hdd_cy)
                self.is_cooling_factor_y = np.nan_to_num(
                    1.0 / float(np.sum(is_cdd_by))) * np.sum(is_cdd_cy)
            except ZeroDivisionError:
                self.is_heating_factor_y = 1
                self.is_cooling_factor_y = 1

            is_peak_yd_heating_factor = self.get_shape_peak_yd_factor(
                is_hdd_cy)
            #is_peak_yd_cooling_factor = self.get_shape_peak_yd_factor(is_cdd_cy)

            # --Heating technologies for service sector (the heating shape follows
            # the gas shape of aggregated sectors)
            #Take from service sector
            is_fuel_shape_any_tech, _ = self.ss_get_sector_enduse_shape(
                data, is_fuel_shape_heating_yd, 'ss_space_heating')

            self.is_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_const'],
                enduses=['is_space_heating'],
                sectors=data['is_sectors'],
                shape_yd=is_fuel_shape_heating_yd,
                shape_yh=is_fuel_shape_any_tech,
                enduse_peak_yd_factor=is_peak_yd_heating_factor)

            self.is_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['primary_heating_electricity'],
                enduses=['is_space_heating'],
                sectors=data['is_sectors'],
                shape_yd=is_fuel_shape_heating_yd,
                enduse_peak_yd_factor=is_peak_yd_heating_factor,
                shape_yh=is_fuel_shape_any_tech)

            self.is_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['secondary_heating_electricity'],
                enduses=['is_space_heating'],
                sectors=data['is_sectors'],
                shape_yd=is_fuel_shape_heating_yd,
                shape_yh=is_fuel_shape_any_tech,
                enduse_peak_yd_factor=is_peak_yd_heating_factor,
            )

            self.is_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_hybrid'],
                enduses=['is_space_heating'],
                sectors=data['is_sectors'],
                shape_yd=is_fuel_shape_heating_yd,
                shape_yh=is_fuel_shape_any_tech,
                enduse_peak_yd_factor=is_peak_yd_heating_factor,
            )

            self.is_load_profiles.add_load_profile(
                unique_identifier=uuid.uuid4(),
                technologies=data['assumptions']['technology_list']
                ['tech_heating_temp_dep'],
                enduses=['is_space_heating'],
                sectors=data['is_sectors'],
                shape_yd=is_fuel_shape_heating_yd,
                shape_yh=is_fuel_shape_any_tech,
                enduse_peak_yd_factor=is_peak_yd_heating_factor)
Ejemplo n.º 7
0
def test_LoadProfileStock():
    """testing
    """

    result_obj = load_profile.LoadProfileStock("test_stock")

    expected = "test_stock"

    assert result_obj.name == expected

    # -----
    result_obj.add_lp(unique_identifier="A123",
                      technologies=['placeholder_tech'],
                      enduses=['cooking'],
                      shape_yd=np.zeros((365)),
                      shape_yh=np.zeros((365, 24)),
                      sectors=False,
                      f_peak_yd=1.0 / 365,
                      shape_peak_dh=np.full((24), 1.0 / 24))

    result = result_obj.stock_enduses

    result2 = load_profile.get_stock_enduses(result_obj.load_profiles)

    assert result == ['cooking']
    assert result2 == ['cooking']

    # ---
    # -----
    result_obj.add_lp(unique_identifier="A123",
                      technologies=['placeholder_tech'],
                      enduses=['cooking'],
                      shape_yd=np.zeros((365)),
                      shape_yh=np.zeros((365, 24)),
                      sectors=['sectorA'],
                      f_peak_yd=1.0 / 365,
                      shape_peak_dh=np.full((24), 1.0 / 24))

    result = result_obj.stock_enduses
    assert result == ['cooking']

    # test get_lp()
    np.testing.assert_array_equal(
        np.zeros((365)),
        result_obj.get_lp('cooking', 'sectorA', 'placeholder_tech',
                          'shape_yd'))
    np.testing.assert_array_equal(
        np.zeros((365, 24)),
        result_obj.get_lp('cooking', 'sectorA', 'placeholder_tech',
                          'shape_yh'))
    np.testing.assert_array_equal(
        np.zeros((365, 24)),
        result_obj.get_lp('cooking', 'sectorA', 'placeholder_tech',
                          'shape_y_dh'))
    np.testing.assert_array_equal(
        np.full((24), 1.0 / 24),
        result_obj.get_lp('cooking', 'sectorA', 'placeholder_tech',
                          'shape_peak_dh'))
    np.testing.assert_array_equal(
        1.0 / 365,
        result_obj.get_lp('cooking', 'sectorA', 'placeholder_tech',
                          'f_peak_yd'))

    # test get_shape_peak_dh()
    '''_var = result_obj.get_lp('cooking', 'sectorA', 'placeholder_tech', 'shape_peak_dh')
Ejemplo n.º 8
0
    def __init__(
        self,
        name,
        base_yr,
        curr_yr,
        strategy_variables,
        t_bases,
        t_diff_param,
        tech_lists,
        technologies,
        assumptions,
        fueltypes,
        model_yeardays_nrs,
        model_yeardays,
        yeardays_month_days,
        all_enduses,
        temp_by,
        tech_lp,
        sectors,
    ):
        """Constructor of weather region
        """
        self.name = name

        # -----------------------------------
        # Calculate current year temperatures
        # -----------------------------------
        temp_cy = change_temp_climate(temp_by, yeardays_month_days,
                                      strategy_variables, base_yr, curr_yr)

        # Change base temperatures depending on change in t_base
        rs_t_base_heating_cy = hdd_cdd.sigm_temp(
            strategy_variables['rs_t_base_heating_future_yr']
            ['scenario_value'], t_bases.rs_t_heating_by, base_yr, curr_yr,
            t_diff_param)
        '''rs_t_base_cooling_cy = hdd_cdd.sigm_temp(
            strategy_variables['rs_t_base_cooling_future_yr']['scenario_value'],
            t_bases.rs_t_cooling_by, base_yr, curr_yr,
            t_diff_param)'''

        ss_t_base_heating_cy = hdd_cdd.sigm_temp(
            strategy_variables['ss_t_base_heating_future_yr']
            ['scenario_value'], t_bases.ss_t_heating_by, base_yr, curr_yr,
            t_diff_param)
        ss_t_base_cooling_cy = hdd_cdd.sigm_temp(
            strategy_variables['ss_t_base_cooling_future_yr']
            ['scenario_value'], t_bases.ss_t_cooling_by, base_yr, curr_yr,
            t_diff_param)

        is_t_base_heating_cy = hdd_cdd.sigm_temp(
            strategy_variables['is_t_base_heating_future_yr']
            ['scenario_value'], t_bases.is_t_heating_by, base_yr, curr_yr,
            t_diff_param)
        '''is_t_base_cooling_cy = hdd_cdd.sigm_temp(
            strategy_variables['is_t_base_cooling_future_yr']['scenario_value'],
            t_bases.is_t_cooling_by,
            base_yr,
            curr_yr,
            t_diff_param)'''

        # -------------------
        # Technology stocks
        # -------------------
        self.rs_tech_stock = technological_stock.TechStock(
            'rs_tech_stock', technologies, tech_lists,
            assumptions.enduse_overall_change['other_enduse_mode_info'],
            base_yr, curr_yr, fueltypes, temp_by, temp_cy,
            t_bases.rs_t_heating_by, all_enduses['rs_enduses'],
            rs_t_base_heating_cy, assumptions.rs_specified_tech_enduse_by)

        self.ss_tech_stock = technological_stock.TechStock(
            'ss_tech_stock', technologies, tech_lists,
            assumptions.enduse_overall_change['other_enduse_mode_info'],
            base_yr, curr_yr, fueltypes, temp_by, temp_cy,
            t_bases.ss_t_heating_by, all_enduses['ss_enduses'],
            ss_t_base_heating_cy, assumptions.ss_specified_tech_enduse_by)

        self.is_tech_stock = technological_stock.TechStock(
            'is_tech_stock', technologies, tech_lists,
            assumptions.enduse_overall_change['other_enduse_mode_info'],
            base_yr, curr_yr, fueltypes, temp_by, temp_cy,
            t_bases.is_t_heating_by, all_enduses['is_enduses'],
            ss_t_base_heating_cy, assumptions.is_specified_tech_enduse_by)

        # -------------------
        # Residential Load profiles
        # ------------------
        self.rs_load_profiles = load_profile.LoadProfileStock(
            "rs_load_profiles")

        # --------Calculate HDD/CDD
        self.rs_hdd_by, _ = hdd_cdd.calc_reg_hdd(temp_by,
                                                 t_bases.rs_t_heating_by,
                                                 model_yeardays)
        self.rs_hdd_cy, rs_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd(
            temp_cy, rs_t_base_heating_cy, model_yeardays)
        #self.rs_cdd_by, _ = hdd_cdd.calc_reg_cdd(
        #    temp_by, t_bases.rs_t_cooling_by, model_yeardays)
        #self.rs_cdd_cy, rs_fuel_shape_cooling_yd = hdd_cdd.calc_reg_cdd(
        #    temp_cy, rs_t_base_cooling_cy, model_yeardays)

        # -------Calculate climate change correction factors
        try:
            self.f_heat_rs_y = np.nan_to_num(
                1.0 / float(np.sum(self.rs_hdd_by))) * np.sum(self.rs_hdd_cy)
            #self.f_cooling_rs_y = np.nan_to_num(
            #    1.0 / float(np.sum(self.rs_cdd_by))) * np.sum(self.rs_cdd_cy)
            self.f_cooling_rs_y = 1
        except ZeroDivisionError:
            self.f_heat_rs_y = 1
            self.f_cooling_rs_y = 1

        # yd peak factors for heating and cooling
        rs_peak_yd_heating_factor = get_shape_peak_yd_factor(self.rs_hdd_cy)
        '''
        # RESIDENITAL COOLING
        #rs_peak_yd_cooling_factor = get_shape_peak_yd_factor(self.rs_cdd_cy)
        rs_cold_techs = tech_lists['rs_cold']
        rs_cold_techs.append('placeholder_tech')

        # ----Cooling residential
        #rs_fuel_shape_cooling_yh = load_profile.calc_yh(
        #    rs_fuel_shape_cooling_yd, tech_lp['rs_shapes_cooling_dh'], model_yeardays)
        #or also (if only yd)
        #shape_yh=tech_lp['rs_shapes_dh'][cooling_enduse]['shape_non_peak_y_dh'] * ss_fuel_shape_coolin_yd[:, np.newaxis],
        rs_fuel_shape_cooling_yh = self.get_shape_cooling_yh(data, rs_fuel_shape_cooling_yd, 'rs_shapes_cooling_dh')

        for cooling_enduse in assumptions.enduse_rs_space_cooling:
            self.rs_load_profiles.add_lp(
                unique_identifier=uuid.uuid4(),
                technologies=rs_cold_techs,
                enduses=enduse, #['rs_cooling'],
                shape_yd=rs_fuel_shape_cooling_yd,
                shape_yh=rs_fuel_shape_cooling_yh,
                f_peak_yd=rs_peak_yd_cooling_factor,
                shape_peak_dh=tech_lp['rs_shapes_cooling_dh']['peakday'])
        '''
        # ------Heating boiler
        rs_profile_boilers_y_dh = load_profile.calc_yh(
            rs_fuel_shape_heating_yd, tech_lp['rs_profile_boilers_y_dh'],
            model_yeardays)
        self.rs_load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=tech_lists['heating_const'],
            enduses=['rs_space_heating', 'rs_water_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_yh=rs_profile_boilers_y_dh,
            f_peak_yd=rs_peak_yd_heating_factor,
            shape_peak_dh=tech_lp['rs_lp_heating_boilers_dh']['peakday'])

        # ------Heating CHP
        rs_profile_chp_y_dh = load_profile.calc_yh(
            rs_fuel_shape_heating_yd, tech_lp['rs_profile_chp_y_dh'],
            model_yeardays)

        self.rs_load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=tech_lists['tech_CHP'],
            enduses=['rs_space_heating', 'rs_water_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_yh=rs_profile_chp_y_dh,
            f_peak_yd=rs_peak_yd_heating_factor,
            shape_peak_dh=tech_lp['rs_lp_heating_CHP_dh']['peakday'])

        # ------Electric heating, storage heating (primary)
        rs_profile_storage_heater_y_dh = load_profile.calc_yh(
            rs_fuel_shape_heating_yd,
            tech_lp['rs_profile_storage_heater_y_dh'], model_yeardays)
        self.rs_load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=tech_lists['storage_heating_electricity'],
            enduses=['rs_space_heating', 'rs_water_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_yh=rs_profile_storage_heater_y_dh,
            f_peak_yd=rs_peak_yd_heating_factor,
            shape_peak_dh=tech_lp['rs_lp_storage_heating_dh']['peakday'])

        # ------Electric heating secondary (direct elec heating)
        rs_profile_elec_heater_y_dh = load_profile.calc_yh(
            rs_fuel_shape_heating_yd, tech_lp['rs_profile_elec_heater_y_dh'],
            model_yeardays)
        self.rs_load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=tech_lists['secondary_heating_electricity'],
            enduses=['rs_space_heating', 'rs_water_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_yh=rs_profile_elec_heater_y_dh,
            f_peak_yd=rs_peak_yd_heating_factor,
            shape_peak_dh=tech_lp['rs_lp_second_heating_dh']['peakday'])

        # ------Heat pump heating
        rs_fuel_shape_hp_yh, _ = get_fuel_shape_heating_hp_yh(
            tech_lp['rs_profile_hp_y_dh'], self.rs_tech_stock, self.rs_hdd_cy,
            model_yeardays)

        self.rs_load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=tech_lists['heating_non_const'],
            enduses=['rs_space_heating', 'rs_water_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_yh=rs_fuel_shape_hp_yh,
            f_peak_yd=rs_peak_yd_heating_factor,
            shape_peak_dh=tech_lp['rs_lp_heating_CHP_dh']['peakday'])

        # ------District_heating_electricity --> Assumption made that same curve as CHP
        rs_profile_chp_y_dh = load_profile.calc_yh(
            rs_fuel_shape_heating_yd, tech_lp['rs_profile_chp_y_dh'],
            model_yeardays)

        self.rs_load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=tech_lists['tech_district_heating'],
            enduses=['rs_space_heating', 'rs_water_heating'],
            shape_yd=rs_fuel_shape_heating_yd,
            shape_yh=rs_profile_chp_y_dh,
            f_peak_yd=rs_peak_yd_heating_factor,
            shape_peak_dh=tech_lp['rs_lp_heating_boilers_dh']['peakday'])

        # -------------------
        # Service Load profiles
        # ------------------
        self.ss_load_profiles = load_profile.LoadProfileStock(
            "ss_load_profiles")

        # --------HDD/CDD
        ss_hdd_by, _ = hdd_cdd.calc_reg_hdd(temp_by, t_bases.ss_t_heating_by,
                                            model_yeardays)
        ss_hdd_cy, ss_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd(
            temp_cy, ss_t_base_heating_cy, model_yeardays)

        ss_cdd_by, _ = hdd_cdd.calc_reg_cdd(temp_by, t_bases.ss_t_cooling_by,
                                            model_yeardays)
        ss_cdd_cy, ss_fuel_shape_coolin_yd = hdd_cdd.calc_reg_cdd(
            temp_cy, ss_t_base_cooling_cy, model_yeardays)

        try:
            self.f_heat_ss_y = np.nan_to_num(
                1.0 / float(np.sum(ss_hdd_by))) * np.sum(ss_hdd_cy)
            self.f_cooling_ss_y = np.nan_to_num(
                1.0 / float(np.sum(ss_cdd_by))) * np.sum(ss_cdd_cy)
        except ZeroDivisionError:
            self.f_heat_ss_y = 1
            self.f_cooling_ss_y = 1

        # ----------------------------------------------
        # Apply weekend correction factor fo ss heating
        # ----------------------------------------------
        ss_peak_yd_heating_factor = get_shape_peak_yd_factor(ss_hdd_cy)
        ss_peak_yd_cooling_factor = get_shape_peak_yd_factor(ss_cdd_cy)

        # --Heating technologies for service sector
        #
        # (the heating shape follows the gas shape of aggregated sectors)
        # meaning that for all technologies, the load profile is the same
        ss_fuel_shape_any_tech, ss_fuel_shape = ss_get_sector_enduse_shape(
            tech_lp['ss_all_tech_shapes_dh'], ss_fuel_shape_heating_yd,
            'ss_space_heating', model_yeardays_nrs)

        # Apply correction factor for weekend_effect
        # ------
        ss_fuel_shape_heating_yd = ss_fuel_shape_heating_yd * assumptions.ss_weekend_f
        ss_fuel_shape_heating_yd_weighted = load_profile.abs_to_rel(
            ss_fuel_shape_heating_yd)
        # ------

        # Flatten list of all potential technologies
        ss_space_heating_tech_lists = list(tech_lists.values())
        all_techs_ss_space_heating = [
            item for sublist in ss_space_heating_tech_lists for item in sublist
        ]

        # ----------------
        # Get peak day and calculate peak load profile for peak day
        # ----------------
        peak_day = get_peak_day_single_fueltype(ss_fuel_shape)
        ss_space_heating_shape_peak_dh = load_profile.abs_to_rel(
            ss_fuel_shape[peak_day])

        self.ss_load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=all_techs_ss_space_heating,
            enduses=['ss_space_heating'],
            sectors=sectors['ss_sectors'],
            shape_yd=ss_fuel_shape_heating_yd_weighted,
            shape_yh=ss_fuel_shape_any_tech,
            f_peak_yd=ss_peak_yd_heating_factor,
            shape_peak_dh=ss_space_heating_shape_peak_dh)

        #------
        # Add cooling technologies for service sector
        #------
        coolings_techs = tech_lists['cooling_const']

        for cooling_enduse in assumptions.ss_enduse_space_cooling:
            for sector in sectors['ss_sectors']:

                # Apply correction factor for weekend_effect 'cdd_weekend_cfactors'
                ss_fuel_shape_coolin_yd = ss_fuel_shape_coolin_yd * assumptions.cdd_weekend_cfactors
                ss_fuel_shape_coolin_yd = load_profile.abs_to_rel(
                    ss_fuel_shape_coolin_yd)

                # Ev auch tech_lp['ss_shapes_cooling_dh']
                ss_shape_yh = load_profile.calc_yh(
                    ss_fuel_shape_coolin_yd,
                    tech_lp['ss_profile_cooling_y_dh'], model_yeardays)

                self.ss_load_profiles.add_lp(
                    unique_identifier=uuid.uuid4(),
                    technologies=coolings_techs,
                    enduses=[cooling_enduse],
                    sectors=[sector],
                    shape_yd=ss_fuel_shape_coolin_yd,
                    shape_yh=ss_shape_yh,
                    f_peak_yd=ss_peak_yd_cooling_factor,
                    shape_peak_dh=tech_lp['ss_shapes_cooling_dh']['peakday'])

        # --------------------------------
        # Industry submodel
        # --------------------------------
        self.is_load_profiles = load_profile.LoadProfileStock(
            "is_load_profiles")

        # --------HDD/CDD
        is_hdd_by, _ = hdd_cdd.calc_reg_hdd(temp_by, t_bases.is_t_heating_by,
                                            model_yeardays)
        #is_cdd_by, _ = hdd_cdd.calc_reg_cdd(
        #    temp_by, t_bases.is_t_cooling_by, model_yeardays)

        # Take same base temperature as for service sector
        is_hdd_cy, is_fuel_shape_heating_yd = hdd_cdd.calc_reg_hdd(
            temp_cy, is_t_base_heating_cy, model_yeardays)
        #is_cdd_cy, _ = hdd_cdd.calc_reg_cdd(
        #    temp_cy, ss_t_base_cooling_cy, model_yeardays)

        try:
            self.f_heat_is_y = np.nan_to_num(
                1.0 / float(np.sum(is_hdd_by))) * np.sum(is_hdd_cy)
            #self.f_cooling_is_y = np.nan_to_num(1.0 / float(np.sum(is_cdd_by))) * np.sum(is_cdd_cy)
            self.f_cooling_is_y = 1
        except ZeroDivisionError:
            self.f_heat_is_y = 1
            self.f_cooling_is_y = 1

        is_peak_yd_heating_factor = get_shape_peak_yd_factor(is_hdd_cy)
        #is_peak_yd_cooling_factor = self.get_shape_peak_yd_factor(is_cdd_cy)

        # Cooling for industrial enduse
        # --Heating technologies for service sector (the heating shape follows
        # the gas shape of aggregated sectors)

        # Flatten list of all potential heating technologies
        is_space_heating_tech_lists = list(tech_lists.values())
        all_techs_is_space_heating = [
            item for sublist in is_space_heating_tech_lists for item in sublist
        ]

        # Apply correction factor for weekend_effect for space heating load profile
        is_fuel_shape_heating_yd = is_fuel_shape_heating_yd * assumptions.is_weekend_f
        is_fuel_shape_heating_yd = load_profile.abs_to_rel(
            is_fuel_shape_heating_yd)

        # Y_dh Heating profile is taken from service sector
        is_fuel_shape_any_tech, _ = ss_get_sector_enduse_shape(
            tech_lp['ss_all_tech_shapes_dh'], is_fuel_shape_heating_yd,
            'ss_space_heating', assumptions.model_yeardays_nrs)

        # Alternatively generate y_dh flat profile
        #from energy_demand.profiles import generic_shapes
        #shape_peak_dh, _, shape_peak_yd_factor, shape_non_peak_yd, shape_non_peak_yh = generic_shapes.flat_shape(
        #    assumptions.model_yeardays_nrs)
        #flat_is_fuel_shape_any_tech = np.full((assumptions.model_yeardays_nrs, 24), (1.0/24.0), dtype=float)
        #flat_is_fuel_shape_any_tech = flat_is_fuel_shape_any_tech * is_fuel_shape_heating_yd[:, np.newaxis]

        self.is_load_profiles.add_lp(
            unique_identifier=uuid.uuid4(),
            technologies=all_techs_is_space_heating,
            enduses=['is_space_heating'],
            sectors=sectors['is_sectors'],
            shape_yd=is_fuel_shape_heating_yd,
            shape_yh=is_fuel_shape_any_tech,  #flat_is_fuel_shape_any_tech,
            f_peak_yd=is_peak_yd_heating_factor)