Skip to content

Commit

Permalink
Remove source params and add name
Browse files Browse the repository at this point in the history
  • Loading branch information
jl-wynen committed Jan 24, 2025
1 parent 9f917cd commit ba9c201
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 52 deletions.
16 changes: 0 additions & 16 deletions src/scippneutron/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@
RadiationProbe
SourceType
.. rubric:: Domain Types
.. autosummary::
:toctree: ../classes
:template: model-template.rst
PulseDuration
SourceFrequency
SourcePeriod
.. rubric:: Attributes
.. autosummary::
Expand All @@ -47,9 +37,6 @@
Software,
Source,
Measurement,
PulseDuration,
SourceFrequency,
SourcePeriod,
SourceType,
ESS_SOURCE,
RadiationProbe,
Expand All @@ -63,9 +50,6 @@
'ORCIDiD',
'Software',
'Source',
'PulseDuration',
'SourceFrequency',
'SourcePeriod',
'SourceType',
'ESS_SOURCE',
'RadiationProbe',
Expand Down
38 changes: 4 additions & 34 deletions src/scippneutron/metadata/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

import enum
from datetime import datetime
from typing import NewType

import scipp as sc
import scippnexus as snx
from dateutil.parser import parse as parse_datetime
from pydantic import BaseModel, ConfigDict, EmailStr
from pydantic import BaseModel, EmailStr

from ._orcid import ORCIDiD

Expand Down Expand Up @@ -292,14 +290,6 @@ def _deduce_package_source_url(package_name: str) -> str | None:
return None


PulseDuration = NewType('PulseDuration', sc.Variable)
PulseDuration.__doc__ = """Duration of a source pulse."""
SourceFrequency = NewType('SourceFrequency', sc.Variable)
SourceFrequency.__doc__ = """Frequency of a source pulse."""
SourcePeriod = NewType('SourcePeriod', sc.Variable)
SourcePeriod.__doc__ = """Period of a source pulse."""


class SourceType(str, enum.Enum):
"""Type of source.
Expand Down Expand Up @@ -327,36 +317,16 @@ class Source(BaseModel):
The ESS source is provided as ``scippneutron.meta.ESS_SOURCE``.
"""

# Needed to allow Scipp objects
model_config = ConfigDict(arbitrary_types_allowed=True)

frequency: SourceFrequency
"""The source frequency in Hz."""
pulse_duration: PulseDuration
"""The pulse duration in s."""

name: str | None = None
"""Name of the source."""
source_type: SourceType
"""Type of this source."""
probe: RadiationProbe
"""Radiation probe of the source."""

@property
def period(self) -> SourcePeriod:
"""The source period in ns."""
return SourcePeriod((1 / self.frequency).to(unit='ns'))

def to_pipeline_params(self) -> dict[type, object]:
"""Package the physical source parameters for a Sciline pipeline."""
return {
PulseDuration: self.pulse_duration,
SourceFrequency: self.frequency,
SourcePeriod: self.period,
}


ESS_SOURCE = Source(
frequency=SourceFrequency(sc.scalar(14.0, unit='Hz')),
pulse_duration=PulseDuration(sc.scalar(0.003, unit='s')),
name="ESS Butterfly",
source_type=SourceType.SpallationNeutronSource,
probe=RadiationProbe.Neutron,
)
Expand Down
2 changes: 0 additions & 2 deletions tests/io/cif_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,6 @@ def test_builder_with_beamline_and_source() -> None:
cif_ = original.with_beamline(
metadata.Beamline(name='Balder', facility='MAX IV'),
metadata.Source(
frequency=metadata.SourceFrequency(sc.scalar(0)),
pulse_duration=metadata.PulseDuration(sc.scalar(0)),
source_type=metadata.SourceType.SynchrotronXraySource,
probe=metadata.RadiationProbe.Xray,
),
Expand Down

0 comments on commit ba9c201

Please sign in to comment.