MeasInterruptT=KeyboardInterrupt|BreakConditionInterrupt|Nonedef_register_parameters(meas:Measurement,param_meas:Sequence[ParamMeasT],setpoints:Sequence[ParameterBase]|None=None,shapes:Shapes|None=None,)->None:real_parameters=[paramforparaminparam_measifisinstance(param,ParameterBase)]forparameterinreal_parameters:meas.register_parameter(parameter,setpoints=setpoints)ifshapesisnotNone:parameter_names=[param.full_nameforparaminreal_parameters]forparaminreal_parameters:ifisinstance(param,MultiParameter):parameter_names.extend(param.full_names)filtered_shapes={name:shapeforname,shapeinshapes.items()ifnameinparameter_names}meas.set_shapes(shapes=filtered_shapes)def_set_write_period(meas:Measurement,write_period:float|None=None)->None:ifwrite_periodisnotNone:meas.write_period=write_perioddef_handle_plotting(data:DataSetProtocol,do_plot:bool=True,interrupted:MeasInterruptT=None,)->AxesTupleListWithDataSet:""" Save the plots created by datasaver as pdf and png Args: data: a dataset to generate plots from as plot. do_plot: Should a plot be produced interrupted: If the measurement was interrupted, this will be the exception. """res:AxesTupleListWithDataSetifdo_plot:res=plot_and_save_image(data)else:res=data,(None,),(None,)ifinterrupted:log.warning(f"Measurement has been interrupted, data may be incomplete: {interrupted}")returnresdef_register_actions(meas:Measurement,enter_actions:ActionsT,exit_actions:ActionsT)->None:foractioninenter_actions:# this omits the possibility of passing# argument to enter and exit actions.# Do we want that?meas.add_before_run(action,())foractioninexit_actions:meas.add_after_run(action,())@contextmanagerdefcatch_interrupts()->Iterator[Callable[[],MeasInterruptT|None]]:interrupt_exception:MeasInterruptT|None=Noneinterrupt_raised=Falsedefget_interrupt_exception()->MeasInterruptT|None:nonlocalinterrupt_exceptionreturninterrupt_exceptiontry:yieldget_interrupt_exceptionexceptKeyboardInterruptase:interrupt_exception=einterrupt_raised=Trueraise# Re-raise KeyboardInterruptexceptBreakConditionInterruptase:interrupt_exception=einterrupt_raised=True# Don't re-raise BreakConditionInterruptfinally:ifinterrupt_raised:log.warning(f"Measurement has been interrupted, data may be incomplete: {interrupt_exception}")