def test_generate_maccor_waveform_file_default(self): velocity_waveform_file = os.path.join(TEST_FILE_DIR, "LA4_velocity_waveform.txt") with ScratchDir('.') as scratch_dir: df_power = convert_velocity_to_power_waveform( velocity_waveform_file, 'mph') df_MWF = pd.read_csv(generate_maccor_waveform_file( df_power, "test_LA4_waveform", scratch_dir), sep='\t', header=None) # Reference mwf file generated by the cycler for the same power waveform. df_MWF_ref = pd.read_csv(os.path.join( TEST_FILE_DIR, "LA4_reference_default_settings.mwf"), sep="\t", header=None) self.assertEqual(df_MWF.shape, df_MWF_ref.shape) # Check that the fourth column for charge/discharge limit is empty (default setting) self.assertTrue(df_MWF.iloc[:, 3].isnull().all()) # Check that sum of durations equals length of the power timeseries self.assertEqual(df_MWF.iloc[:, 5].sum(), len(df_power)) # Check that charge/discharge steps are identical self.assertTrue((df_MWF.iloc[:, 0] == df_MWF_ref.iloc[:, 0]).all()) # Check that power values are close to each other (col 2) relative_differences = np.abs( (df_MWF.iloc[:, 2] - df_MWF_ref.iloc[:, 2]) / df_MWF_ref.iloc[:, 2]) self.assertLessEqual(np.mean(relative_differences) * 100, 0.01) # mean percentage error < 0.01%
def test_generate_maccor_waveform_from_power(self): power_waveform_file = os.path.join(TEST_FILE_DIR, "LA4_power_profile.csv") mwf_config = { "control_mode": "P", "value_scale": 30, "charge_limit_mode": "V", "charge_limit_value": 4.2, "discharge_limit_mode": "V", "discharge_limit_value": 2.7, "charge_end_mode": "V", "charge_end_operation": ">=", "charge_end_mode_value": 4.25, "discharge_end_mode": "V", "discharge_end_operation": "<=", "discharge_end_mode_value": 2.5, "report_mode": "T", "report_value": 3.0000, "range": "A", } with ScratchDir(".") as scratch_dir: waveform_name = "LA4_8rep_lim" df_power = pd.read_csv(power_waveform_file) df_power = pd.concat([ df_power, df_power, df_power, df_power, df_power, df_power, df_power, df_power, ]) df_power.drop(columns=["power"], inplace=True) df_power.rename(columns={"power_scaled": "power"}, inplace=True) df_MWF = pd.read_csv( generate_maccor_waveform_file(df_power, waveform_name, scratch_dir, mwf_config=mwf_config), sep="\t", header=None, ) sign = df_MWF[0].apply(lambda x: -1 if x is "D" else 1) energy = df_MWF[2] * df_MWF[5] * sign self.assertLess(df_MWF[5].sum(), 10961) self.assertLess(energy.sum(), -20000) self.assertGreater(40, df_MWF[2].max()) self.assertLess(-40, df_MWF[2].min()) # Uncomment line below to keep the output in the test file directory shutil.copyfile( os.path.join(scratch_dir, waveform_name + ".MWF"), os.path.join(TEST_FILE_DIR, waveform_name + ".MWF"), )
def test_generate_maccor_waveform_file_custom(self): velocity_waveform_file = os.path.join(TEST_FILE_DIR, "US06_velocity_waveform.txt") mwf_config = { "control_mode": "I", "value_scale": 1, "charge_limit_mode": "R", "charge_limit_value": 2, "discharge_limit_mode": "P", "discharge_limit_value": 3, "charge_end_mode": "V", "charge_end_operation": ">=", "charge_end_mode_value": 4.2, "discharge_end_mode": "V", "discharge_end_operation": "<=", "discharge_end_mode_value": 3, "report_mode": "T", "report_value": 10, "range": "A", } with ScratchDir(".") as scratch_dir: df_power = convert_velocity_to_power_waveform( velocity_waveform_file, "mph") df_MWF = pd.read_csv( generate_maccor_waveform_file(df_power, "test_US06_waveform", scratch_dir, mwf_config=mwf_config), sep="\t", header=None, ) df_MWF_ref = pd.read_csv( os.path.join(TEST_FILE_DIR, "US06_reference_custom_settings.mwf"), sep="\t", header=None, ) # Check dimensions with the reference mwf file self.assertEqual(df_MWF.shape, df_MWF_ref.shape) # Check that control_mode, charge/discharge state, limit and limit_value columns are identical. self.assertTrue( (df_MWF.iloc[:, [0, 1, 3, 4]] == df_MWF_ref.iloc[:, [0, 1, 3, 4]] ).all().all()) # Check that power values are close to each other (col 2) relative_differences = np.abs( (df_MWF.iloc[:, 2] - df_MWF_ref.iloc[:, 2]) / df_MWF_ref.iloc[:, 2]) self.assertLessEqual(np.mean(relative_differences) * 100, 0.01) # mean percentage error < 0.01%
def test_generate_maccor_waveform_file_custom(self): velocity_waveform_file = os.path.join(TEST_FILE_DIR, "US06_velocity_waveform.txt") mwf_config = { 'control_mode': 'I', 'value_scale': 1, 'charge_limit_mode': 'R', 'charge_limit_value': 2, 'discharge_limit_mode': 'P', 'discharge_limit_value': 3, 'charge_end_mode': 'V', 'charge_end_operation': '>=', 'charge_end_mode_value': 4.2, 'discharge_end_mode': 'V', 'discharge_end_operation': '<=', 'discharge_end_mode_value': 3, 'report_mode': 'T', 'report_value': 10, 'range': 'A', } with ScratchDir('.') as scratch_dir: df_power = convert_velocity_to_power_waveform( velocity_waveform_file, 'mph') df_MWF = pd.read_csv(generate_maccor_waveform_file( df_power, "test_US06_waveform", scratch_dir, mwf_config=mwf_config), sep='\t', header=None) df_MWF_ref = pd.read_csv(os.path.join( TEST_FILE_DIR, "US06_reference_custom_settings.mwf"), sep="\t", header=None) # Check dimensions with the reference mwf file self.assertEqual(df_MWF.shape, df_MWF_ref.shape) # Check that control_mode, charge/discharge state, limit and limit_value columns are identical. self.assertTrue( (df_MWF.iloc[:, [0, 1, 3, 4]] == df_MWF_ref.iloc[:, [0, 1, 3, 4]] ).all().all()) # Check that power values are close to each other (col 2) relative_differences = np.abs( (df_MWF.iloc[:, 2] - df_MWF_ref.iloc[:, 2]) / df_MWF_ref.iloc[:, 2]) self.assertLessEqual(np.mean(relative_differences) * 100, 0.01) # mean percentage error < 0.01%