Skip to content
Closed
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
17 changes: 2 additions & 15 deletions src/murfey/client/contexts/tomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from murfey.util import authorised_requests, capture_post, get_machine_config_client
from murfey.util.mdoc import get_block, get_global_data, get_num_blocks
from murfey.util.tomo import midpoint

logger = logging.getLogger("murfey.client.contexts.tomo")

Expand Down Expand Up @@ -64,20 +65,6 @@
return "_".join(split_name[:-5])


def _midpoint(angles: List[float]) -> int:
if not angles:
return 0
if len(angles) <= 2:
return round(angles[0])
sorted_angles = sorted(angles)
return round(
sorted_angles[len(sorted_angles) // 2]
if sorted_angles[len(sorted_angles) // 2]
and sorted_angles[len(sorted_angles) // 2 + 1]
else 0
)


class ProcessFileIncomplete(BaseModel):
dest: Path
source: Path
Expand Down Expand Up @@ -738,7 +725,7 @@
if environment
else None
)
mdoc_metadata["manual_tilt_offset"] = -_midpoint(
mdoc_metadata["manual_tilt_offset"] = -midpoint(

Check warning on line 728 in src/murfey/client/contexts/tomo.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/tomo.py#L728

Added line #L728 was not covered by tests
[float(b["TiltAngle"]) for b in blocks]
)
mdoc_metadata["source"] = str(self._basepath)
Expand Down
4 changes: 2 additions & 2 deletions src/murfey/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import murfey.server.prometheus as prom
import murfey.server.websocket
import murfey.util.db as db
from murfey.client.contexts.tomo import _midpoint
from murfey.server.murfey_db import url # murfey_db
from murfey.util import LogFilter
from murfey.util.config import (
Expand All @@ -60,6 +59,7 @@
)
from murfey.util.processing_params import default_spa_parameters
from murfey.util.state import global_state
from murfey.util.tomo import midpoint

try:
from murfey.server.ispyb import TransportManager # Session
Expand Down Expand Up @@ -2576,7 +2576,7 @@
)
if not stack_file.parent.exists():
stack_file.parent.mkdir(parents=True)
tilt_offset = _midpoint([float(get_angle(t)) for t in tilts])
tilt_offset = midpoint([float(get_angle(t)) for t in tilts])

Check warning on line 2579 in src/murfey/server/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/__init__.py#L2579

Added line #L2579 was not covered by tests
zocalo_message = {
"recipes": ["em-tomo-align"],
"parameters": {
Expand Down
4 changes: 2 additions & 2 deletions src/murfey/server/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import murfey.server.websocket as ws
import murfey.util.eer
from murfey.server import (
_midpoint,
_murfey_id,
_transport_object,
check_tilt_series_mc,
Expand Down Expand Up @@ -108,6 +107,7 @@
)
from murfey.util.processing_params import default_spa_parameters
from murfey.util.state import global_state
from murfey.util.tomo import midpoint

log = logging.getLogger("murfey.server.api")

Expand Down Expand Up @@ -840,7 +840,7 @@
)
if not stack_file.parent.exists():
stack_file.parent.mkdir(parents=True)
tilt_offset = _midpoint([float(get_angle(t)) for t in tilts])
tilt_offset = midpoint([float(get_angle(t)) for t in tilts])

Check warning on line 843 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L843

Added line #L843 was not covered by tests
zocalo_message = {
"recipes": ["em-tomo-align"],
"parameters": {
Expand Down
16 changes: 16 additions & 0 deletions src/murfey/util/tomo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def midpoint(angles: list[float]) -> int:
"""
Utility function to calculate the midpoint of the angles used in a tilt series.
Used primarily in the tomography workflow.
"""
if not angles:
return 0

Check warning on line 7 in src/murfey/util/tomo.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/tomo.py#L7

Added line #L7 was not covered by tests
if len(angles) <= 2:
return round(angles[0])
sorted_angles = sorted(angles)
return round(

Check warning on line 11 in src/murfey/util/tomo.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/util/tomo.py#L9-L11

Added lines #L9 - L11 were not covered by tests
sorted_angles[len(sorted_angles) // 2]
if sorted_angles[len(sorted_angles) // 2]
and sorted_angles[len(sorted_angles) // 2 + 1]
else 0
)
Loading