@@ -20,16 +20,16 @@ def clahe_denoise(args: Tuple[str, str, str]) -> None:
2020 args (Tuple[str, str]):
2121 - src_path: Path to the source micrograph file.
2222 - dest_path: Path to save the denoised image.
23- - format : output format of denoised images
23+ - img_format : output format of denoised images
2424
2525 Raises:
2626 Exception: Logs any exceptions that occur during processing.
2727 """
2828 try :
29- src_path , dest_path , format = args
29+ src_path , dest_path , img_format = args
3030 # Perform denoising
3131 denoised = denoise (src_path )
32- if format == "mrc" :
32+ if img_format == "mrc" :
3333 mrcfile .write (dest_path ,data = denoised )
3434 else :
3535 cv2 .imwrite (dest_path , denoised )
@@ -41,15 +41,15 @@ def clahe_denoise(args: Tuple[str, str, str]) -> None:
4141
4242# Function to process all files in a directory
4343
44- def process_directory (micrographs_dir : str , clahe_denoised_dir : str , max_workers : int , format : str ) -> None :
44+ def process_directory (micrographs_dir : str , clahe_denoised_dir : str , max_workers : int , img_format : str ) -> None :
4545 """
4646 Processes all `.mrc` files in the given directory using parallel workers for denoising.
4747
4848 Args:
4949 micrographs_dir (str): Path to the directory containing raw micrograph files.
5050 clahe_denoised_dir (str): Path to the directory where denoised images will be saved.
5151 max_workers (int): Number of worker processes to use for parallel processing.
52- format (str): Output format of denoised images
52+ img_format (str): Output format of denoised images
5353
5454 Notes:
5555 - Only `.mrc` files are processed.
@@ -63,11 +63,11 @@ def process_directory(micrographs_dir: str, clahe_denoised_dir: str, max_workers
6363 for file_name in os .listdir (micrographs_dir ):
6464 if file_name .endswith (".mrc" ):
6565 src_path = os .path .join (micrographs_dir , file_name )
66- dest_path = os .path .join (clahe_denoised_dir , file_name .replace (".mrc" , "." + format ))
66+ dest_path = os .path .join (clahe_denoised_dir , file_name .replace (".mrc" , "." + img_format ))
6767 if os .path .exists (dest_path ):
6868 logging .info (f"{ dest_path } already exists!" )
6969 else :
70- tasks .append ((src_path , dest_path , format ))
70+ tasks .append ((src_path , dest_path , img_format ))
7171
7272 # Parallel processing of tasks
7373 with ProcessPoolExecutor (max_workers = max_workers ) as executor :
@@ -78,15 +78,15 @@ def process_directory(micrographs_dir: str, clahe_denoised_dir: str, max_workers
7878
7979# Main function
8080
81- def main (source_dir : str , project_dir : str , ncpu : int , format : str ) -> None :
81+ def main (source_dir : str , project_dir : str , ncpu : int , img_format : str ) -> None :
8282 """
8383 Main function to set up logging, determine available CPUs, and start the denoising process.
8484
8585 Args:
8686 source_dir (str): Path to the directory containing raw micrographs.
8787 project_dir (str): Path to the project directory where denoised images will be saved.
8888 ncpu (int): Number of CPUs to use for parallel processing. Defaults to half the available CPUs.
89- format (str): Output format of denoised images
89+ img_format (str): Output format of denoised images
9090
9191 Notes:
9292 - Logging is configured to write messages to a log file and the console.
@@ -116,7 +116,7 @@ def main(source_dir: str, project_dir: str, ncpu: int, format: str) -> None:
116116 logging .info (f"Saving denoised micrographs in { denoise_dir } " )
117117
118118 # Process the directory
119- process_directory (source_dir , denoise_dir , ncpu , format )
119+ process_directory (source_dir , denoise_dir , ncpu , img_format )
120120
121121# Command-line argument parsing
122122
@@ -129,17 +129,17 @@ def parse_args() -> argparse.Namespace:
129129 - raw: Path to raw micrographs.
130130 - project: Path to the project directory.
131131 - ncpu: Number of CPUs to use.
132- - format : output format of denoised images
132+ - img_format : output format of denoised images
133133 """
134134 parser = argparse .ArgumentParser (description = "Denoise micrographs with guided CryoSegNet-style filter" )
135135 parser .add_argument ("--raw" , required = True , help = "Path to raw micrographs" )
136136 parser .add_argument ("--project" , required = True , help = "Denoised micrographs saved in project/denoised" )
137137 parser .add_argument ('--ncpu' , type = int , default = None , help = 'Number of CPUs to use' )
138- parser .add_argument ('--format ' , type = str , choices = ["png" ,"jpg" ,"mrc" ], default = "png" , help = 'Output format of denoised images' )
138+ parser .add_argument ('--img_format ' , type = str , choices = ["png" ,"jpg" ,"mrc" ], default = "png" , help = 'Output format of denoised images' )
139139 return parser .parse_args ()
140140
141141# Entry point for the script
142142
143143if __name__ == "__main__" :
144144 args = parse_args ()
145- main (args .raw , args .project , args .ncpu , args .format )
145+ main (args .raw , args .project , args .ncpu , args .img_format )
0 commit comments