From 140e3192ddb7e7f28acee87e2acaee65ce1332aa Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Tue, 14 May 2024 14:46:46 +0200 Subject: [PATCH 01/12] fix of wrong angle in .norm file --- libeos/reduction.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/libeos/reduction.py b/libeos/reduction.py index e1c480d..92bc846 100644 --- a/libeos/reduction.py +++ b/libeos/reduction.py @@ -340,21 +340,11 @@ class AmorReduction: Rsm_lz = np.where(qz_lz>0.0217, 1-(qz_lz-0.0217)*(0.0625/0.0217), Rsm_lz) Rsm_lz = np.where(qz_lz>0.0217*5, np.nan, Rsm_lz) self.norm_lz = self.norm_lz / Rsm_lz - #if len(lamda_e) > 1e6: - # head = ('normalisation matrix based on the measurements\n' - # f'{fromHDF.file_list}\n' - # f'nu - mu = {self.normAngle}\n' - # f'shape= {np.shape(self.norm_lz)} (lambda, z)\n' - # f'measured at mu = {fromHDF.mu:6.3f} deg\n' - # f'N(l_lambda, z) = theta(z) / sum_i=-1..1 I(l_lambda+i, z)') - # head = head.replace('../', '') - # head = head.replace('./', '') - # head = head.replace('raw/', '') - # np.savetxt(f'{dataPath}/{name}.norm', self.norm_lz, header = head) + if len(lamda_e) > 1e6: with open(n_path, 'wb') as fh: np.save(fh, np.array(fromHDF.file_list), allow_pickle=False) - np.save(fh, np.array(fromHDF.mu), allow_pickle=False) + np.save(fh, np.array(self.normAngle), allow_pickle=False) np.save(fh, self.norm_lz, allow_pickle=False) self.normFileList = fromHDF.file_list self.header.reduction.corrections.append('normalisation with \'additional files\'') From e05fc9e1e124965919647f1856dbb9eb04221f1e Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Wed, 15 May 2024 16:41:06 +0200 Subject: [PATCH 02/12] fixed bug in chopperPhaseOffset use in combination with numba --- libeos/file_reader.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libeos/file_reader.py b/libeos/file_reader.py index 579de06..06dc774 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -227,7 +227,10 @@ class AmorData: def merge_frames(self): total_offset = self.tofCut+self.tau*self.config.chopperPhaseOffset/180. - if nb_helpers: + print(self.tau*self.config.chopperPhaseOffset/180) + #if nb_helpers: + if False: + # TODO: this routine seems to ignore total_offset self.tof_e = nb_helpers.merge_frames(self.tof_e, self.tofCut, self.tau, total_offset) else: self.tof_e = np.remainder(self.tof_e-(self.tofCut-self.tau), self.tau)+total_offset # tof shifted to 1 frame From 21259acda4707ac6734c20649c9abee4a6572187 Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Fri, 31 May 2024 07:34:45 +0200 Subject: [PATCH 03/12] removed and altered comments --- libeos/file_reader.py | 2 -- libeos/reduction.py | 12 ++++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/libeos/file_reader.py b/libeos/file_reader.py index 06dc774..54489f2 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -169,7 +169,6 @@ class AmorData: self.filter_project_x() # correct tof for beam size effect at chopper: t_cor = (delta / 180 deg) * tau - # TODO: check for correctness if not self.config.offSpecular: self.tof_e -= ( self.delta_e / 180. ) * self.tau @@ -227,7 +226,6 @@ class AmorData: def merge_frames(self): total_offset = self.tofCut+self.tau*self.config.chopperPhaseOffset/180. - print(self.tau*self.config.chopperPhaseOffset/180) #if nb_helpers: if False: # TODO: this routine seems to ignore total_offset diff --git a/libeos/reduction.py b/libeos/reduction.py index 92bc846..2ab8e9b 100644 --- a/libeos/reduction.py +++ b/libeos/reduction.py @@ -90,8 +90,8 @@ class AmorReduction: # projection on q-grid q_q, R_q, dR_q, dq_q = self.project_on_qz(qz_lz, ref_lz, err_lz, res_lz, self.norm_lz, self.mask_lz) - filter_q = np.where((self.experiment_config.qzRange[0]q_q) & (q_q>self.experiment_config.qzRange[1]), + False, True) q_q = q_q[filter_q] R_q = R_q[filter_q] dR_q = dR_q[filter_q] @@ -307,11 +307,6 @@ class AmorReduction: n_path = os.path.join(dataPath, f'{name}.norm') if os.path.exists(n_path): logging.warning(f'normalisation matrix: found and using {n_path}') - #self.norm_lz = np.loadtxt(f'{dataPath}/{name}.norm') - #with open(n_path, 'r') as fh: - # fh.readline() - # self.normFileList = fh.readline().split('[')[1].split(']')[0].replace('\'', '').split(', ') - # self.normAngle = float(fh.readline().split('= ')[1]) with open(n_path, 'rb') as fh: self.normFileList = np.load(fh, allow_pickle=True) self.normAngle = np.load(fh, allow_pickle=True) @@ -329,7 +324,7 @@ class AmorReduction: lamda_e = fromHDF.lamda_e detZ_e = fromHDF.detZ_e self.norm_lz, bins_l, bins_z = np.histogram2d(lamda_e, detZ_e, bins = (self.grid.lamda(), self.grid.z())) - self.norm_lz = np.where(self.norm_lz>0, self.norm_lz, np.nan) + self.norm_lz = np.where(self.norm_lz>2, self.norm_lz, np.nan) # correct for the SM reflectivity lamda_l = self.grid.lamda() theta_z = self.normAngle + fromHDF.delta_z @@ -338,6 +333,7 @@ class AmorReduction: qz_lz = 4.0*np.pi * np.sin(np.deg2rad(theta_lz)) / lamda_lz Rsm_lz = np.ones(np.shape(qz_lz)) Rsm_lz = np.where(qz_lz>0.0217, 1-(qz_lz-0.0217)*(0.0625/0.0217), Rsm_lz) + # TODO: introduce variable for `m` and propably for the decay Rsm_lz = np.where(qz_lz>0.0217*5, np.nan, Rsm_lz) self.norm_lz = self.norm_lz / Rsm_lz From 965e5125c8b9f41a6483a5b583e4581bb26d87b7 Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Fri, 31 May 2024 08:30:10 +0200 Subject: [PATCH 04/12] expanded the use of qzRange --- libeos/command_line.py | 1 + libeos/instrument.py | 6 ++++-- libeos/options.py | 3 ++- libeos/reduction.py | 17 +++++++++-------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libeos/command_line.py b/libeos/command_line.py index 66375ac..3bcda6f 100644 --- a/libeos/command_line.py +++ b/libeos/command_line.py @@ -181,6 +181,7 @@ def command_line_options(): ) reduction_config = ReductionConfig( qResolution = clas.qResolution, + qzRange = clas.qzRange, autoscale = clas.autoscale, thetaRange = clas.thetaRange, thetaRangeR = clas.thetaRangeR, diff --git a/libeos/instrument.py b/libeos/instrument.py index 9a48817..3760eb4 100644 --- a/libeos/instrument.py +++ b/libeos/instrument.py @@ -20,10 +20,11 @@ class Detector: class Grid: - def __init__(self, qResolution): + def __init__(self, qResolution, qzRange): self.lamdaCut = const.lamdaCut self.dldl = 0.005 # Delta lambda / lambda self.qResolution = qResolution + self.qzRange = qzRange def q(self): resolutions = [0.005, 0.01, 0.02, 0.025, 0.04, 0.05, 0.1, 1] @@ -35,7 +36,8 @@ class Grid: # linear up to qq q_grid = np.arange(0, qq, qq*dqdq) # exponential from qq on - q_grid = np.append(q_grid, qq*(1.+dqdq)**np.arange(int(np.log(0.3/qq)/np.log(1+dqdq)))) + q_grid = np.append(q_grid, qq*(1.+dqdq)**np.arange(int(np.log(self.qzRange[1]/qq)/np.log(1+dqdq)))) + q_grid = q_grid[q_grid>=self.qzRange[0]] return q_grid def lamda(self): diff --git a/libeos/options.py b/libeos/options.py index 13dedee..6f2a16c 100644 --- a/libeos/options.py +++ b/libeos/options.py @@ -58,6 +58,7 @@ class ExperimentConfig: @dataclass class ReductionConfig: qResolution: float + qzRange: Tuple[float, float] thetaRange: Tuple[float, float] thetaRangeR: Tuple[float, float] @@ -178,4 +179,4 @@ class EOSConfig: return mlst - \ No newline at end of file + diff --git a/libeos/reduction.py b/libeos/reduction.py index 2ab8e9b..a6f3642 100644 --- a/libeos/reduction.py +++ b/libeos/reduction.py @@ -17,7 +17,7 @@ class AmorReduction: self.reader_config = config.reader self.reduction_config = config.reduction self.output_config = config.output - self.grid = Grid(config.reduction.qResolution) + self.grid = Grid(config.reduction.qResolution, config.experiment.qzRange) self.header = Header() self.header.reduction.call = EOSConfig.call_string(self) @@ -87,15 +87,16 @@ class AmorReduction: headerRqz = self.header.orso_header() headerRqz.data_set = f'Nr {i} : mu = {self.file_reader.mu:6.3f} deg' - # projection on q-grid + # projection on qz-grid q_q, R_q, dR_q, dq_q = self.project_on_qz(qz_lz, ref_lz, err_lz, res_lz, self.norm_lz, self.mask_lz) - filter_q = np.where((self.experiment_config.qzRange[0]>q_q) & (q_q>self.experiment_config.qzRange[1]), - False, True) - q_q = q_q[filter_q] - R_q = R_q[filter_q] - dR_q = dR_q[filter_q] - dq_q = dq_q[filter_q] + # The filtering is now done by restricting the qz-grid + #filter_q = np.where((self.experiment_config.qzRange[0]>q_q) & (q_q>self.experiment_config.qzRange[1]), + # False, True) + #q_q = q_q[filter_q] + #R_q = R_q[filter_q] + #dR_q = dR_q[filter_q] + #dq_q = dq_q[filter_q] if self.reduction_config.autoscale: if i==0: From 857fd5162af8e3269d9d3f4b7a9406f8c4d39afc Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Tue, 4 Jun 2024 11:15:09 +0200 Subject: [PATCH 05/12] updated cach path --- events2histogram.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/events2histogram.py b/events2histogram.py index c04835e..587f3d2 100755 --- a/events2histogram.py +++ b/events2histogram.py @@ -156,7 +156,8 @@ class Meta: except (KeyError, IndexError): logging.warning(f" using parameters from nicos cache") #cachePath = '/home/amor/nicosdata/amor/cache/' - cachePath = '/home/nicos/amorcache/' + #cachePath = '/home/nicos/amorcache/' + cachePath = '/home/amor/cache/' value = str(subprocess.getoutput('/usr/bin/grep "value" '+cachePath+'nicos-mu/'+year_date)).split('\t')[-1] self.mu = float(value) value = str(subprocess.getoutput('/usr/bin/grep "value" '+cachePath+'nicos-nu/'+year_date)).split('\t')[-1] @@ -953,7 +954,7 @@ def commandLineArgs(): type=float, help ="value of nu") clas.add_argument("-P", "--chopperPhase", - default=-5., + default=7.5, type=float, help ="chopper phase offset") clas.add_argument("-p", "--plot", From 3e198cf710743c948c487d60cd55a38b1beb282e Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Fri, 7 Jun 2024 09:03:53 +0200 Subject: [PATCH 06/12] typo fix: I_yt -> T_yz --- events2histogram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/events2histogram.py b/events2histogram.py index 587f3d2..9d4037b 100755 --- a/events2histogram.py +++ b/events2histogram.py @@ -523,7 +523,7 @@ class PlotSelection: return elif arg == 'log': vmin = 0 - vmax = max(1, np.log(np.max(I_yt)+.1)/np.log(10)*1.05) + vmax = max(1, np.log(np.max(I_yz)+.1)/np.log(10)*1.05) plt.pcolormesh(bins_y[:],bins_z[:],(np.log(I_yz+6e-1)/np.log(10)).T, cmap=cmap, vmin=vmin, vmax=vmax) else: plt.pcolormesh(bins_y[:],bins_z[:],I_yz.T, cmap=cmap) From 96130276894e883a539150035503d712185746fa Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Wed, 12 Jun 2024 16:56:46 +0200 Subject: [PATCH 07/12] new cach path --- libeos/file_reader.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libeos/file_reader.py b/libeos/file_reader.py index 54489f2..6fd38d8 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -280,7 +280,8 @@ class AmorData: logging.warning(" using parameters from nicos cache") year_date = str(self.start_date).replace('-', '/', 1) #cachePath = '/home/amor/nicosdata/amor/cache/' - cachePath = '/home/nicos/amorcache/' + #cachePath = '/home/nicos/amorcache/' + cachePath = '/home/nicos/cache/' value = str(subprocess.getoutput(f'/usr/bin/grep "value" {cachePath}nicos-mu/{year_date}')).split('\t')[-1] self.mu = float(value) value = str(subprocess.getoutput(f'/usr/bin/grep "value" {cachePath}nicos-nu/{year_date}')).split('\t')[-1] From c433f0732455b00bd27e54ca9b1652892811171e Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Thu, 13 Jun 2024 13:58:17 +0200 Subject: [PATCH 08/12] cach path update --- libeos/file_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libeos/file_reader.py b/libeos/file_reader.py index 6fd38d8..e59aa51 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -281,7 +281,7 @@ class AmorData: year_date = str(self.start_date).replace('-', '/', 1) #cachePath = '/home/amor/nicosdata/amor/cache/' #cachePath = '/home/nicos/amorcache/' - cachePath = '/home/nicos/cache/' + cachePath = '/home/amor/cache/' value = str(subprocess.getoutput(f'/usr/bin/grep "value" {cachePath}nicos-mu/{year_date}')).split('\t')[-1] self.mu = float(value) value = str(subprocess.getoutput(f'/usr/bin/grep "value" {cachePath}nicos-nu/{year_date}')).split('\t')[-1] From 96772ed72d4ad02b5d1a97136577e121651dbad7 Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Tue, 18 Jun 2024 17:46:49 +0200 Subject: [PATCH 09/12] added new ways to calc alphaI --- libeos/command_line.py | 9 +++++---- libeos/file_reader.py | 29 +++++++++++++++++++---------- libeos/options.py | 9 +++------ libeos/reduction.py | 9 +++++++-- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/libeos/command_line.py b/libeos/command_line.py index 3bcda6f..0314b83 100644 --- a/libeos/command_line.py +++ b/libeos/command_line.py @@ -43,9 +43,10 @@ def commandLineArgs(): nargs = '+', default = Defaults.outputFormat, help = "one of [Rqz.ort, Rlt.ort]") - output.add_argument("--offSpecular", - type = bool, - default = Defaults.offSpecular, + output.add_argument("-ai", "--incidentAngle", + type = str, + default = Defaults.incidentAngle, + help = "calulate alpha_i from [alphaF, mu, nu]", ) output.add_argument("-r", "--qResolution", default = Defaults.qResolution, @@ -174,7 +175,7 @@ def command_line_options(): yRange = clas.yRange, lambdaRange = clas.lambdaRange, qzRange = clas.qzRange, - offSpecular = clas.offSpecular, + incidentAngle = clas.incidentAngle, mu = clas.mu, nu = clas.nu, muOffset = clas.muOffset diff --git a/libeos/file_reader.py b/libeos/file_reader.py index e59aa51..a494a89 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -169,8 +169,11 @@ class AmorData: self.filter_project_x() # correct tof for beam size effect at chopper: t_cor = (delta / 180 deg) * tau - if not self.config.offSpecular: + if self.config.incidentAngle == 'alphaF': self.tof_e -= ( self.delta_e / 180. ) * self.tau + else: + # TODO: check sign of correction + self.tof_e -= ( self.kad / 180. ) * self.tau self.calculate_derived_properties() @@ -188,7 +191,7 @@ class AmorData: def calculate_derived_properties(self): self.lamdaMax = const.lamdaCut+1.e13*self.tau*const.hdm/(self.chopperDetectorDistance+124.) - if nb_helpers and not self.config.offSpecular: + if nb_helpers: self.lamda_e, self.qz_e, self.mask_e = nb_helpers.calculate_derived_properties_focussing( self.tof_e, self.detXdist_e, self.delta_e, self.mask_e, self.config.lambdaRange[0], self.config.lambdaRange[1], self.nu, self.mu, @@ -200,17 +203,23 @@ class AmorData: self.mask_e = np.logical_and(self.mask_e, (self.config.lambdaRange[0]<=self.lamda_e) & ( self.lamda_e<=self.config.lambdaRange[1])) # alpha_f - alphaF_e = self.nu-self.mu+self.delta_e # q_z - if self.config.offSpecular: - alphaI = self.kap+self.kad+self.mu - self.qz_e = 2*np.pi*((np.sin(np.deg2rad(alphaF_e))+np.sin(np.deg2rad(alphaI)))/self.lamda_e) - self.qx_e = 2*np.pi*((np.cos(np.deg2rad(alphaF_e))-np.cos(np.deg2rad(alphaI)))/self.lamda_e) - self.header.measurement_scheme = 'energy-dispersive', - else: + if self.config.incidentAngle == 'alphaF': + alphaF_e = self.nu - self.mu + self.delta_e self.qz_e = 4*np.pi*(np.sin(np.deg2rad(alphaF_e))/self.lamda_e) - # qx_e = 0. + # qx_e = 0. self.header.measurement_scheme = 'angle- and energy-dispersive' + elif self.config.incidentAngle == 'nu': + alphaF_e = (self.nu + self.delta_e + self.kap + self.kad) / 2. + self.qz_e = 4*np.pi*(np.sin(np.deg2rad(alphaF_e))/self.lamda_e) + # qx_e = 0. + self.header.measurement_scheme = 'energy-dispersive' + else: + alphaF_e = self.nu - self.mu + self.delta_e + alphaI = self.kap + self.kad + self.mu + self.qz_e = 2*np.pi * ((np.sin(np.deg2rad(alphaF_e)) + np.sin(np.deg2rad(alphaI)))/self.lamda_e) + self.qx_e = 2*np.pi * ((np.cos(np.deg2rad(alphaF_e)) - np.cos(np.deg2rad(alphaI)))/self.lamda_e) + self.header.measurement_scheme = 'energy-dispersive' def filter_project_x(self): pixelLookUp = self.resolve_pixels() diff --git a/libeos/options.py b/libeos/options.py index 6f2a16c..53a3159 100644 --- a/libeos/options.py +++ b/libeos/options.py @@ -14,8 +14,9 @@ class Defaults: #subtract outputName = "fromEOS" outputFormat = ['Rqz.ort'] - offSpecular = False + incidentAngle = 'alphaF' qResolution = 0.01 + incidentAngle = 'alphaF' #timeSlize scale = [1] #autoscale @@ -43,6 +44,7 @@ class ReaderConfig: @dataclass class ExperimentConfig: + incidentAngle: str chopperPhase: float yRange: Tuple[float, float] lambdaRange: Tuple[float, float] @@ -53,7 +55,6 @@ class ExperimentConfig: mu: Optional[float] = None nu: Optional[float] = None muOffset: Optional[float] = None - offSpecular: bool = False @dataclass class ReductionConfig: @@ -152,10 +153,6 @@ class EOSConfig: if self.reduction_config.timeSlize: acts += f' --timeSlize {" ".join(str(ff) for ff in self.reduction_config.timeSlize)}' - # TODO: experiment_config = ExperimentConfig( - # offSpecular = clas.offSpecular, - # ) - mlst = base + inpt + otpt if mask: mlst += mask diff --git a/libeos/reduction.py b/libeos/reduction.py index a6f3642..e72634b 100644 --- a/libeos/reduction.py +++ b/libeos/reduction.py @@ -349,7 +349,12 @@ class AmorReduction: def project_on_lz(self, fromHDF, norm_lz, normAngle, lamda_e, detZ_e): # projection on lambda-z-grid lamda_l = self.grid.lamda() - theta_z = fromHDF.nu - fromHDF.mu + fromHDF.delta_z + if self.experiment_config.incidentAngle == 'alphaF': + theta_z = fromHDF.nu - fromHDF.mu + fromHDF.delta_z + elif self.experiment_config.incidentAngle == 'nu': + theta_z = (fromHDF.nu + fromHDF.delta_z + fromHDF.kap + fromHDF.kad) / 2. + else: + pass lamda_lz = (self.grid.lz().T*lamda_l[:-1]).T theta_lz = self.grid.lz()*theta_z @@ -380,7 +385,7 @@ class AmorReduction: int_lz, bins_l, bins_z = np.histogram2d(lamda_e, detZ_e, bins = (lamda_l, self.grid.z())) # cut normalisation sample horizon int_lz = np.where(mask_lz, int_lz, np.nan) - thetaF_lz = np.where(mask_lz, theta_lz, np.nan) + thetaF_lz = np.where(mask_lz, theta_lz, np.nan) ref_lz = (int_lz * np.absolute(thetaN_lz)) / (norm_lz * np.absolute(thetaF_lz)) err_lz = ref_lz * np.sqrt( 1/(int_lz+.1) + 1/norm_lz ) From d0504e25f1aa753eea9db9682dfff2e92361b030 Mon Sep 17 00:00:00 2001 From: Jochen Stahn <57442805+jochenstahn@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:14:25 +0200 Subject: [PATCH 10/12] corrected chopper phase offset --- libeos/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libeos/options.py b/libeos/options.py index 53a3159..84ff649 100644 --- a/libeos/options.py +++ b/libeos/options.py @@ -27,7 +27,7 @@ class Defaults: qzRange = [0.005, 0.30] chopperSpeed = 500 chopperPhase = -13.5 - chopperPhaseOffset = -5 + chopperPhaseOffset = 7 muOffset = 0 mu = 0 nu = 0 From 42e4defcca74db7e4f8fd8317e60d73d7f007b10 Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Mon, 24 Jun 2024 08:32:56 +0200 Subject: [PATCH 11/12] 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 From 4347ba05715e40bb51fa405c4343eb3b3c3229d4 Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Tue, 25 Jun 2024 13:59:16 +0200 Subject: [PATCH 12/12] fixed a bug in nb_helpers.merge_frames --- libeos/file_reader.py | 4 +--- libeos/nb_helpers.py | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libeos/file_reader.py b/libeos/file_reader.py index d9850c0..a188541 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -249,9 +249,7 @@ class AmorData: def merge_frames(self): total_offset = self.tofCut+self.tau*self.config.chopperPhaseOffset/180. - #if nb_helpers: - if False: - # TODO: this routine seems to ignore total_offset + if nb_helpers: self.tof_e = nb_helpers.merge_frames(self.tof_e, self.tofCut, self.tau, total_offset) else: self.tof_e = np.remainder(self.tof_e-(self.tofCut-self.tau), self.tau)+total_offset # tof shifted to 1 frame diff --git a/libeos/nb_helpers.py b/libeos/nb_helpers.py index 8f69824..52efc95 100644 --- a/libeos/nb_helpers.py +++ b/libeos/nb_helpers.py @@ -9,7 +9,7 @@ def merge_frames(tof_e, tofCut, tau, total_offset): dt = (tofCut-tau) for ti in nb.prange(tof_e.shape[0]): tof_e_out[ti] = ((tof_e[ti]-dt)%tau)+total_offset # tof shifted to 1 frame - return tof_e + return tof_e_out @nb.jit(nb.float64[:](nb.float64[:], nb.uint64[:], nb.float64[:]), nopython=True, parallel=True, cache=True) @@ -62,4 +62,4 @@ def calculate_derived_properties_focussing(tof_e, detXdist_e, delta_e, mask_e, mask_e_out[i] = mask_e[i] & ((lmin<=lamda_e[i]) & (lamda_e[i]<=lmax)) alphaF_e[i] = nu-mu+delta_e[i] qz_e[i] = 4*np.pi*np.sin(np.deg2rad(alphaF_e[i]))/lamda_e[i] - return lamda_e, qz_e, mask_e \ No newline at end of file + return lamda_e, qz_e, mask_e