@@ -44,6 +44,23 @@ def load_no_probe(args, props) -> RawData:
4444 'seed' : None ,
4545 }
4646
47+ def load_empty_with_nan (args , props ) -> RawData :
48+ scan_shape = props ['scan_shape' ]
49+ det_shape = props ['det_shape' ]
50+ nan_pos = props ['nan_inds' ]
51+
52+ patterns = numpy .zeros ((* scan_shape , * det_shape ), dtype = numpy .float32 )
53+ if nan_pos is not None :
54+ patterns [nan_pos ] = numpy .full (det_shape , fill_value = numpy .nan )
55+ return {
56+ 'patterns' : patterns ,
57+ 'mask' : numpy .ones (det_shape , dtype = numpy .float32 ),
58+ 'sampling' : Sampling (det_shape , sampling = (1.0 , 1.0 )),
59+ 'wavelength' : 1.0 ,
60+ 'scan_hook' : None ,
61+ 'probe_hook' : None ,
62+ 'seed' : None ,
63+ }
4764
4865def test_load_raw_data_missing ():
4966 plan = ReconsPlan .from_data ({
@@ -184,4 +201,43 @@ def test_load_3d_raw_data():
184201 recons = initialize_reconstruction (plan )
185202
186203 assert recons .state .scan .data .shape == (* scan_shape , 2 )
187- assert recons .patterns .patterns .shape == (* scan_shape , * det_shape )
204+ assert recons .patterns .patterns .shape == (* scan_shape , * det_shape )
205+
206+ @pytest .mark .parametrize (('scan_shape' , 'nan' , 'loaded_scan' , 'expected_scan' ),[
207+ ((64 , 64 ), None , (64 , 64 ), (4096 ,)),
208+ ((4096 ,), (0 ), (64 , 64 ), (4096 - 1 ,)),
209+ ((64 , 64 ), (0 ,0 ), (4096 - 1 ,1 ), (4096 - 1 ,)),
210+ ((4096 ,), (0 ), (4096 ,1 ), (4096 - 1 ,))
211+ ])
212+ def test_load_raw_data_scan_dropnan (scan_shape , nan , loaded_scan , expected_scan ):
213+ # scan_shape = (64, 64)
214+ det_shape = (128 , 128 )
215+
216+ plan = ReconsPlan .from_data ({
217+ 'name' : 'test' ,
218+ 'raw_data' : {
219+ 'type' : 'tests.test_initialization:load_empty_with_nan' ,
220+ 'scan_shape' : scan_shape ,
221+ 'det_shape' : det_shape ,
222+ 'nan_inds' : nan ,
223+ },
224+ 'init' : {
225+ 'scan' : {
226+ 'type' : 'raster' ,
227+ 'shape' : loaded_scan ,
228+ 'step_size' : (1.0 , 1.0 ),
229+ },
230+ 'probe' : {
231+ 'type' : 'focused' ,
232+ 'conv_angle' : 20.0 ,
233+ 'defocus' : 300.0 ,
234+ }
235+ },
236+ 'post_init' : ['drop_nans' ]
237+ ,
238+ 'engines' : [],
239+ })
240+ recons = initialize_reconstruction (plan )
241+
242+ assert recons .state .scan .data .shape == (* expected_scan , 2 )
243+ assert recons .patterns .patterns .shape == (* expected_scan , * det_shape )
0 commit comments