@@ -34,7 +34,7 @@ def get_fly_scan_angle(scan_id):
3434
3535 img_ini_timestamp = timestamp_tomo [0 ]
3636
37- # something not correct in rotary stage.
37+ # something not correct in rotary stage.
3838 # we do following correction on 2023_5_16
3939 # mot_ini_timestamp = timestamp_mot[1] # timestamp_mot[1] is the time when taking dark image
4040
@@ -286,8 +286,13 @@ def export_fly_scan(h, fpath=None):
286286
287287 x_eng = h .start ["XEng" ]
288288 img_angle = get_fly_scan_angle (uid )
289+
290+ print (f"ANGLE { img_angle .shape } " )
291+
289292 id_stop = find_nearest (img_angle , img_angle [0 ]+ relative_rot_angle - 1 )
290293
294+ print (f"IDSTOP { id_stop } " )
295+
291296 tmp = list (h .data (f"{ det_name } _image" , stream_name = "primary" ))[0 ]
292297 img_tomo = np .array (tmp [:len (img_angle )])
293298 s = img_tomo .shape
@@ -587,17 +592,17 @@ def export_xanes_scan_with_binning(h, fpath=None, binning=1):
587592 img_list = list (h .data (f"{ det_name } _image" , stream_name = "primary" ))
588593 bkg_list = list (h .data (f"{ det_name } _image" , stream_name = "flat" ))
589594 for i in trange (num_eng ):
590- img_xanes_sub = np .array (img_list [i ])
595+ img_xanes_sub = np .array (img_list [i ])
591596 img_xanes_sub_avg = np .median (img_xanes_sub , axis = 0 )
592597 img_bin1 = rescale (img_xanes_sub_avg , 1 / binning )
593598 img_xanes_avg .append (img_bin1 )
594599
595- img_bkg_sub = np .array (bkg_list [i ])
600+ img_bkg_sub = np .array (bkg_list [i ])
596601 img_bkg_sub_avg = np .median (img_bkg_sub , axis = 0 )
597602 img_bin2 = rescale (img_bkg_sub_avg , 1 / binning )
598603 img_bkg_avg .append (img_bin2 )
599604
600-
605+
601606
602607 img_dark = np .array (list (h .data (f"{ det_name } _image" , stream_name = "dark" )))
603608 img_dark_avg = np .mean (img_dark , axis = 1 )[0 ]
@@ -719,7 +724,7 @@ def export_z_scan(h, fpath=None):
719724 num = h .start ["plan_args" ]["steps" ]
720725 chunk_size = h .start ["plan_args" ]["chunk_size" ]
721726 note = h .start ["plan_args" ]["note" ] if h .start ["plan_args" ]["note" ] else "None"
722-
727+
723728 img_zscan = np .mean (np .array (list (h .data (f"{ det_name } _image" , stream_name = "primary" ))), axis = 1 )
724729 img_bkg = np .mean (np .array (list (h .data (f"{ det_name } _image" , stream_name = "flat" ))), axis = 1 ).squeeze ()
725730 img_dark = np .mean (np .array (list (h .data (f"{ det_name } _image" , stream_name = "dark" ))), axis = 1 ).squeeze ()
@@ -836,7 +841,7 @@ def export_test_scan(h, fpath=None):
836841
837842 img_list = list (h .data (f"{ det_name } _image" , stream_name = "primary" ))
838843 n = len (img_list )
839- for i in range (n - 1 , 0 , - 1 ):
844+ for i in range (n - 1 , 0 , - 1 ):
840845 try :
841846 #print(i)
842847 img = np .array (img_list [:i ])[:, 0 ]
@@ -861,7 +866,7 @@ def export_test_scan(h, fpath=None):
861866 img_bkg_avg = img_bkg
862867 print ('img background not taken' )
863868
864- img_norm = (img - img_dark_avg ) * 1.0 / (img_bkg_avg - img_dark_avg )
869+ img_norm = (img - img_dark_avg ) * 1.0 / (img_bkg_avg - img_dark_avg )
865870 img_norm [np .isnan (img_norm )] = 0
866871 img_norm [np .isinf (img_norm )] = 0
867872 fname = fpath + scan_type + "_id_" + str (scan_id ) + ".h5"
@@ -932,7 +937,7 @@ def export_test_scan2(h, fpath=None):
932937 img_bkg = np .ones ((1 , img .shape [1 ], img .shape [2 ]))
933938 img_bkg_avg = img_bkg
934939
935- img_norm = (img - img_dark_avg ) * 1.0 / (img_bkg_avg - img_dark_avg )
940+ img_norm = (img - img_dark_avg ) * 1.0 / (img_bkg_avg - img_dark_avg )
936941 img_norm [np .isnan (img_norm )] = 0
937942 img_norm [np .isinf (img_norm )] = 0
938943 fname = fpath + scan_type + "_id_" + str (scan_id ) + ".h5"
@@ -999,7 +1004,7 @@ def export_radiography_scan(h, fpath=None):
9991004 img_bkg = np .array (list (h .data (f"{ det_name } _image" , stream_name = "flat" )))[0 ]
10001005 img_bkg_avg = np .mean (img_bkg , axis = 0 , keepdims = True )
10011006
1002- img_norm = (img - img_dark_avg ) * 1.0 / (img_bkg_avg - img_dark_avg )
1007+ img_norm = (img - img_dark_avg ) * 1.0 / (img_bkg_avg - img_dark_avg )
10031008 img_norm [np .isnan (img_norm )] = 0
10041009 img_norm [np .isinf (img_norm )] = 0
10051010 fname = fpath + scan_type + "_id_" + str (scan_id ) + ".h5"
@@ -1275,7 +1280,7 @@ def export_raster_2D_2(h, binning=4, fpath=None):
12751280 col_size = x_num * cl
12761281 img_patch = np .zeros ([1 , row_size , col_size ])
12771282
1278-
1283+
12791284 pos_file_for_print = np .zeros ([x_num * y_num , 4 ])
12801285 pos_file = ["cord_x\t cord_y\t x_pos_relative\t y_pos_relative\n " ]
12811286 index = 0
@@ -1303,7 +1308,7 @@ def export_raster_2D_2(h, binning=4, fpath=None):
13031308 except :
13041309 img_patch_bin = img_patch
13051310 binning = 1
1306-
1311+
13071312 fout_h5 = fpath + f"raster2D_scan_{ scan_id } _binning_{ binning } .h5"
13081313 fout_tiff = fpath + f"raster2D_scan_{ scan_id } _binning_{ binning } .tiff"
13091314 fout_txt = fpath + f"raster2D_scan_{ scan_id } _cord.txt"
@@ -1321,7 +1326,7 @@ def export_raster_2D_2(h, binning=4, fpath=None):
13211326 """
13221327 s = img.shape
13231328 tmp = bin_ndarray(img, new_shape=(s[0], int(s[1]/binning), int(s[2]/binning)))
1324- for i in range(num_img):
1329+ for i in range(num_img):
13251330 fout = f'{new_dir}/img_{i:02d}_binning_{binning}.tiff'
13261331 print(f'saving {fout}')
13271332 tifffile.imsave(fout, np.array(tmp[i], dtype=np.float32))
@@ -1389,21 +1394,21 @@ def export_raster_2D(h, binning=4, fpath=None, reverse=False, bkg_scan_id=None):
13891394 img_dark = np .array (list (h_ref .data (f"{ det_name } _image" , stream_name = "dark" )))[0 ]
13901395 img_dark_avg = np .mean (img_dark , axis = 0 , keepdims = True ) #(1, 1020, 1024)
13911396 except :
1392- img_dark_avg = np .zeros ((1 , * s [1 :]))
1397+ img_dark_avg = np .zeros ((1 , * s [1 :]))
13931398
13941399 try :
13951400 img_bkg = np .array (list (h_ref .data (f"{ det_name } _image" , stream_name = "flat" )))[0 ]
13961401 img_bkg_avg = np .mean (img_bkg , axis = 0 , keepdims = True ) #(1, 1020, 1024)
13971402 except :
13981403 img_bkg_avg = np .ones ((1 , * s [1 :]))
1399-
1404+
14001405 if reverse :
14011406 img_raw = img_raw [:, ::- 1 , ::- 1 ]
14021407 img_dark_avg = img_dark_avg [:, ::- 1 , ::- 1 ]
14031408 img_bkg_avg = img_bkg_avg [:, ::- 1 , ::- 1 ]
14041409
1405-
1406-
1410+
1411+
14071412
14081413 img = (img - img_dark_avg ) / (img_bkg_avg - img_dark_avg )
14091414 x_num = round ((x_range [1 ] - x_range [0 ]) + 1 )
@@ -1416,7 +1421,7 @@ def export_raster_2D(h, binning=4, fpath=None, reverse=False, bkg_scan_id=None):
14161421 pix = pxl_sz
14171422 else :
14181423 warn_msg = ''
1419-
1424+
14201425 frac = np .round (pix / pxl_sz , 2 ) # e.g., 10nm/20nm = 0.5
14211426 rl = int (s [1 ] * frac ) # num of pixel (row) in cropped_and_centered image
14221427 rs = s [1 ]/ 2 * (1 - frac )
@@ -1436,7 +1441,7 @@ def export_raster_2D(h, binning=4, fpath=None, reverse=False, bkg_scan_id=None):
14361441 col_size = x_num * cl
14371442 img_patch = np .zeros ([1 , row_size , col_size ])
14381443
1439-
1444+
14401445 pos_file_for_print = np .zeros ([x_num * y_num , 4 ])
14411446 pos_file = ["cord_x\t cord_y\t x_pos_relative\t y_pos_relative\n " ]
14421447 index = 0
@@ -1481,7 +1486,7 @@ def export_raster_2D(h, binning=4, fpath=None, reverse=False, bkg_scan_id=None):
14811486 """
14821487 s = img.shape
14831488 tmp = bin_ndarray(img, new_shape=(s[0], int(s[1]/binning), int(s[2]/binning)))
1484- for i in range(num_img):
1489+ for i in range(num_img):
14851490 fout = f'{new_dir}/img_{i:02d}_binning_{binning}.tiff'
14861491 print(f'saving {fout}')
14871492 tifffile.imsave(fout, np.array(tmp[i], dtype=np.float32))
@@ -1538,20 +1543,20 @@ def export_multipos_2D_xanes_scan2(h, fpath=None):
15381543
15391544 len_img = len (img_xanes )
15401545 len_bkg = len (img_bkg )
1541-
1546+
15421547 idx = int (len_img // num_pos )
15431548
15441549 id_end = int (min (idx , len_bkg ) * num_pos )
15451550 img_xanes = img_xanes [:id_end ]
1546- eng_list = eng_list [:id_end ]
1547-
1551+ eng_list = eng_list [:id_end ]
1552+
15481553
15491554 for j in range (num_pos ):
15501555 img = img_xanes [j ::num_pos ]
15511556 img_n = (img - img_dark ) / (img_bkg - img_dark )
15521557 fn = fpath
15531558 fname = (f"{ fn } { scan_type } _id_{ scan_id } _pos_{ j :02d} .h5" )
1554-
1559+
15551560 try :
15561561 print (f"saving { fname } " )
15571562 with h5py .File (fname , "w" ) as hf :
@@ -1567,7 +1572,7 @@ def export_multipos_2D_xanes_scan2(h, fpath=None):
15671572 hf .create_dataset ("Pixel Size" , data = str (pxl_sz ) + "nm" )
15681573 except Exception as err :
15691574 print (err )
1570- del img_xanes
1575+ del img_xanes
15711576 del img_bkg
15721577 gc .collect ()
15731578 '''
0 commit comments