Exemplo n.º 1
0
    def test_load_berlin_format_data(self):

        data_actual_file_locations = load_hbefa_cold_berlin_format_data(
            berlin_format_link_data=f'{self.init_path}/test_data/berlin_format_data/shape_data.csv',
            berlin_format_fleet_composition=f'{self.init_path}/test_data/berlin_format_data/fleet_comp_data.csv',
            berlin_format_emission_factors=f'{self.init_path}/test_data/berlin_format_data/hbefa_cold_starts_ef.csv',
            berlin_format_cold_starts_data=f'{self.init_path}/test_data/berlin_format_data/cold_starts.csv',
            output_folder=f'{self.init_path}/temp_for_hbefa_cold_data_loading_test'
        )

        yeti_format_emission_factors_expected = pd.read_csv(f'{self.init_path}/test_data/yeti_format_data/hbefa_cold_starts_ef.csv')
        yeti_format_vehicle_data_expected = pd.read_csv(f'{self.init_path}/test_data/yeti_format_data/vehicle_data.csv')
        yeti_format_link_data_expected = pd.read_csv(f'{self.init_path}/test_data/yeti_format_data/link_data.csv')
        yeti_format_cold_starts_expected = pd.read_csv(f'{self.init_path}/test_data/yeti_format_data/cold_starts.csv')

        self.assertTrue(df_equal(
            pd.read_csv(data_actual_file_locations["yeti_format_emission_factors"]),
            yeti_format_emission_factors_expected))
        self.assertTrue(df_equal(
            pd.read_csv(data_actual_file_locations["yeti_format_vehicle_data"]),
            yeti_format_vehicle_data_expected))
        self.assertTrue(df_equal(
            pd.read_csv(data_actual_file_locations["yeti_format_link_data"]),
            yeti_format_link_data_expected))
        self.assertTrue(df_equal(
            pd.read_csv(data_actual_file_locations["yeti_format_cold_starts_data"]),
            yeti_format_cold_starts_expected))
Exemplo n.º 2
0
    def test_use_hbefa_ef_works_correctly(self):

        data_loader = HbefaDataLoader(
            link_data_file=f'{self.init_path}/test_data/berlin_format_data/shape_data.csv',
            fleet_comp_file=f'{self.init_path}/test_data/berlin_format_data/fleet_comp_data.csv',
            emission_factor_file=f'{self.init_path}/test_data/berlin_format_data/hbefa_ef_data.csv',
            los_speeds_file=f'{self.init_path}/test_data/berlin_format_data/los_speed_data.csv',
            traffic_data_file=f'{self.init_path}/test_data/berlin_format_data/traffic_data.csv'
        )
        (link_data, vehicle_data, traffic_data, los_speeds_data,
         emission_factor_data, missing_ef_data) = data_loader.load_data()
        link_data.Length = link_data.Length.apply(lambda val: round(val, 4))

        yeti_format_data = load_hbefa_hot_yeti_format_data(
            yeti_format_emission_factors=f'{self.init_path}/test_data/yeti_format_data/hbefa_ef_data.csv',
            yeti_format_vehicle_data=f'{self.init_path}/test_data/yeti_format_data/vehicle_data.csv',
            yeti_format_link_data=f'{self.init_path}/test_data/yeti_format_data/link_data.csv',
            yeti_format_traffic_data=f'{self.init_path}/test_data/yeti_format_data/traffic_data.csv'
        )

        link_data_pre = yeti_format_data["link_data"]
        vehicle_data_pre = yeti_format_data["vehicle_data"]
        traffic_data_pre = yeti_format_data["traffic_data"]
        emission_factor_data_pre = yeti_format_data["emission_factor_data"]

        self.assertTrue(df_equal(link_data, link_data_pre))
        self.assertTrue(df_equal(vehicle_data, vehicle_data_pre))
        self.assertTrue(los_speeds_data is None)
        self.assertTrue(df_equal(traffic_data, traffic_data_pre))
        self.assertTrue(df_equal(emission_factor_data, emission_factor_data_pre))
Exemplo n.º 3
0
    def test_yeti_format_data_to_emissions(self):

        StrategyInvoker().calculate_and_save_emissions(
            save_interval_in_rows=2,
            emissions_output_folder="temp",
            pollutants=["PollutantType.NOx"],
            Strategy=CopertStrategy,
            only_hot=True,
            link_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/link_data.csv"),
            traffic_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/traffic_data.csv"
            ),
            vehicle_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/vehicle_data.csv"
            ),
            emission_factor_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/emission_factor_data.csv"
            ),
            los_speeds_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/los_speeds_data.csv"
            ))

        emissions_actual = pd.read_csv("temp/PollutantType.NOx_emissions.csv")
        shutil.rmtree("temp")
        emissions_expected = pd.read_csv(
            f'{self.init_path}/test_data/emissions_expected.csv')

        self.assertEqual(len(emissions_expected), len(emissions_actual))

        emissions_actual = emissions_actual.round(5)
        emissions_expected = emissions_expected.round(5)

        self.assertTrue(df_equal(emissions_actual, emissions_expected))
Exemplo n.º 4
0
    def test_load_builder_data(self):

        data_actual = load_hbefa_cold_yeti_format_data(
            yeti_format_emission_factors=f'{self.init_path}/test_data/yeti_format_data/hbefa_cold_starts_ef.csv',
            yeti_format_vehicle_data=f'{self.init_path}/test_data/yeti_format_data/vehicle_data.csv',
            yeti_format_link_data=f'{self.init_path}/test_data/yeti_format_data/link_data.csv',
            yeti_format_cold_starts_data=f'{self.init_path}/test_data/yeti_format_data/cold_starts.csv'
        )

        yeti_format_emission_factors_expected = pd.read_csv(f'{self.init_path}/test_data/yeti_format_data/hbefa_cold_starts_ef.csv')
        yeti_format_vehicle_data_expected = pd.read_csv(f'{self.init_path}/test_data/yeti_format_data/vehicle_data.csv')
        yeti_format_link_data_expected = pd.read_csv(f'{self.init_path}/test_data/yeti_format_data/link_data.csv')
        yeti_format_cold_starts_expected = pd.read_csv(f'{self.init_path}/test_data/yeti_format_data/cold_starts.csv')

        self.assertTrue(df_equal(data_actual["link_data"], yeti_format_link_data_expected))
        self.assertTrue(df_equal(data_actual["vehicle_data"], yeti_format_vehicle_data_expected))
        self.assertTrue(df_equal(data_actual["traffic_data"], yeti_format_cold_starts_expected))
        self.assertTrue(df_equal(data_actual["emission_factor_data"], yeti_format_emission_factors_expected))
Exemplo n.º 5
0
    def test_load_data(self):

        ef_data, missing_ef_data = self.loader.load_data()
        ef_data_expected = pd.read_csv(
            f"{self.init_path}/test_data/yeti_format_data/emission_factor_data.csv"
        )

        self.assertEqual(sorted(list(ef_data_expected.columns)),
                         sorted(list(ef_data.columns)))
        self.assertTrue(df_equal(ef_data, ef_data_expected))
Exemplo n.º 6
0
    def test_link_data_loader(self) -> None:

        if os.path.isfile("./tests/test_data/berlin_format_data/shape_data.csv"):
            self.init_path = "./tests"
        else:
            self.init_path = ".."

        link_data = LinkDataLoader(
            link_data=pd.read_csv(f"{self.init_path}/test_data/berlin_format_data/shape_data.csv")
        ).load_data()

        link_data_with_speed = LinkDataLoader(
            link_data=pd.read_csv(f"{self.init_path}/test_data/berlin_format_data/shape_data_with_speed.csv")
        ).load_data()

        link_data_expected = pd.read_csv(f"{self.init_path}/test_data/yeti_format_data/link_data.csv")
        link_data_with_speed_expected = pd.read_csv(f"{self.init_path}/test_data/yeti_format_data/link_data_with_speed.csv")

        self.assertTrue(df_equal(link_data, link_data_expected))
        self.assertTrue(df_equal(link_data_with_speed, link_data_with_speed_expected))
Exemplo n.º 7
0
    def test_load_nh3_ef_data(self):

        nh3_ef_data = self.loader.load_nh3_ef_data()

        nh3_ef_data_expected = pd.DataFrame({
            "VehicleName": ["pc vehicle_a", "lcv vehicle_b"],
            "EF": [1, 2.5],
            "Pollutant": ["PollutantType.NH3", "PollutantType.NH3"]
        })

        self.assertTrue(df_equal(nh3_ef_data, nh3_ef_data_expected))
Exemplo n.º 8
0
    def test_data_is_equal(self):
        (link_data, vehicle_data, traffic_data, los_speeds_data,
         emission_factor_data, missing_ef_data) = self.loader.load_data()
        link_data.Length = link_data.Length.apply(lambda val: round(val, 4))

        yeti_format_data = load_copert_hot_yeti_format_data(
            yeti_format_emission_factors=f'{self.init_path}/test_data/yeti_format_data/emission_factor_data.csv',
            yeti_format_los_speeds=f'{self.init_path}/test_data/yeti_format_data/los_speeds_data.csv',
            yeti_format_vehicle_data=f'{self.init_path}/test_data/yeti_format_data/vehicle_data.csv',
            yeti_format_link_data=f'{self.init_path}/test_data/yeti_format_data/link_data.csv',
            yeti_format_traffic_data=f'{self.init_path}/test_data/yeti_format_data/traffic_data.csv'
        )
        link_data_pre = yeti_format_data["link_data"]
        vehicle_data_pre = yeti_format_data["vehicle_data"]
        traffic_data_pre = yeti_format_data["traffic_data"]
        los_speeds_data_pre = yeti_format_data["los_speeds_data"]
        emission_factor_data_pre = yeti_format_data["emission_factor_data"]

        self.assertTrue(df_equal(link_data, link_data_pre))
        self.assertTrue(df_equal(vehicle_data, vehicle_data_pre))
        self.assertTrue(df_equal(los_speeds_data, los_speeds_data_pre))
        self.assertTrue(df_equal(traffic_data, traffic_data_pre))
        self.assertTrue(
            df_equal(missing_ef_data, pd.read_csv(f"{self.init_path}/test_data/other_data/missing_ef_data.csv")))

        # avoid error due to floating point inaccuracy
        for colname in ['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon','Zita', 'Hta', 'Thita', 'ReductionPerc']:
            emission_factor_data[colname] = pd.Series(
                np.around(emission_factor_data[colname].values, 5))
            emission_factor_data_pre[colname] = pd.Series(
                np.around(emission_factor_data_pre[colname].values, 5))

        self.assertTrue(df_equal(emission_factor_data, emission_factor_data_pre))
Exemplo n.º 9
0
    def test_load_speed_dependent_ef_data(self):

        speed_dependent_ef_data = self.loader.load_speed_dependent_ef_data()
        speed_dependent_ef_data_expected = pd.read_csv(
            f"{self.init_path}/test_data/other_data/speed_dependent_ef_data.csv"
        )

        self.assertFalse(speed_dependent_ef_data_expected.empty)
        self.assertFalse(speed_dependent_ef_data.empty)

        self.assertTrue(
            df_equal(speed_dependent_ef_data,
                     speed_dependent_ef_data_expected))
Exemplo n.º 10
0
    def test_load_data(self):

        if os.path.isfile(
                "./tests/test_data/berlin_format_data/shape_data.csv"):
            self.init_path = "./tests"
        else:
            self.init_path = ".."

        loader = PMNonExhaustDataLoader(
            link_data_file=
            f'{self.init_path}/test_data/berlin_format_data/shape_data.csv',
            fleet_comp_file=
            f'{self.init_path}/test_data/berlin_format_data/fleet_comp_data.csv',
            los_speeds_file=
            f'{self.init_path}/test_data/berlin_format_data/los_speed_data.csv',
            traffic_data_file=
            f'{self.init_path}/test_data/berlin_format_data/traffic_data.csv')
        (link_data, vehicle_data, traffic_data, los_speeds_data, _,
         _) = loader.load_data()

        expected_data = load_pm_non_exhaust_yeti_format_data(
            yeti_format_los_speeds=
            f'{self.init_path}/test_data/yeti_format_data/los_speeds_data.csv',
            yeti_format_vehicle_data=
            f'{self.init_path}/test_data/yeti_format_data/vehicle_data.csv',
            yeti_format_link_data=
            f'{self.init_path}/test_data/yeti_format_data/link_data.csv',
            yeti_format_traffic_data=
            f'{self.init_path}/test_data/yeti_format_data/traffic_data.csv')

        self.assertTrue(
            df_equal(link_data, expected_data["link_data"].round(5)))
        self.assertTrue(df_equal(vehicle_data, expected_data["vehicle_data"]))
        self.assertTrue(df_equal(traffic_data, expected_data["traffic_data"]))
        self.assertTrue(
            df_equal(los_speeds_data, expected_data["los_speeds_data"]))
Exemplo n.º 11
0
    def test_load_data(self):

        if os.path.isfile(
                "./tests/test_data/berlin_format_data/fleet_comp_data.csv"):
            init_path = "./tests"
        else:
            init_path = ".."

        vehicle_data = VehicleDataLoader(fleet_comp_data=pd.read_csv(
            f"{init_path}/test_data/berlin_format_data/fleet_comp_data.csv")
                                         ).load_data()

        vehicle_data_expected = pd.read_csv(
            f"{init_path}/test_data/yeti_format_data/vehicle_data.csv")

        self.assertTrue(df_equal(vehicle_data, vehicle_data_expected))
Exemplo n.º 12
0
    def test_convert_dir_and_day_type(self):

        df = pd.DataFrame({
            "XY": [1, 2, 3, 4],
            "Dir": ["R", Dir.L, "L", "R"],
            "DayType": [DayType.FRI, "1", "2", "3"]
        })

        expected_output = pd.DataFrame({
            "XY": [1, 2, 3, 4],
            "Dir": [Dir.R, Dir.L, Dir.L, Dir.R],
            "DayType":
            [DayType.FRI, DayType.MONtoTHU, DayType.FRI, DayType.SAT]
        })

        actual_output = convert_dir_and_day_type(df)

        self.assertTrue(df_equal(actual_output, expected_output))
Exemplo n.º 13
0
    def test_load_data(self):

        if os.path.isfile(
                "./tests/test_data/berlin_format_data/hbefa_ef_data.csv"):
            init_path = "./tests"
        else:
            init_path = ".."

        yeti_format_hbefa_ef_data, _ = HbefaEmissionFactorDataLoader(
            ef_data=pd.read_csv(
                f"{init_path}/test_data/berlin_format_data/hbefa_ef_data.csv")
        ).load_data()

        yeti_format_hbefa_ef_data_expected = pd.read_csv(
            f"{init_path}/test_data/yeti_format_data/hbefa_ef_data.csv")

        self.assertTrue(
            df_equal(yeti_format_hbefa_ef_data,
                     yeti_format_hbefa_ef_data_expected))
Exemplo n.º 14
0
    def test(self):

        sys.argv = f"run_yeti.py -c tests/test_data/acceptance_test_data/acceptance_test_config.yaml".split(
        )
        execfile(f"run_yeti.py")

        emissions_actual = pd.read_csv(
            "tests/test_acceptance_tests/output/PollutantType.NOx_emissions.csv"
        )
        emissions_expected = pd.read_csv(
            "tests/test_data/acceptance_test_data/EMoutput_artificialdata.csv")

        emissions_actual = emissions_actual.sort_values(
            by=["LinkID", "Dir", "DayType", "Hour"])
        emissions_expected = emissions_expected.sort_values(
            by=["LinkID", "Dir", "DayType", "Hour"])

        emissions_expected = emissions_expected.round(3)
        emissions_actual = emissions_actual.round(3)

        self.assertTrue(df_equal(emissions_actual, emissions_expected))
Exemplo n.º 15
0
    def test_load_data(self):

        if os.path.isfile(
                "./tests/test_data/berlin_format_data/traffic_data.csv"):
            init_path = "./tests"
        else:
            init_path = ".."

        traffic_data = TrafficDataLoader(
            fleet_comp_data=pd.read_csv(
                f"{init_path}/test_data/berlin_format_data/fleet_comp_data.csv"
            ),
            link_data=pd.read_csv(
                f"{init_path}/test_data/berlin_format_data/shape_data.csv"),
            traffic_count_data=pd.read_csv(
                f"{init_path}/test_data/berlin_format_data/traffic_data.csv")
        ).load_data()

        traffic_data_expected = pd.read_csv(
            f"{init_path}/test_data/yeti_format_data/traffic_data.csv")

        self.assertTrue(df_equal(traffic_data, traffic_data_expected))
Exemplo n.º 16
0
    def test_determine_missing_ef_data(self):

        ef_data = pd.DataFrame({
            "VehicleName": ["pc vehicle_a", "pc vehicle_a", "pc vehicle_b"],
            "Pollutant":
            [PollutantType.NOx, PollutantType.NH3, PollutantType.CO]
        })
        missing_ef_data_expected = pd.DataFrame({
            "Pollutant": [
                PollutantType.CO, PollutantType.VOC, PollutantType.PM_Exhaust,
                PollutantType.NOx, PollutantType.CO, PollutantType.NH3,
                PollutantType.VOC, PollutantType.PM_Exhaust
            ],
            "VehicleName": [
                "pc vehicle_a", "pc vehicle_a", "pc vehicle_a",
                "lcv vehicle_b", "lcv vehicle_b", "lcv vehicle_b",
                "lcv vehicle_b", "lcv vehicle_b"
            ]
        })
        missing_ef_data = self.loader.determine_missing_ef_data(ef_data)

        self.assertTrue(df_equal(missing_ef_data, missing_ef_data_expected))
Exemplo n.º 17
0
    def test_berlin_format_data_to_emissions(self):

        if os.path.isfile("./tests/test_data/emissions_expected_hbefa_ef.csv"):
            self.init_path = "./tests"
        else:
            self.init_path = "."

        StrategyInvoker().calculate_and_save_emissions(
            save_interval_in_rows=5,
            emissions_output_folder="temp",
            pollutants=["PollutantType.NOx"],
            Strategy=HbefaStrategy,
            only_hot=True,
            link_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/link_data.csv"),
            traffic_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/traffic_data.csv"
            ),
            vehicle_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/vehicle_data.csv"
            ),
            emission_factor_data=pd.read_csv(
                f"{self.init_path}/test_data/yeti_format_data/hbefa_ef_data.csv"
            ))

        emissions_actual = pd.read_csv("temp/PollutantType.NOx_emissions.csv")
        shutil.rmtree("temp")

        emissions_expected = pd.read_csv(
            f'{self.init_path}/test_data/emissions_expected_hbefa_ef.csv')

        self.assertEqual(len(emissions_expected), len(emissions_actual))

        emissions_actual = emissions_actual.round(5)
        emissions_expected = emissions_expected.round(5)

        self.assertTrue(df_equal(emissions_actual, emissions_expected))