Skip to content

Commit

Permalink
Remove unnecessary converter
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn committed Jan 23, 2025
1 parent 99e7b0c commit b67a9e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
16 changes: 7 additions & 9 deletions panimg/image_builders/tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,28 @@ def _extract_openslide_properties(
) -> GrandChallengeTiffFile:
if not gc_file.voxel_width_mm and "openslide.mpp-x" in image.get_fields():
gc_file.voxel_width_mm = float(image.get("openslide.mpp-x")) / 1000

if not gc_file.voxel_height_mm and "openslide.mpp-y" in image.get_fields():
gc_file.voxel_height_mm = float(image.get("openslide.mpp-y")) / 1000

if (
not gc_file.image_height
and "openslide.level[0].height" in image.get_fields()
):
gc_file.image_height = int(image.get("openslide.level[0].height"))

if (
not gc_file.image_width
and "openslide.level[0].width" in image.get_fields()
):
gc_file.image_width = int(image.get("openslide.level[0].width"))

if (
not gc_file.resolution_levels
and "openslide.level-count" in image.get_fields()
):
gc_file.resolution_levels = int(image.get("openslide.level-count"))

return gc_file


Expand Down Expand Up @@ -305,7 +310,6 @@ def _convert(
*,
files: list[Path],
associated_files_getter: Callable[[Path], list[Path]] | None,
converter,
output_directory: Path,
file_errors: dict[Path, list[str]],
) -> list[GrandChallengeTiffFile]:
Expand All @@ -322,7 +326,6 @@ def _convert(
tiff_file = _convert_to_tiff(
path=file,
pk=gc_file.pk,
converter=converter,
output_directory=output_directory,
)
except Exception as e:
Expand All @@ -341,13 +344,11 @@ def _convert(
return converted_files


def _convert_to_tiff(
*, path: Path, pk: UUID, converter, output_directory: Path
) -> Path:
def _convert_to_tiff(*, path: Path, pk: UUID, output_directory: Path) -> Path:
new_file_name = output_directory / path.name / f"{pk}.tif"
new_file_name.parent.mkdir()

image = converter.Image.new_from_file(
image = pyvips.Image.new_from_file(
str(path.absolute()), access="sequential"
)

Expand Down Expand Up @@ -455,7 +456,6 @@ def associated_files(file_path: Path):
def _load_gc_files(
*,
files: set[Path],
converter,
output_directory: Path,
file_errors: DefaultDict[Path, list[str]],
) -> list[GrandChallengeTiffFile]:
Expand Down Expand Up @@ -488,7 +488,6 @@ def _load_gc_files(
converted_files = _convert(
files=complex_files,
associated_files_getter=handler,
converter=converter,
output_directory=output_directory,
file_errors=file_errors,
)
Expand Down Expand Up @@ -523,7 +522,6 @@ def image_builder_tiff( # noqa: C901
with TemporaryDirectory() as output_directory:
loaded_files = _load_gc_files(
files=files,
converter=pyvips,
output_directory=Path(output_directory),
file_errors=file_errors,
)
Expand Down
1 change: 0 additions & 1 deletion tests/test_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ def test_handle_complex_files(tmpdir_factory):
_convert(
files=files,
associated_files_getter=_get_mrxs_files,
converter=mock_converter,
output_directory=Path(tmpdir_factory.mktemp("output")),
file_errors=defaultdict(list),
)
Expand Down

0 comments on commit b67a9e8

Please sign in to comment.