Skip to content

Commit

Permalink
increased sleep time for calibration routine
Browse files Browse the repository at this point in the history
Signed-off-by: elistavitski <[email protected]>
  • Loading branch information
estavitski committed Oct 22, 2024
1 parent 0dab9e3 commit 8304f4c
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 7 deletions.
15 changes: 12 additions & 3 deletions xas/energy_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_energy_offset_old(uid, db, db_proc, dE=25, plot_fun=None, attempts=5, sl
else:
return e0, e_cor

def get_energy_offset(uid, db, db_proc, dE=25, plot_fun=None, attempts=5, sleep_time=1, full_return=False):
def get_energy_offset(uid, db, db_proc, dE=25, plot_fun=None, attempts=20, sleep_time=2, full_return=False):
print('running get_energy_offset')
start = db[uid].start
fname_raw = start['interp_filename']
Expand All @@ -190,7 +190,7 @@ def get_energy_offset(uid, db, db_proc, dE=25, plot_fun=None, attempts=5, sleep_
# print('bla')
break
except:
print(f'[Energy Calibration] Attempt to read data {i + 1}')
print(f'[Energy Calibration] Attempt to read data {i + 1} {ttime.ctime()}')
ttime.sleep(sleep_time)
df = None

Expand All @@ -204,7 +204,16 @@ def get_energy_offset(uid, db, db_proc, dE=25, plot_fun=None, attempts=5, sleep_
edge = start['edge']
e0 = float(start['e0'])
# energy_ref, mu_ref = get_foil_spectrum(element, edge, db_proc)
energy_ref, mu_ref = db_proc.foil_spectrum(element, edge)
energy_ref, mu_ref = db_proc.foil_spectrum(element, edge) ## unsorted array of energy and mu

_foil_spectrum_tuple = db_proc.foil_spectrum(element, edge)
_dataframe_foil = pd.DataFrame(np.column_stack(_foil_spectrum_tuple))
_dataframe_foil = _dataframe_foil.sort_values(0)

energy_ref = np.array(_dataframe_foil[0])
mu_ref = np.array(_dataframe_foil[1])


mask = (energy_ref >= (e0 - dE)) & (energy_ref <= (e0 + dE))

energy_shift_coarse = energy_ref[np.argmin(np.abs(mu_ref - 0.5))] - energy[np.argmin(np.abs(mu - 0.5))]
Expand Down
7 changes: 4 additions & 3 deletions xas/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ def get_processed_df_from_uid_for_epics_fly_scan(db, uid, save_interpolated_file
raise e
if 'spectrometer' in hdr.start:
if 'roi_polygon' in hdr.start['detectors']['Pilatus 100k New']['config']:
johann_image_kwargs = filter_johann_image_kwargs(processing_kwargs)
if (hdr.start['spectrometer'] == 'johann') and (load_images):
interpolated_df = reduce_johann_images(interpolated_df, hdr, **johann_image_kwargs)
# if 'roi_polygon' in hdr.start['detectors']['Pilatus 100k']['config']:
# johann_image_kwargs = filter_johann_image_kwargs(processing_kwargs)
# if (hdr.start['spectrometer'] == 'johann') and (load_images):
# interpolated_df = reduce_johann_images(interpolated_df, hdr, **johann_image_kwargs)

johann_calibration_kwargs = filter_johann_calibration_kwargs(processing_kwargs)
if (hdr.start['spectrometer'] == 'johann') and (load_images):
Expand Down
140 changes: 139 additions & 1 deletion xas/scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1888,4 +1888,142 @@ def get_timestamps_for_pbs(uid, db):

plt.figure(2, clear=True)
plt.plot(img_closeset_arr, img_closeset_arr / img_mask_arr, 'k.')
# plt.axis('square')
# plt.axis('square')



hhm_y_precise = {}
hhm_y_precise['uid'] = []
hhm_y_precise['value'] = []
def find_optimal_hhm_Y_values():
energy_tab = [ 4900, 5100, 5500, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 15000, 17500, 20000]
# energy_tab = [9000]
for energy in energy_tab:
yield from bps.mv(hhm.energy, energy)
yield from prepare_beamline_plan(energy, move_cm_mirror = True, move_hhm_y = True)
yield from quick_pitch_optimization()
yield from bp.relative_scan([bpm_fm], hhm.y_precise, -0.5, 0.5, 21)


hdr = db[-1]
hhm_y_precise['uid'].append(hdr.start['uid'])
t = hdr.table()
index = np.argmax(t['bpm_fm_stats1_total'])
hhm_y_precise['value'].append(t['hhm_y_precise'][index+1])





#2024-09-19

[9.937850000000001,
9.57315,
9.467450000000001,
9.3162,
9.177100000000001,
9.08755,
9.025,
8.978050000000001,
8.9411,
8.9609,
8.88475,
8.84365,
8.85205,
8.816450000000001]


uids =['d0166c48-ebcf-4647-820f-f10f53e768f8',
'93b12235-e1ba-4ef4-93e7-7ea558450f0d',
'3e49c021-69de-4011-937f-0637a56ddf40',
'ebfafa6f-5ef5-4820-a77f-8f0b9436959e',
'9f8e8399-a0af-4099-ae57-b89f4e9687cf',
'021337a6-693c-4a0f-a529-5246e574f941',
'8a21ec71-c4ae-4a95-94ee-6b8e6e5b24c4',
'6ec12c6d-492e-44d1-93c9-9876a1b53f96',
'922fa456-e258-43c6-b6ba-b498f6f61bf9',
'7794afc8-4dd0-4591-98ff-c576df92790e',
'c7354f86-c247-4ad4-858f-2d0e7043f326',
'496d2087-10dd-4ff1-83f1-7ab7410d8bd2',
'1baf04d6-a8e3-4a6b-882d-e31ca3a5b75a',
'db7bb3d2-866d-47d4-a1fd-463d94c46416']

with open('inclinometer_data.json') as jd:
d = json.load(jd)

d = {'motor_det_th1': {'0': -27,
'1': -24,
'2': -21,
'3': -18,
'4': -15,
'5': -12,
'6': -9,
'7': -6,
'8': -3,
'9': 0,
'10': 3,
'11': 6,
'12': 9,
'13': 12,
'14': 15,
'15': 18,
'16': 21,
'17': 24,
'18': 27,
'19': 30,
'20': 33,
'21': 36,
'22': 39,
'23': 42,
'24': 45,
'25': 48,
'26': 51,
'27': 54,
'28': 57,
'29': 60,
'30': 63,
'31': 66,
'32': 69},
'motor_det_inc1': {'0': 14653,
'1': 14388,
'2': 14119,
'3': 13855,
'4': 13575,
'5': 13316,
'6': 13047,
'7': 12782,
'8': 12514,
'9': 12244,
'10': 11980,
'11': 11705,
'12': 11436,
'13': 11172,
'14': 10903,
'15': 10639,
'16': 10370,
'17': 10106,
'18': 9836,
'19': 9567,
'20': 9303,
'21': 9039,
'22': 8774,
'23': 8505,
'24': 8241,
'25': 7972,
'26': 7707,
'27': 7438,
'28': 7164,
'29': 6900,
'30': 6631,
'31': 6366,
'32': 6097}}


plt.figure();
plt.plot(d['motor_det_th1'].keys(), d['motor_det_th1'].values())






1 change: 1 addition & 0 deletions xas/vonhamos.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sklearn.covariance import MinCovDet

PILATUS_KEY = 'Pilatus 100k New'
# PILATUS_KEY = 'Pilatus 100k'

DET2KEY = {'Pilatus 100k' : 'pil100k',
'Pilatus 100k New': 'pil100k2'}
Expand Down

0 comments on commit 8304f4c

Please sign in to comment.