Add eosls command to list files with some header info
Some checks failed
Unit Testing / test (3.8) (push) Failing after 10s
Unit Testing / test (3.9) (push) Failing after 10s
Unit Testing / test (3.12) (push) Successful in 27s
Unit Testing / test (3.10) (push) Successful in 29s

This commit is contained in:
2026-02-26 16:41:54 +01:00
parent 246c179481
commit a22c23658f
6 changed files with 68 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ from typing import List, Type
from .options import ArgParsable
def commandLineArgs(config_items: List[Type[ArgParsable]], program_name=None):
def commandLineArgs(config_items: List[Type[ArgParsable]], program_name=None, extra_args=[]):
"""
Process command line argument.
The type of the default values is used for conversion and validation.
@@ -36,4 +36,7 @@ def commandLineArgs(config_items: List[Type[ArgParsable]], program_name=None):
f'--{cpc.argument}', **cpc.add_argument_args
)
for ma in extra_args:
clas.add_argument(**ma)
return clas.parse_args()

57
eos/ls.py Normal file
View File

@@ -0,0 +1,57 @@
"""
eosls executable script to list available datafiles in current folder with some metadata information.
Author: Jochen Stahn (algorithms, python draft),
Artur Glavic (structuring and optimisation of code)
"""
import os
import logging
from eos.options import LSConfig
from eos.command_line import commandLineArgs
def main():
logging.getLogger().setLevel(logging.CRITICAL)
clas = commandLineArgs([LSConfig], 'eosls', extra_args=[
dict(dest='path', nargs='*', default=['.'], help='paths to list file in')])
config = LSConfig.from_args(clas)
from glob import glob
import tabulate
from eos.file_reader import AmorHeader
files = []
for path in clas.path:
files+=glob(os.path.join(path, 'amor*.hdf'))
files.sort()
data = {
'File name': [],
'Start Time': [],
'mu': [],
'nu': [],
'div': [],
'Sample': [],
'T [K]': [],
'H [T]': [],
}
for fi in files:
data['File name'].append(os.path.basename(fi))
ah = AmorHeader(fi)
data['Sample'].append(ah.sample.name)
data['Start Time'].append(ah.fileDate.strftime('%y %m-%d %H:%M:%S'))
data['mu'].append('%.3f' % ah.geometry.mu)
data['nu'].append('%.3f' % ah.geometry.nu)
data['div'].append('%.3f' % ah.geometry.div)
T = ah.sample.sample_parameters.get('temperature', None)
data['T [K]'].append(T.magnitude if T is not None else '-')
H = ah.sample.sample_parameters.get('magnetic_field', None)
data['H [T]'].append(H.magnitude if H is not None else '-')
print(tabulate.tabulate(data, headers="keys"))
if __name__ == '__main__':
main()

View File

@@ -1,5 +1,5 @@
"""
events2histogram vizualising data from Amor@SINQ, PSI
amor-nicos vizualising data from Amor@SINQ, PSI
Author: Jochen Stahn (algorithms, python draft),
Artur Glavic (structuring and optimisation of code)

View File

@@ -750,3 +750,7 @@ class E2HConfig:
reader: ReaderConfig
experiment: ExperimentConfig
reduction: E2HReductionConfig
@dataclass
class LSConfig(ArgParsable):
...

View File

@@ -3,5 +3,6 @@ h5py
orsopy
numba
matplotlib
tabulate
backports.strenum; python_version<"3.11"
backports.zoneinfo; python_version<"3.9"

View File

@@ -34,5 +34,6 @@ Homepage = "https://github.com/jochenstahn/amor"
[options.entry_points]
console_scripts =
eos = eos.__main__:main
eosls = eos.ls:main
events2histogram = eos.e2h:main
amor-nicos = eos.nicos:main