pcdsdevices.lens.LensStack
- class pcdsdevices.lens.LensStack(x_prefix, y_prefix, z_prefix, z_offset, z_dir, E, att_obj, lcls_obj=None, mono_obj=None, *args, path, lens_set=None, **kwargs)
Class for Be lens.
- Parameters:
x_prefix (str) – The EPICS prefix that identifies the x motor.
y_prefix (str) – The EPICS prefix that identifies the y motor.
z_prefix (str) – The EPICS prefix that identifies the z motor.
lens_set (list, optional) – List of lens sets. e.g. [numer1, lensthick1, number2, lensthick2…]
z_offset (number) – Distance from sample to lens_z=0 in meters.
z_dir (number) – 1 or -1, represents beam direction wrt z direction.
E (number, optional) – Beam energy
att_obj (attenuator object, optional)
lcls_obj – Object that gets PVs from lcls (for energy)
mono_obj – Object that gets energy from monochromator
path (str) – Path to the file that defines which lenses are being used.
Examples
Before using the LclsStack class configure the defaults used in some calculations:
>>> import pcdsdevices.lens as lens >>> import pcdscalc.be_lens_calcs as be
>>> be.configure_defaults(distance=4, fwhm_unfocused=500e-6)
Also, provide the path of the be lens set file to be used for the calculations.
If no lens sets are added in the file yet, use the
be_lens_calcs.set_lens_set_to_file
function to set the lens sets:>>> path = '../path/to/lens_set'
>>> sets_list = [[3, 0.0001, 1, 0.0002], [1, 0.0001, 1, 0.0003, 1, 0.0005], [2, 0.0001, 1, 0.0005]] >>> be.set_lens_set_to_file(sets_list, path)
Make sure you have an attenuator object imported eg.:
>>> from xpp.db import xpp_attenuator
or create one:
>>> from pcdsdevices.attenuator import Attenuator >>> att = Attenuator('att', 4, name='att')
Import the LCLS object:
>>> from xpp.db import lcls
or create one:
>>> from pcdsdevices.beam_stats import LCLS >>> lcls = LCLS()
Create the LensStack() object by providing the x, y and z
prefixes
, as well as all the other parameters.>>> be_stack = lens.LensStack(path=path, x_prefix='X:PREF', y_prefix='Y:PREF', z_prefix='Z:PREF', att_obj=att, z_offset=3.852, z_dir=-1, E=8, name='be_stack')
For this documentation purposes we will use the SimLensStack:
>>> sim = lens.SimLensStack(path=path, x_prefix='x', y_prefix='y', z_prefix='z', z_offset=3.852, z_dir=-1, E=8, att_obj=att, name='sim') FWHM at lens : 5.000e-04 waist : 3.113e-07 waist FWHM : 3.666e-07 rayleigh_range : 1.965e-03 focal length : 2.680e+00 size : 2.092e-04 size FWHM : 2.463e-04
You can check what current sets are in the file as follows:
>>> sim.read_lens(print_only=True) [[3, 0.0001, 1, 0.0002], [1, 0.0001, 1, 0.0003, 1, 0.0005], [2, 0.0001, 1, 0.0005]]
If
print_only
isFalse
,self.lens_pack
will be set to use the current sets:>>> sim.read_lens() [[3, 0.0001, 1, 0.0002], [1, 0.0001, 1, 0.0003, 1, 0.0005], [2, 0.0001, 1, 0.0005]]
>>> sim.lens_pack [[3, 0.0001, 1, 0.0002], [1, 0.0001, 1, 0.0003, 1, 0.0005], [2, 0.0001, 1, 0.0005]]
You can also create the lens sets using this class like so:
>>> sets_list = [[3, 0.0001, 1, 0.0002], [1, 0.0001, 1, 0.0003, 1, 0.0005], [2, 0.0001, 1, 0.0005]] >>> sim.create_lens(sets_list)
For calculations, one set at the time will be used. Use the
set_lens_set
method to choose what set to use. Ex. to use the second set:>>> sim.set_lens_set(2)
>>> sim.lens_set [1, 0.0001, 1, 0.0003, 1, 0.0005]
Now you can try to tweak the two motors with key arrors using
sim.tweak()
or with calling the relative moveumvr
:>>> sim.x.umvr(3)
You can then call the
align()
function to create presets>>> sim.align() FWHM at lens : 5.000e-04 waist : 3.113e-07 waist FWHM : 3.666e-07 rayleigh_range : 1.965e-03 focal length : 2.680e+00 size : 2.092e-04 size FWHM : 2.463e-04 sim_x: -0.1000, sim_y: 0.2000, scale: 0.1
Check the positions of the motors like so:
>>> sim.x sim_x ----- preset: align_position_one position: -0.1
>>> sim.calib_z() FWHM at lens : 5.000e-04 waist : 3.113e-07 waist FWHM : 3.666e-07 rayleigh_range : 1.965e-03 focal length : 2.680e+00 size : 2.092e-04 size FWHM : 2.463e-04 80
>>> sim.beam_size() FWHM at lens : 5.000e-04 waist : 3.113e-07 waist FWHM : 3.666e-07 rayleigh_range : 1.965e-03 focal length : 2.680e+00 size : 2.092e-04 size FWHM : 2.463e-04 0.00024626624937199417
Now if you move the
calib_z
it will move the x, y, and z motors at the same time based on the last time we ran thealign
method.>>> sim.calib_z.move(pos)
The
beam_size
will do a calculation on top of that and move thecalib_z
motor underneath, so you can move x, y, and z appropriately to get the correct spot size at the sample:>>> sim.beam_size.move(size)
Attribute
Class
Suffix
Docs
Kind
Notes
x (FCpt)
{self.x_prefix}
normal
Inherited from
LensStackBase
y (FCpt)
{self.y_prefix}
normal
Inherited from
LensStackBase
z (FCpt)
{self.z_prefix}
normal
Inherited from
LensStackBase
calib_z
normal
Inherited from
LensStackBase
beam_size
normal
Inherited from
LensStackBase
Methods
- align(z_position=None, edge_offset=20)
Generate equations for aligning the beam based on user input.
This program uses two points, one made on the lower limit and the other made on the upper limit, after the user uses the tweak function to put the beam into alignment, and uses those two points to make two equations to determine a y- and x-position for any z-value the user wants that will keep the beam focused. The beam line will be saved in a file in the presets folder, and can be used with the pseudo positioner on the z-axis. If called with an integer, automatically moves the z-motor.
- Parameters:
z_position (number, optional)
edge_offset (number, optional)
- check_single(pseudo_single, single_pos)
Check if a new position for a single pseudo positioner is valid
- configure(d: Dict[str, Any]) Tuple[Dict[str, Any], Dict[str, Any]]
Configure the device for something during a run
This default implementation allows the user to change any of the
configuration_attrs
. Subclasses might override this to perform additional input validation, cleanup, etc.- Parameters:
d (dict) – The configuration dictionary. To specify the order that the changes should be made, use an OrderedDict.
- Returns:
(old, new) tuple of dictionaries
Where old and new are pre- and post-configure configuration states.
- create_lens(lens_set, make_backup=True)
Write lens set to the file provided when creating this object.
- Parameters:
Examples
>>> sets_list = [[3, 0.0001, 1, 0.0002], [1, 0.0001, 1, 0.0003, 1, 0.0005], [2, 0.0001, 1, 0.0005]] >>> create_lens(sets_list)
- describe() OrderedDictType[str, Dict[str, Any]]
Provide schema and meta-data for
read()
.This keys in the
OrderedDict
this method returns must match the keys in theOrderedDict
return byread()
.This provides schema related information, (ex shape, dtype), the source (ex PV name), and if available, units, limits, precision etc.
- Returns:
data_keys (OrderedDict) – The keys must be strings and the values must be dict-like with the
event_model.event_descriptor.data_key
schema.
- forward(pseudo_pos)
Run a forward(pseudo -> real) calculation.
Calculate a RealPosition from a given PseudoPosition.
calc_distance_for_size
calculates distance for beam size (fwhm size)- Parameters:
pseudo_pos (PseudoPosition) – Pseudo position to move to.
- Returns:
RealPosition
- Raises:
AttributeError – If pseudo motor is not setup for use.
- get(**kwargs)
Get the value of all components in the device
Keyword arguments are passed onto each signal.get(). Components beginning with an underscore will not be included.
- inverse(real_pos)
Run an inverse (real -> pseudo) calculation.
calc_beam_fwhm
returns fwhm (Full width at half maximum) size for certain lenses configuration and energy at a given distance.- Parameters:
real_pos (RealPosition)
- Returns:
PseudoPosition
- move(position, wait=True, timeout=None, moved_cb=None)
Move to a specified position, optionally waiting for motion to complete.
Moves z to pos and x and y to their calibrated offset positions. If safe is True, then
._make_safe()
gets called TODO: should i have asafe
attribute here like the old code?- Parameters:
position – Pseudo position to move to.
wait (bool, optional) – Defaults to True
timeout (float, optional) – Maximum time to wait for the motion. If None, the default timeout for this positioner is used.
moved_cb (callable) – Call this callback when movement has finished. This callback must accept one keyword argument: ‘obj’ which will be set to this positioner instance.
- move_single(pseudo, position, **kwargs)
Move one PseudoSingle axis to a position
All other positioners will use their current setpoint/target value, if available. Failing that, their current readback value will be used (see
PseudoSingle.sync
andPseudoSingle.target
).
- post_elog_status()
Post device status to the primary elog, if possible.
- read() OrderedDictType[str, Dict[str, Any]]
Read data from the device.
This method is expected to be as instantaneous as possible, with any substantial acquisition time taken care of in
trigger()
.The
OrderedDict
returned by this method must have identical keys (in the same order) as theOrderedDict
returned bydescribe()
.By convention, the first key in the return is the ‘primary’ key and maybe used by heuristics in
bluesky
.The values in the ordered dictionary must be dict (-likes) with the keys
{'value', 'timestamp'}
. The'value'
may have any type, the timestamp must be a float UNIX epoch timestamp in UTC.- Returns:
data (OrderedDict) – The keys must be strings and the values must be dict-like with the keys
{'value', 'timestamp'}
- read_configuration() OrderedDictType[str, Dict[str, Any]]
Dictionary mapping names to value dicts with keys: value, timestamp
To control which fields are included, change the Component kinds on the device, or modify the
configuration_attrs
list.
- read_lens(print_only=False)
Read the lens sets from file provided in the path.
- screen()
Open a screen for controlling the device.
Default behavior is the typhos screen, but this method can be overridden for more specialized screens.
- set(position, **kwargs)
Move to a new position asynchronously
- Parameters:
position (PseudoPosition) – Position for the all of the pseudo axes
- Returns:
status (MoveStatus)
- set_current_position(position)
Adjust all offsets so that the pseudo position matches the input.
This will raise an AttributeError if any of the real motors is missing a
set_current_position
method.- Parameters:
position (PseudoPos) – The position
- set_lens_set(index)
Temporary method to get the set from the lens set file at the index.
TODO: this method will obviously change when we know how we want to get the lens, for now it is merely choosing it manually.
- Parameters:
index (int) – Index to indicate which set in the list to get.
Examples
>>> set_lens_set(2)
- stop(success=False)
Stop the Device and all (instantiated) subdevices
- summary()
- to_pseudo_tuple(*args, **kwargs)
Convert arguments to a PseudoPosition namedtuple and kwargs
- to_real_tuple(*args, **kwargs)
Convert arguments to a RealPosition namedtuple and kwargs
- trigger() StatusBase
Trigger the device and return status object.
This method is responsible for implementing ‘trigger’ or ‘acquire’ functionality of this device.
If there is an appreciable time between triggering the device and it being able to be read (via the
read()
method) then this method is also responsible for arranging that theStatusBase
object returned by this method is notified when the device is ready to be read.If there is no delay between triggering and being readable, then this method must return a
StatusBase
object which is already completed.- Returns:
status (StatusBase) –
StatusBase
object which will be marked as complete when the device is ready to be read.
- tweak()
Call the tweak function from
pcdsdevice.interface
.Use the Left arrow to move x motor left. Use the Right arrow to move x motor right. Use the Down arrow to move y motor down. Use the Up arrow to move y motor up. Use Shift & Up arrow to scale*2. Use Shift & Down arrow to scale/2. Press q to quit.
Attributes
- backup_path
- composite_egu
The composite engineering units (EGU) from all PseudoSingles
- concurrent
If concurrent is set, motors will move concurrently (in parallel)
- configuration_attrs
- connected
- egu
The engineering units (EGU) for positions
- high_limit
All PseudoSingle high limits as a namedtuple
- hints
- kind
- limits
All PseudoSingle limits as a namedtuple
- low_limit
All PseudoSingle low limits as a namedtuple
- moving
- position
Pseudo motor position namedtuple
- pseudo_positioners
Pseudo positioners instances in a namedtuple
- Returns:
positioner_instances (PseudoPosition)
- real_position
Real motor position namedtuple
- real_positioners
Real positioners instances in a namedtuple
- Returns:
positioner_instances (RealPosition)
- sequential
If sequential is set, motors will move in the sequence they were defined in (i.e., in series)
- settle_time
Amount of time to wait after moves to report status completion
- subscriptions: ClassVar[FrozenSet[str]] = frozenset({'_req_done', 'acq_done', 'done_moving', 'readback', 'start_moving'})
- target
Last commanded target positions
- timeout
Amount of time to wait before to considering a motion as failed