From 42e4defcca74db7e4f8fd8317e60d73d7f007b10 Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Mon, 24 Jun 2024 08:32:56 +0200 Subject: [PATCH] introduced raw data directory path --- eos.py | 46 +++++++++++++++++++++++++++++++++++++++++ libeos/command_line.py | 7 ++++++- libeos/file_reader.py | 38 +++++++++++++++++++++++----------- libeos/options.py | 4 ++++ neos.py | 47 +----------------------------------------- 5 files changed, 83 insertions(+), 59 deletions(-) create mode 100644 eos.py mode change 100644 => 120000 neos.py diff --git a/eos.py b/eos.py new file mode 100644 index 0000000..61a2232 --- /dev/null +++ b/eos.py @@ -0,0 +1,46 @@ +#!/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 +from libeos.reduction import AmorReduction + +#===================================================================================================== +# 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() + # Create reducer with these arguments + reducer = AmorReduction(config) + # Perform actual reduction + reducer.reduce() + + logging.info('######## eos - finished ########') + +if __name__ == '__main__': + main() diff --git a/libeos/command_line.py b/libeos/command_line.py index 0314b83..f01e66f 100644 --- a/libeos/command_line.py +++ b/libeos/command_line.py @@ -24,10 +24,14 @@ def commandLineArgs(): default = Defaults.normalisationFileIdentifier, nargs = '+', help = "file number(s) of normalisation measurement") + input_data.add_argument("--raw", + type = str, + default = Defaults.raw, + help = "relative path to directory with .hdf files") input_data.add_argument("-d", "--dataPath", type = str, default = Defaults.dataPath, - help = "relative path to directory with .hdf files") + help = "relative path for output") input_data.add_argument("-Y", "--year", default = Defaults.year, type = int, @@ -166,6 +170,7 @@ def command_line_options(): reader_config = ReaderConfig( year = clas.year, + raw = clas.raw, dataPath = clas.dataPath ) experiment_config = ExperimentConfig( diff --git a/libeos/file_reader.py b/libeos/file_reader.py index a494a89..d9850c0 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -78,21 +78,35 @@ class AmorData: self.lamda_e = _lamda_e self.wallTime_e = _wallTime_e + #------------------------------------------------------------------------------------------------- + #def path_generator(self, number): + # fileName = f'amor{self.reader_config.year}n{number:06d}.hdf' + # if os.path.exists(os.path.join(self.reader_config.dataPath,fileName)): + # path = self.reader_config.dataPath + # elif os.path.exists(fileName): + # path = '.' + # elif os.path.exists(os.path.join('.','raw', fileName)): + # path = os.path.join('.','raw') + # elif os.path.exists(os.path.join('..','raw', fileName)): + # path = os.path.join('..','raw') + # elif os.path.exists(f'/afs/psi.ch/project/sinqdata/{self.reader_config.year}/amor/{int(number/1000)}/{fileName}'): + # path = f'/afs/psi.ch/project/sinqdata/{self.reader_config.year}/amor/{int(number/1000)}' + # else: + # sys.exit(f'# ERROR: the file {fileName} is nowhere to be found!') + # return os.path.join(path, fileName) #------------------------------------------------------------------------------------------------- def path_generator(self, number): fileName = f'amor{self.reader_config.year}n{number:06d}.hdf' - if os.path.exists(os.path.join(self.reader_config.dataPath,fileName)): - path = self.reader_config.dataPath - elif os.path.exists(fileName): - path = '.' - elif os.path.exists(os.path.join('.','raw', fileName)): - path = os.path.join('.','raw') - elif os.path.exists(os.path.join('..','raw', fileName)): - path = os.path.join('..','raw') - elif os.path.exists(f'/afs/psi.ch/project/sinqdata/{self.reader_config.year}/amor/{int(number/1000)}/{fileName}'): - path = f'/afs/psi.ch/project/sinqdata/{self.reader_config.year}/amor/{int(number/1000)}' - else: - sys.exit(f'# ERROR: the file {fileName} is nowhere to be found!') + path = '' + for rawd in self.reader_config.raw: + if os.path.exists(os.path.join(rawd,fileName)): + path = rawd + break + if not path: + if os.path.exists(f'/afs/psi.ch/project/sinqdata/{self.reader_config.year}/amor/{int(number/1000)}/{fileName}'): + path = f'/afs/psi.ch/project/sinqdata/{self.reader_config.year}/amor/{int(number/1000)}' + else: + sys.exit(f'# ERROR: the file {fileName} can not be found in {self.reader_config.raw}!') return os.path.join(path, fileName) #------------------------------------------------------------------------------------------------- def expand_file_list(self, short_notation): diff --git a/libeos/options.py b/libeos/options.py index 84ff649..74af445 100644 --- a/libeos/options.py +++ b/libeos/options.py @@ -10,6 +10,7 @@ class Defaults: #fileIdentifier normalisationFileIdentifier = [] dataPath = '.' + raw = ['.', './raw', '../raw', '../../raw'] year = datetime.now().year #subtract outputName = "fromEOS" @@ -40,6 +41,7 @@ class Defaults: class ReaderConfig: year: int dataPath: str + raw: Tuple[str] startTime: Optional[float] = 0 @dataclass @@ -102,6 +104,8 @@ class EOSConfig: inpt += f' -Y {datetime.now().year}' if self.reader_config.dataPath != '.': inpt += f' --dataPath {self.reader_config.dataPath}' + if self.reader_config.raw != '.': + inpt = f' --rawd {self.reader_config.raw}' if self.reduction_config.subtract: inpt += f' -subtract {self.reduction_config.subtract}' if self.reduction_config.normalisationFileIdentifier: diff --git a/neos.py b/neos.py deleted file mode 100644 index 61a2232..0000000 --- a/neos.py +++ /dev/null @@ -1,46 +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 -from libeos.reduction import AmorReduction - -#===================================================================================================== -# 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() - # Create reducer with these arguments - reducer = AmorReduction(config) - # Perform actual reduction - reducer.reduce() - - logging.info('######## eos - finished ########') - -if __name__ == '__main__': - main() diff --git a/neos.py b/neos.py new file mode 120000 index 0000000..6496bc3 --- /dev/null +++ b/neos.py @@ -0,0 +1 @@ +eos.py \ No newline at end of file