def timetool_data(event: Dict[str, Any]) -> float: """ Gets timetool data for an event retrieved from psana at LCLS. At LCLS, timetool data is recovered from an Epics variable. This function retrieves the information from the Epics variable identified by the 'psana_timetools_epics_name' entry in the 'data_retrieval_layer' parameter group of the configuration file. Arguments: event: A dictionary storing the event data. Returns: The readout of the timetool instrument. """ # TODO: Determine return type time_tl: Union[float, None] = event["additional_info"][ "psana_detector_interface"]["timetool_data"]() if time_tl is None: raise exceptions.OmDataExtractionError( "Could not retrieve time tool data from psana.") return time_tl
def xrays_active(event: Dict[str, Any]) -> bool: """ Initializes the psana Detector interface for the x-ray beam status at LCLS. At LCLS, the status of the x-ray beam is determined by monitoring an EVR event source. This function determines the status of the x-ray beam by checking if the EVR source provides a specific event code for the current frame. * The name of the event source must be specified in the 'psana_evr_source_name' entry of the 'data_retrieval_layer' parameter group of the configuration file. * The EVR event code that signals an active x-ray beam must be provided in the 'psana_evr_code_for_active_xray_beam" entry in the same parameter group. * If the source shows this EVR code for the current frame, the x-ray beam is considered active. Arguments: event: A dictionary storing the event data. Returns: True if the x-ray beam is active for the current frame. False otherwise. """ current_evr_codes: Union[ List[int], None] = event["additional_info"]["psana_detector_interface"][ "xrays_active"].psana_detector_handle.eventCodes(event["data"]) if current_evr_codes is None: raise exceptions.OmDataExtractionError( "Could not retrieve event codes from psana.") return event["additional_info"][ "active_xrays_evr_code"] in current_evr_codes
def detector_data(event: Dict[str, Any]) -> numpy.ndarray: """ Retrieves a CSPAD detector data frame from psana. This function retrieves a single CSPAD detector frame from psana. It returns the frame as a 2D array storing pixel data. Arguments: event: A dictionary storing the event data. Returns: One frame of detector data. """ cspad_psana: numpy.ndarray = event["additional_info"][ "psana_detector_interface"]["detector_data"].calib(event["data"]) if cspad_psana is None: raise exceptions.OmDataExtractionError( "Could not retrieve detector data from psana.") # Rearranges the data into 'slab' format. cspad_reshaped: numpy.ndarray = cspad_psana.reshape((4, 8, 185, 388)) cspad_slab: numpy.ndarray = numpy.zeros(shape=(1480, 1552), dtype=cspad_reshaped.dtype) index: int for index in range(cspad_reshaped.shape[0]): cspad_slab[:, index * cspad_reshaped.shape[3]:(index + 1) * cspad_reshaped.shape[3]] = cspad_reshaped[index].reshape( (cspad_reshaped.shape[1] * cspad_reshaped.shape[2], cspad_reshaped.shape[3])) return cspad_slab
def beam_energy(event: Dict[str, Any]) -> float: """ Gets the beam energy for an event retrieved from psana at LCLS. At LCLS, detector beam energy information is retrieved from an Epics variable. This function retrieves the information from the Epics variable identified by the 'psana_detector_distance_epics_name' entry in the 'data_retrieval_layer' parameter group of the configuration file. Arguments: event: A dictionary storing the event data. Returns: The energy of the beam in eV. """ # beam_en = ( # event["additional_info"]["psana_detector_interface"]["beam_energy"] # .get(event["data"]) # .ebeamPhotonEnergy() # ) wavelength: Union[float, None] = event["additional_info"][ "psana_detector_interface"]["beam_energy"]() if wavelength is None: raise exceptions.OmDataExtractionError( "Could not retrieve beam energy information from psana.") h: float = 6.626070e-34 # J.m c: float = 2.99792458e8 # m/s joulesPerEv: float = 1.602176621e-19 # J/eV photonEnergy: float = (h / joulesPerEv * c) / (wavelength * 1e-9) return photonEnergy
def epixka2m_detector_data(event: Dict[str, Any]) -> numpy.ndarray: """ Retrieves a Epix10KA 2M detector data frame from psana. This function retrieves a single EPIX10KA 2M detector frame from psana. It returns the frame as a 2D array storing pixel data. Arguments: event: A dictionary storing the event data. Returns: One frame of detector data. """ epixka2m_psana: numpy.ndarray = event["additional_info"][ "psana_detector_interface"]["detector_data"].calib(event["data"]) if epixka2m_psana is None: raise exceptions.OmDataExtractionError( "Could not retrieve detector data from psana.") # Rearranges the data into 'slab' format. epixka2m_reshaped: numpy.ndarray = epixka2m_psana.reshape(16 * 352, 384) return epixka2m_reshaped
def detector_data(event: Dict[str, Any]) -> numpy.ndarray: """ Retrieves one Jungfrau 4M detector data frame from psana. This function retrieves a single Jungfrau 4M detector frame from psana. It returns the frame as a 2D array storing pixel data. Arguments: event: A dictionary storing the event data. Returns: One frame of detector data. """ jungfrau_psana: numpy.ndarray = event["additional_info"][ "psana_detector_interface"]["detector_data"].calib(event["data"]) if jungfrau_psana is None: raise exceptions.OmDataExtractionError( "Could not retrieve detector data from psana.") # Rearranges the data into 'slab' format. jungfrau_reshaped: numpy.ndarray = jungfrau_psana.reshape(8 * 512, 1024) return jungfrau_reshaped
def extract_data( self, event: Dict[str, Any], ) -> Dict[str, Any]: """ Extracts data from a frame stored in an event. This function extracts data from a frame stored in an event. It works by calling, one after the other, all the Data Extraction Functions associated with the event, passing the event itself as input to each of them. The data extracted by each function is collected and returned to the caller. After retrieving a data event, OM calls this function on each frame in the event in sequence. The function is invoked each time on the full event: an internal flag keeps track of which frame should be processed in any given call. Arguments: event: A dictionary storing the event data. Returns: A dictionary storing the data returned by the Data Extraction Functions. * Each dictionary key identifies the Data Extraction Function used to extract the data. * The corresponding dictionary value stores the data returned by the function. """ data: Dict[str, Any] = {} f_name: str func: Callable[[Dict[str, Dict[str, Any]]], Any] for f_name, func in event["data_extraction_funcs"].items(): try: data[f_name] = func(event) # One should never do the following, but it is not possible to anticipate # every possible error raised by the facility frameworks. except Exception: exc_type, exc_value = sys.exc_info()[:2] if exc_type is not None: raise exceptions.OmDataExtractionError( "OM 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: Dict[str, Any]) -> numpy.ndarray: """ Retrieves one Rayonix 4M detector data frame from psana. This function retrieves a single Rayonix detector frame from psana. It returns the frame as a 2D array storing pixel data. Arguments: event: A dictionary storing the event data. Returns: One frame of detector data. """ rayonix_psana: numpy.ndarray = event["additional_info"][ "psana_detector_interface"]["detector_data"].calib(event["data"]) if rayonix_psana is None: raise exceptions.OmDataExtractionError( "Could not retrieve detector data from psana.") return rayonix_psana
def opal_data(event: Dict[str, Any]) -> numpy.ndarray: """ Gets Opal camera data for an event retrieved from psana at LCLS. This function retrieves data from the Opal camera identified by the 'psana_opal_name' entry in the 'data_retrieval_layer' parameter group of the configuration file . Arguments: event: A dictionary storing the event data. Returns: A 2D array containing the image from the Opal camera. """ op_data: Union[numpy.ndarray, None] = event["additional_info"][ "psana_detector_interface"]["opal_data"].calib(event["data"]) if op_data is None: raise exceptions.OmDataExtractionError( "Could not retrieve Opel camera data from psana.") return op_data
def timestamp(event: Dict[str, Any]) -> numpy.float64: """ Gets the timestamp of an event retrieved from psana at LCLS. At LCLS, the time stamp of a data event is provided by the LCLS timing system. Arguments: event: A dictionary storing the event data. Returns: The timestamp of the event in seconds from the Epoch. """ # Returns the timestamp stored in the event dictionary, without extracting it # again. # TODO: Determine return type timest: numpy.float64 = event["additional_info"]["timestamp"] if timest is None: raise exceptions.OmDataExtractionError( "Could not retrieve timestamp information from psana.") return timest
def digitizer_data(event: Dict[str, Any]) -> numpy.ndarray: """ 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 'data_retrieval_layer' parameter group of the configuration file. Arguments: event: A dictionary storing the event data. Returns: The waveform from the digitizer. """ # TODO: Determine return type digit_data: Union[numpy.ndarray, None] = event["additional_info"][ "psana_detector_interface"]["digitizer_data"].waveform(event["data"]) if digit_data is None: raise exceptions.OmDataExtractionError( "Could not retrieve digitizer data from psana.") return digit_data
def detector_distance(event: Dict[str, Any]) -> float: """ Gets the detector distance for an event retrieved from psana at LCLS. At LCLS, detector distance information is retrieved from an Epics variable. This function retrieves the information from the Epics variable identified by the 'psana_detector_distance_epics_name' entry in the 'data_retrieval_ayer' parameter group of the configuration file. Arguments: event: A dictionary storing the event data. Returns: The distance between the detector and the sample in mm. """ det_dist: Union[float, None] = event["additional_info"][ "psana_detector_interface"]["detector_distance"]() if det_dist is None: raise exceptions.OmDataExtractionError( "Could not retrieve detector distance information from psana.") return det_dist