-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lens4escan #1202
Draft
vespos
wants to merge
6
commits into
pcdshub:master
Choose a base branch
from
vespos:lens4escan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Lens4escan #1202
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a9b9275
working setup for Yano exp Feb 2024
vespos 13802a2
lens_for_escan not working
vespos de2990e
atol=5 is way too small for self-seeding
vespos b270fb4
Merge branch 'master' into lens4escan
vespos acb1268
Merge branch 'pcdshub:master' into lens4escan
vespos ee3c0b7
check in small changes
vespos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
from collections import defaultdict | ||
from datetime import date | ||
|
||
import numpy as np | ||
from ophyd.device import Component as Cpt | ||
from ophyd.device import FormattedComponent as FCpt | ||
from pcdscalc import be_lens_calcs as calcs | ||
|
@@ -132,15 +131,16 @@ class LensStackBase(BaseInterface, PseudoPositioner): | |
tab_component_names = True | ||
|
||
def __init__(self, x_prefix, y_prefix, z_prefix, lens_set, | ||
z_offset, z_dir, E, att_obj, lcls_obj=None, | ||
mono_obj=None, *args, **kwargs): | ||
z_offset, z_dir, E, att_obj, | ||
lcls_obj=None, mono_obj=None, *args, **kwargs): | ||
self.x_prefix = x_prefix | ||
self.y_prefix = y_prefix | ||
self.z_prefix = z_prefix | ||
self.z_dir = z_dir | ||
self.z_offset = z_offset | ||
|
||
self._E = E | ||
self._E = None | ||
self._which_E = None | ||
self._att_obj = att_obj | ||
self._lcls_obj = lcls_obj | ||
self._mono_obj = mono_obj | ||
|
@@ -150,6 +150,33 @@ def __init__(self, x_prefix, y_prefix, z_prefix, lens_set, | |
|
||
super().__init__(x_prefix, *args, **kwargs) | ||
|
||
@property | ||
def energy(self): | ||
if self._E is not None: | ||
self._which_E = "User" | ||
return self._E | ||
elif self._mono_obj is not None: | ||
if self._mono_obj.inserted: | ||
self._which_E = 'ccm' | ||
return self._mono_obj.energy.energy.get().readback | ||
else: | ||
print('CCM not in, defaulting to LCLS energy') | ||
|
||
if self._lcls_obj is not None: | ||
self._which_E = 'lcls' | ||
return self._lcls_obj.hard_e_energy.get() | ||
|
||
@energy.setter | ||
def energy(self, energy): | ||
self._E = energy | ||
|
||
def get_current_beam_info(self): | ||
dist_m = self.z.position / 1000 * self.z_dir + self.z_offset | ||
beamsize = calcs.calc_beam_fwhm(self.energy, self.lens_set, | ||
distance=dist_m) | ||
print(f"Distance for beamsize {beamsize}: {dist_m}m") | ||
return | ||
|
||
def tweak(self): | ||
""" | ||
Call the tweak function from `pcdsdevice.interface`. | ||
|
@@ -186,11 +213,13 @@ def forward(self, pseudo_pos): | |
AttributeError | ||
If pseudo motor is not setup for use. | ||
""" | ||
if not np.isclose(pseudo_pos.beam_size, self.beam_size.position): | ||
# if not np.isclose(pseudo_pos.beam_size, self.beam_size.position): | ||
if True: | ||
beam_size = pseudo_pos.beam_size | ||
dist = calcs.calc_distance_for_size(beam_size, self.lens_set, | ||
self._E)[0] | ||
self.energy)[0] | ||
z_pos = (dist - self.z_offset) * self.z_dir * 1000 | ||
z_pos = z_pos - 100 # dirty trick to get z in the range | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DO NOT FORGET TO REMOVE BEFORE MERGE |
||
else: | ||
z_pos = pseudo_pos.calib_z | ||
try: | ||
|
@@ -229,8 +258,9 @@ def inverse(self, real_pos): | |
""" | ||
dist_m = real_pos.z / 1000 * self.z_dir + self.z_offset | ||
logger.info('dist_m %s', dist_m) | ||
beamsize = calcs.calc_beam_fwhm(self._E, self.lens_set, | ||
distance=dist_m) | ||
beamsize = calcs.calc_beam_fwhm(self.energy, self.lens_set, | ||
distance=dist_m, | ||
printsummary=False) | ||
return self.PseudoPosition(calib_z=real_pos.z, beam_size=beamsize) | ||
|
||
def align(self, z_position=None, edge_offset=20): | ||
|
@@ -302,8 +332,9 @@ def move(self, position, wait=True, timeout=None, moved_cb=None): | |
positioner instance. | ||
""" | ||
if self._make_safe() is True: | ||
return super().move(position, wait=wait, timeout=timeout, | ||
moved_cb=moved_cb) | ||
st = super().move(position, wait=wait, timeout=timeout, | ||
moved_cb=moved_cb) | ||
return st | ||
else: | ||
logger.warning('Aborting moving for safety.') | ||
return | ||
|
@@ -322,20 +353,30 @@ def _make_safe(self): | |
logger.warning('Cannot do safe moveZ, no attenuator' | ||
' object provided.') | ||
return False | ||
filt, thk = self._att_obj.filters[0], 0 | ||
for f in self._att_obj.filters: | ||
t = f.thickness.get() | ||
if t > thk: | ||
filt, thk = f, t | ||
if not filt.inserted: | ||
filt.insert() | ||
if 'Attenuator' in self._att_obj.__class__.__name__: | ||
filt, thk = self._att_obj.filters[0], 0 | ||
for f in self._att_obj.filters: | ||
t = f.thickness.get() | ||
if t > thk: | ||
filt, thk = f, t | ||
if not filt.inserted: | ||
filt.insert(wait=True) | ||
time.sleep(0.01) | ||
if filt.inserted: | ||
logger.info('Beam stop attenuator moved in!') | ||
safe = True | ||
else: | ||
logger.warning('Beam stop attenuator did not move in!') | ||
safe = False | ||
elif 'PulsePicker' in self._att_obj.__class__.__name__: | ||
self._att_obj.close(wait=True) | ||
time.sleep(0.01) | ||
if filt.inserted: | ||
logger.info('Beam stop attenuator moved in!') | ||
safe = True | ||
else: | ||
logger.warning('Beam stop attenuator did not move in!') | ||
safe = False | ||
if self._att_obj.inserted: | ||
logger.info('Pulse picker closed!') | ||
safe = True | ||
else: | ||
logger.warning('Pulse picker did not close!') | ||
safe = False | ||
return safe | ||
|
||
|
||
|
@@ -530,11 +571,13 @@ def __init__(self, x_prefix, y_prefix, z_prefix, z_offset, z_dir, E, | |
|
||
if lens_set is None: | ||
# Defaulting this a the first set in the file for now | ||
lens_set = calcs.get_lens_set(1, self.path) | ||
self.lens_set = calcs.get_lens_set(1, self.path) | ||
else: | ||
self.lens_set = lens_set | ||
|
||
super().__init__( | ||
x_prefix, y_prefix, z_prefix, lens_set, z_offset, z_dir, E, | ||
att_obj, *args, **kwargs | ||
att_obj, lcls_obj, mono_obj, *args, **kwargs | ||
) | ||
|
||
def read_lens(self, print_only=False): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: to check again