def test_download_s3_object(self): download_s3_object(bucket=self.bucket, key=self.key, destination_path=self.destination_path) os._exists(self.destination_path)
def test_raw_to_features(self): download_s3_object(bucket=self.maccor_file_w_parameters_s3["bucket"], key=self.maccor_file_w_parameters_s3["key"], destination_path=self.maccor_file_w_parameters) dp = MaccorDatapath.from_file(self.maccor_file_w_parameters) dp.autostructure() processed_run_path = os.path.join(TEST_FILE_DIR, "processed_diagnostic.json") # Dump to the structured file and check the file size dumpfn(dp, processed_run_path) dp = loadfn(processed_run_path) for fclass in ( DeltaQFastCharge, CycleSummaryStats, TrajectoryFastCharge, DiagnosticSummaryStats, HPPCResistanceVoltageFeatures, ): f = fclass(dp) self.assertTrue(f.validate()[0]) f.create_features() if fclass.__class__.__name__ == "HPPCResistanceVoltageFeatures": self.assertAlmostEqual(f.features['r_c_0s_00'].iloc[0], -0.159771397, 5) self.assertAlmostEqual(f.features['r_c_0s_10'].iloc[0], -0.143679, 5) self.assertAlmostEqual(f.features['r_c_0s_20'].iloc[0], -0.146345, 5) self.assertAlmostEqual(f.features['D_6'].iloc[0], -0.167919, 5) self.assertAlmostEqual(f.features['D_7'].iloc[0], 0.094136, 5) self.assertAlmostEqual(f.features['D_8'].iloc[0], 0.172496, 5)
def test_raw_to_features(self): os.environ["BEEP_PROCESSING_DIR"] = TEST_FILE_DIR download_s3_object(bucket=self.maccor_file_w_parameters_s3["bucket"], key=self.maccor_file_w_parameters_s3["key"], destination_path=self.maccor_file_w_parameters) with ScratchDir("."): os.environ["BEEP_PROCESSING_DIR"] = TEST_FILE_DIR # os.environ['BEEP_PROCESSING_DIR'] = os.getcwd() dp = MaccorDatapath.from_file(self.maccor_file_w_parameters) dp.autostructure() processed_run_path = os.path.join(TEST_FILE_DIR, "processed_diagnostic.json") # Dump to the structured file and check the file size dumpfn(dp, processed_run_path) # Create dummy json obj json_obj = { "file_list": [processed_run_path], "run_list": [0], } json_string = json.dumps(json_obj) newjsonpaths = process_file_list_from_json( json_string, processed_dir=os.getcwd()) reloaded = json.loads(newjsonpaths) import pprint pprint.pprint(reloaded) result_list = ['success'] * 7 self.assertEqual(reloaded['result_list'], result_list) rpt_df = loadfn(reloaded['file_list'][0]) self.assertEqual( np.round(rpt_df.X['m0_Amp_rpt_0.2C_1'].iloc[0], 6), 0.867371)
def test_get_diagnostic(self): maccor_file_w_parameters_s3 = { "bucket": "beep-sync-test-stage", "key": "big_file_tests/PreDiag_000287_000128.092" } maccor_file_w_parameters = os.path.join(TEST_FILE_DIR, "PreDiag_000287_000128.092") download_s3_object(bucket=maccor_file_w_parameters_s3["bucket"], key=maccor_file_w_parameters_s3["key"], destination_path=maccor_file_w_parameters) md = MaccorDatapath.from_file(maccor_file_w_parameters) ( v_range, resolution, nominal_capacity, full_fast_charge, diagnostic_available, ) = md.determine_structuring_parameters() self.assertEqual(nominal_capacity, 4.84) # self.assertEqual(v_range, [2.7, 4.2]) # This is an older assertion, value changed when # different cell types were added self.assertEqual(v_range, [2.5, 4.2]) self.assertEqual( diagnostic_available["cycle_type"], ["reset", "hppc", "rpt_0.2C", "rpt_1C", "rpt_2C"], ) diag_summary = md.summarize_diagnostic(diagnostic_available) reg_summary = md.summarize_cycles(diagnostic_available) self.assertEqual(len(reg_summary.cycle_index.tolist()), 230) self.assertEqual(reg_summary.cycle_index.tolist()[:10], [0, 6, 7, 8, 9, 10, 11, 12, 13, 14]) # Check data types are being set correctly for diagnostic summary diag_dyptes = diag_summary.dtypes.tolist() diag_columns = diag_summary.columns.tolist() diag_dyptes = [str(dtyp) for dtyp in diag_dyptes] for indx, col in enumerate(diag_columns): self.assertEqual(diag_dyptes[indx], STRUCTURE_DTYPES["diagnostic_summary"][col]) self.assertEqual( diag_summary.cycle_index.tolist(), [ 1, 2, 3, 4, 5, 36, 37, 38, 39, 40, 141, 142, 143, 144, 145, 246, 247 ], ) self.assertEqual( diag_summary.cycle_type.tolist(), [ "reset", "hppc", "rpt_0.2C", "rpt_1C", "rpt_2C", "reset", "hppc", "rpt_0.2C", "rpt_1C", "rpt_2C", "reset", "hppc", "rpt_0.2C", "rpt_1C", "rpt_2C", "reset", "hppc", ], ) self.assertEqual(diag_summary.paused.max(), 0) diag_interpolated = md.interpolate_diagnostic_cycles( diagnostic_available, resolution=1000) # Check data types are being set correctly for interpolated data diag_dyptes = diag_interpolated.dtypes.tolist() diag_columns = diag_interpolated.columns.tolist() diag_dyptes = [str(dtyp) for dtyp in diag_dyptes] for indx, col in enumerate(diag_columns): self.assertEqual(diag_dyptes[indx], STRUCTURE_DTYPES["diagnostic_interpolated"][col]) # Provide visual inspection to ensure that diagnostic interpolation is being done correctly diag_cycle = diag_interpolated[ (diag_interpolated.cycle_type == "rpt_0.2C") & (diag_interpolated.step_type == 1)] self.assertEqual(diag_cycle.cycle_index.unique().tolist(), [3, 38, 143]) plt.figure() plt.plot(diag_cycle.discharge_capacity, diag_cycle.voltage) plt.savefig( os.path.join(TEST_FILE_DIR, "discharge_capacity_interpolation.png")) plt.figure() plt.plot(diag_cycle.voltage, diag_cycle.discharge_dQdV) plt.savefig( os.path.join(TEST_FILE_DIR, "discharge_dQdV_interpolation.png")) self.assertEqual(len(diag_cycle.index), 3000) hppcs = diag_interpolated[(diag_interpolated.cycle_type == "hppc") & pd.isnull(diag_interpolated.current)] self.assertEqual(len(hppcs), 0) hppc_dischg1 = diag_interpolated[ (diag_interpolated.cycle_index == 37) & (diag_interpolated.step_type == 2) & (diag_interpolated.step_index_counter == 3) & ~pd.isnull(diag_interpolated.current)] plt.figure() plt.plot(hppc_dischg1.test_time, hppc_dischg1.voltage) plt.savefig(os.path.join(TEST_FILE_DIR, "hppc_discharge_pulse_1.png")) self.assertEqual(len(hppc_dischg1), 176) # processed_cycler_run = cycler_run.to_processed_cycler_run() md.autostructure() self.assertNotIn( diag_summary.cycle_index.tolist(), md.structured_data.cycle_index.unique(), ) self.assertEqual( reg_summary.cycle_index.tolist(), md.structured_summary.cycle_index.tolist(), ) processed_cycler_run_loc = os.path.join(TEST_FILE_DIR, "processed_diagnostic.json") # Dump to the structured file and check the file size # File size had to be incteased as datapath dump includes ALL data now dumpfn(md, processed_cycler_run_loc) proc_size = os.path.getsize(processed_cycler_run_loc) self.assertLess(proc_size, 260000000) # Reload the structured file and check for errors test = loadfn(processed_cycler_run_loc) self.assertIsInstance(test.diagnostic_summary, pd.DataFrame) diag_dyptes = test.diagnostic_summary.dtypes.tolist() diag_columns = test.diagnostic_summary.columns.tolist() diag_dyptes = [str(dtyp) for dtyp in diag_dyptes] for indx, col in enumerate(diag_columns): self.assertEqual(diag_dyptes[indx], STRUCTURE_DTYPES["diagnostic_summary"][col]) diag_dyptes = test.diagnostic_data.dtypes.tolist() diag_columns = test.diagnostic_data.columns.tolist() diag_dyptes = [str(dtyp) for dtyp in diag_dyptes] for indx, col in enumerate(diag_columns): self.assertEqual(diag_dyptes[indx], STRUCTURE_DTYPES["diagnostic_interpolated"][col]) self.assertEqual(test.structured_summary.cycle_index.tolist()[:10], [0, 6, 7, 8, 9, 10, 11, 12, 13, 14]) plt.figure() single_charge = test.structured_data[ (test.structured_data.step_type == "charge") & (test.structured_data.cycle_index == 25)] self.assertEqual(len(single_charge.index), 1000) plt.plot(single_charge.charge_capacity, single_charge.voltage) plt.savefig( os.path.join(TEST_FILE_DIR, "charge_capacity_interpolation_regular_cycle.png")) os.remove(processed_cycler_run_loc)
def test_get_diagnostic(self): os.environ["BEEP_PROCESSING_DIR"] = TEST_FILE_DIR download_s3_object(bucket=self.maccor_file_w_parameters_s3["bucket"], key=self.maccor_file_w_parameters_s3["key"], destination_path=self.maccor_file_w_parameters) cycler_run = RawCyclerRun.from_file(self.maccor_file_w_parameters) ( v_range, resolution, nominal_capacity, full_fast_charge, diagnostic_available, ) = cycler_run.determine_structuring_parameters() self.assertEqual(nominal_capacity, 4.84) self.assertEqual(v_range, [2.7, 4.2]) self.assertEqual( diagnostic_available["cycle_type"], ["reset", "hppc", "rpt_0.2C", "rpt_1C", "rpt_2C"], ) diag_summary = cycler_run.get_diagnostic_summary(diagnostic_available) # Check data types are being set correctly for diagnostic summary diag_dyptes = diag_summary.dtypes.tolist() diag_columns = diag_summary.columns.tolist() diag_dyptes = [str(dtyp) for dtyp in diag_dyptes] for indx, col in enumerate(diag_columns): self.assertEqual(diag_dyptes[indx], STRUCTURE_DTYPES["diagnostic_summary"][col]) self.assertEqual( diag_summary.cycle_index.tolist(), [ 1, 2, 3, 4, 5, 36, 37, 38, 39, 40, 141, 142, 143, 144, 145, 246, 247 ], ) self.assertEqual( diag_summary.cycle_type.tolist(), [ "reset", "hppc", "rpt_0.2C", "rpt_1C", "rpt_2C", "reset", "hppc", "rpt_0.2C", "rpt_1C", "rpt_2C", "reset", "hppc", "rpt_0.2C", "rpt_1C", "rpt_2C", "reset", "hppc", ], ) self.assertEqual(diag_summary.paused.max(), 0) diag_interpolated = cycler_run.get_interpolated_diagnostic_cycles( diagnostic_available, resolution=1000) # Check data types are being set correctly for interpolated data diag_dyptes = diag_interpolated.dtypes.tolist() diag_columns = diag_interpolated.columns.tolist() diag_dyptes = [str(dtyp) for dtyp in diag_dyptes] for indx, col in enumerate(diag_columns): self.assertEqual(diag_dyptes[indx], STRUCTURE_DTYPES["diagnostic_interpolated"][col]) # Provide visual inspection to ensure that diagnostic interpolation is being done correctly diag_cycle = diag_interpolated[ (diag_interpolated.cycle_type == "rpt_0.2C") & (diag_interpolated.step_type == 1)] self.assertEqual(diag_cycle.cycle_index.unique().tolist(), [3, 38, 143]) plt.figure() plt.plot(diag_cycle.discharge_capacity, diag_cycle.voltage) plt.savefig( os.path.join(TEST_FILE_DIR, "discharge_capacity_interpolation.png")) plt.figure() plt.plot(diag_cycle.voltage, diag_cycle.discharge_dQdV) plt.savefig( os.path.join(TEST_FILE_DIR, "discharge_dQdV_interpolation.png")) self.assertEqual(len(diag_cycle.index), 3000) hppcs = diag_interpolated[(diag_interpolated.cycle_type == "hppc") & pd.isnull(diag_interpolated.current)] self.assertEqual(len(hppcs), 0) hppc_dischg1 = diag_interpolated[ (diag_interpolated.cycle_index == 37) & (diag_interpolated.step_type == 2) & (diag_interpolated.step_index_counter == 3) & ~pd.isnull(diag_interpolated.current)] plt.figure() plt.plot(hppc_dischg1.test_time, hppc_dischg1.voltage) plt.savefig(os.path.join(TEST_FILE_DIR, "hppc_discharge_pulse_1.png")) self.assertEqual(len(hppc_dischg1), 176) processed_cycler_run = cycler_run.to_processed_cycler_run() self.assertNotIn( diag_summary.index.tolist(), processed_cycler_run.cycles_interpolated.cycle_index.unique(), ) processed_cycler_run_loc = os.path.join(TEST_FILE_DIR, "processed_diagnostic.json") dumpfn(processed_cycler_run, processed_cycler_run_loc) proc_size = os.path.getsize(processed_cycler_run_loc) self.assertLess(proc_size, 47000000) test = loadfn(processed_cycler_run_loc) self.assertIsInstance(test.diagnostic_summary, pd.DataFrame) diag_dyptes = test.diagnostic_summary.dtypes.tolist() diag_columns = test.diagnostic_summary.columns.tolist() diag_dyptes = [str(dtyp) for dtyp in diag_dyptes] for indx, col in enumerate(diag_columns): self.assertEqual(diag_dyptes[indx], STRUCTURE_DTYPES["diagnostic_summary"][col]) diag_dyptes = test.diagnostic_interpolated.dtypes.tolist() diag_columns = test.diagnostic_interpolated.columns.tolist() diag_dyptes = [str(dtyp) for dtyp in diag_dyptes] for indx, col in enumerate(diag_columns): self.assertEqual(diag_dyptes[indx], STRUCTURE_DTYPES["diagnostic_interpolated"][col]) plt.figure() single_charge = test.cycles_interpolated[ (test.cycles_interpolated.step_type == "charge") & (test.cycles_interpolated.cycle_index == 25)] self.assertEqual(len(single_charge.index), 1000) plt.plot(single_charge.charge_capacity, single_charge.voltage) plt.savefig( os.path.join(TEST_FILE_DIR, "charge_capacity_interpolation_regular_cycle.png")) os.remove(processed_cycler_run_loc)