diff --git a/src/murfey/client/contexts/atlas.py b/src/murfey/client/contexts/atlas.py
index 6269a3507..11ae5ae63 100644
--- a/src/murfey/client/contexts/atlas.py
+++ b/src/murfey/client/contexts/atlas.py
@@ -7,6 +7,7 @@
from murfey.client.context import Context, _atlas_destination, _get_source
from murfey.client.instance_environment import MurfeyInstanceEnvironment
from murfey.util.client import capture_post
+from murfey.util.spa_metadata import get_grid_square_atlas_positions
logger = logging.getLogger("murfey.client.contexts.atlas")
@@ -158,3 +159,52 @@ def post_transfer_epu(
logger.info(
f"Registered data collection group for atlas {str(transferred_atlas_jpg)!r}"
)
+
+ elif environment and transferred_file.name == "Atlas.dm":
+ # Register all grid squares on this atlas
+ gs_pix_positions = get_grid_square_atlas_positions(transferred_file)
+ for gs, pos_data in gs_pix_positions.items():
+ if pos_data:
+ capture_post(
+ base_url=str(environment.url.geturl()),
+ router_name="session_control.spa_router",
+ function_name="register_grid_square",
+ token=self._token,
+ instrument_name=environment.instrument_name,
+ session_id=environment.murfey_session,
+ gsid=int(gs),
+ data={
+ "tag": str(transferred_file.parent),
+ "x_location": pos_data[0],
+ "y_location": pos_data[1],
+ "x_stage_position": pos_data[2],
+ "y_stage_position": pos_data[3],
+ "width": pos_data[4],
+ "height": pos_data[5],
+ "angle": pos_data[6],
+ },
+ )
+ if gs_pix_positions:
+ for p in transferred_file.parts:
+ if p.startswith("Sample"):
+ sample = int(p.replace("Sample", ""))
+ break
+ else:
+ logger.warning(
+ f"Sample could not be identified for {transferred_file}"
+ )
+ return
+ capture_post(
+ base_url=str(environment.url.geturl()),
+ router_name="session_control.spa_router",
+ function_name="register_atlas",
+ token=self._token,
+ instrument_name=environment.instrument_name,
+ session_id=environment.murfey_session,
+ data={
+ "name": f"{environment.visit}-sample-{sample}",
+ "acquisition_uuid": environment.acquisition_uuid,
+ "register_grid": True,
+ "tag": str(transferred_file.parent),
+ },
+ )
diff --git a/src/murfey/client/contexts/spa_metadata.py b/src/murfey/client/contexts/spa_metadata.py
index 34a58c925..b32728ccb 100644
--- a/src/murfey/client/contexts/spa_metadata.py
+++ b/src/murfey/client/contexts/spa_metadata.py
@@ -152,7 +152,7 @@ def post_transfer(
"angle": pos_data[6],
},
)
- if pos_data:
+ if gs_pix_positions:
capture_post(
base_url=str(environment.url.geturl()),
router_name="session_control.spa_router",
diff --git a/src/murfey/server/api/workflow.py b/src/murfey/server/api/workflow.py
index fddb41b6d..4d27fe9b5 100644
--- a/src/murfey/server/api/workflow.py
+++ b/src/murfey/server/api/workflow.py
@@ -232,6 +232,7 @@ def register_dc_group(
)
).all():
# Case where we switch from atlas to processing
+ original_tag = dcg_murfey[0].tag
dcg_murfey[0].tag = dcg_params.tag or dcg_murfey[0].tag
if _transport_object:
_transport_object.send(
@@ -243,6 +244,13 @@ def register_dc_group(
},
)
db.add(dcg_murfey[0])
+ for grid_square in db.exec(
+ select(GridSquare)
+ .where(GridSquare.tag == original_tag)
+ .where(GridSquare.session_id == session_id)
+ ).all():
+ grid_square.tag = dcg_params.tag or original_tag
+ db.add(grid_square)
db.commit()
else:
dcg_parameters = {
diff --git a/tests/client/contexts/test_atlas.py b/tests/client/contexts/test_atlas.py
index 915f9b3eb..b132154bb 100644
--- a/tests/client/contexts/test_atlas.py
+++ b/tests/client/contexts/test_atlas.py
@@ -33,10 +33,7 @@ def test_atlas_context_mrc(mock_capture_post, tmp_path):
atlas_mrc.parent.mkdir(parents=True)
atlas_mrc.touch()
- context.post_transfer(
- atlas_mrc,
- environment=env,
- )
+ context.post_transfer(atlas_mrc, environment=env)
mock_capture_post.assert_called_once_with(
base_url="http://localhost:8000",
router_name="session_control.spa_router",
@@ -72,10 +69,7 @@ def test_atlas_context_xml(mock_capture_post, tmp_path):
""
)
- context.post_transfer(
- atlas_xml,
- environment=env,
- )
+ context.post_transfer(atlas_xml, environment=env)
dcg_data = {
"experiment_type_id": 44, # Atlas
"tag": str(atlas_xml.parent),
@@ -95,3 +89,87 @@ def test_atlas_context_xml(mock_capture_post, tmp_path):
session_id=1,
data=dcg_data,
)
+
+
+@patch("murfey.client.contexts.atlas.capture_post")
+def test_atlas_context_dm(mock_capture_post, tmp_path):
+ env = MurfeyInstanceEnvironment(
+ url=urlparse("http://localhost:8000"),
+ client_id=0,
+ sources=[tmp_path / "cm12345-6"],
+ default_destinations={
+ tmp_path / "cm12345-6": f"{tmp_path}/destination/cm12345-6"
+ },
+ instrument_name="m01",
+ visit="cm12345-6",
+ murfey_session=1,
+ acquisition_uuid="uuid1",
+ )
+
+ # Write sample dm file
+ atlas_dm = tmp_path / "cm12345-6/Supervisor_atlas/Sample2/Atlas/Atlas.dm"
+ atlas_dm.parent.mkdir(parents=True)
+ grid_square_values = (
+ ""
+ "12001500"
+ "23"
+ "130560"
+ "0.14"
+ ""
+ )
+ with open(atlas_dm, "w") as new_xml:
+ new_xml.write(
+ "<_items>"
+ # First tile with two grid squares
+ ""
+ f"101{grid_square_values}"
+ ""
+ f"102{grid_square_values}"
+ ""
+ # Second tile with two grid squares
+ ""
+ f"103{grid_square_values}"
+ ""
+ f"104{grid_square_values}"
+ ""
+ # Close all
+ ""
+ )
+
+ context = AtlasContext("tomo", tmp_path, {}, "token")
+ context.post_transfer(atlas_dm, environment=env)
+
+ assert mock_capture_post.call_count == 5
+ mock_capture_post.assert_any_call(
+ base_url="http://localhost:8000",
+ router_name="session_control.spa_router",
+ function_name="register_grid_square",
+ token="token",
+ instrument_name="m01",
+ session_id=1,
+ gsid=101,
+ data={
+ "tag": str(atlas_dm.parent),
+ "x_location": 1200,
+ "y_location": 1500,
+ "x_stage_position": 2e9,
+ "y_stage_position": 3e9,
+ "width": 130,
+ "height": 560,
+ "angle": 0.14,
+ },
+ )
+ mock_capture_post.assert_any_call(
+ base_url="http://localhost:8000",
+ router_name="session_control.spa_router",
+ function_name="register_atlas",
+ token="token",
+ instrument_name="m01",
+ session_id=1,
+ data={
+ "name": "cm12345-6-sample-2",
+ "acquisition_uuid": "uuid1",
+ "register_grid": True,
+ "tag": str(atlas_dm.parent),
+ },
+ )