Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added back swaxs files #16

Open
wants to merge 3 commits into
base: feature/swaxs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/om/algorithms/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def get_radial_bin_labels(self) -> NDArray[numpy.int_]:
"""
return self._radial_bin_labels

def get_num_radial_bins(self):
return self._num_bins

def get_bad_pixel_map(self) -> Union[NDArray[numpy.bool_], None]:
"""
Gets the bad pixel map provided to the algorithm.
Expand Down
2 changes: 2 additions & 0 deletions src/om/data_retrieval_layer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
from .data_retrieval_psana import ( # noqa: F401
CxiLclsCspadDataRetrieval,
CxiLclsDataRetrieval,
CxiLclsEpix10kaDataRetrieval,
CxiLclsEpix10kaSinglePanelDataRetrieval,
LclsEpix100DataRetrieval,
MfxLclsDataRetrieval,
MfxLclsRayonixDataRetrieval,
Expand Down
2 changes: 1 addition & 1 deletion src/om/data_retrieval_layer/data_event_handlers_psana.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _psana_offline_event_generator(
# processing node is assigned the residual events.
run: Any
for run in psana_source.runs():
times: Any = run.times()
times: Any = run.times()#[:100]
num_events_curr_node: int = int(
numpy.ceil(len(times) / float(mpi_pool_size - 1))
)
Expand Down
202 changes: 200 additions & 2 deletions src/om/data_retrieval_layer/data_retrieval_psana.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DiodeTotalIntensityPsana,
EpicsVariablePsana,
Epix10kaPsana,
Epix10kaSinglePanelPsana,
Epix100Psana,
EventIdPsana,
EvrCodesPsana,
Expand Down Expand Up @@ -199,10 +200,109 @@ def __init__(self, *, monitor_parameters: MonitorParameters, source: str):
data_source_name="detector_distance",
monitor_parameters=monitor_parameters,
),
"detector_distance": FloatEntryFromConfiguration(
data_source_name="fallback_detector_distance_in_mm",
# "detector_distance": FloatEntryFromConfiguration(
# data_source_name="fallback_detector_distance_in_mm",
# monitor_parameters=monitor_parameters,
# ),
"timetool_data": EpicsVariablePsana(
data_source_name="timetool", monitor_parameters=monitor_parameters
),
"optical_laser_active": EvrCodesPsana(
data_source_name="active_optical_laser",
monitor_parameters=monitor_parameters,
),
"xrays_active": EvrCodesPsana(
data_source_name="active_xrays",
monitor_parameters=monitor_parameters,
),
"post_sample_intensity": DiodeTotalIntensityPsana(
data_source_name="post_sample_intensity",
monitor_parameters=monitor_parameters,
),
"lcls_extra": LclsExtraPsana(
data_source_name="lcls_extra",
monitor_parameters=monitor_parameters,
),
}

self._data_event_handler: OmDataEventHandlerProtocol = PsanaDataEventHandler(
source=source,
monitor_parameters=monitor_parameters,
data_sources=data_sources,
)

def get_data_event_handler(self) -> OmDataEventHandlerProtocol:
"""
Retrieves the Data Event Handler used by the Data Retrieval class.

Please see the documentation of the base Protocol class for additional
information about this method.

Returns:

The Data Event Handler used by the Data Retrieval class.
"""
return self._data_event_handler

class CxiLclsEpix10kaDataRetrieval(OmDataRetrievalProtocol):
"""
See documentation of the `__init__` function.
"""

def __init__(self, *, monitor_parameters: MonitorParameters, source: str):
"""
Data Retrieval from psana at the CXI beamline of the LCLS facility (CSPAD).

This class implements OM's Data Retrieval Layer for the CXI beamline of the
LCLS facility, using the CSPAD x-ray detector. This detector was used at the
beamline until early 2020.

This class implements the interface described by its base Protocol class.
Please see the documentation of that class for additional information about
the interface.

* This class considers an individual data event as equivalent to the content of
a psana event, which stores data related to a single detector frame.

* A string combining psana's timestamp and fiducial information, with the
following format:
`{timestamp: seconds}-{timestamp: nanoseconds}-{fiducials}`, is used as event
identifier.

* Psana provides timestamp, beam energy and detector distance data for each
event, retrieved from various sensors in the system.

* The source string required by this Data Retrieval class is a string of the
type used by psana to identify specific runs, experiments, or live data
streams.

Arguments:

monitor_parameters: An object OM's configuration parameters.

source: A string describing the data event source.
"""
data_sources: Dict[str, OmDataSourceProtocol] = {
"timestamp": TimestampPsana(
data_source_name="timestamp", monitor_parameters=monitor_parameters
),
"event_id": EventIdPsana(
data_source_name="eventid", monitor_parameters=monitor_parameters
),
"detector_data": Epix10kaPsana(
data_source_name="detector", monitor_parameters=monitor_parameters
),
"beam_energy": BeamEnergyPsana(
data_source_name="beam_energy", monitor_parameters=monitor_parameters
),
"detector_distance": EpicsVariablePsana(
data_source_name="detector_distance",
monitor_parameters=monitor_parameters,
),
# "detector_distance": FloatEntryFromConfiguration(
# data_source_name="fallback_detector_distance_in_mm",
# monitor_parameters=monitor_parameters,
# ),
"timetool_data": EpicsVariablePsana(
data_source_name="timetool", monitor_parameters=monitor_parameters
),
Expand Down Expand Up @@ -243,6 +343,104 @@ def get_data_event_handler(self) -> OmDataEventHandlerProtocol:
"""
return self._data_event_handler

class CxiLclsEpix10kaSinglePanelDataRetrieval(OmDataRetrievalProtocol):
"""
See documentation of the `__init__` function.
"""

def __init__(self, *, monitor_parameters: MonitorParameters, source: str):
"""
Data Retrieval from psana at the CXI beamline of the LCLS facility (CSPAD).

This class implements OM's Data Retrieval Layer for the CXI beamline of the
LCLS facility, using the CSPAD x-ray detector. This detector was used at the
beamline until early 2020.

This class implements the interface described by its base Protocol class.
Please see the documentation of that class for additional information about
the interface.

* This class considers an individual data event as equivalent to the content of
a psana event, which stores data related to a single detector frame.

* A string combining psana's timestamp and fiducial information, with the
following format:
`{timestamp: seconds}-{timestamp: nanoseconds}-{fiducials}`, is used as event
identifier.

* Psana provides timestamp, beam energy and detector distance data for each
event, retrieved from various sensors in the system.

* The source string required by this Data Retrieval class is a string of the
type used by psana to identify specific runs, experiments, or live data
streams.

Arguments:

monitor_parameters: An object OM's configuration parameters.

source: A string describing the data event source.
"""
data_sources: Dict[str, OmDataSourceProtocol] = {
"timestamp": TimestampPsana(
data_source_name="timestamp", monitor_parameters=monitor_parameters
),
"event_id": EventIdPsana(
data_source_name="eventid", monitor_parameters=monitor_parameters
),
"detector_data": Epix10kaSinglePanelPsana(
data_source_name="detector", monitor_parameters=monitor_parameters
),
"beam_energy": BeamEnergyPsana(
data_source_name="beam_energy", monitor_parameters=monitor_parameters
),
"detector_distance": EpicsVariablePsana(
data_source_name="detector_distance",
monitor_parameters=monitor_parameters,
),
# "detector_distance": FloatEntryFromConfiguration(
# data_source_name="fallback_detector_distance_in_mm",
# monitor_parameters=monitor_parameters,
# ),
"timetool_data": EpicsVariablePsana(
data_source_name="timetool", monitor_parameters=monitor_parameters
),
"optical_laser_active": EvrCodesPsana(
data_source_name="active_optical_laser",
monitor_parameters=monitor_parameters,
),
"xrays_active": EvrCodesPsana(
data_source_name="active_xrays",
monitor_parameters=monitor_parameters,
),
"post_sample_intensity": DiodeTotalIntensityPsana(
data_source_name="post_sample_intensity",
monitor_parameters=monitor_parameters,
),
"lcls_extra": LclsExtraPsana(
data_source_name="lcls_extra",
monitor_parameters=monitor_parameters,
),
}

self._data_event_handler: OmDataEventHandlerProtocol = PsanaDataEventHandler(
source=source,
monitor_parameters=monitor_parameters,
data_sources=data_sources,
)

def get_data_event_handler(self) -> OmDataEventHandlerProtocol:
"""
Retrieves the Data Event Handler used by the Data Retrieval class.

Please see the documentation of the base Protocol class for additional
information about this method.

Returns:

The Data Event Handler used by the Data Retrieval class.
"""
return self._data_event_handler

class LclsEpix100DataRetrieval(OmDataRetrievalProtocol):
"""
Expand Down
91 changes: 91 additions & 0 deletions src/om/data_retrieval_layer/data_sources_psana.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,97 @@ def get_data(

return epixka2m_reshaped

class Epix10kaSinglePanelPsana(OmDataSourceProtocol):
"""
See documentation of the `__init__` function.
"""

def __init__(
self,
*,
data_source_name: str,
monitor_parameters: MonitorParameters,
):
"""
Epix10KA 2M detector data frames from psana at the LCLS facility.

This class deals with the retrieval of Epix10Ka 2M detector data frames from
the psana software framework.

This class implements the interface described by its base Protocol class.
Please see the documentation of that class for additional information about
the interface.

Arguments:

data_source_name: A name that identifies the current data source. It is
used, for example, in communications with the user or for the retrieval
of a sensor's initialization parameters.

monitor_parameters: An object storing OM's configuration parameters.
"""
self._data_source_name = data_source_name
self._monitor_parameters = monitor_parameters

def initialize_data_source(self) -> None:
"""
Initializes the Epix10KA 2M detector frame data source.

Please see the documentation of the base Protocol class for additional
information about this method.

This function initializes data retrieval for the detector whose psana name
matches the `psana_{source_protocols_name}_name` entry in OM's
`data_retrieval_layer` configuration parameter group, or for the detector with
a given psana name, if the `source_protocols_name` argument has the format
`psana-{psana detector name}`.
"""
self._data_retrieval_function: Callable[
[Any], Any
] = _get_psana_data_retrieval_function(
source_protocols_name=self._data_source_name,
monitor_parameters=self._monitor_parameters,
)

def get_data(
self, *, event: Dict[str, Any]
) -> Union[NDArray[numpy.float_], NDArray[numpy.int_]]:
"""
Retrieves an Epix10KA 2M detector data frame from psana.

This method overrides the corresponding method of the base class: please also
refer to the documentation of that class for more information.

This function retrieves from psana the detector data frame associated with the
provided event. It returns the frame as a 2D array storing pixel information.
Data is retrieved in calibrated or non-calibrated form depending on the
value of the `{source_protocols_name}_calibration` entry in OM's
`data_retrieval_layer` configuration parameter group.

Arguments:

event: A dictionary storing the event data.

Returns:

A detector data frame.

Raises:

OmDataExtractionError: Raised when data cannot be retrieved from psana.
"""
epixka2m_psana: Union[
NDArray[numpy.float_], NDArray[numpy.int_]
] = self._data_retrieval_function(event["data"])
if epixka2m_psana is None:
raise OmDataExtractionError("Could not retrieve detector data from psana.")

# Rearranges the data into 'slab' format.
epixka2m_reshaped: Union[
NDArray[numpy.float_], NDArray[numpy.int_]
] = epixka2m_psana.reshape(352, 384)

return epixka2m_reshaped

class Jungfrau4MPsana(OmDataSourceProtocol):
"""
Expand Down
Loading