def save_sino_summaries(gen='g2'): """Create and save the sinogram summaries Parameters ---------- gen : str Must be in ['g1', 'g2'], string to identify which data gen """ # Load the data and metadata if gen in ['g1']: data = load_pickle(os.path.join(__DATA_DIR, 'g1/g1_fd.pickle')) metadata = load_pickle( os.path.join(__DATA_DIR, 'g1/g1_metadata.pickle')) else: # If Gen-2 data = load_pickle(os.path.join(__DATA_DIR, 'g2/g2_fd.pickle')) metadata = load_pickle( os.path.join(__DATA_DIR, 'g2/g2_metadata.pickle')) # Convert to the time-domain data = np.abs(to_td(data)) metadata = np.array(metadata) # Get the sinogram summaries (average and stdev signals) sino_summaries, sino_md = get_sino_summaries(dataset=data, metadata=metadata) # Save to .pickle files save_pickle(sino_summaries, os.path.join(__OUT_DIR, '%s_sino_summaries.pickle' % gen)) save_pickle(sino_md, os.path.join(__OUT_DIR, '%s_sino_summaries_md.pickle' % gen))
# Load the G1 validation data g1_tr_d = load_pickle(os.path.join(__DATA_DIR, 'g1-train-test/train_fd.pickle')) g1_tr_md = load_pickle(os.path.join(__DATA_DIR, 'g1-train-test/train_md.pickle')) # Set the G1 data to be the validation data val_data = g1_tr_d val_md = g1_tr_md # Correct the initial antenna position used in G1 scans val_data = correct_g1_ini_ant_ang(val_data) # Preprocess data, take magnitude and apply time-window, augment # training dataset val_data = np.abs(to_td(val_data)) val_data = resize_features_for_keras(val_data) train_data = np.abs(to_td(train_data)) train_data, train_md = full_aug(train_data, train_md) train_data = resize_features_for_keras(train_data) # Get the validation and train set class labels and make categorical val_labels = get_class_labels(val_md) val_labels = to_categorical(val_labels) train_labels = get_class_labels(train_md) train_labels = to_categorical(train_labels) # Create arrays for storing the AUC on the train and validation # sets for this regularization parameter after training with # correct labels train_set_aucs = np.zeros([__N_RUNS, __N_EPOCHS])
__N_RUNS = 20 ############################################################################### if __name__ == "__main__": logger = get_script_logger(__file__) # Load the training data and metadata from Gen-2 g2_d = load_pickle(os.path.join(__DATA_DIR, 'g2/g2_fd.pickle')) g2_md = load_pickle(os.path.join(__DATA_DIR, 'g2/g2_metadata.pickle')) g2_md = np.array(g2_md) # Convert to the time-domain, crop the signals, take magnitude g2_d = np.abs(to_td(g2_d)) # Get all of the Adipose IDs adi_ids = np.array([md['phant_id'].split('F')[0] for md in g2_md]) unique_adi_ids = np.unique(adi_ids) adi_results = dict() # Init dict for storing results # Init lists for storing metadata of samples which are # incorrectly / correctly classified incor_preds = [] cor_preds = [] for adi_id in unique_adi_ids: # For each adipose ID logger.info('\tWorking on Adi ID:\t%s' % adi_id)
############################################################################### __DATA_DIR = os.path.join(get_proj_path(), 'data/umbmid/g2/') __FIG_OUT_DIR = os.path.join(get_proj_path(), 'output/figs/') verify_path(__FIG_OUT_DIR) ############################################################################### if __name__ == "__main__": # Load phantom dataset (UM-BMID Gen1) phant_data = load_pickle(os.path.join(__DATA_DIR, 'g2_fd.pickle')) # Convert dataset to the time-domain sinograms = to_td(phant_data) # Take sample sinogram sinogram = sinograms[201, :, :] # Define scan times scan_ts = np.linspace(0.5e-9, 5.5e-9, 35) plot_sino(td_data=sinogram, ini_t=scan_ts[0], fin_t=scan_ts[-1], save_fig=True, save_str=os.path.join(__FIG_OUT_DIR, 'sino_example'), transparent=False, dpi=300, cbar_fmt='%.3f')