Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/murfey/cli/inject_spa_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
SPAFeedbackParameters,
SPARelionParameters,
)
from murfey.util.spa_params import default_spa_parameters
from murfey.util.processing_params import default_spa_parameters

Check warning on line 24 in src/murfey/cli/inject_spa_processing.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/cli/inject_spa_processing.py#L24

Added line #L24 was not covered by tests


def run():
Expand Down
2 changes: 1 addition & 1 deletion src/murfey/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
get_microscope,
get_security_config,
)
from murfey.util.spa_params import default_spa_parameters
from murfey.util.processing_params import default_spa_parameters
from murfey.util.state import global_state

try:
Expand Down
2 changes: 1 addition & 1 deletion src/murfey/server/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
TiltSeriesInfo,
Visit,
)
from murfey.util.spa_params import default_spa_parameters
from murfey.util.processing_params import default_spa_parameters
from murfey.util.state import global_state

log = logging.getLogger("murfey.server.api")
Expand Down
84 changes: 80 additions & 4 deletions src/murfey/server/api/clem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import re
import traceback
from ast import literal_eval
from importlib.metadata import EntryPoint # type hinting only
from logging import getLogger
from pathlib import Path
from typing import Optional, Type, Union
from typing import Literal, Optional, Type, Union

from backports.entry_points_selectable import entry_points
from fastapi import APIRouter
from pydantic import BaseModel, validator
from sqlalchemy.exc import NoResultFound
from sqlmodel import Session, select

Expand All @@ -23,7 +25,6 @@
CLEMTIFFFile,
)
from murfey.util.db import Session as MurfeySession
from murfey.util.models import TIFFSeriesInfo

# Set up logger
logger = getLogger("murfey.server.api.clem")
Expand Down Expand Up @@ -622,7 +623,7 @@
"/sessions/{session_id}/clem/preprocessing/process_raw_lifs"
) # API posts to this URL
def process_raw_lifs(
session_id: int, # Used by the decorator
session_id: int,
lif_file: Path,
db: Session = murfey_db,
):
Expand Down Expand Up @@ -654,9 +655,15 @@
return True


class TIFFSeriesInfo(BaseModel):
series_name: str
tiff_files: list[Path]
series_metadata: Path


@router.post("/sessions/{session_id}/clem/preprocessing/process_raw_tiffs")
def process_raw_tiffs(
session_id: int, # Used by the decorator
session_id: int,
tiff_info: TIFFSeriesInfo,
db: Session = murfey_db,
):
Expand Down Expand Up @@ -687,3 +694,72 @@
messenger=_transport_object,
)
return True


class AlignAndMergeParams(BaseModel):
# Processing parameters
series_name: str
images: list[Path]
metadata: Path
# Optional processing parameters
crop_to_n_frames: Optional[int] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted on the cryoemservices PR, these could possibly default to something else rather than None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these still apply after our discussion as a group earlier, or are you have to have them as None?

align_self: Literal["enabled", ""] = ""
flatten: Literal["mean", "min", "max", ""] = ""
align_across: Literal["enabled", ""] = ""

@validator(
"images",
pre=True,
)
def parse_stringified_list(cls, value):
if isinstance(value, str):
try:
eval_result = literal_eval(value)

Check warning on line 717 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L716-L717

Added lines #L716 - L717 were not covered by tests
if isinstance(eval_result, list):
parent_tiffs = [Path(p) for p in eval_result]
return parent_tiffs
except (SyntaxError, ValueError):
raise ValueError("Unable to parse input")

Check warning on line 722 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L719-L722

Added lines #L719 - L722 were not covered by tests
# Return value as-is; if it fails, it fails
return value

Check warning on line 724 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L724

Added line #L724 was not covered by tests


@router.post("/sessions/{session_id}/clem/processing/align_and_merge_stacks")
def align_and_merge_stacks(
session_id: int,
align_and_merge_params: AlignAndMergeParams,
db: Session = murfey_db,
):
try:

Check warning on line 733 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L733

Added line #L733 was not covered by tests
# Try and load relevant Murfey workflow
workflow: EntryPoint = list(

Check warning on line 735 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L735

Added line #L735 was not covered by tests
entry_points().select(group="murfey.workflows", name="clem.align_and_merge")
)[0]
except IndexError:
raise RuntimeError("The relevant Murfey workflow was not found")

Check warning on line 739 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L738-L739

Added lines #L738 - L739 were not covered by tests

# Get instrument name from the database to load the correct config file
session_row: MurfeySession = db.exec(

Check warning on line 742 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L742

Added line #L742 was not covered by tests
select(MurfeySession).where(MurfeySession.id == session_id)
).one()
instrument_name = session_row.instrument_name

Check warning on line 745 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L745

Added line #L745 was not covered by tests

# Pass arguments to correct workflow
workflow.load()(

Check warning on line 748 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L748

Added line #L748 was not covered by tests
# Match the arguments found in murfey.workflows.clem.align_and_merge
# Session parameters
session_id=session_id,
instrument_name=instrument_name,
# Processing parameters
series_name=align_and_merge_params.series_name,
images=align_and_merge_params.images,
metadata=align_and_merge_params.metadata,
# Optional processing parameters
crop_to_n_frames=align_and_merge_params.crop_to_n_frames,
align_self=align_and_merge_params.align_self,
flatten=align_and_merge_params.flatten,
align_across=align_and_merge_params.align_across,
# Optional session parameters
messenger=_transport_object,
)
return True

Check warning on line 765 in src/murfey/server/api/clem.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/clem.py#L765

Added line #L765 was not covered by tests
2 changes: 1 addition & 1 deletion src/murfey/server/demo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
TiltSeriesInfo,
Visit,
)
from murfey.util.spa_params import default_spa_parameters
from murfey.util.processing_params import default_spa_parameters

Check warning on line 93 in src/murfey/server/demo_api.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/demo_api.py#L93

Added line #L93 was not covered by tests
from murfey.util.state import global_state

log = logging.getLogger("murfey.server.demo_api")
Expand Down
13 changes: 0 additions & 13 deletions src/murfey/util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,6 @@ class FractionationParameters(BaseModel):
fractionation_file_name: str = "eer_fractionation.txt"


"""
Cryo-CLEM
=========
Models related to the cryo-CLEM workflow.
"""


class TIFFSeriesInfo(BaseModel):
series_name: str
tiff_files: List[Path]
series_metadata: Path


"""
FIB
===
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from typing import Literal, Optional

from pydantic import BaseModel


class CLEMAlignAndMergeParameters(BaseModel):
crop_to_n_frames: Optional[int] = 50
align_self: Literal["enabled", ""] = "enabled"
flatten: Literal["mean", "min", "max", ""] = "mean"
align_across: Literal["enabled", ""] = "enabled"


default_clem_align_and_merge_parameters = CLEMAlignAndMergeParameters()


class SPAParameters(BaseModel):
nr_iter_2d: int = 25
nr_iter_3d: int = 25
Expand Down
8 changes: 5 additions & 3 deletions src/murfey/workflows/clem/align_and_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def submit_cluster_request(
images: list[Path],
metadata: Path,
# Optional processing parameters
align_self: Optional[str] = None,
flatten: Optional[Literal["min", "max", "mean"]] = "mean",
align_across: Optional[str] = None,
crop_to_n_frames: Optional[int] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. Something to consider

align_self: Literal["enabled", ""] = "",
flatten: Literal["mean", "min", "max", ""] = "mean",
align_across: Literal["enabled", ""] = "",
# Optional session parameters
messenger: Optional[TransportManager] = None,
):
Expand Down Expand Up @@ -64,6 +65,7 @@ def submit_cluster_request(
"series_name": series_name,
"images": [str(file) for file in images],
"metadata": str(metadata),
"crop_to_n_frames": crop_to_n_frames,
"align_self": align_self,
"flatten": flatten,
"align_across": align_across,
Expand Down
17 changes: 11 additions & 6 deletions src/murfey/workflows/clem/register_preprocessing_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
CLEMTIFFFile,
)
from murfey.util.db import Session as MurfeySession
from murfey.util.processing_params import (

Check warning on line 28 in src/murfey/workflows/clem/register_preprocessing_results.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/workflows/clem/register_preprocessing_results.py#L28

Added line #L28 was not covered by tests
default_clem_align_and_merge_parameters as processing_params,
)
from murfey.workflows.clem import get_db_entry
from murfey.workflows.clem.align_and_merge import submit_cluster_request

Expand Down Expand Up @@ -187,9 +190,10 @@
series_name=result.series_name,
images=image_stacks,
metadata=result.metadata,
align_self=None,
flatten="mean",
align_across=None,
crop_to_n_frames=processing_params.crop_to_n_frames,
align_self=processing_params.align_self,
flatten=processing_params.flatten,
align_across=processing_params.align_across,
messenger=_transport_object,
)
if cluster_response is False:
Expand Down Expand Up @@ -369,9 +373,10 @@
series_name=result.series_name,
images=image_stacks,
metadata=result.metadata,
align_self=None,
flatten="mean",
align_across=None,
crop_to_n_frames=processing_params.crop_to_n_frames,
align_self=processing_params.align_self,
flatten=processing_params.flatten,
align_across=processing_params.align_across,
messenger=_transport_object,
)
if cluster_response is False:
Expand Down
Loading