From 5b8114f20a0fe7ea7f20eae94a89ce6aabd5a409 Mon Sep 17 00:00:00 2001 From: Ziwen Liu <67518483+ziw-liu@users.noreply.github.com> Date: Tue, 30 May 2023 17:12:51 -0700 Subject: [PATCH] remove outdated scripts (#6) --- scripts/align_z_focus.py | 190 ------------------- scripts/metadata_renaming.py | 54 ------ scripts/test_zarr_reading.py | 205 -------------------- scripts/visualize_data_augmentation.py | 248 ------------------------- 4 files changed, 697 deletions(-) delete mode 100755 scripts/align_z_focus.py delete mode 100644 scripts/metadata_renaming.py delete mode 100644 scripts/test_zarr_reading.py delete mode 100644 scripts/visualize_data_augmentation.py diff --git a/scripts/align_z_focus.py b/scripts/align_z_focus.py deleted file mode 100755 index 0f758a8e..00000000 --- a/scripts/align_z_focus.py +++ /dev/null @@ -1,190 +0,0 @@ -""" -This script align the z-focus of z-stacks to account for any mis-registration in z caused by - light paths or z-drift during imaging. z-stacks are aligned across different imaging modalities -(label-free & fluorescence), FOVs, times. The focus within each (channel group, p, t) is found -and then aligned. The first channel of each channel group is the reference channel that used to -define the focus of the entire group. Only single-paged tiff input & output are supported for now. -""" - -import os -import warnings -import cv2 -import numpy as np -import pandas as pd - - -def brenner_gradient(im): - assert len(im.shape) == 2, 'Input image must be 2D' - return np.mean((im[:-2, :] - im[2:, :]) ** 2) - - -def read_img(img_file): - """read a single image at (c,t,p,z)""" - img = cv2.imread(img_file, -1) # flag -1 to preserve the bit dept of the raw image - if img is None: - warnings.warn('image "{}" cannot be found. Return None instead.'.format(img_file)) - else: - img = img.astype(np.float32, copy=False) # convert to float32 without making a copy to save memory - return img - - -def get_sms_im_name(time_idx=None, - channel_name=None, - slice_idx=None, - pos_idx=None, - extra_field=None, - ext='.npy', - int2str_len=3): - """ - Create an image name given parameters and extension - This function is custom for the computational microscopy (SMS) - group, who has the following file naming convention: - File naming convention is assumed to be: - img_channelname_t***_p***_z***.tif - This function will alter list and dict in place. - - :param int time_idx: Time index - :param str channel_name: Channel name - :param int slice_idx: Slice (z) index - :param int pos_idx: Position (FOV) index - :param str extra_field: Any extra string you want to include in the name - :param str ext: Extension, e.g. '.png' - :param int int2str_len: Length of string of the converted integers - :return st im_name: Image file name - """ - - im_name = "img" - if channel_name is not None: - im_name += "_" + str(channel_name) - if time_idx is not None: - im_name += "_t" + str(time_idx).zfill(int2str_len) - if pos_idx is not None: - im_name += "_p" + str(pos_idx).zfill(int2str_len) - if slice_idx is not None: - im_name += "_z" + str(slice_idx.astype('int64')).zfill(int2str_len) - if extra_field is not None: - im_name += "_" + extra_field - im_name += ext - - return im_name - - -def main(input_dir, - output_dir, - ref_chans, - chan_groups, - conditions, - conditions_new, - max_focus_idx, - min_focus_idx): - - assert len(conditions) == len(conditions_new), 'length mismatch for "conditions" and "conditions_new"' - condi_mapping = dict(zip(conditions, conditions_new)) # {'': ''} - meta_master = pd.DataFrame() - for condition in conditions: - print('processing condition {}...'.format(condition)) - # Load frames metadata and determine indices if exists - fmeta_path = os.path.join(input_dir, condition, 'frames_meta.csv') - if os.path.isfile(fmeta_path): - frames_meta = pd.read_csv(fmeta_path, index_col=0) - else: - raise FileNotFoundError('"frames_meta.csv" generated by microDL is required') - - # print(frames_meta['pos_idx'].unique()) - dst_dir = os.path.join(output_dir, condi_mapping[condition]) - os.makedirs(dst_dir, exist_ok=True) - - pos_ids = frames_meta['pos_idx'].unique() - pos_ids.sort() - frames_meta['condition'] = condi_mapping[condition] # empty - # loop through reference stack at each position - - for pos_idx in pos_ids: - frames_meta_p = frames_meta[frames_meta['pos_idx'] == pos_idx] - t_ids = frames_meta_p['time_idx'].unique() - t_ids.sort() - for t_idx in t_ids: - frames_meta_pt = frames_meta_p[frames_meta_p['time_idx'] == t_idx] - focus_idx = None - for chans in chan_groups: - for chan in chans: - print( - 'Processing position {}, time {}, channel {}...'.format(pos_idx, t_idx, chan)) - frames_meta_ptc = frames_meta_pt[frames_meta_pt['channel_name'] == chan] - z_ids = frames_meta_ptc['slice_idx'].unique() - z_ids.sort() - if chan in ref_chans: - focus_scores = [] - for z_idx in z_ids: - frames_meta_ptcz = frames_meta_ptc[frames_meta_ptc['slice_idx'] == z_idx] - im_path = os.path.join(frames_meta_ptcz['dir_name'].values[0], - frames_meta_ptcz['file_name'].values[0]) - img = read_img(im_path) - focus_score = brenner_gradient(img) - focus_scores.append(focus_score) - if chan == 'Brightfield': - focus_idx = z_ids[np.argmin(focus_scores)] - else: - focus_idx = z_ids[np.argmax(focus_scores)] - else: - assert focus_idx is not None, 'reference channel must be the first channel in the channel group' - if focus_idx <= max_focus_idx and focus_idx >= min_focus_idx: - frames_meta.loc[(frames_meta['pos_idx'] == pos_idx) & - (frames_meta_p['time_idx'] == t_idx) & - (frames_meta_pt['channel_name'] == chan), 'focus_idx'] = focus_idx - frames_meta.loc[(frames_meta['pos_idx'] == pos_idx) & - (frames_meta_p['time_idx'] == t_idx) & - (frames_meta_pt['channel_name'] == chan), 'focus_score'] = focus_scores - frames_meta['dst_dir'] = dst_dir - meta_master = meta_master.append(frames_meta) #['channel_idx', 'pos_idx', 'slice_idx', 'time_idx', 'channel_name', 'dir_name', 'file_name', 'condition', 'focus_idx', 'focus_score', 'dst_dir'] - # plot focus scores - # for chan in ref_chans: - # frames_meta_c = frames_meta[frames_meta['channel_name'] == chan] - # ax = sns.lineplot(data=frames_meta_c, x='slice_idx', y='focus_score', hue='time_idx') - # ax.figure.savefig(os.path.join(input_dir, 'focus_scores_{}_{}.png'.format(condition, chan))) - # plt.close() - focus_offset = meta_master['focus_idx'] - int(meta_master['focus_idx'].median()) - z_ids_new = np.arange(z_ids[0] - focus_offset.min(), z_ids[-1] - focus_offset.max() + 1) - meta_master['slice_idx_new'] = meta_master['slice_idx'] - focus_offset - meta_master.loc[~meta_master['slice_idx_new'].isna(), 'slice_idx_new'] = \ - meta_master.loc[~meta_master['slice_idx_new'].isna(), 'slice_idx_new'].astype('int64') - meta_master = meta_master.loc[meta_master['slice_idx_new'].isin(z_ids_new), :] - meta_master.reset_index(drop=True, inplace=True) - for row_idx in list(meta_master.index): - meta_row = meta_master.loc[row_idx] - if np.isnan(meta_row['slice_idx_new']): - continue - im_src_path = os.path.join(meta_row['dir_name'], - meta_row['file_name']) - im_name_dst = get_sms_im_name( - time_idx=meta_row['time_idx'], - channel_name=meta_row['channel_name'], - slice_idx=meta_row['slice_idx_new'], - pos_idx=meta_row['pos_idx'], - ext='.tif', - ) - os.link(im_src_path, - os.path.join(meta_row['dst_dir'], im_name_dst)) - meta_master.to_csv(os.path.join(output_dir, 'frames_meta.csv'), sep=',') - - -if __name__ == '__main__': - input_dir = '/hpc/projects/comp_micro/projects/HEK/2022_03_15_orgs_nuc_mem_63x_04NA/all_pos_single_page/all_pos_Phase1e-3_Denconv_Nuc8e-4_Mem8e-4_pad15_bg50' - output_dir = input_dir + '_registered_refmem_min25_max60' - max_focus_idx = 60 # maximal focus idx, if the focus of the fov is above it will be neglected - min_focus_idx = 25 # minimal focus idx, if the focus of a fov is above it will be neglected - conditions = [''] # name of the sub-folders for multiple condition (well) dataset. Put '' if no subfolder. - conditions_new = conditions # new condition names in the output directory - pol_chans = ['phase'] # list all polarization channels, reference channel must be listed first - fluor_chans = ['membrane', 'nucleus'] # list all fluorescence channels, reference channel must be listed first - ref_chans = ['phase', 'membrane'] # choose a reference channel from the polarization group and from the fluorescence group for alignment - chan_groups = [pol_chans, fluor_chans] - - main(input_dir, - output_dir, - ref_chans, - chan_groups, - conditions, - conditions_new, - max_focus_idx, - min_focus_idx) diff --git a/scripts/metadata_renaming.py b/scripts/metadata_renaming.py deleted file mode 100644 index b084bc03..00000000 --- a/scripts/metadata_renaming.py +++ /dev/null @@ -1,54 +0,0 @@ -''' -This script corrects for mis-mounted absolute paths in data. You - -Metadata of preprocessed data will have absolute paths referring to the data location in the form of -whatever mount was used to acces the data. -For example, metadata might refer to a source image for a tile as '/home/soorya.pradeep/CompMicro/...' -This means that unless you have access to user Soorya Pradeep, the preprocessing script will break -''' - -import pandas as pd -import argparse - -def parse_args(): - """Parse command line arguments - - In python namespaces are implemented as dictionaries - :return: namespace containing the arguments passed. - """ - parser = argparse.ArgumentParser() - parser.add_argument( - '--mounting', - type=str, - help="desired mounting to '/CompMicro' directory", - ) - - parser.add_argument( - '--meta_path', - type=str, - help="path to 'frames_meta.csv' metadata file in question", - ) - - parser.add_argument( - '--wrong_mount_length', - type=str, - help="length of incorrect mounting before /CompMicro: (ex) /home/soorya.pradeep/CompMicro is 2", - ) - - args = parser.parse_args() - return args - -if __name__ == 'main': - args = parse_args() - - path = args.meta_path - mounting = args.mounting - wmlength = args.wrong_mounting_length - - frames_meta = pd.read_csv(path) - - for i in range(len(frames_meta['dir_name'])): - new_path = mounting + '/' + '/'.join(frames_meta['dir_name'][i].split('/')[1 + wmlength:]) - frames_meta['dir_name'][i] = new_path - frames_meta.to_csv(path) - diff --git a/scripts/test_zarr_reading.py b/scripts/test_zarr_reading.py deleted file mode 100644 index 584286f6..00000000 --- a/scripts/test_zarr_reading.py +++ /dev/null @@ -1,205 +0,0 @@ -#%% -''' -Script for testing .zarr reading. Compares with .tiff reader to show that output preprocessed tiles and -metadata are the same from both inputs: -''' - -import numpy as np -import pandas as pd -import os -import shutil -import unittest -import argparse -import glob -import time - -import viscy.utils.aux_utils as aux_utils -import viscy.cli.preprocess_script as preprocess_script - -def parse_args(): - """Parse command line arguments - - In python namespaces are implemented as dictionaries - :return: namespace containing the arguments passed. - """ - parser = argparse.ArgumentParser() - parser.add_argument( - '--zarr_dir', - type=str, - help='path to directory of zarr files', - ) - - parser.add_argument( - '--tiff_dir', - type=str, - help='path to directory of tiff files', - ) - parser.add_argument( - '--preprocess', - type=str, - help='path to yaml preprocess config file', - ) - - args = parser.parse_args() - return args - -class TestZarrReading(unittest.TestCase): - - def setUp(self): - """ - Write .yml files for preprocessing with .zarr and .tif from the same directory - Specify a directory of .zarr files. - """ - self.zarr_tiles = None - self.tiff_tiles = None - - def compare_tiling(self, tiff_tile_dir, zarr_tile_dir): - ''' - Compares .npy files output from preprocessing done through reading zarr and tiff - files. If any .npy files are substantially different, errors - - :param str tiff_tile_dir: directory containing tiff-preprocessed tiles - :param str zarr_tile_dir: directory containing zarr-preprocessed tiles - ''' - tiff_tile_names = self._get_files_of_type(tiff_tile_dir, ftype = '.npy') - zarr_tile_names = self._get_files_of_type(zarr_tile_dir, ftype = '.npy') - - assert len(tiff_tile_names) == len(zarr_tile_names), 'Different numbers of tiles' - - for i in range(len(tiff_tile_names)): - tiff_tile = np.load(os.path.join(tiff_tile_dir, tiff_tile_names[i])) - zarr_tile = np.load(os.path.join(zarr_tile_dir, zarr_tile_names[i])) - print(f'Comparing tile {i}/{len(zarr_tile_names)}...', end='\r') - time.sleep(0.00001) - - er_msg = f'Tiles {zarr_tile_names[i]} (zarr) and {tiff_tile_names[i]} (tiff) unequal' - np.testing.assert_equal(tiff_tile, zarr_tile, err_msg = er_msg) - print('\n', end='\r') - print('\t --> compare_tiling passed') - - - def compare_metadata(self, tiff_tile_dir, zarr_tile_dir): - ''' - Compares metadata files output from preprocessing done through reading zarr and tiff - data storage. If metadata is different, errors. - - :param str tiff_tile_dir: directory containing tiff-preprocessed tiles - :param str zarr_tile_dir: directory containing zarr-preprocessed tiles - ''' - tiff_meta_files = self._get_files_of_type(tiff_tile_dir, ftype='.csv') - zarr_meta_files = self._get_files_of_type(zarr_tile_dir, ftype='.csv') - for i in range(len(tiff_meta_files)): - tiff_meta = pd.read_csv(tiff_meta_files[i]) - zarr_meta = pd.read_csv(zarr_meta_files[i]) - print(f'Comparing metadata {i+1}/{len(tiff_meta_files)}...', end='\r') - - try: - tiff_meta.compare(zarr_meta) - except: - er_msg = f'Metadata {zarr_meta_files[i]} (zarr) and {tiff_meta_files[i]} (tiff) unequal' - raise AssertionError(er_msg) - print('\n', end='\r') - print('\t --> compare_metadata passed') - - def _get_files_of_type(self, root_dir, ftype = '.csv'): - ''' - Recursively search for and return all filenames of type 'ftype' in - directory or subdirectories of 'root_dir' - ''' - PATH = root_dir - EXT = '*' + ftype - all_csv_files = [y for x in os.walk(PATH) for y in glob.glob(os.path.join(x[0], EXT))] - return all_csv_files - -def get_base_preprocess(): - ''' - Get base 2d preprocessing config file - - august 1, :mito, nucleus, phase:, 1_control, 2_roseo.., 3_roseo.., 2D data - /hpc/projects/CompMicro/projects/Rickettsia/2022_RickettsiaAnalysis_Soorya/3_Cell_Image_Preprocessing/VirtualStainingMicroDL_A549_2022_08_1/SinglePageTiffs_TrainingSet2/ - - Sep 15 - ''' - base_preprocess_config = { - 'output_dir': None, - 'verbose': 10, - 'input_dir': None, - 'channel_ids': [0,1,2], - 'slice_ids': [8,9,10,11,12], - 'pos_ids': [0, 1], - 'num_workers': 4, - 'normalize': - {'normalize_im': 'dataset', - 'min_fraction': 0.25, - 'normalize_channels': [True, True, True]}, - 'uniform_struct': True, - 'masks': - {'channels': [1], - 'str_elem_radius': 3, - 'mask_type': 'unimodal', - 'mask_ext': '.png'}, - 'make_weight_map': False, - 'tile': - {'tile_size': [256, 256], - 'step_size': [128, 128], - 'depths': [1, 1, 5], - 'image_format': 'zyx', - 'min_fraction': 0.25}, - 'metadata': - {'order': 'cztp', - 'name_parser': 'parse_sms_name',} - } - return base_preprocess_config - -def main(zarr_dir = None, tiff_dir = None, preprocess = None): - print('Testing zarr reading') - - if (zarr_dir,tiff_dir,preprocess) == (None,None,None): - args = parse_args() - - if zarr_dir == None and tiff_dir == None: - zarr_dir = args.zarr_dir - tiff_dir = args.tiff_dir #convert_zarr(zarr_dir) - - preprocess_config = aux_utils.read_config(preprocess) - - zarr_preprocess_config = preprocess_config.copy() - zarr_preprocess_config['input_dir'] = zarr_dir - zarr_preprocess_config['output_dir'] = '/hpc/projects/CompMicro/projects/virtualstaining/torch_microDL/data/temp_zarr_tiles/' - - tiff_preprocess_config = preprocess_config.copy() - tiff_preprocess_config['input_dir'] = tiff_dir - tiff_preprocess_config['output_dir'] = '/hpc/projects/CompMicro/projects/virtualstaining/torch_microDL/data/temp_tiff_tiles/' - - #generate tiles using tiff and zarr - print('\t Running zarr preprocessing...',end='') - zarr_prep_config, runtime = preprocess_script.pre_process(zarr_preprocess_config) - print('Done') - print('\t Running tiff preprocessing ...',end='') - tiff_prep_config, runtime = preprocess_script.pre_process(tiff_preprocess_config) - print('Done') - - #initiate tester and run tests - tester = TestZarrReading() - - try: - print('Running tests...') - #compare methods - tester.compare_tiling(tiff_prep_config['output_dir'], zarr_prep_config['output_dir']) - tester.compare_metadata(tiff_prep_config['output_dir'], zarr_prep_config['output_dir']) - - #cleanup directories if pass - shutil.rmtree(tiff_prep_config['output_dir']) - shutil.rmtree(zarr_prep_config['output_dir']) - - except Exception as e: - print(e.args) - - -if __name__ == 'main': - main() - -# %% -main('/hpc/projects/CompMicro/projects/Rickettsia/2022_RickettsiaAnalysis_Soorya/2_Cell_Phase_Reconstruction/Analysis_2022_09_15_A549NuclMemRecon/A5493DPhaseRecon/', - '/hpc/projects/CompMicro/projects/Rickettsia/2022_RickettsiaAnalysis_Soorya/3_Cell_Image_Preprocessing/VirtualStainingMicroDL_A549NuclMem_2022_09_14_15/Data_UnalignedTiffImages_Sep15/', - '/hpc/projects/CompMicro/projects/virtualstaining/tf_microDL/config/test_config_preprocess_A549MemNuclStain_Set2.yml') \ No newline at end of file diff --git a/scripts/visualize_data_augmentation.py b/scripts/visualize_data_augmentation.py deleted file mode 100644 index dfae353a..00000000 --- a/scripts/visualize_data_augmentation.py +++ /dev/null @@ -1,248 +0,0 @@ -import cv2 -import numpy as np -import pandas as pd -import os -import typer - - -from enum import Enum -import glob -import time -import sys -import matplotlib.pyplot as plt - -sys.path.insert(0, "/home/shalin.mehta/code/microDL") - -import microDL.micro_dl.training.training as training -import viscy.utils.aux_utils as aux_utils -import microDL.micro_dl.utils.cli_utils as torch_io_utils -import viscy.plotting.plot_utils as plot_utils - - -def visualize_dataloading( - torch_config, save_dir, save_type="plot_group", image_extension=".png" -): - """ - Draws one epoch worth of samples from the dataloader and saves them - at 'save_dir' as type 'image_extension'. Note that the pipeline - performs random sampling, so each new pipeline constructed will - query images from random positions and ROIs - - :param dict torch_config: config with all the necessary parameters ans structure - to perform preprocessing and training - :param str save_dir: directory to save samples images at - :param str save_type: format to save images in. One of {'group_plot', 'plot', 'image_only'} - :param str image_extension: image save type, defaults to ".png" - """ - trainer = training.TorchTrainer(torch_config=torch_config) - - trainer.generate_dataloaders() - assert len(trainer.train_dataloader) > 0, "No samples found in the train dataloader" - - if not os.path.exists(save_dir): - os.makedirs(save_dir) - - for i, minibatch in enumerate(trainer.train_dataloader): - torch_io_utils.show_progress_bar( - dataloader=trainer.train_dataloader, - current=i, - process="Saving image slices", - ) - sample_dir = os.path.join(save_dir, f"sample_{i}") - if not os.path.exists(sample_dir): - os.makedirs(sample_dir) - - input_ = minibatch[0][0][0].cpu().detach().numpy() - target_ = minibatch[1][0][0].cpu().detach().numpy() - - if save_type == "group_plot": - for c in range(input_.shape[0]): - input_imgs = input_[c] - target_img = target_[c][0] # pull the first slice - name = f"data_chan_{c}" - - metric_dict = { - "input_max": [np.max(input_)], - "input_min": [np.min(input_)], - "target_max": [np.max(target_)], - "target_min": [np.min(target_)], - } - - plot_utils.save_predicted_images( - input_imgs=input_imgs, - target_img=target_img, - pred_img=np.zeros((target_img.shape)), - metric=pd.DataFrame.from_dict(metric_dict), - output_dir=sample_dir, - output_fname=name, - ext=image_extension[1:], - ) - else: - matplotlib = False - if save_type == "plot": - matplotlib = True - - for c in range(input_.shape[0]): - for z in range(input_.shape[1]): - slice = input_[c, z] - name = f"input_chan_{c}_slice_{z}" - save_file = os.path.join(sample_dir, name + image_extension) - save_slice(save_file=save_file, slice=slice, matplotlib=matplotlib) - - for c in range(input_.shape[0]): - for z in range(target_.shape[1]): - slice = target_[c, z] - name = f"target_chan_{c}_slice_{z}" - save_file = os.path.join(sample_dir, name + image_extension) - save_slice(save_file=save_file, slice=slice, matplotlib=matplotlib) - - -def save_slice(save_file, slice, matplotlib): - """ - Handles saving of slices of different formats, as well as plotting in mat - plotlib and saving the plot - - :param str save_file: filename to save to - :param np.ndarray slice: slice to save (must be 2d) - :param bool matplotlib: Whether to save matplotlib versions or not - """ - if ".png" in save_file[-5:]: - if matplotlib: - title = save_file.split("/")[-1][:-4] - cmap_gray = "input" in title - plt.title(title) - plt.imshow(slice, cmap="gray") if cmap_gray else plt.imshow(slice) - plt.savefig(save_file) - plt.close() - else: - # Png must be saved as uint16 - slice = np.clip(slice, 0, 65535) - slice = slice.astype(np.uint16) - cv2.imwrite(filename=save_file, img=slice) - elif matplotlib: - raise ValueError("Matplotlib plots only save-able as png files") - elif ".tif" in save_file[-5:]: - cv2.imwrite(filename=save_file, img=slice) - elif ".npy" in save_file[-5:]: - np.save(save_file, slice, allow_pickle=True) - else: - raise ValueError("Only '.png', '.tif', and '.npy' extensions supported.") - - -class plot_save_type(str, Enum): - group_plot = "group_plot" - plot = "plot" - image_only = "image_only" - - -def main( - config: str = typer.Option( - ..., - help="Path to YAML config that specifies dataset and augmentation parameters", - ), - save_dir: str = typer.Option(..., help="Directory to save samples images at"), - extension: str = typer.Option(".png", help="File type of saved images."), - save_type: plot_save_type = typer.Option( - plot_save_type.group_plot, - case_sensitive=False, - help="Format to save images in.", - ), -): - """ - Generates a set of images from the training set to visualize the data with and without augmentation. - """ - if not os.path.exists(save_dir): - os.makedirs(save_dir) - - augmented_save_dir = os.path.join(save_dir, "augmented") - raw_save_dir = os.path.join(save_dir, "raw") - - start = time.time() - - torch_config = aux_utils.read_config( - config # "/hpc/projects/CompMicro/projects/virtualstaining/torch_microDL/config_files/2022_11_01_VeroMemNuclStain/data_visualization_12_13/torch_config_25D.yml" - ) - - # visualize augmented data - print( - f"Visualizing augmented data, saving as {extension} files" - f" in {augmented_save_dir}..." - ) - visualize_dataloading(torch_config, augmented_save_dir, save_type.value, extension) - - # visualize raw data - print(f"Visualizing raw data, saving as {extension} files" f" in {raw_save_dir}...") - torch_config["training"].pop("augmentations") - visualize_dataloading(torch_config, raw_save_dir, save_type.value, extension) - - print(f"Done. Time taken: {time.time() - start}") - - -if __name__ == "__main__": - typer.run(main) - -# # def parse_args(): -# """Parse command line arguments - -# In python namespaces are implemented as dictionaries -# :return: namespace containing the arguments passed. -# """ -# parser = argparse.ArgumentParser() -# parser.add_argument( -# "--config", -# type=str, -# help=( -# "path to config with all the necessary parameters and structure" -# " to perform preprocessing and training and some augmentation" -# ), -# ) - -# parser.add_argument( -# "--save_dir", -# type=str, -# help="directory to save samples images at", -# ) -# parser.add_argument( -# "--extension", -# type=str, -# default=".png", -# help="image save type, defaults to '.png'", -# ) -# parser.add_argument( -# "--save_type", -# type=str, -# default="group_plot", -# help="format to save images in. One of {'group_plot', 'plot', 'image_only'}", -# ) - -# args = parser.parse_args() -# return args - - -# args = parse_args() -# save_dir = ( -# args.save_dir -# ) # "/hpc/projects/CompMicro/projects/virtualstaining/torch_microDL/data_visualization/augmentation_test_12_14/" -# extension = args.extension # ".png" -# save_type = args.save_type # "plot_group" -# torch_config = aux_utils.read_config( -# args.config # "/hpc/projects/CompMicro/projects/virtualstaining/torch_microDL/config_files/2022_11_01_VeroMemNuclStain/data_visualization_12_13/torch_config_25D.yml" -# ) - -# # setup save locations for both samples -# augmented_save_dir = os.path.join(save_dir, "augmented") -# raw_save_dir = os.path.join(save_dir, "raw") - -# # visualize augmented data -# print( -# f"Visualizing augmented data, saving as {extension} files" -# f" in {augmented_save_dir}..." -# ) -# visualize_dataloading(torch_config, augmented_save_dir, save_type, extension) - -# # visualize raw data -# print(f"Visualizing raw data, saving as {extension} files" f" in {raw_save_dir}...") -# torch_config["training"].pop("augmentations") -# visualize_dataloading(torch_config, raw_save_dir, save_type, extension) - -# print(f"Done. Time taken: {time.time() - start}")