From 65b99940dea2dd62d63f1f7024e8d8d9d74ca1db Mon Sep 17 00:00:00 2001 From: yxd92326 Date: Thu, 24 Jul 2025 15:30:46 +0100 Subject: [PATCH 1/2] Flip the tomogram y coordinates so origin is at top --- src/murfey/workflows/tomo/tomo_metadata.py | 6 +++++- tests/workflows/tomo/test_tomo_metadata.py | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/murfey/workflows/tomo/tomo_metadata.py b/src/murfey/workflows/tomo/tomo_metadata.py index aefc112ac..e7aedca11 100644 --- a/src/murfey/workflows/tomo/tomo_metadata.py +++ b/src/murfey/workflows/tomo/tomo_metadata.py @@ -329,6 +329,7 @@ def register_batch_position_in_database( ] ) + # Apply stage corrections to the location corrected_vector = np.matmul( np.linalg.inv(reference_shift_matrix), np.matmul( @@ -339,7 +340,10 @@ def register_batch_position_in_database( ), ), ) - centre_batch_pixel = corrected_vector / search_map.pixel_size + [ + # Invert y coordinate + inverted_corrected_vector = np.matmul([[1, 0], [0, -1]], corrected_vector) + # Apply shift from centre + centre_batch_pixel = inverted_corrected_vector / search_map.pixel_size + [ search_map.width / 2, search_map.height / 2, ] diff --git a/tests/workflows/tomo/test_tomo_metadata.py b/tests/workflows/tomo/test_tomo_metadata.py index c169d2a73..c1c458224 100644 --- a/tests/workflows/tomo/test_tomo_metadata.py +++ b/tests/workflows/tomo/test_tomo_metadata.py @@ -249,8 +249,8 @@ def test_register_batch_position_update(murfey_db_session: Session): # These two should have been updated, values are known as used identity matrices bp_final_parameters = murfey_db_session.exec(select(TiltSeries)).one() - assert bp_final_parameters.x_location == 880 * 512 / search_map.width - assert bp_final_parameters.y_location == 1780 * 512 / search_map.width + assert bp_final_parameters.x_location == 880 * 512 / 2000 + assert bp_final_parameters.y_location == (4000 - 1780) * 512 / 2000 def test_register_batch_position_update_skip(murfey_db_session: Session): @@ -361,5 +361,5 @@ def test_register_batch_position_new(murfey_db_session: Session): # These two should have been updated, values are known as used identity matrices bp_final_parameters = murfey_db_session.exec(select(TiltSeries)).one() - assert bp_final_parameters.x_location == 880 * 512 / search_map.width - assert bp_final_parameters.y_location == 1780 * 512 / search_map.width + assert bp_final_parameters.x_location == 880 * 512 / 2000 + assert bp_final_parameters.y_location == (4000 - 1780) * 512 / 2000 From f7c75aa78a00550c5c9b4b07369482b046ec406c Mon Sep 17 00:00:00 2001 From: yxd92326 Date: Thu, 24 Jul 2025 15:41:18 +0100 Subject: [PATCH 2/2] Beam shift also needs flipping --- src/murfey/workflows/tomo/tomo_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/murfey/workflows/tomo/tomo_metadata.py b/src/murfey/workflows/tomo/tomo_metadata.py index e7aedca11..9c145ab6a 100644 --- a/src/murfey/workflows/tomo/tomo_metadata.py +++ b/src/murfey/workflows/tomo/tomo_metadata.py @@ -358,7 +358,7 @@ def register_batch_position_in_database( tilt_series.y_location = ( ( centre_batch_pixel[1] - - batch_parameters.y_beamshift / search_map.pixel_size + + batch_parameters.y_beamshift / search_map.pixel_size ) * 512 / search_map.width