From 30f616d3ab4a6a75da97178c537296a4fbf3271e Mon Sep 17 00:00:00 2001 From: Artur Glavic Date: Thu, 26 Feb 2026 12:54:33 +0100 Subject: [PATCH] Add option to append Rqz datasets --- eos/options.py | 8 ++++++++ eos/reduction_reflectivity.py | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/eos/options.py b/eos/options.py index 1d66432..233e41e 100644 --- a/eos/options.py +++ b/eos/options.py @@ -543,6 +543,14 @@ class ReflectivityOutputConfig(ArgParsable): }, ) + append: bool = field( + default=False, + metadata={ + 'group': 'output', + 'help': 'if file already exists, append result as additional ORSO dataset (only Rqz.ort)', + }, + ) + def _output_format_list(self, outputFormat): format_list = [] if OutputFomatOption.ort in outputFormat\ diff --git a/eos/reduction_reflectivity.py b/eos/reduction_reflectivity.py index 4a9756e..d95ab0f 100644 --- a/eos/reduction_reflectivity.py +++ b/eos/reduction_reflectivity.py @@ -329,8 +329,23 @@ class ReflectivityReduction: def save_Rqz(self): fname = os.path.join(self.config.output.outputPath, f'{self.config.output.outputName}.Rqz.ort') logging.warning(f' {fname}') - theSecondLine = f' {self.header.experiment.title} | {self.header.experiment.start_date} | sample {self.header.sample.name} | R(q_z)' - fileio.save_orso(self.datasetsRqz, fname, data_separator='\n', comment=theSecondLine) + if os.path.exists(fname) and self.config.output.append: + logging.info(' file already exists, append as new dataset') + with open(fname, 'r') as f: + f.readline() + theSecondLine = f.readline()[3:] + prev_data = fileio.load_orso(fname) + prev_names = [di.info.data_set for di in prev_data] + for i, di in enumerate(self.datasetsRqz): + while di.info.data_set in prev_names: + if di.info.data_set.startswith('Nr '): + di.info.data_set = f'Nr {i+len(prev_data)} :'+di.info.data_set.split(':', 1)[1] + break + di.info.data_set = di.info.data_set+'_' + fileio.save_orso(prev_data+self.datasetsRqz, fname, data_separator='\n', comment=theSecondLine) + else: + theSecondLine = f' {self.header.experiment.title} | {self.header.experiment.start_date} | sample {self.header.sample.name} | R(q_z)' + fileio.save_orso(self.datasetsRqz, fname, data_separator='\n', comment=theSecondLine) def save_Rtl(self): fname = os.path.join(self.config.output.outputPath, f'{self.config.output.outputName}.Rlt.ort')