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

Load monitors separately from the remainder of the files #104

Merged
merged 10 commits into from
Feb 28, 2024

Conversation

jl-wynen
Copy link
Member

Fixes #99

I only did this for the Loki NeXus files because we cannot split loading of the ISIS files so easily. And I don't think those matter for performance in the long run.

src/esssans/loki/general.py Outdated Show resolved Hide resolved
@@ -79,121 +82,169 @@ def _merge_events(a, b):

def _merge_runs(
data_groups: sciline.Series[
Filename[ScatteringRunType], LoadedSingleFileContents[ScatteringRunType]
Filename[ScatteringRunType], LoadedSingleFileDetector[ScatteringRunType]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below, the name is saying this can be either detector or monitor data, but here we are saying it only applies to detector data?
I know it's just an internal function whose types are not checked when building the pipeline, but I still got a bit confused when reading.

events = DETECTOR_BANK_RESHAPING[data_name](events)

dg[f'{data_name}_events'] = events
return dg


def load_nexus(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def load_nexus(
def load_nexus_detector(

data_entries = (detector_name, incident_monitor_name, transmission_monitor_name)
) -> LoadedSingleFileDetector[RunType]:
return LoadedSingleFileDetector[RunType](
_load_events(filename, detector_name, transform_path, source_name, sample_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use keyword args to make sure we don't mix things up, such as swapping source and sample names?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A type checker should flag those errors. But I can change to keyword args

sample_name: Optional[NeXusSampleName],
) -> LoadedSingleFileMonitor[RunType, MonitorType]:
return LoadedSingleFileMonitor[RunType, MonitorType](
_load_events(filename, monitor_name, transform_path, source_name, sample_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also kwargs?

providers = (load_nexus, to_file_contents, to_path)
providers = (load_nexus, load_nexus_monitor, to_detector, to_monitor, to_path)
"""Providers for loading single files."""
event_merging_providers = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jl-wynen jl-wynen merged commit e3815f2 into main Feb 28, 2024
3 checks passed
@jl-wynen jl-wynen deleted the split-monitor-loading branch February 28, 2024 14:45
Copy link
Member

@SimonHeybrock SimonHeybrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be simplified further?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jl-wynen The things moved into this file do not belong here, as it is for the Pooch registry, is in all our repos.

Comment on lines 39 to +42
def get_detector_data(
dg: LoadedFileContents[ScatteringRunType], detector_name: NeXusDetectorName
dg: LoadedDetector[ScatteringRunType], detector_name: NeXusDetectorName
) -> RawData[ScatteringRunType]:
da = dg[NEXUS_INSTRUMENT_PATH][detector_name][f'{detector_name}_events']
return RawData[ScatteringRunType](da)
return RawData[ScatteringRunType](dg[f'{detector_name}_events'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this exist?

Comment on lines 45 to 51
def get_monitor_data(
dg: LoadedFileContents[RunType], monitor_name: NeXusMonitorName[MonitorType]
monitor: LoadedMonitor[RunType, MonitorType],
monitor_name: NeXusMonitorName[MonitorType],
) -> CalibratedMonitor[RunType, MonitorType]:
mon_dg = dg[NEXUS_INSTRUMENT_PATH][monitor_name]
out = mon_dg[f'{monitor_name}_events']
out.coords['position'] = mon_dg['position']
out = monitor[f'{monitor_name}_events'].copy(deep=False)
out.coords['position'] = monitor['position']
return CalibratedMonitor[RunType, MonitorType](out)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this function still exist?

Comment on lines 54 to +64
def detector_pixel_shape(
dg: LoadedFileContents[ScatteringRunType], detector_name: NeXusDetectorName
dg: LoadedDetector[ScatteringRunType],
) -> DetectorPixelShape[ScatteringRunType]:
return DetectorPixelShape[ScatteringRunType](
dg[NEXUS_INSTRUMENT_PATH][detector_name]['pixel_shape']
)
return DetectorPixelShape[ScatteringRunType](dg['pixel_shape'])


def detector_lab_frame_transform(
dg: LoadedFileContents[ScatteringRunType],
detector_name: NeXusDetectorName,
detector: LoadedDetector[ScatteringRunType],
transform_path: TransformationPath,
) -> LabFrameTransform[ScatteringRunType]:
return LabFrameTransform[ScatteringRunType](
dg[NEXUS_INSTRUMENT_PATH][detector_name][transform_path]
)
return LabFrameTransform[ScatteringRunType](detector[transform_path])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't all this be done in the detector load function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on whether you want this to be visible in the graph. Or whether it may need to be customised.
Note that I wanted to modify the existing structure as little as possible because I don't have an overview of the workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load monitors separately from the remainder of the files
3 participants