LaserCoordination¶
- class lsst.ts.externalscripts.coordination.LaserCoordination(index, descr='')¶
- Bases: - BaseScript- ES-Coordination-Laser-001: Laser coordination - A SAL script that is used for testing two lab LinearStages, the TunableLaser and an Electrometer. It propagates the laser while the two linear stages move in a grid pattern with a given step increment. At each step, an electrometer will take a reading. The data is written to a csv file and then plotted as coordinate vs. electrometer reading. - Parameters:
- Attributes:
 - Attributes Summary - Get the checkpoints at which to pause and stop. - Get the group ID (a - str), or "" if not set.- Get the block ID (a - str), or "" if not set.- Get the current state. - Get the name of the current - state.state.- Methods Summary - amain(**kwargs)- Run the script from the command line. - assert_state(action, states)- Assert that the current state is in - statesand the script is not exiting.- checkpoint([name])- Await this at any "nice" point your script can be paused or stopped. - cleanup()- Perform final cleanup, if any. - close([exception, cancel_start])- Shut down, clean up resources and set done_task done. - Shut down pending tasks. - configure(config)- Configures the script. - do_configure(data)- Configure the currently loaded script. - do_resume(data)- Resume the currently paused script. - do_run(data)- Run the script and quit. - do_setCheckpoints(data)- Set or clear the checkpoints at which to pause and stop. - do_setGroupId(data)- Set or clear the group_id attribute. - do_setLogLevel(data)- Set logging level. - do_stop(data)- Stop the script. - Return a jsonschema to validate configuration, as a - dict.- make_from_cmd_line(**kwargs)- Make a script from command-line arguments. - Return the group ID supplemented with a new subgroup. - Output the logLevel event. - run()- Run the script. - set_metadata(metadata)- Set metadata fields in the provided struct, given the current configuration. - set_state([state, reason, keep_old_reason, ...])- Set the script state. - Handle termination signals. - start()- Finish construction. - Additional work after - startbefore fully started.- Attributes Documentation - checkpoints¶
- Get the checkpoints at which to pause and stop. - Returns - self.evt_checkpoints.datawhich has these fields:- pause: checkpoints at which to pause, a regular expression
- stop: checkpoints at which to stop, a regular expression
 
 - domain¶
 - state¶
- Get the current state. - Returns - self.evt_state.data, which has these fields:
 - Methods Documentation - async classmethod amain(**kwargs: Any) None¶
- Run the script from the command line. - Parameters:
- kwargs
- Keyword arguments for the script constructor. Must not include - index. Ignored (other than testing for- index) if the command specifies- --schema.
 
- Raises:
- RuntimeError
- If - kwargsincludes- index.
 
 - Notes - The final return code will be: - 0 if final state is - lsst.ts.xml.enums.Script.ScriptState.DONEor- lsst.ts.xml.enums.Script.ScriptState.STOPPED.
- 1 if final state is anything else, or if script.done_task is an exception (which would be raised by the script’s cleanup code). 
 - Issues a RuntimeWarning if script.done_task is an exception and the final script state is anything other than Failed. This should never happen. 
 - assert_state(action: str, states: Sequence[ScriptState]) None¶
- Assert that the current state is in - statesand the script is not exiting.
 - async checkpoint(name: str = '') None¶
- Await this at any “nice” point your script can be paused or stopped. - Parameters:
- namestr, optional
- Name of checkpoint; “” if it has no name. 
 
- name
- Raises:
 
 - async cleanup() None¶
- Perform final cleanup, if any. - This method is called as the script state is exiting, unless the script had not yet started to run, or the script process is aborted by SIGTERM or SIGKILL. 
 - async close(exception: Exception | None = None, cancel_start: bool = True) None¶
- Shut down, clean up resources and set done_task done. - May be called multiple times. The first call closes the Controller; subsequent calls wait until the Controller is closed. - Subclasses should override - close_tasksinstead of- close, unless you have a good reason to do otherwise.- Parameters:
- exceptionException, optional
- The exception that caused stopping, if any, in which case the - self.done_taskexception is set to this value. Specify- Nonefor a normal exit, in which case the- self.done_taskresult is set to- None.
- cancel_startbool, optional
- Cancel the start task? Leave this true unless calling this from the start task. 
 
- exception
 - Notes - Removes the SAL log handler, calls - close_tasksto stop all background tasks, pauses briefly to allow final SAL messages to be sent, then closes the domain.
 - async close_tasks() None¶
- Shut down pending tasks. Called by - close.- Perform all cleanup other than disabling logging to SAL and closing the domain. 
 - async configure(config)¶
- Configures the script. - Parameters:
- wanted_remoteslistofstr
- A list of remotes_names that should be used for running the script. - full list: - ‘linear_stage_1_remote’ 
- ‘linear_stage_2_remote’ 
- ‘electrometer_remote’ 
- ‘tunable_laser_remote’ 
 
- wavelengthsrange
- A range of wavelengths to iterate through. Units: Nanometers 
- file_location
- stepsint(the default is 5 mm)
- The amount of mm to move the linear stages by. 
- max_linear_stage_positionint
- Units: millimeters 
- integration_timeint
- Units: seconds 
- scan_durationfloat
- Units: seconds 
- timeoutint
- Units: seconds 
 
- wanted_remotes
 
 - async do_configure(data: BaseMsgType) None¶
- Configure the currently loaded script. - Parameters:
- datacmd_configure.DataType
- Configuration. 
 
- data
- Raises:
- base.ExpectedError
- If - self.state.stateis not- lsst.ts.xml.enums.Script.ScriptState.UNCONFIGURED.
 
 - Notes - This method does the following: - Parse the - configfield as yaml-encoded- dictand validate it (including setting default values).
- Call - configure.
- Set the pause and stop checkpoints. 
- Set the log level if - data.logLevel != 0.
- Call - set_metadata.
- Output the metadata event. 
- Change the script state to - lsst.ts.xml.enums.Script.ScriptState.CONFIGURED.
 
 - async do_resume(data: BaseMsgType) None¶
- Resume the currently paused script. - Parameters:
- datacmd_resume.DataType
- Ignored. 
 
- data
- Raises:
- base.ExpectedError
- If - self.state.stateis not- lsst.ts.xml.enums.Script.ScriptState.PAUSED.
 
 
 - async do_run(data: BaseMsgType) None¶
- Run the script and quit. - The script must have been configured and the group ID set. - Parameters:
- datacmd_run.DataType
- Ignored. 
 
- data
- Raises:
- base.ExpectedError
- If - self.state.stateis not- lsst.ts.xml.enums.Script.ScriptState.CONFIGURED. If- self.group_idis blank.
 
 
 - async do_setCheckpoints(data: BaseMsgType) None¶
- Set or clear the checkpoints at which to pause and stop. - This command is deprecated. Please set the checkpoints using the - configurecommand.- Parameters:
- datacmd_setCheckpoints.DataType
- Names of checkpoints for pausing and stopping, each a single regular expression; “” for no checkpoints, “.*” for all. 
 
- data
- Raises:
- base.ExpectedError
- If - self.state.stateis not one of:- lsst.ts.xml.enums.Script.ScriptState.UNCONFIGURED
- lsst.ts.xml.enums.Script.ScriptState.CONFIGURED
- lsst.ts.xml.enums.Script.ScriptState.RUNNING
- lsst.ts.xml.enums.Script.ScriptState.PAUSED
 
 
 
 - async do_setGroupId(data: BaseMsgType) None¶
- Set or clear the group_id attribute. - The script must be in the Configured state. This command may be called multiple times. It is typically called when the script reaches the top position on the script queue. - Parameters:
- datacmd_setGroupId.DataType
- Group ID, or “” to clear the group ID. 
 
- data
- Raises:
- base.ExpectedError
- If - state.stateis not- lsst.ts.xml.enums.Script.ScriptState.CONFIGURED.
 
 
 - async do_setLogLevel(data: BaseMsgType) None¶
- Set logging level. - Parameters:
- datacmd_setLogLevel.DataType
- Logging level. 
 
- data
 
 - async do_stop(data: BaseMsgType) None¶
- Stop the script. - Parameters:
- datacmd_stop.DataType
- Ignored. 
 
- data
 - Notes - This is a no-op if the script is already exiting. This does not wait for _exit to run. 
 - classmethod get_schema()¶
- Return a jsonschema to validate configuration, as a - dict.- Please provide default values for all fields for which defaults make sense. This makes the script easier to use. - If your script has no configuration then return - None, in which case the- configfield of the- configurecommand must be an empty string.
 - classmethod make_from_cmd_line(**kwargs: Any) BaseScript | None¶
- Make a script from command-line arguments. - Return None if - --schemaspecified.- Parameters:
- kwargs
- Keyword arguments for the script constructor. Must not include - index.
 
- Raises:
- RuntimeError
- If - kwargsincludes- index.
 
 
 - next_supplemented_group_id() str¶
- Return the group ID supplemented with a new subgroup. - The returned string has this format: f”{self.group_id}#{subgroup_id}”, where - subgroup_idis an integer that starts at 1 and is incremented for every call to this method.- Raises:
- RuntimeError
- If there is no group ID. 
 
 
 - async run()¶
- Run the script. - Your subclass must provide an implementation, as follows: - At points where you support pausing call - checkpoint.
- Raise an exception on error. Raise - base.ExpectedErrorto avoid logging a traceback.
 - Notes - This method is only called when the script state is - ScriptState.CONFIGURED. The remaining state transitions are handled automatically.
 - set_metadata(metadata)¶
- Set metadata fields in the provided struct, given the current configuration. - Parameters:
- metadataself.evt_metadata.DataType()
- Metadata to update. Set those fields for which you have useful information. 
 
- metadata
 - Notes - This method is called after - configureby- do_configure. The script state will be- ScriptState.UNCONFIGURED.
 - async set_state(state: ScriptState | int | None = None, reason: str | None = None, keep_old_reason: bool = False, force_output: bool = False) None¶
- Set the script state. - Parameters:
- stateScriptStateorint, optional
- New state, or None if no change 
- reasonstr, optional
- Reason for state change. - Nonefor no new reason.
- keep_old_reasonbool
- If true, keep old reason; append the - reasonargument after “;” if it is is a non-empty string. If false replace with- reason, or “” if- reasonis- None.
- force_outputbool, optional
- If true the output even if not changed. 
 
- state
 - Notes - The lastCheckpoint field is set from self.last_checkpoint, and the numCheckpoints field is set from self.num_checkpoints.