From 8c3861c984147e13ef54f7b4899fcfff655be14a Mon Sep 17 00:00:00 2001 From: halvorhv Date: Wed, 31 Aug 2022 20:36:31 +0200 Subject: [PATCH 1/3] Fixed split_scan_data for trans data w/o roi --- nafuma/xanes/io.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nafuma/xanes/io.py b/nafuma/xanes/io.py index 4b98727..3311746 100644 --- a/nafuma/xanes/io.py +++ b/nafuma/xanes/io.py @@ -10,7 +10,7 @@ def split_scan_data(data: dict, options={}) -> list: ''' Splits a XANES-file from BM31 into different files depending on the edge. Has the option to add intensities of all scans of same edge into the same file. As of now only picks out xmap_rois (fluoresence mode) and for Mn, Fe, Co and Ni K-edges.''' - required_options = ['log', 'logfile', 'save', 'save_folder', 'replace', 'active_roi', 'add_rois', 'return'] + required_options = ['log', 'logfile', 'save', 'save_folder', 'replace', 'active_roi', 'add_rois', 'return', 'skip_if_no_roi'] default_options = { 'log': False, @@ -20,7 +20,8 @@ def split_scan_data(data: dict, options={}) -> list: 'replace': False, # whether to replace the files if they already exist 'active_roi': None, 'add_rois': False, # Whether to add the rois of individual scans of the same edge together - 'return': True + 'return': True, + 'skip_if_no_roi': True } options = aux.update_options(options=options, required_options=required_options, default_options=default_options) @@ -100,10 +101,14 @@ def split_scan_data(data: dict, options={}) -> list: if not ('xmap_roi00' in headers[i]) and (not 'xmap_roi01' in headers[i]): + if options['skip_if_no_roi']: + if options['log']: + aux.write_log(message='... ... Did not find fluoresence data. Skipping...', options=options) + continue if options['log']: - aux.write_log(message='... ... Did not find fluoresence data. Skipping...', options=options) + aux.write_log(message='... ... Did not find fluoresence data, but still proceeding ...', options=options) - continue + From 8714e86753ddeb699d004d6f1084b9d7d95d40c7 Mon Sep 17 00:00:00 2001 From: halvorhv Date: Thu, 1 Sep 2022 14:08:26 +0200 Subject: [PATCH 2/3] Also hh:mm:ss is importable as time stamp from xas --- nafuma/xanes/io.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nafuma/xanes/io.py b/nafuma/xanes/io.py index 3311746..373a3bc 100644 --- a/nafuma/xanes/io.py +++ b/nafuma/xanes/io.py @@ -367,8 +367,13 @@ def read_metadata(data: dict, options={}) -> dict: if options['get_timestamp']: with open(filename, 'r') as f: - time = f.readline().strip('# Time: ') - time = datetime.datetime.strptime(time, "%a %b %d %H:%M:%S %Y ") + #time = f.readline().strip('# Time: ') #<-- Previous code + time = f.readline().split('# Time: ')[-1] #Hope this does not fuck you up, Rasmus - but I needed another space here + split_operator=time[-9] #This should be the operator that splits hours, minutes and seconds + if split_operator == ".": + time = datetime.datetime.strptime(time, "%a %b %d %H.%M.%S %Y ") + if split_operator == ":": + time = datetime.datetime.strptime(time, "%a %b %d %H:%M:%S %Y ") if options['adjust_time']: time_elapsed = scan_data['Htime'].iloc[-1] - scan_data['Htime'].iloc[0] From 716e4acb822a78f690fe1492b5ef9bdd2642a5df Mon Sep 17 00:00:00 2001 From: halvorhv Date: Thu, 1 Sep 2022 14:09:03 +0200 Subject: [PATCH 3/3] Also hh:mm:ss is usable when selecting spectra --- nafuma/xanes/plot.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nafuma/xanes/plot.py b/nafuma/xanes/plot.py index 440308c..78230c6 100644 --- a/nafuma/xanes/plot.py +++ b/nafuma/xanes/plot.py @@ -64,14 +64,22 @@ def plot_xanes(data, options={}): def pick_out_scans(metadata: dict, timestamp: list): # If either start or end are None, set to way back when or way into the future + split_operator=timestamp[0][-3] #Adding this to enable reading of both "." and ":" as operators to split hour:minute:second + if not timestamp[0]: timestamp[0] = datetime.datetime.strptime('1970 01 01 00:00:00', '%Y %m %d %H:%M:%S') else: - timestamp[0] = datetime.datetime.strptime(timestamp[0], "%d.%b %y %H.%M.%S") + if split_operator == ".": + timestamp[0] = datetime.datetime.strptime(timestamp[0], "%d.%b %y %H.%M.%S") + if split_operator == ":": + timestamp[0] = datetime.datetime.strptime(timestamp[0], "%d.%b %y %H:%M:%S") if not timestamp[1]: timestamp[1] = datetime.datetime.strptime('3000 01 01 00:00:00', '%Y %m %d %H:%M:%S') else: - timestamp[1] = datetime.datetime.strptime(timestamp[1], "%d.%b %y %H.%M.%S") + if split_operator == ".": + timestamp[1] = datetime.datetime.strptime(timestamp[1], "%d.%b %y %H.%M.%S") + if split_operator == ":": + timestamp[1] = datetime.datetime.strptime(timestamp[1], "%d.%b %y %H:%M:%S") scans = [] for i, time in enumerate(metadata['time']):