Example #1
0
 def test_solution_to_dataframe(self):
     input_file = self.total_cost_cbc
     reader = ReadCbc()
     with StringIO(input_file) as file_buffer:
         actual = reader.read(file_buffer)
     expected = self.total_cost_otoole_df
     pd.testing.assert_frame_equal(actual[0]["TotalDiscountedCost"],
                                   expected["TotalDiscountedCost"])
Example #2
0
 def test_convert_cbc_to_csv_long_read(self, cbc_solution, input_data,
                                       expected):
     cbc_reader = ReadCbc()
     with StringIO(cbc_solution) as file_buffer:
         actual = cbc_reader.read(file_buffer,
                                  kwargs={"input_data": input_data
                                          })[0]["TotalDiscountedCost"]
     assert isinstance(actual, pd.DataFrame)
     pd.testing.assert_frame_equal(actual, expected["TotalDiscountedCost"])
Example #3
0
    def test_convert_cbc_to_csv_short(self):
        cbc_results = pd.DataFrame(
            data=[
                ["RateOfActivity", "SIMPLICITY,ID,GAS_EXTRACTION,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,IN,GAS_EXTRACTION,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,SD,GAS_EXTRACTION,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,SN,GAS_EXTRACTION,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,WD,GAS_EXTRACTION,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,WN,GAS_EXTRACTION,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,ID,DUMMY,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,IN,DUMMY,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,SD,DUMMY,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,SN,DUMMY,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,WD,DUMMY,1,2014", 1],
                ["RateOfActivity", "SIMPLICITY,WN,DUMMY,1,2014", 1],
            ],
            columns=["Variable", "Index", "Value"],
        )
        input_data = {
            "EmissionActivityRatio":
            pd.DataFrame(
                data=[["SIMPLICITY", "GAS_EXTRACTION", "CO2", 1, 2014, 1.0]],
                columns=[
                    "REGION",
                    "TECHNOLOGY",
                    "EMISSION",
                    "MODE_OF_OPERATION",
                    "YEAR",
                    "VALUE",
                ],
            ).set_index([
                "REGION", "TECHNOLOGY", "EMISSION", "MODE_OF_OPERATION", "YEAR"
            ]),
            "YearSplit":
            pd.DataFrame(
                data=[
                    ["ID", 2014, 0.1667],
                    ["IN", 2014, 0.0833],
                    ["SD", 2014, 0.1667],
                    ["SN", 2014, 0.0833],
                    ["WD", 2014, 0.3333],
                    ["WN", 2014, 0.1667],
                ],
                columns=["TIMESLICE", "YEAR", "VALUE"],
            ).set_index(["TIMESLICE", "YEAR"]),
        }

        expected = pd.DataFrame(
            data=[["SIMPLICITY", "CO2", 2014, 1.0]],
            columns=["REGION", "EMISSION", "YEAR", "VALUE"],
        ).set_index(["REGION", "EMISSION", "YEAR"])

        cbc_reader = ReadCbc()
        actual = cbc_reader._convert_dataframe_to_csv(cbc_results, input_data)
        assert isinstance(actual, dict)
        pd.testing.assert_frame_equal(actual["AnnualEmissions"], expected)
Example #4
0
 def test_manage_infeasible_variables(self):
     input_file = self.cbc_infeasible
     reader = ReadCbc()
     with StringIO(input_file) as file_buffer:
         actual = reader._convert_to_dataframe(file_buffer)
     expected = pd.DataFrame(
         [
             ["RateOfActivity", "GLOBAL,S4D24,INRNGIM00,1,2041", 0],
             [
                 "RateOfActivity", "GLOBAL,S4D24,INRNGIM00,1,2042",
                 -7.7011981e-07
             ],
             [
                 "RateOfActivity", "GLOBAL,S1D1,INRNGIM00,1,2043",
                 -3.6128354e-06
             ],
             [
                 "RateOfActivity", "GLOBAL,S1D8,INRNGIM00,1,2043",
                 -3.1111316e-06
             ],
             [
                 "RateOfActivity", "GLOBAL,S1D9,INRNGIM00,1,2043",
                 -8.2325306e-07
             ],
             [
                 "RateOfActivity", "GLOBAL,S1D10,INRNGIM00,1,2043",
                 -3.1112991e-06
             ],
             [
                 "RateOfActivity", "GLOBAL,S2D3,INRNGIM00,1,2043",
                 -1.6357402e-06
             ],
             [
                 "RateOfActivity", "GLOBAL,S2D6,INRNGIM00,1,2043",
                 -3.1111969e-06
             ],
             [
                 "RateOfActivity", "GLOBAL,S2D14,INRNGIM00,1,2043",
                 -1.3925924e-07
             ],
         ],
         columns=["Variable", "Index", "Value"],
     )
     pd.testing.assert_frame_equal(actual, expected)
Example #5
0
    def test_read_cbc_dataframe_to_otoole_dataframe(self):

        prelim_data = pd.DataFrame(
            data=[
                ["Trade", "Globe,Globe,IP,L_AGR,2016", -1.0],
                ["Trade", "Globe,Globe,IP,L_AGR,2017", -2.0],
                ["Trade", "Globe,Globe,IP,L_AGR,2018", -3.0],
                ["Trade", "Globe,Globe,IP,L_AGR,2019", -4.0],
                ["Trade", "Globe,Globe,IP,L_AGR,2020", -5.0],
            ],
            columns=["Variable", "Index", "Value"],
        )
        actual = ReadCbc()._convert_dataframe_to_csv(prelim_data, {})["Trade"]
        pd.testing.assert_frame_equal(actual, self.otoole_data)
Example #6
0
 def test_convert_cbc_to_csv_long(self, results, cbc_input, expected):
     cbc_reader = ReadCbc()
     actual = cbc_reader._convert_dataframe_to_csv(results, cbc_input)
     assert isinstance(actual, dict)
     for name, df in actual.items():
         pd.testing.assert_frame_equal(df, expected[name])
Example #7
0
 def test_read_cbc_to_dataframe(self, cbc_input, expected):
     cbc_reader = ReadCbc()
     with StringIO(cbc_input) as file_buffer:
         actual = cbc_reader._convert_to_dataframe(file_buffer)
     pd.testing.assert_frame_equal(actual, expected)
Example #8
0
 def test_read_cbc_to_otoole_dataframe(self, cbc_input, expected):
     with StringIO(cbc_input) as file_buffer:
         actual = ReadCbc().read(file_buffer, kwargs={"input_data":
                                                      {}})[0]["Trade"]
     pd.testing.assert_frame_equal(actual, expected)