11# SPDX-License-Identifier: BSD-3-Clause
22# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
33# flake8: noqa: F403, F405
4+ from datetime import datetime
5+ from pathlib import Path
6+ from zoneinfo import ZoneInfo
47
58import numpy as np
69import pytest
710import sciline
811import scipp as sc
12+ from orsopy import fileio
913
1014from ess .estia import EstiaWorkflow
1115from ess .estia .data import estia_mcstas_reference_run , estia_mcstas_sample_run
1216from ess .estia .load import load_mcstas_events
17+ from ess .reflectometry import orso
1318from ess .reflectometry .types import (
1419 BeamDivergenceLimits ,
1520 Filename ,
@@ -35,6 +40,7 @@ def estia_mcstas_pipeline() -> sciline.Pipeline:
3540 wf [ZIndexLimits ] = sc .scalar (0 ), sc .scalar (14 * 32 )
3641 wf [BeamDivergenceLimits ] = sc .scalar (- 1.0 , unit = 'deg' ), sc .scalar (1.0 , unit = 'deg' )
3742 wf [WavelengthBins ] = sc .geomspace ('wavelength' , 3.5 , 12 , 2001 , unit = 'angstrom' )
43+ wf [QBins ] = sc .geomspace ('Q' , 0.005 , 0.1 , 200 , unit = '1/angstrom' )
3844 wf [ProtonCurrent [SampleRun ]] = sc .DataArray (
3945 sc .array (dims = ('time' ,), values = []),
4046 coords = {'time' : sc .array (dims = ('time' ,), values = [], unit = 's' )},
@@ -43,7 +49,30 @@ def estia_mcstas_pipeline() -> sciline.Pipeline:
4349 sc .array (dims = ('time' ,), values = []),
4450 coords = {'time' : sc .array (dims = ('time' ,), values = [], unit = 's' )},
4551 )
46-
52+ wf [orso .OrsoCreator ] = orso .OrsoCreator (
53+ fileio .base .Person (
54+ name = "Max Mustermann" ,
55+ affiliation = "European Spallation Source ERIC" ,
56+ 57+ )
58+ )
59+ wf [orso .OrsoExperiment ] = orso .OrsoExperiment (
60+ fileio .data_source .Experiment (
61+ title = 'McStas run' ,
62+ instrument = 'Estia' ,
63+ facility = 'ESS' ,
64+ start_date = datetime (2025 , 3 , 20 , tzinfo = ZoneInfo ("Europe/Stockholm" )),
65+ probe = 'neutron' ,
66+ )
67+ )
68+ wf [orso .OrsoOwner ] = orso .OrsoOwner (
69+ fileio .base .Person (
70+ name = 'John Doe' ,
71+ 72+ affiliation = 'ESS' ,
73+ )
74+ )
75+ wf [orso .OrsoSample ] = orso .OrsoSample (fileio .data_source .Sample .empty ())
4776 return wf
4877
4978
@@ -62,7 +91,6 @@ def test_mcstas_compute_reducible_data(estia_mcstas_pipeline: sciline.Pipeline):
6291
6392def test_can_compute_reflectivity_curve (estia_mcstas_pipeline : sciline .Pipeline ):
6493 estia_mcstas_pipeline [Filename [SampleRun ]] = estia_mcstas_sample_run (11 )
65- estia_mcstas_pipeline [QBins ] = sc .geomspace ('Q' , 0.005 , 0.1 , 200 , unit = '1/angstrom' )
6694 r = estia_mcstas_pipeline .compute (ReflectivityOverQ )
6795 assert "Q" in r .coords
6896 assert "Q_resolution" in r .coords
@@ -80,3 +108,29 @@ def test_can_compute_reflectivity_curve(estia_mcstas_pipeline: sciline.Pipeline)
80108
81109 assert max_q > sc .scalar (0.075 , unit = '1/angstrom' )
82110 assert min_q < sc .scalar (0.007 , unit = '1/angstrom' )
111+
112+
113+ def test_orso_pipeline (estia_mcstas_pipeline : sciline .Pipeline ):
114+ estia_mcstas_pipeline [Filename [SampleRun ]] = estia_mcstas_sample_run (11 )
115+ res = estia_mcstas_pipeline .compute (orso .OrsoIofQDataset )
116+ assert res .info .data_source .experiment .instrument == "Estia"
117+ assert res .info .reduction .software .name == "ess.reflectometry"
118+ assert res .info .reduction .corrections == [
119+ "chopper ToF correction" ,
120+ "footprint correction" ,
121+ "supermirror calibration" ,
122+ ]
123+ assert res .data .ndim == 2
124+ assert res .data .shape [1 ] == 4
125+ assert np .all (res .data [:, 1 ] >= 0 )
126+ assert np .isfinite (res .data ).all ()
127+
128+
129+ def test_save_reduced_orso_file (
130+ estia_mcstas_pipeline : sciline .Pipeline , output_folder : Path
131+ ):
132+ estia_mcstas_pipeline [Filename [SampleRun ]] = estia_mcstas_sample_run (11 )
133+ res = estia_mcstas_pipeline .compute (orso .OrsoIofQDataset )
134+ fileio .orso .save_orso (
135+ datasets = [res ], fname = output_folder / 'estia_reduced_iofq.ort'
136+ )
0 commit comments