Skip to content

Commit

Permalink
Changing CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHoerst committed Jan 19, 2024
1 parent 3462563 commit 1a65dfd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ tests/tmp_results_folder/*
pathopatch.egg-info/
dist
build
push_build.yml
1 change: 1 addition & 0 deletions examples/patch_extraction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 28 additions & 3 deletions pathopatch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pathopatch/wsi_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1a65dfd

Please sign in to comment.