diff --git a/.gitignore b/.gitignore index 58b99de..eff31a5 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ tests/tmp_results_folder/* pathopatch.egg-info/ dist build +push_build.yml diff --git a/examples/patch_extraction.yaml b/examples/patch_extraction.yaml index 4132616..8402d72 100644 --- a/examples/patch_extraction.yaml +++ b/examples/patch_extraction.yaml @@ -77,3 +77,4 @@ log_path: # Path where log files should be stored. Otherwise log_level: # Set the logging level. [str][Optional, defaults to info] hardware_selection: # Select hardware device (just if available, otherwise always cucim). [str] [Optional, defaults to cucim] wsi_properties: # Dictionary with manual WSI metadata. Required keys are: ... TODO: add keys [dict] [Optional, default selection from files] +# TODO: Change WSI properties to mpp and magnification diff --git a/pathopatch/cli.py b/pathopatch/cli.py index 260951b..81cdbcc 100644 --- a/pathopatch/cli.py +++ b/pathopatch/cli.py @@ -577,9 +577,14 @@ def __init__(self) -> None: help="Select hardware device (just if available, otherwise always cucim). Defaults to cucim.", ) parser.add_argument( - "--wsi_properties", - type=dict, - help="Dictionary with manual WSI metadata, but just applies if metadata cannot be derived from OpenSlide (e.g., for .tiff files). Supported keys are slide_mpp and magnification", + "--wsi_magnification", + type=float, + help="Manual WSI magnification, but just applies if metadata cannot be derived from OpenSlide (e.g., for .tiff files).", + ) + parser.add_argument( + "--wsi_mpp", + type=float, + help="Manual WSI MPP, but just applies if metadata cannot be derived from OpenSlide (e.g., for .tiff files).", ) self.parser = parser @@ -608,6 +613,16 @@ def get_config(self) -> Tuple[PreProcessingConfig, logging.Logger]: raise ValueError("Please provide config file as `.yaml` file") with open(opt.config, "r") as config_file: yaml_config = yaml.safe_load(config_file) + if "wsi_magnification" in yaml_config or "wsi_mpp" in yaml_config: + yaml_config["wsi_properties"] = {} + if "wsi_magnification" in yaml_config: + yaml_config["wsi_properties"]["magnification"] = yaml_config[ + "wsi_magnification" + ] + yaml_config.pop("wsi_magnification") + if "wsi_mpp" in yaml_config: + yaml_config["wsi_properties"]["slide_mpp"] = yaml_config["wsi_mpp"] + yaml_config.pop("wsi_mpp") yaml_config = PreProcessingYamlConfig(**yaml_config) # convert to dict and override missing values @@ -622,6 +637,16 @@ def get_config(self) -> Tuple[PreProcessingConfig, logging.Logger]: else: opt_dict = vars(opt) opt_dict = {k: v for k, v in opt_dict.items() if v is not None} + if "wsi_magnification" in opt_dict or "wsi_mpp" in opt_dict: + opt_dict["wsi_properties"] = {} + if "wsi_magnification" in opt_dict: + opt_dict["wsi_properties"]["magnification"] = opt_dict[ + "wsi_magnification" + ] + opt_dict.pop("wsi_magnification") + if "wsi_mpp" in opt_dict: + opt_dict["wsi_properties"]["slide_mpp"] = opt_dict["wsi_mpp"] + opt_dict.pop("wsi_mpp") # generate final setup self.preprocessconfig = PreProcessingConfig(**opt_dict) diff --git a/pathopatch/wsi_extraction.py b/pathopatch/wsi_extraction.py index 868804a..3cb3066 100644 --- a/pathopatch/wsi_extraction.py +++ b/pathopatch/wsi_extraction.py @@ -10,10 +10,10 @@ import sys import os -# project_root = os.path.dirname(os.path.abspath(__file__)) -# sys.path.append(project_root) -# project_root = os.path.dirname(os.path.abspath(project_root)) -# sys.path.append(project_root) +project_root = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(project_root) +project_root = os.path.dirname(os.path.abspath(project_root)) +sys.path.append(project_root) import logging