Skip to content

Commit

Permalink
raise error when image not found
Browse files Browse the repository at this point in the history
  • Loading branch information
melonora committed Sep 8, 2024
1 parent b46df9a commit 7640890
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/spatialdata_io/readers/visium_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ def _get_bins(path: Path) -> list[str]:
)

# hires image
hires_image_path = [path for path in all_files if VisiumHDKeys.IMAGE_HIRES_FILE in str(path)][0]
hires_image_path = [path for path in all_files if VisiumHDKeys.IMAGE_HIRES_FILE in str(path)]
if len(hires_image_path) == 0:
raise OSError(f"No image path found containing the hires image: {VisiumHDKeys.IMAGE_HIRES_FILE}")
load_image(
path=hires_image_path,
path=hires_image_path[0],
suffix="_hires_image",
)
set_transformation(
Expand All @@ -304,13 +306,11 @@ def _get_bins(path: Path) -> list[str]:
)

# lowres image
lowres_image_path = [path for path in all_files if VisiumHDKeys.IMAGE_LOWRES_FILE in str(path)][0]
lowres_image_path = [path for path in all_files if VisiumHDKeys.IMAGE_LOWRES_FILE in str(path)]
if len(lowres_image_path) == 0:
raise OSError(f"No image path found containing the lowres image: {VisiumHDKeys.IMAGE_LOWRES_FILE}")
load_image(
path=(
lowres_image_path
if lowres_image_path.exists()
else path / f"{filename_prefix}spatial" / VisiumHDKeys.IMAGE_LOWRES_FILE
),
path=lowres_image_path[0],
suffix="_lowres_image",
)
set_transformation(
Expand All @@ -320,14 +320,12 @@ def _get_bins(path: Path) -> list[str]:
)

# cytassist image
cytassist_path = [path for path in all_files if VisiumHDKeys.IMAGE_CYTASSIST in str(path)][0]
cytassist_path = [path for path in all_files if VisiumHDKeys.IMAGE_CYTASSIST in str(path)]
if len(cytassist_path) == 0:
raise OSError(f"No image path found containing the cytassist image: {VisiumHDKeys.IMAGE_CYTASSIST}")
if load_all_images:
load_image(
path=(
cytassist_path
if cytassist_path.exists()
else path / f"{filename_prefix}spatial" / VisiumHDKeys.IMAGE_CYTASSIST
),
path=cytassist_path[0],
suffix="_cytassist_image",
)
image = images[dataset_id + "_cytassist_image"]
Expand Down

0 comments on commit 7640890

Please sign in to comment.