Skip to content

Commit 9cd3fa8

Browse files
committed
Update particle stack tests
1 parent e537e42 commit 9cd3fa8

File tree

1 file changed

+71
-11
lines changed

1 file changed

+71
-11
lines changed

tests/pydantic_models/test_particle_stack.py

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,37 @@ def test_particle_stack_image_extraction():
213213
mip1_ground_truth = np.array([[0, 0, 0], [0, mip1, 0], [0, 0, 0]], dtype=np.float32)
214214
mip2_ground_truth = np.array([[0, 0, 0], [0, mip2, 0], [0, 0, 0]], dtype=np.float32)
215215

216+
h, w = (32, 32)
217+
box_h, box_w = (34, 34)
218+
extracted_box_size_mip = (box_h - h + 1, box_w - w + 1)
219+
216220
ps = ParticleStack(
217221
df_path="", # Setting data frame directly, so give empty path
218-
extracted_box_size=(34, 34), # This will give a correlation box size of 3x3
219-
original_template_size=(32, 32),
222+
extracted_box_size=(
223+
box_h,
224+
box_w,
225+
), # This gives a correlation box size of 3x3
226+
original_template_size=(h, w),
220227
skip_df_load=True,
221228
)
222229
ps._df = df # Set the DataFrame directly
223230

231+
mip_images, mip_indices = ps.load_images_grouped_by_column(column_name="mip_path")
232+
micrograph_images, micrograph_indices = ps.load_images_grouped_by_column(
233+
column_name="micrograph_path"
234+
)
235+
224236
# Default is top-left reference, make sure it works itself
225-
extracted_images = ps.construct_image_stack()
226-
extracted_mips = ps.construct_cropped_statistic_stack(stat="mip")
237+
extracted_images = ps.construct_image_stack(
238+
images=micrograph_images,
239+
indices=micrograph_indices,
240+
extraction_size=(box_h, box_w),
241+
)
242+
extracted_mips = ps.construct_image_stack(
243+
images=mip_images,
244+
indices=mip_indices,
245+
extraction_size=extracted_box_size_mip,
246+
)
227247

228248
assert extracted_images.shape == (2, 34, 34)
229249
assert extracted_mips.shape == (2, 3, 3)
@@ -268,26 +288,66 @@ def test_particle_stack_top_left_and_center_self_consistency():
268288
# Create ParticleStack instances for both references
269289
ps_tl = ParticleStack(
270290
df_path="", # Setting data frame directly, so give empty path
271-
extracted_box_size=(34, 34), # This will give a correlation box size of 3x3
291+
extracted_box_size=(34, 34), # This gives a correlation box size of 3x3
272292
original_template_size=(32, 32),
273293
skip_df_load=True,
274294
)
275295
ps_tl._df = df_tl # Set the DataFrame directly
276296

297+
h, w = (32, 32)
298+
box_h, box_w = (34, 34)
299+
extracted_box_size_mip = (box_h - h + 1, box_w - w + 1)
300+
277301
ps_center = ParticleStack(
278302
df_path="", # Setting data frame directly, so give empty path
279-
extracted_box_size=(34, 34), # This will give a correlation box size of 3x3
280-
original_template_size=(32, 32),
303+
extracted_box_size=(
304+
box_h,
305+
box_w,
306+
), # This gives a correlation box size of 3x3
307+
original_template_size=(h, w),
281308
skip_df_load=True,
282309
)
283310
ps_center._df = df_center # Set the DataFrame directly
284311

312+
mip_images_tl, mip_indices_tl = ps_tl.load_images_grouped_by_column(
313+
column_name="mip_path"
314+
)
315+
mip_images_c, mip_indices_c = ps_center.load_images_grouped_by_column(
316+
column_name="mip_path"
317+
)
318+
micrograph_images_tl, micrograph_indices_tl = ps_tl.load_images_grouped_by_column(
319+
column_name="micrograph_path"
320+
)
321+
micrograph_images_c, micrograph_indices_c = ps_center.load_images_grouped_by_column(
322+
column_name="micrograph_path"
323+
)
324+
285325
# Extract images and MIPs for both references
286-
extracted_images_tl = ps_tl.construct_image_stack(pos_reference="top-left")
287-
extracted_images_center = ps_center.construct_image_stack(pos_reference="center")
326+
extracted_images_tl = ps_tl.construct_image_stack(
327+
images=micrograph_images_tl,
328+
indices=micrograph_indices_tl,
329+
extraction_size=(box_h, box_w),
330+
pos_reference="top-left",
331+
)
332+
extracted_images_center = ps_center.construct_image_stack(
333+
images=micrograph_images_c,
334+
indices=micrograph_indices_c,
335+
extraction_size=(box_h, box_w),
336+
pos_reference="center",
337+
)
288338

289-
extracted_mips_tl = ps_tl.construct_cropped_statistic_stack(stat="mip")
290-
extracted_mips_center = ps_center.construct_cropped_statistic_stack(stat="mip")
339+
extracted_mips_tl = ps_tl.construct_image_stack(
340+
images=mip_images_tl,
341+
indices=mip_indices_tl,
342+
extraction_size=extracted_box_size_mip,
343+
pos_reference="top-left",
344+
)
345+
extracted_mips_center = ps_center.construct_image_stack(
346+
images=mip_images_c,
347+
indices=mip_indices_c,
348+
extraction_size=extracted_box_size_mip,
349+
pos_reference="top-left",
350+
)
291351

292352
# Check shapes
293353
assert extracted_images_tl.shape == (2, 34, 34)

0 commit comments

Comments
 (0)