def test_feature_class(self): with ScratchDir("."): os.environ["BEEP_PROCESSING_DIR"] = os.getcwd() pcycler_run_loc = os.path.join( TEST_FILE_DIR, "2017-06-30_2C-10per_6C_CH10_structure.json" ) pcycler_run = loadfn(pcycler_run_loc) featurizer = DeltaQFastCharge.from_run( pcycler_run_loc, os.getcwd(), pcycler_run ) path, local_filename = os.path.split(featurizer.name) folder = os.path.split(path)[-1] self.assertEqual( local_filename, "2017-06-30_2C-10per_6C_CH10_features_DeltaQFastCharge.json", ) self.assertEqual(folder, "DeltaQFastCharge") dumpfn(featurizer, featurizer.name) processed_run_list = [] processed_result_list = [] processed_message_list = [] processed_paths_list = [] run_id = 1 featurizer_classes = [DeltaQFastCharge, TrajectoryFastCharge] for featurizer_class in featurizer_classes: featurizer = featurizer_class.from_run( pcycler_run_loc, os.getcwd(), pcycler_run ) if featurizer: self.assertEqual(featurizer.metadata["channel_id"], 9) self.assertEqual(featurizer.metadata["protocol"], None) self.assertEqual(featurizer.metadata["barcode"], None) dumpfn(featurizer, featurizer.name) processed_paths_list.append(featurizer.name) processed_run_list.append(run_id) processed_result_list.append("success") processed_message_list.append({"comment": "", "error": ""}) else: processed_paths_list.append(pcycler_run_loc) processed_run_list.append(run_id) processed_result_list.append("incomplete") processed_message_list.append( { "comment": "Insufficient or incorrect data for featurization", "error": "", } ) self.assertEqual(processed_result_list, ["success", "success"]) trajectory = loadfn( os.path.join( "TrajectoryFastCharge", "2017-06-30_2C-10per_6C_CH10_features_TrajectoryFastCharge.json", ) ) self.assertEqual(trajectory.X.loc[0, "capacity_0.8"], 161)
def test_feature_label_full_model(self): processed_cycler_run_path = os.path.join(TEST_FILE_DIR, PROCESSED_CYCLER_FILE) with ScratchDir('.'): os.environ['BEEP_ROOT'] = os.getcwd() pcycler_run = loadfn(processed_cycler_run_path) featurizer = DeltaQFastCharge.from_run(processed_cycler_run_path, os.getcwd(), pcycler_run) self.assertEqual(featurizer.X.columns.tolist()[4], "charge_time_cycles_1:5")
def test_feature_serialization_for_training(self): processed_cycler_run_path = os.path.join(TEST_FILE_DIR, PROCESSED_CYCLER_FILE) with ScratchDir('.'): os.environ['BEEP_ROOT'] = os.getcwd() pcycler_run = loadfn(processed_cycler_run_path) featurizer = DeltaQFastCharge.from_run(processed_cycler_run_path, os.getcwd(), pcycler_run) dumpfn(featurizer, featurizer.name) features_reloaded = loadfn(featurizer.name) self.assertIsInstance(features_reloaded, DeltaQFastCharge)
def test_feature_generation_full_model(self): processed_cycler_run_path = os.path.join(TEST_FILE_DIR, PROCESSED_CYCLER_FILE) with ScratchDir('.'): os.environ['BEEP_ROOT'] = os.getcwd() pcycler_run = loadfn(processed_cycler_run_path) featurizer = DeltaQFastCharge.from_run(processed_cycler_run_path, os.getcwd(), pcycler_run) self.assertEqual(len(featurizer.X), 1) # just test if works for now # Ensure no NaN values self.assertFalse(np.any(featurizer.X.isnull()))
def test_feature_class(self): with ScratchDir('.'): os.environ['BEEP_PROCESSING_DIR'] = os.getcwd() pcycler_run_loc = os.path.join( TEST_FILE_DIR, '2017-06-30_2C-10per_6C_CH10_structure.json') pcycler_run = loadfn(pcycler_run_loc) featurizer = DeltaQFastCharge.from_run(pcycler_run_loc, os.getcwd(), pcycler_run) path, local_filename = os.path.split(featurizer.name) folder = os.path.split(path)[-1] self.assertEqual( local_filename, '2017-06-30_2C-10per_6C_CH10_features_DeltaQFastCharge.json') self.assertEqual(folder, 'DeltaQFastCharge') dumpfn(featurizer, featurizer.name) processed_run_list = [] processed_result_list = [] processed_message_list = [] processed_paths_list = [] run_id = 1 featurizer_classes = [DeltaQFastCharge, TrajectoryFastCharge] for featurizer_class in featurizer_classes: featurizer = featurizer_class.from_run(pcycler_run_loc, os.getcwd(), pcycler_run) if featurizer: self.assertEqual(featurizer.metadata['channel_id'], 9) self.assertEqual(featurizer.metadata['protocol'], None) self.assertEqual(featurizer.metadata['barcode'], None) dumpfn(featurizer, featurizer.name) processed_paths_list.append(featurizer.name) processed_run_list.append(run_id) processed_result_list.append("success") processed_message_list.append({'comment': '', 'error': ''}) else: processed_paths_list.append(pcycler_run_loc) processed_run_list.append(run_id) processed_result_list.append("incomplete") processed_message_list.append({ 'comment': 'Insufficient or incorrect data for featurization', 'error': '' }) self.assertEqual(processed_result_list, ["success", "success"]) trajectory = loadfn( os.path.join( 'TrajectoryFastCharge', '2017-06-30_2C-10per_6C_CH10_features_TrajectoryFastCharge.json' )) self.assertEqual(trajectory.X.loc[0, 'capacity_0.8'], 161)
def test_feature_label_full_model(self): processed_cycler_run_path = os.path.join(TEST_FILE_DIR, self.processed_cycler_file) with ScratchDir("."): os.environ["BEEP_PROCESSING_DIR"] = os.getcwd() pcycler_run = auto_load_processed(processed_cycler_run_path) featurizer = DeltaQFastCharge.from_run(processed_cycler_run_path, os.getcwd(), pcycler_run) self.assertEqual(featurizer.X.columns.tolist()[4], "charge_time_cycles_1:5")
def test_feature_serialization_for_training(self): processed_cycler_run_path = os.path.join(TEST_FILE_DIR, self.processed_cycler_file) with ScratchDir("."): os.environ["BEEP_PROCESSING_DIR"] = os.getcwd() pcycler_run = auto_load_processed(processed_cycler_run_path) featurizer = DeltaQFastCharge.from_run(processed_cycler_run_path, os.getcwd(), pcycler_run) dumpfn(featurizer, featurizer.name) features_reloaded = loadfn(featurizer.name) self.assertIsInstance(features_reloaded, DeltaQFastCharge)
def test_feature_serialization(self): processed_cycler_run_path = os.path.join(TEST_FILE_DIR, PROCESSED_CYCLER_FILE) with ScratchDir('.'): os.environ['BEEP_ROOT'] = os.getcwd() pcycler_run = loadfn(processed_cycler_run_path) featurizer = DeltaQFastCharge.from_run(processed_cycler_run_path, os.getcwd(), pcycler_run) dumpfn(featurizer, featurizer.name) features_reloaded = loadfn(featurizer.name) self.assertIsInstance(features_reloaded, DeltaQFastCharge) # test nominal capacity is being generated self.assertEqual(features_reloaded.X.loc[0, 'nominal_capacity_by_median'], 1.0628421000000001)
def test_feature_serialization(self): processed_cycler_run_path = os.path.join(TEST_FILE_DIR, self.processed_cycler_file) with ScratchDir("."): os.environ["BEEP_PROCESSING_DIR"] = os.getcwd() pcycler_run = auto_load_processed(processed_cycler_run_path) featurizer = DeltaQFastCharge.from_run(processed_cycler_run_path, os.getcwd(), pcycler_run) dumpfn(featurizer, featurizer.name) features_reloaded = loadfn(featurizer.name) self.assertIsInstance(features_reloaded, DeltaQFastCharge) # test nominal capacity is being generated self.assertEqual( features_reloaded.X.loc[0, "nominal_capacity_by_median"], 1.0628421000000001)
def test_feature_generation_full_model(self): processed_cycler_run_path = os.path.join(TEST_FILE_DIR, self.processed_cycler_file) with ScratchDir("."): os.environ["BEEP_PROCESSING_DIR"] = os.getcwd() pcycler_run = auto_load_processed(processed_cycler_run_path) featurizer = DeltaQFastCharge.from_run(processed_cycler_run_path, os.getcwd(), pcycler_run) self.assertEqual(len(featurizer.X), 1) # just test if works for now # Ensure no NaN values # print(featurizer.X.to_dict()) self.assertFalse(np.any(featurizer.X.isnull())) self.assertEqual( np.round( featurizer.X.loc[ 0, 'intercept_discharge_capacity_cycle_number_91:100'], 6), np.round(1.1050065801818196, 6))