Skip to content

Commit

Permalink
Ignore reference run metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jl-wynen committed Feb 7, 2024
1 parent eb93975 commit a0dbe24
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 57 deletions.
6 changes: 3 additions & 3 deletions src/essreflectometry/amor/orso.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from orsopy.fileio.orso import Column, Orso, OrsoDataset

from ..orso import OrsoDataSource, OrsoInstrument, OrsoIofQDataset, OrsoReduction
from ..types import NormalizedIofQ1D, QResolution, Run, ThetaData, WavelengthData
from ..types import NormalizedIofQ1D, QResolution, Sample, ThetaData, WavelengthData


def build_orso_instrument(
events_in_wavelength: WavelengthData[Run], events_in_theta: ThetaData[Run]
) -> OrsoInstrument[Run]:
events_in_wavelength: WavelengthData[Sample], events_in_theta: ThetaData[Sample]
) -> OrsoInstrument:
"""Build ORSO instrument metadata from intermediate reduction results for Amor.
This assumes specular reflection and sets the incident angle equal to the computed
Expand Down
87 changes: 33 additions & 54 deletions src/essreflectometry/orso.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
"""ORSO utilities for reflectometry."""
"""ORSO utilities for reflectometry.
The Sciline providers and types in this module largely ignore the metadata
of reference runs and only use the metadata of the sample run.
"""

import os
import platform
from datetime import datetime, timezone
from typing import NewType, Optional

import sciline
from dateutil.parser import parse as parse_datetime
from orsopy.fileio import base as orso_base
from orsopy.fileio import data_source, orso, reduction

from .types import Filename, RawData, Reference, Run, Sample


class OrsoExperiment(
sciline.Scope[Run, data_source.Experiment], data_source.Experiment
):
"""ORSO experiment for a run."""


class OrsoInstrument(
sciline.Scope[Run, data_source.InstrumentSettings], data_source.InstrumentSettings
):
"""ORSO instrument settings for a run."""


class OrsoOwner(sciline.Scope[Run, orso_base.Person], orso_base.Person):
"""ORSO owner of a file."""


class OrsoReduction(sciline.Scope[Run, reduction.Reduction], reduction.Reduction):
"""ORSO measurement for a run."""
from .types import Filename, RawData, Reference, Sample

OrsoCreator = NewType('OrsoCreator', orso_base.Person)
"""ORSO creator, that is, the person who processed the data."""

class OrsoSample(sciline.Scope[Run, data_source.Sample], data_source.Sample):
"""ORSO sample of a run."""
OrsoDataSource = NewType('OrsoDataSource', data_source.DataSource)
"""ORSO data source."""

OrsoExperiment = NewType('OrsoExperiment', data_source.Experiment)
"""ORSO experiment for the sample run."""

OrsoCreator = NewType('OrsoCreator', orso_base.Person)
"""ORSO creator, that is, the person who processed the data."""
OrsoInstrument = NewType('OrsoInstrument', data_source.InstrumentSettings)
"""ORSO instrument settings for the sample run."""

OrsoIofQDataset = NewType('OrsoIofQDataset', orso.OrsoDataset)
"""ORSO dataset for reduced I-of-Q data."""

OrsoDataSource = NewType('OrsoDataSource', data_source.DataSource)
"""ORSO data source."""

OrsoMeasurement = NewType('OrsoMeasurement', data_source.Measurement)
"""ORSO measurement."""

OrsoOwner = NewType('OrsoOwner', orso_base.Person)
"""ORSO owner of a measurement."""

OrsoReduction = NewType('OrsoReduction', reduction.Reduction)
"""ORSO data reduction metadata."""

def parse_orso_experiment(raw_data: RawData[Run]) -> OrsoExperiment[Run]:
OrsoSample = NewType('OrsoSample', data_source.Sample)
"""ORSO sample."""


def parse_orso_experiment(raw_data: RawData[Sample]) -> OrsoExperiment:
"""Parse ORSO experiment metadata from raw NeXus data."""
return OrsoExperiment(
data_source.Experiment(
Expand All @@ -64,7 +58,7 @@ def parse_orso_experiment(raw_data: RawData[Run]) -> OrsoExperiment[Run]:
)


def parse_orso_owner(raw_data: RawData[Run]) -> OrsoOwner[Run]:
def parse_orso_owner(raw_data: RawData[Sample]) -> OrsoOwner:
"""Parse ORSO owner metadata from raw NeXus data."""
return OrsoOwner(
orso_base.Person(
Expand All @@ -75,7 +69,7 @@ def parse_orso_owner(raw_data: RawData[Run]) -> OrsoOwner[Run]:
)


def parse_orso_sample(raw_data: RawData[Run]) -> OrsoSample[Run]:
def parse_orso_sample(raw_data: RawData[Sample]) -> OrsoSample:
"""Parse ORSO sample metadata from raw NeXus data."""
if not raw_data.get('sample'):
return OrsoSample(data_source.Sample.empty())
Expand All @@ -85,7 +79,7 @@ def parse_orso_sample(raw_data: RawData[Run]) -> OrsoSample[Run]:
def build_orso_measurement(
sample_filename: Filename[Sample],
reference_filename: Optional[Filename[Reference]],
instrument: Optional[OrsoInstrument[Sample]],
instrument: Optional[OrsoInstrument],
) -> OrsoMeasurement:
"""Assemble ORSO measurement metadata."""
# TODO populate timestamp
Expand Down Expand Up @@ -132,32 +126,17 @@ def build_orso_reduction(creator: Optional[OrsoCreator]) -> OrsoReduction:


def build_orso_data_source(
owner: Optional[OrsoOwner[Sample]],
sample: Optional[OrsoSample[Sample]],
sample_experiment: Optional[OrsoExperiment[Sample]],
reference_experiment: Optional[OrsoExperiment[Reference]],
owner: Optional[OrsoOwner],
sample: Optional[OrsoSample],
experiment: Optional[OrsoExperiment],
measurement: Optional[OrsoMeasurement],
) -> OrsoDataSource:
"""Judiciously assemble an ORSO DataSource.
Makes some assumptions about how sample and reference runs should be merged,
giving precedence to the sample run.
"""
# We simply assume that the owner of the reference measurement
# has no claim on this data.
if (reference_experiment is not None) and (
(sample_experiment.facility != reference_experiment.facility)
or (sample_experiment.instrument != reference_experiment.instrument)
):
raise ValueError(
'The sample and reference experiments were done at different instruments'
)

"""Assemble an ORSO DataSource."""
return OrsoDataSource(
data_source.DataSource(
owner=owner,
sample=sample,
experiment=sample_experiment,
experiment=experiment,
measurement=measurement,
)
)
Expand Down

0 comments on commit a0dbe24

Please sign in to comment.