def digitizer_data(event): # type (data_event.DataEvent) -> numpy.array TODO: Determine return type """ Get digitizer data for an event retrieved from psana at LCLS. This function retrieves data from the digitizer identified by the 'psana_digitizer_name' entry in the 'DataRetrievalLayer' configuration parameter group. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: numpy.array: the waveform from the digitizer. """ digit_data = event["psana_detector_interface"]["digitizer_data"].waveform( event.data) if digit_data is None: raise exceptions.OndaDataExtractionError( "Could not retrieve digitizer data from psana.") return digit_data
def detector_distance(event): # type (data_event.DataEvent) -> float """ Gets the detector distance for an event retrieved from psana at LCLS. Detector distance information is recovered from an Epics controller at LCLS . This function retrieves the information from the Epics controller identified by the 'psana_detector_distance_epics_name' entry in the 'DataRetrievalLayer' configuration parameter group. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: float: the distance between the detector and the sample in mm. """ det_dist = event.framework_info["psana_detector_interface"][ "detector_distance"]() if det_dist is None: raise exceptions.OndaDataExtractionError( "Could not retrieve detector distance information from psana.") return det_dist
def timetool_data(event): # type (data_event.DataEvent) -> float # TODO: Determine return type """ Gets timetool data for an event retrieved from psana at LCLS. Timetool data is recovered from an Epics controller at LCLS. This function retrieves the data from the Epics controller identified by the 'psana_timetools_epics_name' entry in the 'DataRetrievalLayer' configuration parameter group. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: float: the readout of the timetool instrument. """ time_tl = event.framework_info["psana_detector_interface"][ "timetool_data"]() if time_tl is None: raise exceptions.OndaDataExtractionError( "Could not retrieve time tool data from psana.") return time_tl
def extract_data(self): # type: () -> Dict[str, Any] """ Extracts data from an event. This function calls in sequence all the Data Extraction functions that have been attached to the event, and returns the extracted data. Returns: Dict[str, Any]: a dictionary storing the values returned by the Data Extraction functions. * Each dictionary key identifies a function attached to the event. * The corresponding dictionary value stores the data returned by the function. """ data = {} try: for f_name, func in iteritems(self.data_extraction_functions): data[f_name] = func(self) # One should never do the following, but it is not possible to anticipate # every possible error raised by the facility frameworks. except Exception: # pylint: disable=broad-except exc_type, exc_value = sys.exc_info()[:2] if exc_type is not None: raise exceptions.OndaDataExtractionError( "OnDA Warning: Cannot interpret {0} event data due to the " "following error: {1}: {2}".format(func.__name__, exc_type.__name__, exc_value)) return data
def detector_data(event, data_extraction_func_name): # type: (data_event.DataEvent, str) -> numpy.ndarray """ Retrieves from psana one frame of pnCCD detector data. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: numpy.ndarray: one frame of detector data. """ pnccd_psana = event.framework_info["psana_detector_interface"][ data_extraction_func_name].calib(event.framework_info["psana_event"]) if pnccd_psana is None: raise exceptions.OndaDataExtractionError( "Could not retrieve detector from psana.") # Rearranges the data into 'slab' format. pnccd_slab = numpy.zeros(shape=(1024, 1024), dtype=pnccd_psana.dtype) pnccd_slab[0:512, 0:512] = pnccd_psana[0] pnccd_slab[512:1024, 0:512] = pnccd_psana[1][::-1, ::-1] pnccd_slab[512:1024, 512:1024] = pnccd_psana[2][::-1, ::-1] pnccd_slab[0:512, 512:1024] = pnccd_psana[3] return pnccd_slab
def detector_data(event): # type: (data_event.DataEvent) -> numpy.ndarray """ Retrieves one frame of CSPAD detector data from psana. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: numpy.ndarray: one frame of detector data. """ cspad_psana = event.framework_info["psana_detector_interface"][ "detector_data" ].calib(event.data) if cspad_psana is None: raise exceptions.OndaDataExtractionError( "Could not retrieve detector data from psana." ) # Rearranges the data into 'slab' format. cspad_reshaped = cspad_psana.reshape((4, 8, 185, 388)) cspad_slab = numpy.zeros(shape=(1480, 1552), dtype=cspad_reshaped.dtype) for i in range(cspad_reshaped.shape[0]): cspad_slab[ :, i * cspad_reshaped.shape[3] : (i + 1) * cspad_reshaped.shape[3] ] = cspad_reshaped[i].reshape( (cspad_reshaped.shape[1] * cspad_reshaped.shape[2], cspad_reshaped.shape[3]) ) return cspad_slab
def beam_energy(event): # type (data_event.DataEvent) -> float """ Gets the beam energy for an event retrieved from psana at LCLS. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: float: the energy of the beam in eV. """ beam_en = ( event.framework_info["psana_detector_interface"]["beam_energy"].get( event.data).ebeamPhotonEnergy()) if beam_en is None: raise exceptions.OndaDataExtractionError( "Could not retrieve beam energy information from psana.") return beam_en
def timestamp(event): # type (data_event.DataEvent) -> numpy.float64 """ Gets the timestamp of an event retrieved from psana at LCLS. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: numpy.float64: the timestamp of the event in seconds from the Epoch. """ # Returns the timestamp stored in the event dictionary, without extracting it # again. timest = event.framework_info["timestamp"] if timest is None: raise exceptions.OndaDataExtractionError( "Could not retrieve timestamp information from psana.") return timest
def opal_data(event): # type (data_event.DataEvent) -> numpy.ndarray """ Gets Opal camera data for an event retrieved from psana at LCLS. This function retrieves data from the Opel camera identified by the 'psana_opal_name' entry in the 'DataRetrievalLayer' configuration parameter group. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: numpy.ndarray: a 2D array containing the image from the Opal camera. """ op_data = event["psana_detector_interface"]["opal_data"].calib(event.data) if op_data is None: raise exceptions.OndaDataExtractionError( "Could not retrieve Opel camera data from psana.") return op_data
def optical_laser_active(event): # type (data_event.DataEvent) -> bool """ Gets the status of an optical laser for an event retrieved from psana at LCLS. The status of an optical laser is determined by monitoring an EVR event source at LCLS. This function determines the status of the optical laser by checking if the EVR source provides a specific event code for the current frame. * The name of the source must be specified in the 'psana_evr_source_name' entry of the 'DataRetrievalLayer' configuration parameter group. * The EVR event code that signals an active optical laser must be provided in the 'psana_evr_code_for_active_optical_laser' entry in the same parameter group. * If the source shows this EVR code for the current frame, the optical laser is considered active. Arguments: event (:class:`~onda.utils.data_event.DataEvent`): an object storing the event data. Returns: bool: True if the optical laser is active for the current frame. False otherwise. """ current_evr_codes = event["psana_detector_interface"][ "optical_laser_active"].psana_detector_handle.eventCodes(event.data) if current_evr_codes is None: raise exceptions.OndaDataExtractionError( "Could not retrieve event codes from psana.") return (event["psana_detector_interface"] ["optical_laser_active"].active_laser_evr_code in current_evr_codes)