Skip to content

Commit

Permalink
Add basic logger
Browse files Browse the repository at this point in the history
Replace prints in download_annotations
  • Loading branch information
phcerdan committed Dec 19, 2023
1 parent fed1750 commit bbb8d58
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mdai_utils/download_annotations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import difflib
import json
import logging
import os
from pathlib import Path
from typing import Union
Expand All @@ -16,6 +17,8 @@
DEFAULT_DATA_PATH: str = "./data"
LABELS_FOLDER_IDENTIFIER: str = "segmentations"

logger = logging.getLogger(__name__)


def supersample_vertices(vertices, original_image_shape, upscale_factor):
"""
Expand Down Expand Up @@ -413,7 +416,7 @@ def merge_slices_into3D(


def main(args):
print(args)
logger.info(args)

parameters = {}
if args.parameters is not None:
Expand Down Expand Up @@ -495,13 +498,13 @@ def main(args):
# Get the json for annotations
last_json_file = get_last_json_file(out_folder, match_str=mdai_project_id)

print(f"Last json file: {last_json_file}")
logger.info(f"Last json file: {last_json_file}")

# And get the folder where dicoms are, we use the match, because we are not always downloading data
match_folder = match_folder_to_json_file(
last_json_file, folder_to_search=out_folder
last_json_file, folder_to_search=out_folder, hint_str=mdai_dataset_id
)
print(f"Matching data folder (dicoms): {match_folder or 'None'}")
logger.info(f"Matching data folder (dicoms): {match_folder or 'None'}")

now = datetime.datetime.utcnow()
now_formatted_date = now.strftime("%Y-%m-%d-%H%M%S")
Expand Down Expand Up @@ -590,13 +593,13 @@ def main(args):
with open(pair_data_json_file, "w") as f:
json.dump(pair_data, f, indent=2)

print(f"pair_data_folder: {labels_parent_folder}")
logging.info(f"pair_data_folder: {labels_parent_folder}")

if create_volumes is not None and create_volumes != "none":
pair_data_json_file = Path(labels_parent_folder) / "pair_data.json"
volumes_path = Path(volumes_path)
if not volumes_path.exists():
print("Creating volumes_path: {}".format(volumes_path))
logging.info("Creating volumes_path: {}".format(volumes_path))
volumes_path.mkdir(parents=True, exist_ok=True)
process_grayscale = create_volumes in ["all", "grayscale"]
if process_grayscale and match_folder is None:
Expand Down

0 comments on commit bbb8d58

Please sign in to comment.