@@ -280,6 +280,35 @@ def test_pixel_size(caplog):
280280 np .testing .assert_allclose (src .pixel_size , user_px_sz )
281281
282282
283+ def test_pixel_size_type (tmp_path ):
284+ """
285+ Test that pixel_size dtype is stored in doubles as an attribute
286+ and in metadata.
287+ """
288+ # Test for diffetent types of sources.
289+ sim = Simulation (n = 2 , pixel_size = 1 )
290+ arr_src = ArrayImageSource (sim .images [:].asnumpy (), pixel_size = 1 )
291+
292+ starfile = tmp_path / "source.star"
293+ sim .save (starfile )
294+ rln_src = RelionSource (starfile , pixel_size = 1 )
295+
296+ # Check attribute type
297+ assert isinstance (sim .pixel_size , float )
298+ assert isinstance (arr_src .pixel_size , float )
299+ assert isinstance (rln_src .pixel_size , float )
300+
301+ # Check type in _metadata dict
302+ assert isinstance (sim ._metadata ["_rlnImagePixelSize" ][0 ], float )
303+ assert isinstance (arr_src ._metadata ["_rlnImagePixelSize" ][0 ], float )
304+ assert isinstance (rln_src ._metadata ["_rlnImagePixelSize" ][0 ], float )
305+
306+ # Check get_metadata type
307+ assert isinstance (sim .get_metadata ("_rlnImagePixelSize" )[0 ], float )
308+ assert isinstance (arr_src .get_metadata ("_rlnImagePixelSize" )[0 ], float )
309+ assert isinstance (rln_src .get_metadata ("_rlnImagePixelSize" )[0 ], float )
310+
311+
283312@pytest .mark .parametrize ("dtype" , [np .float32 , np .float64 ])
284313def test_dtype_passthrough (dtype ):
285314 """
0 commit comments