diff --git a/eos/command_line.py b/eos/command_line.py index 6c95123..6b598e4 100644 --- a/eos/command_line.py +++ b/eos/command_line.py @@ -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() diff --git a/eos/ls.py b/eos/ls.py new file mode 100644 index 0000000..6dada86 --- /dev/null +++ b/eos/ls.py @@ -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() diff --git a/eos/nicos.py b/eos/nicos.py index 6d6f892..fb4dfb3 100644 --- a/eos/nicos.py +++ b/eos/nicos.py @@ -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) diff --git a/eos/options.py b/eos/options.py index 233e41e..def801c 100644 --- a/eos/options.py +++ b/eos/options.py @@ -750,3 +750,7 @@ class E2HConfig: reader: ReaderConfig experiment: ExperimentConfig reduction: E2HReductionConfig + +@dataclass +class LSConfig(ArgParsable): + ... \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5d8f474..b87a2cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,6 @@ h5py orsopy numba matplotlib +tabulate backports.strenum; python_version<"3.11" backports.zoneinfo; python_version<"3.9" diff --git a/setup.cfg b/setup.cfg index 2c9fa4a..c6883ff 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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