From f504c7dd691fa7fa360680e7dbad58e218ec866f Mon Sep 17 00:00:00 2001 From: rasmusvt Date: Thu, 31 Mar 2022 13:52:59 +0200 Subject: [PATCH 1/2] Add interactive offset_y --- beamtime/xrd/io.py | 20 +++++++++++++++----- beamtime/xrd/plot.py | 11 ++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/beamtime/xrd/io.py b/beamtime/xrd/io.py index 14c0f98..dc53b29 100644 --- a/beamtime/xrd/io.py +++ b/beamtime/xrd/io.py @@ -341,11 +341,13 @@ def read_data(data, options={}, index=0): diffractogram, wavelength = read_xy(data=data, options=options, index=index) - if options['normalise']: - diffractogram['I'] = diffractogram['I'] / diffractogram['I'].max() - if options['offset']: + if options['offset'] or options['normalise']: + # Make copy of the original intensities before any changes are made through normalisation or offset, to easily revert back if need to update. + diffractogram['I_org'] = diffractogram['I'] + diffractogram['2th_org'] = diffractogram['2th'] + diffractogram = apply_offset(diffractogram, wavelength, index, options) @@ -355,13 +357,21 @@ def read_data(data, options={}, index=0): def apply_offset(diffractogram, wavelength, index, options): + + options['current_offset_y'] = options['offset_y'] + options['current_offset_x'] = options['offset_x'] + #Apply offset along y-axis - diffractogram['I_org'] = diffractogram['I'] # make copy of original intensities + diffractogram['I'] = diffractogram['I_org'] # Reset intensities + + if options['normalise']: + diffractogram['I'] = diffractogram['I'] / diffractogram['I'].max() + diffractogram['I'] = diffractogram['I'] + index*options['offset_y'] # Apply offset along x-axis relative_shift = (wavelength / 1.54059)*options['offset_x'] # Adjusts the offset-factor to account for wavelength, so that offset_x given is given in 2th_cuka-units - diffractogram['2th_org'] = diffractogram['2th'] + diffractogram['2th'] = diffractogram['2th_org'] diffractogram['2th'] = diffractogram['2th'] + index*relative_shift diff --git a/beamtime/xrd/plot.py b/beamtime/xrd/plot.py index 78c3906..d7a9a5c 100644 --- a/beamtime/xrd/plot.py +++ b/beamtime/xrd/plot.py @@ -81,6 +81,13 @@ def plot_diffractogram(data, options={}): options['xlim'] = [diffractogram[options['x_vals']].min(), diffractogram[options['x_vals']].max()] + if options['interactive_session_active']: + if options['offset']: + if (options['offset_x'] != options['current_offset_x']) or (options['offset_y'] != options['current_offset_y']): + for i, (diff, wl) in enumerate(zip(data['diffractogram'], data['wavelength'])): + xrd.io.apply_offset(diff, wl, i, options) + + # Start inteactive session with ipywidgets. Disables options['interactive'] in order for the interactive loop to not start another interactive session if options['interactive']: options['interactive'] = False @@ -156,7 +163,9 @@ def plot_diffractogram(data, options={}): if options['interactive_session_active']: btp.update_widgets(options=options) - xrd.io.up + + + return diffractogram, fig, ax From 6f9fefae086b6729e7b68379eb969ee10542e493 Mon Sep 17 00:00:00 2001 From: rasmusvt Date: Thu, 31 Mar 2022 14:02:04 +0200 Subject: [PATCH 2/2] Add interactive offset_x --- beamtime/xrd/plot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beamtime/xrd/plot.py b/beamtime/xrd/plot.py index d7a9a5c..012e9b8 100644 --- a/beamtime/xrd/plot.py +++ b/beamtime/xrd/plot.py @@ -236,7 +236,8 @@ def plot_diffractogram_interactive(data, options): x_vals=widgets.Dropdown(options=['2th', 'd', '1/d', 'q', 'q2', 'q4', '2th_cuka', '2th_moka'], value='2th', description='X-values'), xlim=options['widgets']['xlim']['w'], ylim=widgets.FloatRangeSlider(value=[ymin_start, ymax_start], min=ymin, max=ymax, step=0.5, layout=widgets.Layout(width='95%')), - offset_y=widgets.FloatSlider(value=options['offset_y'], min=-5, max=5) + offset_y=widgets.BoundedFloatText(value=options['offset_y'], min=-5, max=5, step=0.01), + offset_x=widgets.BoundedFloatText(value=options['offset_x'], min=-1, max=1, step=0.01) ) else: