Add eosls command to list files with some header info
This commit is contained in:
@@ -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
57
eos/ls.py
Normal 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()
|
||||
@@ -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)
|
||||
|
||||
@@ -750,3 +750,7 @@ class E2HConfig:
|
||||
reader: ReaderConfig
|
||||
experiment: ExperimentConfig
|
||||
reduction: E2HReductionConfig
|
||||
|
||||
@dataclass
|
||||
class LSConfig(ArgParsable):
|
||||
...
|
||||
@@ -3,5 +3,6 @@ h5py
|
||||
orsopy
|
||||
numba
|
||||
matplotlib
|
||||
tabulate
|
||||
backports.strenum; python_version<"3.11"
|
||||
backports.zoneinfo; python_version<"3.9"
|
||||
|
||||
Reference in New Issue
Block a user