Skip to content

Commit

Permalink
fix: #1629 improve API for use with dask
Browse files Browse the repository at this point in the history
  • Loading branch information
raylim committed Oct 31, 2023
1 parent 4e9e24e commit 44a6f50
Show file tree
Hide file tree
Showing 17 changed files with 1,379 additions and 876 deletions.
15 changes: 13 additions & 2 deletions src/luna/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import json
import os
import re
import shutil
import subprocess
import tempfile
import time
import urllib
import warnings
from contextlib import ExitStack
from contextlib import ExitStack, contextmanager
from functools import wraps
from importlib import import_module
from io import BytesIO
Expand Down Expand Up @@ -77,8 +78,18 @@ def wrapper(*args, **kwargs):
return wrapper


@contextmanager
def make_temp_directory():
temp_dir = tempfile.mkdtemp()
try:
yield temp_dir
finally:
shutil.rmtree(temp_dir)


def local_cache_urlpath(
file_key_write_mode: dict[str, str] = {}, dir_key_write_mode: dict[str, str] = {}
file_key_write_mode: dict[str, str] = {},
dir_key_write_mode: dict[str, str] = {},
):
"""Decorator for caching url/paths locally"""

Expand Down
32 changes: 31 additions & 1 deletion src/luna/pathology/cli/dsa_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import requests
from fsspec import open
from loguru import logger
from pandera.typing import DataFrame

from luna.common.models import SlideSchema
from luna.common.utils import get_config, save_metadata, timed
from luna.pathology.dsa.dsa_api_handler import (
get_item_uuid,
Expand Down Expand Up @@ -85,7 +87,7 @@ def cli(
f"Unable to infer image_filename from {annotation_file_urlpath}"
)
logger.info(f"Image filename inferred as {image_filename}")
dsa_uuid = upload_annotation_to_dsa(
dsa_uuid = _upload_annotation_to_dsa(
config["dsa_endpoint_url"],
annotation_file_urlpath,
config["collection_name"],
Expand All @@ -104,6 +106,34 @@ def cli(


def upload_annotation_to_dsa(
dsa_endpoint_url: str,
slide_manifest: DataFrame[SlideSchema],
annotation_column: str,
collection_name: str,
image_filename: str,
username: str,
password: str,
force: bool = False,
insecure: bool = False,
storage_options: dict = {},
):
uuids = []
for slide in slide_manifest.itertuples(name="Slide"):
uuids += _upload_annotation_to_dsa(
dsa_endpoint_url,
slide[annotation_column],
collection_name,
image_filename,
username,
password,
force,
insecure,
storage_options,
)
return uuids


def _upload_annotation_to_dsa(
dsa_endpoint_url: str,
annotation_file_urlpaths: Union[str, List[str]],
collection_name: str,
Expand Down
Loading

0 comments on commit 44a6f50

Please sign in to comment.