Skip to content

Commit

Permalink
Merge pull request #29 from fractal-analytics-platform/update-depende…
Browse files Browse the repository at this point in the history
…ncies

Update dependencies, drop Python 3.9 support
  • Loading branch information
jluethi authored Aug 12, 2024
2 parents f3b3401 + 42043f6 commit 6e2d18f
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 144 deletions.
6 changes: 3 additions & 3 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ author_name: Joel Luethi
git_versioning: true
github_username: fractal-analytics-platform
mode: customize
module_name: fractal_faim_hcs
module_name: fractal_faim_ipa
project_license: BSD-3-Clause
project_name: fractal-faim-hcs
project_name: fractal-faim-ipa
project_short_description: Provides Fractal tasks for the MD to OME-Zarr conversion
of faim-hcs
of faim-ipa
test_pre_release: false
use_black: true
use_mypy: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
platform: [ubuntu-latest, macos-latest]

steps:
Expand All @@ -54,7 +54,7 @@ jobs:
run: python -m pip install pytest devtools jsonschema requests wget

- name: 🧪 Run Tests
run: pytest --color=yes --cov --cov-report=xml --cov-report=term-missing
run: pytest -s --color=yes --cov --cov-report=xml --cov-report=term-missing

- name: Coverage
uses: codecov/codecov-action@v4
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![PyPI](https://img.shields.io/pypi/v/fractal-faim-ipa.svg?color=green)](https://pypi.org/project/fractal-faim-ipa)
[![Python Version](https://img.shields.io/pypi/pyversions/fractal-faim-ipa.svg?color=green)](https://python.org)
[![CI](https://github.com/jluethi/fractal-faim-ipa/actions/workflows/ci.yml/badge.svg)](https://github.com/jluethi/fractal-faim-ipa/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/jluethi/fractal-faim-ipa/branch/main/graph/badge.svg)](https://codecov.io/gh/jluethi/fractal-faim-ipa)

Provides Fractal tasks for the conversion of Molecular Devices ImageXpress microscope to OME-Zarr.

Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ name = "fractal-faim-ipa"
dynamic = ["version"]
description = "Provides Fractal tasks for the MD to OME-Zarr conversion of faim-ipa"
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
license = { text = "BSD-3-Clause" }
authors = [
{ name = "Joel Luethi", email = "[email protected]" },
Expand All @@ -34,17 +34,17 @@ classifiers = [
]

dependencies = [
"fractal-tasks-core==1.0.2",
"fractal-tasks-core==1.2.1",
"pydantic",
"zarr",
"faim-ipa==0.3.11",
"faim-ipa==0.5.0",
]

# https://peps.python.org/pep-0621/#dependencies-optional-dependencies
# "extras" (e.g. for `pip install .[test]`)
[project.optional-dependencies]
# add dependencies used for testing here
test = ["pytest", "pytest-cov"]
test = ["pytest", "pytest-cov", "jsonschema"]
# add anything else you like to have in your dev environment here
dev = [
"black",
Expand All @@ -53,6 +53,8 @@ dev = [
"pdbpp", # https://github.com/pdbpp/pdbpp
"rich", # https://github.com/Textualize/rich
"ruff",
"pre-commit",
"devtools",
]

[project.urls]
Expand All @@ -78,8 +80,6 @@ extend-select = [
"F", # flakes
"D", # pydocstyle
"I", # isort
"U", # pyupgrade
# "S", # bandit
"C", # flake8-comprehensions
"B", # flake8-bugbear
"A001", # flake8-builtins
Expand Down
4 changes: 2 additions & 2 deletions src/fractal_faim_ipa/convert_ome_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from faim_ipa.hcs.converter import ConvertToNGFFPlate, NGFFPlate, PlateLayout
from faim_ipa.stitching import stitching_utils
from fractal_tasks_core.tables import write_table
from pydantic.decorator import validate_arguments
from pydantic import validate_call

from fractal_faim_ipa.md_converter_utils import ModeEnum
from fractal_faim_ipa.roi_tables import create_ROI_tables

logger = logging.getLogger(__name__)


@validate_arguments
@validate_call
def convert_ome_zarr(
*,
zarr_urls: list[str],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
from typing import Optional, Union

import pandas as pd
from tqdm import tqdm

from faim_ipa.hcs.acquisition import (
PlateAcquisition,
TileAlignmentOptions,
WellAcquisition,
)
from faim_ipa.io.metadata import ChannelMetadata
from faim_ipa.io.metaseries import load_metaseries_tiff_metadata
from faim_ipa.utils import rgb_to_hex, wavelength_to_rgb
from tqdm import tqdm

from fractal_faim_ipa.imagexpress_zmb.ImageXpressWellAcquisition import (
ImageXpressWellAcquisition,
)
from faim_ipa.io.ChannelMetadata import ChannelMetadata
from faim_ipa.io.MetaSeriesTiff import load_metaseries_tiff_metadata
from faim_ipa.utils import rgb_to_hex, wavelength_to_rgb


class ImageXpressPlateAcquisition(PlateAcquisition):
Expand Down Expand Up @@ -45,8 +45,7 @@ def _parse_files(self) -> pd.DataFrame:
DataFrame
Table of all files in the acquisition.
"""

files = pd.DataFrame(
files = pd.DataFrame(
ImageXpressPlateAcquisition._list_and_match_files(
root_dir=self._acquisition_dir,
root_re=self._get_root_re(),
Expand Down
42 changes: 21 additions & 21 deletions src/fractal_faim_ipa/imagexpress_zmb/ImageXpressWellAcquisition.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from pathlib import Path
from typing import Optional, Union

import numpy as np
import dask
import dask.array as da
import numpy as np
import pandas as pd

from faim_ipa.hcs.acquisition import TileAlignmentOptions, WellAcquisition
from faim_ipa.io.MetaSeriesTiff import load_metaseries_tiff_metadata
from faim_ipa.stitching import Tile
from faim_ipa.stitching.Tile import TilePosition
from faim_ipa.io.metaseries import load_metaseries_tiff_metadata
from faim_ipa.stitching.tile import Tile, TilePosition


class ImageXpressWellAcquisition(WellAcquisition):
Expand All @@ -32,28 +30,30 @@ def __init__(
def _assemble_tiles(self) -> list[Tile]:
def _load_positions(fn):
metadata = load_metaseries_tiff_metadata(fn)
out = np.array([
metadata["pixel-size-y"],
metadata["pixel-size-x"],
int(metadata["stage-position-y"] / metadata["spatial-calibration-y"]),
int(metadata["stage-position-x"] / metadata["spatial-calibration-x"]),
])
out = np.array(
[
metadata["pixel-size-y"],
metadata["pixel-size-x"],
int(
metadata["stage-position-y"] / metadata["spatial-calibration-y"]
),
int(
metadata["stage-position-x"] / metadata["spatial-calibration-x"]
),
]
)
return out

fns = self._files.path.to_numpy()
lazy_positions = [dask.delayed(_load_positions)(fn) for fn in fns]
arrays = [
da.from_delayed(
lazy_position,
dtype=int,
shape=(4,)
)
da.from_delayed(lazy_position, dtype=int, shape=(4,))
for lazy_position in lazy_positions
]
positions = da.stack(arrays, axis=0).compute()

tiles = []
for (i, row), pos in zip(self._files.iterrows(), positions):
for (_i, row), pos in zip(self._files.iterrows(), positions):
file = row["path"]
time_point = row["t"] if "t" in row.index and row["t"] is not None else 0
channel = row["channel"]
Expand Down Expand Up @@ -98,12 +98,12 @@ def get_axes(self) -> list[str]:
axes = ["y", "x"]

if "z" in self._files.columns:
axes = ["z"] + axes
axes = ["z", *axes]

if self._files["channel"].nunique() > 1:
axes = ["c"] + axes
axes = ["c", *axes]

if "t" in self._files.columns and self._files["t"].nunique() > 1:
axes = ["t"] + axes
axes = ["t", *axes]

return axes
32 changes: 16 additions & 16 deletions src/fractal_faim_ipa/imagexpress_zmb/MixedAcquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import numpy as np
import pandas as pd

from faim_ipa.hcs.acquisition import TileAlignmentOptions
from faim_ipa.io.metaseries import load_metaseries_tiff_metadata

from fractal_faim_ipa.imagexpress_zmb import ImageXpressPlateAcquisition
from faim_ipa.io.MetaSeriesTiff import load_metaseries_tiff_metadata


class MixedAcquisition(ImageXpressPlateAcquisition):
Expand All @@ -19,14 +19,14 @@ class MixedAcquisition(ImageXpressPlateAcquisition):
└── 2023-02-21 --> {date}
└── 1334 --> {acquisition id}
├── ZStep_1
   ├── Projection-Mix_E07_s1_w1E78EB128-BD0D-4D94-A6AD-3FF28BB1B105.tif
   ├── Projection-Mix_E07_s1_w1_thumb187DE64B-038A-4671-BF6B-683721723769.tif
   ├── Projection-Mix_E07_s1_w2C0A49256-E289-4C0F-ADC9-F7728ABDB141.tif
   ├── Projection-Mix_E07_s1_w2_thumb57D4B151-71BF-480E-8CC4-C23A2690B763.tif
   ├── Projection-Mix_E07_s1_w427CCB2E4-1BF4-45E7-8BC7-264B48EF9C4A.tif
   ├── Projection-Mix_E07_s1_w4_thumb555647D0-77F1-4A43-9472-AE509F95E236.tif
   ├── ...
   └── Projection-Mix_E08_s2_w4_thumbD2785594-4F49-464F-9F80-1B82E30A560A.tif
├── Projection-Mix_E07_s1_w1E78EB128-BD0D-4D94-A6AD-3FF28BB1B105.tif
├── Projection-Mix_E07_s1_w1_thumb187DE64B-038A-4671-BF6B-683721723769.tif
├── Projection-Mix_E07_s1_w2C0A49256-E289-4C0F-ADC9-F7728ABDB141.tif
├── Projection-Mix_E07_s1_w2_thumb57D4B151-71BF-480E-8CC4-C23A2690B763.tif
├── Projection-Mix_E07_s1_w427CCB2E4-1BF4-45E7-8BC7-264B48EF9C4A.tif
├── Projection-Mix_E07_s1_w4_thumb555647D0-77F1-4A43-9472-AE509F95E236.tif
├── ...
└── Projection-Mix_E08_s2_w4_thumbD2785594-4F49-464F-9F80-1B82E30A560A.tif
├── ...
└── ZStep_9
├── Projection-Mix_E07_s1_w1091EB8A5-272A-466D-B8A0-7547C6BA392B.tif
Expand Down Expand Up @@ -60,7 +60,9 @@ def _parse_files(self) -> pd.DataFrame:
# single-planes and projections are unnecessarily duplicated
# -> remove duplicates from files
for c in files.channel.unique():
file = files[(files.channel == c) & (files.z!='0') & (files.z!='1')].iloc[0]
file = files[
(files.channel == c) & (files.z != "0") & (files.z != "1")
].iloc[0]
metadata = load_metaseries_tiff_metadata(file.path)
# projections have no "Z Step" attribute
# single-planes have always metadata["Z Step"] == 1, for each duplicate
Expand All @@ -73,9 +75,7 @@ def _parse_files(self) -> pd.DataFrame:
return files

def _get_root_re(self) -> re.Pattern:
return re.compile(
r".*[\/\\]TimePoint_(?P<t>\d+)[\/\\]ZStep_(?!0)(?P<z>\d+)"
)
return re.compile(r".*[\/\\]TimePoint_(?P<t>\d+)[\/\\]ZStep_(?!0)(?P<z>\d+)")

def _get_filename_re(self) -> re.Pattern:
return re.compile(
Expand All @@ -87,14 +87,14 @@ def _get_z_spacing(self) -> Optional[float]:

def _compute_z_spacing(self, files: pd.DataFrame) -> Optional[float]:
assert "z" in files.columns, "No z column in files DataFrame."
channel_with_stack = np.sort(files[files.z!='1']["channel"].unique())[0]
channel_with_stack = np.sort(files[files.z != "1"]["channel"].unique())[0]
subset = files[files["channel"] == channel_with_stack]
subset = subset[subset["well"] == np.sort(subset["well"].unique())[0]]
subset = subset[subset["field"] == np.sort(subset["field"].unique())[0]]

plane_positions = []

for i, row in subset.iterrows():
for _i, row in subset.iterrows():
file = row["path"]
if "z" in row.keys() and row["z"] is not None:
metadata = load_metaseries_tiff_metadata(file)
Expand Down
32 changes: 16 additions & 16 deletions src/fractal_faim_ipa/imagexpress_zmb/StackAcquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import numpy as np
import pandas as pd

from faim_ipa.hcs.acquisition import TileAlignmentOptions
from faim_ipa.io.metaseries import load_metaseries_tiff_metadata

from fractal_faim_ipa.imagexpress_zmb import ImageXpressPlateAcquisition
from faim_ipa.io.MetaSeriesTiff import load_metaseries_tiff_metadata


class StackAcquisition(ImageXpressPlateAcquisition):
Expand All @@ -19,14 +19,14 @@ class StackAcquisition(ImageXpressPlateAcquisition):
└── 2023-02-21 --> {date}
└── 1334 --> {acquisition id}
├── ZStep_1
   ├── Projection-Mix_E07_s1_w1E78EB128-BD0D-4D94-A6AD-3FF28BB1B105.tif
   ├── Projection-Mix_E07_s1_w1_thumb187DE64B-038A-4671-BF6B-683721723769.tif
   ├── Projection-Mix_E07_s1_w2C0A49256-E289-4C0F-ADC9-F7728ABDB141.tif
   ├── Projection-Mix_E07_s1_w2_thumb57D4B151-71BF-480E-8CC4-C23A2690B763.tif
   ├── Projection-Mix_E07_s1_w427CCB2E4-1BF4-45E7-8BC7-264B48EF9C4A.tif
   ├── Projection-Mix_E07_s1_w4_thumb555647D0-77F1-4A43-9472-AE509F95E236.tif
   ├── ...
   └── Projection-Mix_E08_s2_w4_thumbD2785594-4F49-464F-9F80-1B82E30A560A.tif
├── Projection-Mix_E07_s1_w1E78EB128-BD0D-4D94-A6AD-3FF28BB1B105.tif
├── Projection-Mix_E07_s1_w1_thumb187DE64B-038A-4671-BF6B-683721723769.tif
├── Projection-Mix_E07_s1_w2C0A49256-E289-4C0F-ADC9-F7728ABDB141.tif
├── Projection-Mix_E07_s1_w2_thumb57D4B151-71BF-480E-8CC4-C23A2690B763.tif
├── Projection-Mix_E07_s1_w427CCB2E4-1BF4-45E7-8BC7-264B48EF9C4A.tif
├── Projection-Mix_E07_s1_w4_thumb555647D0-77F1-4A43-9472-AE509F95E236.tif
├── ...
└── Projection-Mix_E08_s2_w4_thumbD2785594-4F49-464F-9F80-1B82E30A560A.tif
├── ...
└── ZStep_9
├── Projection-Mix_E07_s1_w1091EB8A5-272A-466D-B8A0-7547C6BA392B.tif
Expand Down Expand Up @@ -61,7 +61,9 @@ def _parse_files(self) -> pd.DataFrame:
# single-planes and projections are unnecessarily duplicated
# -> remove duplicates from files & remove all projections
for c in files.channel.unique():
file = files[(files.channel == c) & (files.z!='0') & (files.z!='1')].iloc[0]
file = files[
(files.channel == c) & (files.z != "0") & (files.z != "1")
].iloc[0]
metadata = load_metaseries_tiff_metadata(file.path)
# projections have no "Z Step" attribute
# single-planes have always metadata["Z Step"] == 1, for each duplicate
Expand All @@ -74,9 +76,7 @@ def _parse_files(self) -> pd.DataFrame:
return files

def _get_root_re(self) -> re.Pattern:
return re.compile(
r".*[\/\\]TimePoint_(?P<t>\d+)[\/\\]ZStep_(?!0)(?P<z>\d+)"
)
return re.compile(r".*[\/\\]TimePoint_(?P<t>\d+)[\/\\]ZStep_(?!0)(?P<z>\d+)")

def _get_filename_re(self) -> re.Pattern:
return re.compile(
Expand All @@ -88,14 +88,14 @@ def _get_z_spacing(self) -> Optional[float]:

def _compute_z_spacing(self, files: pd.DataFrame) -> Optional[float]:
assert "z" in files.columns, "No z column in files DataFrame."
channel_with_stack = np.sort(files[files.z!='1']["channel"].unique())[0]
channel_with_stack = np.sort(files[files.z != "1"]["channel"].unique())[0]
subset = files[files["channel"] == channel_with_stack]
subset = subset[subset["well"] == np.sort(subset["well"].unique())[0]]
subset = subset[subset["field"] == np.sort(subset["field"].unique())[0]]

plane_positions = []

for i, row in subset.iterrows():
for _i, row in subset.iterrows():
file = row["path"]
if "z" in row.keys() and row["z"] is not None:
metadata = load_metaseries_tiff_metadata(file)
Expand Down
2 changes: 1 addition & 1 deletion src/fractal_faim_ipa/roi_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import pandas as pd
from faim_ipa.hcs.acquisition import PlateAcquisition, WellAcquisition
from faim_ipa.stitching import Tile
from faim_ipa.stitching.tile import Tile


def create_ROI_tables(plate_acquisition: PlateAcquisition):
Expand Down
Loading

0 comments on commit 6e2d18f

Please sign in to comment.