From b848d66290f3ed0e21e53cbedad7f95eaa3ebf5d Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Fri, 4 Oct 2024 15:10:11 +0200 Subject: [PATCH] changed path variable names + new option lowCurrentThreshold --- libeos/command_line.py | 24 +++++++++++++++--------- libeos/file_reader.py | 14 +++++++------- libeos/options.py | 19 +++++++++++-------- libeos/reduction.py | 22 +++++++++++----------- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/libeos/command_line.py b/libeos/command_line.py index 4d51ab8..6bb2a4b 100644 --- a/libeos/command_line.py +++ b/libeos/command_line.py @@ -26,14 +26,14 @@ def commandLineArgs(): input_data.add_argument("-nm", "--normalisationMethod", default = Defaults.normalisationMethod, help = "normalisation method: [o]verillumination, [u]nderillumination, [d]irect_beam") - input_data.add_argument("--raw", + input_data.add_argument("-rp", "--rawPath", type = str, - default = Defaults.raw, - help = "relative path to directory with .hdf files") - input_data.add_argument("-d", "--dataPath", + default = Defaults.rawPath, + help = "ath to directory with .hdf files") + input_data.add_argument("-op", "--outputPath", type = str, - default = Defaults.dataPath, - help = "relative path for output") + default = Defaults.outputPath, + help = "path for output") input_data.add_argument("-Y", "--year", default = Defaults.year, type = int, @@ -98,6 +98,11 @@ def commandLineArgs(): nargs = 2, type = float, help = "q_z range") + masks.add_argument("-ct", "--lowCurrentThreshold", + default = Defaults.lowCurrentThreshold, + type = float, + help = "proton current threshold for discarding neutron pulses") + overwrite = clas.add_argument_group('overwrite') overwrite.add_argument("-cs", "--chopperSpeed", @@ -172,8 +177,7 @@ def command_line_options(): reader_config = ReaderConfig( year = clas.year, - raw = clas.raw, - dataPath = clas.dataPath + rawPath = clas.rawPath, ) experiment_config = ExperimentConfig( sampleModel = clas.sampleModel, @@ -182,6 +186,7 @@ def command_line_options(): yRange = clas.yRange, lambdaRange = clas.lambdaRange, qzRange = clas.qzRange, + lowCurrentThreshold = clas.lowCurrentThreshold, incidentAngle = clas.incidentAngle, mu = clas.mu, nu = clas.nu, @@ -202,7 +207,8 @@ def command_line_options(): ) output_config = OutputConfig( outputFormats = output_format_list(clas.outputFormat), - outputName = clas.outputName + outputName = clas.outputName, + outputPath = clas.outputPath, ) return EOSConfig(reader_config, experiment_config, reduction_config, output_config) diff --git a/libeos/file_reader.py b/libeos/file_reader.py index bb0b8ae..ad3d8c3 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -120,7 +120,7 @@ class AmorData: def path_generator(self, number): fileName = f'amor{self.reader_config.year}n{number:06d}.hdf' path = '' - for rawd in self.reader_config.raw: + for rawd in self.reader_config.rawPath: if os.path.exists(os.path.join(rawd,fileName)): path = rawd break @@ -128,7 +128,7 @@ class AmorData: 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}!') + sys.exit(f'# ERROR: the file {fileName} can not be found in {self.reader_config.rawPath}') return os.path.join(path, fileName) #------------------------------------------------------------------------------------------------- def expand_file_list(self, short_notation): @@ -168,7 +168,7 @@ class AmorData: if self.readHeaderInfo: self.read_header_info() - logging.warning(f' data from file: {fileName}') + logging.warning(f' from file: {fileName}') self.read_individual_header() # add header content @@ -244,11 +244,11 @@ class AmorData: def associate_pulse_with_monitor(self): if self.monitorType == 'protonCharge': - lowCurrentThreshold = 0.05 # mA + #lowCurrentThreshold = 0.05 # mA self.currentTime -= self.seriesStartTime self.monitorPerPulse = get_current_per_pulse(self.pulseTimeS, self.currentTime, self.current) * 2*self.tau * 1e-3 # filter low-current pulses - self.monitorPerPulse = np.where(self.monitorPerPulse > 2*self.tau *lowCurrentThreshold, self.monitorPerPulse, 0) + self.monitorPerPulse = np.where(self.monitorPerPulse > 2*self.tau * self.config.lowCurrentThreshold/1e3, self.monitorPerPulse, 0) # remove 'partially filled' pulses self.monitorPerPulse[0] = 0 self.monitorPerPulse[-1] = 0 @@ -275,8 +275,8 @@ class AmorData: self.tof_e = self.tof_e[filter_e] self.pixelID_e = self.pixelID_e[filter_e] self.wallTime_e = self.wallTime_e[filter_e] - logging.warning(f' rejected {np.shape(self.monitorPerPulse)[0]-np.shape(goodTimeS)[0]} pulses due to low beam current') - logging.warning(f' rejected {np.shape(filter_e)[0]-np.shape(self.tof_e)[0]} events due to low beam current') + logging.info(f' rejected {np.shape(self.monitorPerPulse)[0]-np.shape(goodTimeS)[0]} pulses due to low beam current') + logging.info(f' rejected {np.shape(filter_e)[0]-np.shape(self.tof_e)[0]} events due to low beam current') def filter_qz_range(self, norm): if self.config.qzRange[1]<0.3 and not norm: diff --git a/libeos/options.py b/libeos/options.py index 2b0c6ab..5d35cae 100644 --- a/libeos/options.py +++ b/libeos/options.py @@ -5,13 +5,14 @@ from dataclasses import dataclass, field from typing import Optional, Tuple from datetime import datetime from os import path +import numpy as np import logging class Defaults: # fileIdentifier - dataPath = '.' - raw = ['.', path.join('.','raw'), path.join('..','raw'), path.join('..','..','raw')] + outputPath = '.' + rawPath = ['.', path.join('.','raw'), path.join('..','raw'), path.join('..','..','raw')] year = datetime.now().year normalisationFileIdentifier = [] normalisationMethod = 'o' @@ -35,6 +36,7 @@ class Defaults: mu = 0 nu = 0 sampleModel = None + lowCurrentThreshold = 50 # @@ -42,8 +44,7 @@ class Defaults: @dataclass class ReaderConfig: year: int - dataPath: str - raw: Tuple[str] + rawPath: Tuple[str] startTime: Optional[float] = 0 @dataclass @@ -53,6 +54,7 @@ class ExperimentConfig: yRange: Tuple[float, float] lambdaRange: Tuple[float, float] qzRange: Tuple[float, float] + lowCurrentThreshold: float sampleModel: Optional[str] = None chopperPhaseOffset: float = 0 @@ -80,6 +82,7 @@ class ReductionConfig: class OutputConfig: outputFormats: list outputName: str + outputPath: str @dataclass class EOSConfig: @@ -105,10 +108,10 @@ class EOSConfig: inpt += f' -Y {self.reader.year}' else: inpt += f' -Y {datetime.now().year}' - if self.reader.dataPath != '.': - inpt += f' --dataPath {self.reader.dataPath}' - #if self.reader.raw != '.': - # inpt = f' --rawd {self.reader.raw}' + if self.output.outputPath != '.': + inpt += f' --outputdPath {self.output.outputPath}' + if np.shape(self.reader.rawPath)[0] == 1: + inpt += f' --rawPath {self.reader.rawPath}' if self.reduction.subtract: inpt += f' -subtract {self.reduction.subtract}' if self.reduction.normalisationFileIdentifier: diff --git a/libeos/reduction.py b/libeos/reduction.py index 5c66557..103fc86 100644 --- a/libeos/reduction.py +++ b/libeos/reduction.py @@ -23,9 +23,9 @@ class AmorReduction: self.header.reduction.call = config.call_string() def reduce(self): - if not os.path.exists(f'{self.reader_config.dataPath}'): - logging.debug(f'Creating destination path {self.reader_config.dataPath}') - os.system(f'mkdir {self.reader_config.dataPath}') + if not os.path.exists(f'{self.output_config.outputPath}'): + logging.debug(f'Creating destination path {self.output_config.outputPath}') + os.system(f'mkdir {self.output_config.outputPath}') # load or create normalisation matrix if self.reduction_config.normalisationFileIdentifier: @@ -185,15 +185,15 @@ class AmorReduction: # make overwriting log lines possible by removing newline at the end #logging.StreamHandler.terminator = "\r" logging.warning(f' time slizing') + logging.info(' slize time monitor') for ti, time in enumerate(np.arange(start, stop, interval)): - logging.info(f' slize {ti:4d} t = {time:5.0f}') filter_e = np.where((time