Move execution script from eos.py to package and rename package to eos, add entry point to setup

This commit is contained in:
2025-10-06 11:38:52 +02:00
parent 3a21a8505a
commit 2467ba38b8
25 changed files with 71 additions and 86 deletions
+2
View File
@@ -8,3 +8,5 @@ raw
test_results
build
dist
profile_test.prof
amor_eos.log
-48
View File
@@ -1,48 +0,0 @@
#!/usr/bin/env python
"""
eos reduces measurements performed on Amor@SINQ, PSI
Author: Jochen Stahn (algorithms, python draft),
Artur Glavic (structuring and optimisation of code)
conventions (not strictly followed, yet):
- array names end with the suffix '_x[y]' with the meaning
_e = events
_tof
_l = lambda
_t = theta
_z = detector z
_lz = (lambda, detector z)
_q = q_z
"""
import logging
from libeos.command_line import command_line_options
from libeos.logconfig import setup_logging
#=====================================================================================================
# TODO:
# - calculate resolution using the chopperPhase
# - deal with background correction
# - format of 'call' + add '-Y' if not supplied
#=====================================================================================================
def main():
setup_logging()
logging.warning('######## eos - data reduction for Amor ########')
# read command line arguments and generate classes holding configuration parameters
config = command_line_options()
# only import heavy module if sufficient command line parameters were provieded
from libeos.reduction import AmorReduction
# Create reducer with these arguments
reducer = AmorReduction(config)
# Perform actual reduction
reducer.reduce()
logging.info('######## eos - finished ########')
if __name__ == '__main__':
main()
+1 -1
View File
@@ -1,5 +1,5 @@
"""
Package to handle data redction at AMOR instrument to be used by eos.py script.
Package to handle data redction at AMOR instrument to be used by __main__.py script.
"""
__version__ = '3.0.0'
+41
View File
@@ -0,0 +1,41 @@
"""
eos reduces measurements performed on Amor@SINQ, PSI
Author: Jochen Stahn (algorithms, python draft),
Artur Glavic (structuring and optimisation of code)
"""
import logging
# need to do absolute import here as pyinstaller requires it
from eos.options import EOSConfig, ReaderConfig, ExperimentConfig, ReductionConfig, OutputConfig
from eos.command_line import commandLineArgs
from eos.logconfig import setup_logging, update_loglevel
def main():
setup_logging()
# read command line arguments and generate classes holding configuration parameters
clas = commandLineArgs([ReaderConfig, ExperimentConfig, ReductionConfig, OutputConfig],
'eos')
update_loglevel(clas.verbose)
reader_config = ReaderConfig.from_args(clas)
experiment_config = ExperimentConfig.from_args(clas)
reduction_config = ReductionConfig.from_args(clas)
output_config = OutputConfig.from_args(clas)
config = EOSConfig(reader_config, experiment_config, reduction_config, output_config)
logging.warning('######## eos - data reduction for Amor ########')
# only import heavy module if sufficient command line parameters were provided
from eos.reduction import AmorReduction
# Create reducer with these arguments
reducer = AmorReduction(config)
# Perform actual reduction
reducer.reduce()
logging.info('######## eos - finished ########')
if __name__ == '__main__':
main()
+6 -18
View File
@@ -1,10 +1,10 @@
import argparse
from .logconfig import update_loglevel
from .options import ReaderConfig, EOSConfig, ExperimentConfig, OutputConfig, ReductionConfig
from typing import List
from .options import ArgParsable
def commandLineArgs():
def commandLineArgs(config_items: List[ArgParsable], program_name=None):
"""
Process command line argument.
The type of the default values is used for conversion and validation.
@@ -12,14 +12,15 @@ def commandLineArgs():
msg = "eos reads data from (one or several) raw file(s) of the .hdf format, \
performs various corrections, conversations and projections and exports\
the resulting reflectivity in an orso-compatible format."
clas = argparse.ArgumentParser(description = msg, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
clas = argparse.ArgumentParser(prog=program_name,
description = msg, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
clas.add_argument('-v', '--verbose', action='count', default=0)
clas_groups = {}
all_arguments = []
for cls in [ReaderConfig, ExperimentConfig, OutputConfig, ReductionConfig]:
for cls in config_items:
all_arguments += cls.get_commandline_parameters()
all_arguments.sort() # parameters are sorted alphabetically, unless they have higher priority
@@ -36,16 +37,3 @@ def commandLineArgs():
)
return clas.parse_args()
def command_line_options():
clas = commandLineArgs()
update_loglevel(clas.verbose)
reader_config = ReaderConfig.from_args(clas)
experiment_config = ExperimentConfig.from_args(clas)
reduction_config = ReductionConfig.from_args(clas)
output_config = OutputConfig.from_args(clas)
return EOSConfig(reader_config, experiment_config, reduction_config, output_config)
View File
View File
@@ -18,8 +18,8 @@ def extract_walltime(tof_e, dataPacket_p, dataPacketTime_p):
def filter_project_x(pixelLookUp, pixelID_e, ymin, ymax):
(detY_e, detZ_e, detXdist_e, delta_e) = pixelLookUp[np.int_(pixelID_e)-1, :].T
# define mask and filter y range
mask_e = (ymin<=detY_e) & (detY_e<=ymax[1])
return (detY_e, detZ_e, detXdist_e, delta_e, mask_e)
mask_e = (ymin<=detY_e) & (detY_e<=ymax)
return (detZ_e, detXdist_e, delta_e, mask_e)
def calculate_derived_properties_focussing(tof_e, detXdist_e, delta_e, mask_e,
lmin, lmax, nu, mu, chopperDetectorDistance, hdm):
+10 -10
View File
@@ -297,6 +297,15 @@ class NormalisationMethod(StrEnum):
@dataclass
class ReductionConfig(ArgParsable):
fileIdentifier: List[str] = field(
metadata={
'short': 'f',
'priority': 100,
'group': 'input data',
'help': 'file number(s) or offset (if < 1)',
},
)
qResolution: float = field(
default=0.01,
metadata={
@@ -329,15 +338,6 @@ class ReductionConfig(ArgParsable):
'help': 'theta region of interest w.r.t. beam center',
},
)
fileIdentifier: List[str] = field(
default_factory=lambda: ['0'],
metadata={
'short': 'f',
'priority': 100,
'group': 'input data',
'help': 'file number(s) or offset (if < 1)',
},
)
normalisationMethod: NormalisationMethod = field(
default=NormalisationMethod.over_illuminated,
metadata={
@@ -492,7 +492,7 @@ class EOSConfig:
# return self.calculate_call_string()
def call_string(self):
base = 'python eos.py'
base = 'eos'
inpt = ''
if self.reader.year:
+6 -4
View File
@@ -3,7 +3,7 @@ universal = 1
[metadata]
name = amor_eos
version = attr: libeos.__version__
version = attr: eos.__version__
author = Jochen Stahn - Paul Scherrer Institut
author_email = jochen.stahn@psi.ch
description = EOS reflectometry reduction for AMOR instrument
@@ -19,9 +19,7 @@ classifiers =
[options]
python_requires = >=3.8
packages =
libeos
scripts =
eos.py
eos
install_requires =
numpy
h5py
@@ -30,3 +28,7 @@ install_requires =
[project.urls]
Homepage = "https://github.com/jochenstahn/amor"
[options.entry_points]
console_scripts =
eos = eos.__main__:main
+1 -1
View File
@@ -2,7 +2,7 @@ import os
import cProfile
from unittest import TestCase
from dataclasses import fields, MISSING
from libeos import options, reduction, logconfig
from eos import options, reduction, logconfig
logconfig.setup_logging()
logconfig.update_loglevel(1)
+1 -1
View File
@@ -2,7 +2,7 @@
a = Analysis(
['eos.py'],
['eos/__main__.py'],
pathex=[],
binaries=[],
datas=[],
+1 -1
View File
@@ -9,7 +9,7 @@ datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
a = Analysis(
['eos.py'],
['eos/__main__.py'],
pathex=[],
binaries=[],
datas=[],