Unit Testing / test (3.11) (push) Successful in 54s
Unit Testing / test (3.8) (push) Successful in 52s
Unit Testing / test (3.10) (push) Successful in 1m3s
Unit Testing / test (3.12) (push) Successful in 1m4s
Unit Testing / test (3.9) (push) Successful in 1m1s
126 lines
4.8 KiB
Python
126 lines
4.8 KiB
Python
import os
|
|
import cProfile
|
|
import numpy as np
|
|
from unittest import TestCase
|
|
from dataclasses import fields, MISSING
|
|
from eos import options, reduction_reflectivity, logconfig
|
|
from orsopy import fileio
|
|
|
|
logconfig.setup_logging()
|
|
logconfig.update_loglevel(1)
|
|
|
|
# TODO: add unit tests for individual parts of reduction
|
|
|
|
class FullAmorTest(TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
# generate map for option defaults
|
|
cls._field_defaults = {}
|
|
for opt in [options.ExperimentConfig, options.ReflectivityReductionConfig, options.ReflectivityOutputConfig]:
|
|
defaults = {}
|
|
for field in fields(opt):
|
|
if field.default not in [None, MISSING]:
|
|
defaults[field.name] = field.default
|
|
elif field.default_factory not in [None, MISSING]:
|
|
defaults[field.name] = field.default_factory()
|
|
cls._field_defaults[opt.__name__] = defaults
|
|
cls.pr = cProfile.Profile()
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.pr.dump_stats("profile_test.prof")
|
|
|
|
def setUp(self):
|
|
self.pr.enable()
|
|
self.reader_config = options.ReaderConfig(
|
|
year=2026,
|
|
rawPath=["test_data"],
|
|
)
|
|
|
|
def tearDown(self):
|
|
self.pr.disable()
|
|
for fi in ['test_results/test.Rqz.ort', 'test_results/5952.norm']:
|
|
try:
|
|
os.unlink(fi)
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
def test_time_slicing(self):
|
|
experiment_config = options.ExperimentConfig(
|
|
yRange=(18, 48),
|
|
lambdaRange=(3., 11.5),
|
|
sampleModel='air | 10 H2O | D2O'
|
|
)
|
|
reduction_config = options.ReflectivityReductionConfig(
|
|
qResolution=0.01,
|
|
qzRange=(0.01, 0.15),
|
|
thetaRange=(-0.75, 0.75),
|
|
fileIdentifier=["3629", "3630"],
|
|
scale=[1],
|
|
normalisationFileIdentifier=[],
|
|
timeSlize=[300.0]
|
|
)
|
|
output_config = options.ReflectivityOutputConfig(
|
|
outputFormats=[options.OutputFomatOption.Rqz_ort],
|
|
outputName='test',
|
|
outputPath='test_results',
|
|
)
|
|
config=options.ReflectivityConfig(self.reader_config, experiment_config, reduction_config, output_config)
|
|
# run three times to get similar timing to noslicing runs
|
|
reducer = reduction_reflectivity.ReflectivityReduction(config)
|
|
reducer.reduce()
|
|
reducer = reduction_reflectivity.ReflectivityReduction(config)
|
|
reducer.reduce()
|
|
reducer = reduction_reflectivity.ReflectivityReduction(config)
|
|
reducer.reduce()
|
|
|
|
def test_noslicing(self):
|
|
experiment_config = options.ExperimentConfig(
|
|
yRange=(18, 48),
|
|
lambdaRange=(3., 11.5),
|
|
)
|
|
reduction_config = options.ReflectivityReductionConfig(
|
|
qResolution=0.01,
|
|
thetaRange=(-0.75, 0.75),
|
|
fileIdentifier=["3629", "3630"],
|
|
scale=[1],
|
|
normalisationFileIdentifier=["3631"],
|
|
autoscale=(0.0, 0.05),
|
|
)
|
|
output_config = options.ReflectivityOutputConfig(
|
|
outputFormats=[options.OutputFomatOption.Rqz_ort],
|
|
outputName='test',
|
|
outputPath='test_results',
|
|
)
|
|
config=options.ReflectivityConfig(self.reader_config, experiment_config, reduction_config, output_config)
|
|
reducer = reduction_reflectivity.ReflectivityReduction(config)
|
|
reducer.reduce()
|
|
# run second time to reuse norm file
|
|
reducer = reduction_reflectivity.ReflectivityReduction(config)
|
|
reducer.reduce()
|
|
|
|
def test_noslicing_nmon(self):
|
|
experiment_config = options.ExperimentConfig(
|
|
yRange=(18, 48),
|
|
lambdaRange=(3., 11.5),
|
|
)
|
|
reduction_config = options.ReflectivityReductionConfig(
|
|
qResolution=0.01,
|
|
thetaRange=(-0.75, 0.75),
|
|
fileIdentifier=["3629", "3630"],
|
|
scale=[1],
|
|
normalisationFileIdentifier=["3631"],
|
|
autoscale=(0.0, 0.05),
|
|
)
|
|
output_config = options.ReflectivityOutputConfig(
|
|
outputFormats=[options.OutputFomatOption.Rqz_ort],
|
|
outputName='test',
|
|
outputPath='test_results',
|
|
)
|
|
config=options.ReflectivityConfig(self.reader_config, experiment_config, reduction_config, output_config)
|
|
reducer = reduction_reflectivity.ReflectivityReduction(config)
|
|
reducer.reduce()
|
|
# run second time to reuse norm file
|
|
reducer = reduction_reflectivity.ReflectivityReduction(config)
|
|
reducer.reduce()
|