Skip to content

Commit 25d07be

Browse files
mrakitinFXI Operator
authored andcommitted
Pre-data-security updates
1 parent 163c94b commit 25d07be

File tree

6 files changed

+92
-96
lines changed

6 files changed

+92
-96
lines changed

startup/.42-scans_legacy.py.swx

Whitespace-only changes.

startup/10-area-detector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ class KinetixKlass(SingleTriggerV33, DetectorBase):
364364
def cam_name(self):
365365
print(self.prefix.split("{")[1].strip("}").split(":")[1])
366366

367-
root_path = "/nsls2/data/fxi-new/legacy/Kinetix"
367+
# root_path = "/nsls2/data/fxi-new/legacy/Kinetix"
368+
root_path = "/nsls2/data/fxi-new/legacy/Marana" # CHANGE IT BACK ONCE THE FOLDERS ARE CREATED !!!!!!!!!!!!!!!!!!
368369
hdf5 = Cpt(
369370
HDF5PluginWithFileStore,
370371
suffix="HDF1:",

startup/40-scan_pre_define.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ def _set_cam_chunk_size(detectors, chunk_size, scan_type='fly'):
8282
for detector in detectors:
8383
#print(f'try to unstage:\n {detector}\n')
8484
#yield from unstage(detector)
85-
detector.unstage()
85+
try:
86+
detector.unstage()
87+
except Exception as e:
88+
print(e)
89+
pass
8690
#print('sleep 0.2 sec')
8791
yield from bps.sleep(0.2)
8892

startup/41-scans.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ def fly_scan(
594594
"""
595595
global ZONE_PLATE
596596

597-
detectors = [KinetixU, ic3]
597+
#detectors = [KinetixU, ic3]
598+
detectors = [KinetixU]
598599
offset_angle = -1 * rs
599600
current_rot_angle = zps.pi_r.position
600601
target_rot_angle = current_rot_angle + relative_rot_angle
@@ -3548,9 +3549,10 @@ def xanes_3D(
35483549
):
35493550
txt = "start 3D xanes scan, containing following fly_scan:\n"
35503551
insert_text(txt)
3552+
print(txt)
35513553

35523554
for eng in eng_list:
3553-
yield from move_zp_ccd(eng, move_flag=1)
3555+
yield from move_zp_ccd_TEST(eng, move_flag=1)
35543556
my_note = note + f"_energy={eng}"
35553557
yield from bps.sleep(1)
35563558
print(f"current energy: {eng}")
@@ -3573,8 +3575,8 @@ def xanes_3D(
35733575
binning=binning,
35743576
)
35753577
yield from bps.sleep(1)
3576-
KinetixU.unstage()
3577-
yield from mv(KinetixU.cam.image_mode, 2)
3578+
#KinetixU.unstage()
3579+
#yield from mv(KinetixU.cam.image_mode, 2)
35783580
export_pdf(1)
35793581

35803582
'''

startup/80-load_scan.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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\tcord_y\tx_pos_relative\ty_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\tcord_y\tx_pos_relative\ty_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

Comments
 (0)