|
2 | 2 |
|
3 | 3 | from sqlmodel import Session, select |
4 | 4 |
|
5 | | -from murfey.util.db import DataCollectionGroup, SearchMap |
6 | | -from murfey.util.models import SearchMapParameters |
| 5 | +from murfey.util.db import DataCollectionGroup, SearchMap, TiltSeries |
| 6 | +from murfey.util.models import BatchPositionParameters, SearchMapParameters |
7 | 7 | from murfey.workflows.tomo import tomo_metadata |
8 | 8 | from tests.conftest import ExampleVisit |
9 | 9 |
|
|
12 | 12 | def test_register_search_map_update_with_dimensions( |
13 | 13 | mock_transport, murfey_db_session: Session |
14 | 14 | ): |
15 | | - """Test the updating of an existing grid square""" |
16 | | - # Create a grid square to update |
| 15 | + """Test the updating of an existing search map, without enough to find location""" |
| 16 | + # Create a search map to update |
17 | 17 | search_map = SearchMap( |
18 | 18 | id=1, |
19 | 19 | name="SearchMap_1", |
@@ -64,8 +64,8 @@ def test_register_search_map_update_with_dimensions( |
64 | 64 | def test_register_search_map_update_with_all_parameters( |
65 | 65 | mock_transport, murfey_db_session: Session |
66 | 66 | ): |
67 | | - """Test the updating of an existing grid square""" |
68 | | - # Create a grid square to update |
| 67 | + """Test the updating of an existing search map with all required parameters""" |
| 68 | + # Create a search map to update |
69 | 69 | search_map = SearchMap( |
70 | 70 | id=1, |
71 | 71 | name="SearchMap_1", |
@@ -123,7 +123,7 @@ def test_register_search_map_update_with_all_parameters( |
123 | 123 | assert sm_final_parameters.height == 4000 |
124 | 124 | assert sm_final_parameters.x_stage_position == 0.3 |
125 | 125 | assert sm_final_parameters.y_stage_position == 0.4 |
126 | | - assert sm_final_parameters.pixel_size == 0.1 |
| 126 | + assert sm_final_parameters.pixel_size == 1e-7 |
127 | 127 | assert sm_final_parameters.image == "path/to/image" |
128 | 128 | assert sm_final_parameters.binning == 1 |
129 | 129 | assert sm_final_parameters.reference_matrix_m11 == 1.01 |
@@ -156,6 +156,7 @@ def test_register_search_map_update_with_all_parameters( |
156 | 156 | def test_register_search_map_insert_with_ispyb( |
157 | 157 | mock_transport, murfey_db_session: Session, tmp_path |
158 | 158 | ): |
| 159 | + """Insert a new search map""" |
159 | 160 | # Create a data collection group for lookups |
160 | 161 | dcg = DataCollectionGroup( |
161 | 162 | id=1, |
@@ -199,3 +200,175 @@ def test_register_search_map_insert_with_ispyb( |
199 | 200 | assert sm_final_parameters.y_stage_position == 1.4 |
200 | 201 | assert sm_final_parameters.pixel_size == 1.02 |
201 | 202 | assert sm_final_parameters.x_location is None |
| 203 | + |
| 204 | + |
| 205 | +def test_register_batch_position_update(murfey_db_session: Session): |
| 206 | + """Test the updating of an existing tilt series with batch positions""" |
| 207 | + # Create a tilt series to update |
| 208 | + tilt_series = TiltSeries( |
| 209 | + tag="Position_1", |
| 210 | + rsync_source="session_tag", |
| 211 | + session_id=ExampleVisit.murfey_session_id, |
| 212 | + search_map_id=1, |
| 213 | + ) |
| 214 | + murfey_db_session.add(tilt_series) |
| 215 | + murfey_db_session.commit() |
| 216 | + |
| 217 | + # Make sure search map is present |
| 218 | + search_map = SearchMap( |
| 219 | + id=1, |
| 220 | + name="SearchMap_1", |
| 221 | + session_id=ExampleVisit.murfey_session_id, |
| 222 | + tag="session_tag", |
| 223 | + x_stage_position=1, |
| 224 | + y_stage_position=2, |
| 225 | + pixel_size=0.01, |
| 226 | + reference_matrix_m11=1, |
| 227 | + reference_matrix_m12=0, |
| 228 | + reference_matrix_m21=0, |
| 229 | + reference_matrix_m22=1, |
| 230 | + stage_correction_m11=1, |
| 231 | + stage_correction_m12=0, |
| 232 | + stage_correction_m21=0, |
| 233 | + stage_correction_m22=1, |
| 234 | + image_shift_correction_m11=1, |
| 235 | + image_shift_correction_m12=0, |
| 236 | + image_shift_correction_m21=0, |
| 237 | + image_shift_correction_m22=1, |
| 238 | + height=4000, |
| 239 | + width=2000, |
| 240 | + ) |
| 241 | + murfey_db_session.add(search_map) |
| 242 | + murfey_db_session.commit() |
| 243 | + |
| 244 | + # Parameters to update with |
| 245 | + new_parameters = BatchPositionParameters( |
| 246 | + tag="session_tag", |
| 247 | + x_stage_position=0.1, |
| 248 | + y_stage_position=0.2, |
| 249 | + x_beamshift=0.3, |
| 250 | + y_beamshift=0.4, |
| 251 | + search_map_name="SearchMap_1", |
| 252 | + ) |
| 253 | + |
| 254 | + # Run the registration |
| 255 | + tomo_metadata.register_batch_position_in_database( |
| 256 | + ExampleVisit.murfey_session_id, "Position_1", new_parameters, murfey_db_session |
| 257 | + ) |
| 258 | + |
| 259 | + # These two should have been updated, values are known as used identity matrices |
| 260 | + bp_final_parameters = murfey_db_session.exec(select(TiltSeries)).one() |
| 261 | + assert bp_final_parameters.x_location == 880 |
| 262 | + assert bp_final_parameters.y_location == 1780 |
| 263 | + |
| 264 | + |
| 265 | +def test_register_batch_position_update_skip(murfey_db_session: Session): |
| 266 | + """Test the updating of an existing batch position, skipped as already done""" |
| 267 | + # Create a tilt series to update |
| 268 | + tilt_series = TiltSeries( |
| 269 | + tag="Position_1", |
| 270 | + rsync_source="session_tag", |
| 271 | + session_id=ExampleVisit.murfey_session_id, |
| 272 | + search_map_id=1, |
| 273 | + x_location=100, |
| 274 | + y_location=200, |
| 275 | + ) |
| 276 | + murfey_db_session.add(tilt_series) |
| 277 | + murfey_db_session.commit() |
| 278 | + |
| 279 | + # Make sure search map is present |
| 280 | + search_map = SearchMap( |
| 281 | + id=1, |
| 282 | + name="SearchMap_1", |
| 283 | + session_id=ExampleVisit.murfey_session_id, |
| 284 | + tag="session_tag", |
| 285 | + x_stage_position=1, |
| 286 | + y_stage_position=2, |
| 287 | + pixel_size=0.01, |
| 288 | + reference_matrix_m11=1, |
| 289 | + reference_matrix_m12=0, |
| 290 | + reference_matrix_m21=0, |
| 291 | + reference_matrix_m22=1, |
| 292 | + stage_correction_m11=1, |
| 293 | + stage_correction_m12=0, |
| 294 | + stage_correction_m21=0, |
| 295 | + stage_correction_m22=1, |
| 296 | + image_shift_correction_m11=1, |
| 297 | + image_shift_correction_m12=0, |
| 298 | + image_shift_correction_m21=0, |
| 299 | + image_shift_correction_m22=1, |
| 300 | + height=4000, |
| 301 | + width=2000, |
| 302 | + ) |
| 303 | + murfey_db_session.add(search_map) |
| 304 | + murfey_db_session.commit() |
| 305 | + |
| 306 | + # Parameters to update with |
| 307 | + new_parameters = BatchPositionParameters( |
| 308 | + tag="session_tag", |
| 309 | + x_stage_position=0.1, |
| 310 | + y_stage_position=0.2, |
| 311 | + x_beamshift=0.3, |
| 312 | + y_beamshift=0.4, |
| 313 | + search_map_name="SearchMap_1", |
| 314 | + ) |
| 315 | + |
| 316 | + # Run the registration |
| 317 | + tomo_metadata.register_batch_position_in_database( |
| 318 | + ExampleVisit.murfey_session_id, "Position_1", new_parameters, murfey_db_session |
| 319 | + ) |
| 320 | + |
| 321 | + # These two should have been updated, values are known as used identity matrices |
| 322 | + bp_final_parameters = murfey_db_session.exec(select(TiltSeries)).one() |
| 323 | + assert bp_final_parameters.x_location == 100 |
| 324 | + assert bp_final_parameters.y_location == 200 |
| 325 | + |
| 326 | + |
| 327 | +def test_register_batch_position_new(murfey_db_session: Session): |
| 328 | + """Test the registration of a new tilt series with batch positions""" |
| 329 | + # Make sure search map is present |
| 330 | + search_map = SearchMap( |
| 331 | + id=1, |
| 332 | + name="SearchMap_1", |
| 333 | + session_id=ExampleVisit.murfey_session_id, |
| 334 | + tag="session_tag", |
| 335 | + x_stage_position=1, |
| 336 | + y_stage_position=2, |
| 337 | + pixel_size=0.01, |
| 338 | + reference_matrix_m11=1, |
| 339 | + reference_matrix_m12=0, |
| 340 | + reference_matrix_m21=0, |
| 341 | + reference_matrix_m22=1, |
| 342 | + stage_correction_m11=1, |
| 343 | + stage_correction_m12=0, |
| 344 | + stage_correction_m21=0, |
| 345 | + stage_correction_m22=1, |
| 346 | + image_shift_correction_m11=1, |
| 347 | + image_shift_correction_m12=0, |
| 348 | + image_shift_correction_m21=0, |
| 349 | + image_shift_correction_m22=1, |
| 350 | + height=4000, |
| 351 | + width=2000, |
| 352 | + ) |
| 353 | + murfey_db_session.add(search_map) |
| 354 | + murfey_db_session.commit() |
| 355 | + |
| 356 | + # Parameters to update with |
| 357 | + new_parameters = BatchPositionParameters( |
| 358 | + tag="session_tag", |
| 359 | + x_stage_position=0.1, |
| 360 | + y_stage_position=0.2, |
| 361 | + x_beamshift=0.3, |
| 362 | + y_beamshift=0.4, |
| 363 | + search_map_name="SearchMap_1", |
| 364 | + ) |
| 365 | + |
| 366 | + # Run the registration |
| 367 | + tomo_metadata.register_batch_position_in_database( |
| 368 | + ExampleVisit.murfey_session_id, "Position_1", new_parameters, murfey_db_session |
| 369 | + ) |
| 370 | + |
| 371 | + # These two should have been updated, values are known as used identity matrices |
| 372 | + bp_final_parameters = murfey_db_session.exec(select(TiltSeries)).one() |
| 373 | + assert bp_final_parameters.x_location == 880 |
| 374 | + assert bp_final_parameters.y_location == 1780 |
0 commit comments