Fix arcsin issue and allow plotting w/o reflection data
This commit is contained in:
parent
55b22d5bf1
commit
da8907083b
2 changed files with 52 additions and 15 deletions
|
|
@ -80,7 +80,8 @@ def integrate_1d(data, options={}, index=0):
|
||||||
res = ai.integrate1d(data['image'], options['nbins'], unit=options['unit'], filename=filename)
|
res = ai.integrate1d(data['image'], options['nbins'], unit=options['unit'], filename=filename)
|
||||||
|
|
||||||
data['path'][index] = filename
|
data['path'][index] = filename
|
||||||
diffractogram, wavelength = read_xy(data=data, options=options, index=index)
|
diffractogram, _ = read_xy(data=data, options=options, index=index)
|
||||||
|
wavelength = find_wavelength_from_poni(path=data['calibrant'])
|
||||||
|
|
||||||
if not options['save']:
|
if not options['save']:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
@ -282,8 +283,12 @@ def read_brml(data, options={}, index=0):
|
||||||
|
|
||||||
#if 'wavelength' not in data.keys():
|
#if 'wavelength' not in data.keys():
|
||||||
# Find wavelength
|
# Find wavelength
|
||||||
for chain in root.findall('./FixedInformation/Instrument/PrimaryTracks/TrackInfoData/MountedOptics/InfoData/Tube/WaveLengthAlpha1'):
|
|
||||||
wavelength = float(chain.attrib['Value'])
|
if not data['wavelength'][index]:
|
||||||
|
for chain in root.findall('./FixedInformation/Instrument/PrimaryTracks/TrackInfoData/MountedOptics/InfoData/Tube/WaveLengthAlpha1'):
|
||||||
|
wavelength = float(chain.attrib['Value'])
|
||||||
|
else:
|
||||||
|
wavelength = data['wavelength'][index]
|
||||||
|
|
||||||
|
|
||||||
diffractogram = pd.DataFrame(diffractogram)
|
diffractogram = pd.DataFrame(diffractogram)
|
||||||
|
|
@ -306,7 +311,11 @@ def read_xy(data, options={}, index=0):
|
||||||
|
|
||||||
#if 'wavelength' not in data.keys():
|
#if 'wavelength' not in data.keys():
|
||||||
# Get wavelength from scan
|
# Get wavelength from scan
|
||||||
wavelength = find_wavelength_from_xy(path=data['path'][index])
|
|
||||||
|
if not data['wavelength'][index]:
|
||||||
|
wavelength = find_wavelength_from_xy(path=data['path'][index])
|
||||||
|
else:
|
||||||
|
wavelength = data['wavelength'][index]
|
||||||
|
|
||||||
with open(data['path'][index], 'r') as f:
|
with open(data['path'][index], 'r') as f:
|
||||||
position = 0
|
position = 0
|
||||||
|
|
@ -387,6 +396,7 @@ def read_data(data, options={}, index=0):
|
||||||
diffractogram = apply_offset(diffractogram, wavelength, index, options)
|
diffractogram = apply_offset(diffractogram, wavelength, index, options)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
diffractogram = translate_wavelengths(data=diffractogram, wavelength=wavelength)
|
diffractogram = translate_wavelengths(data=diffractogram, wavelength=wavelength)
|
||||||
|
|
||||||
return diffractogram, wavelength
|
return diffractogram, wavelength
|
||||||
|
|
@ -506,7 +516,7 @@ def translate_wavelengths(data: pd.DataFrame, wavelength: float, to_wavelength=N
|
||||||
|
|
||||||
data['2th_cuka'] = np.NAN
|
data['2th_cuka'] = np.NAN
|
||||||
|
|
||||||
data['2th_cuka'].loc[data['2th'] <= max_2th_cuka] = 2*np.arcsin(cuka/wavelength * np.sin((data['2th']/2) * np.pi/180)) * 180/np.pi
|
data['2th_cuka'].loc[data['2th'] <= max_2th_cuka] = 2*np.arcsin(cuka/wavelength * np.sin((data['2th'].loc[data['2th'] <= max_2th_cuka]/2) * np.pi/180)) * 180/np.pi
|
||||||
|
|
||||||
# Translate to MoKalpha
|
# Translate to MoKalpha
|
||||||
moka = 0.71073 # Å
|
moka = 0.71073 # Å
|
||||||
|
|
@ -518,7 +528,7 @@ def translate_wavelengths(data: pd.DataFrame, wavelength: float, to_wavelength=N
|
||||||
|
|
||||||
data['2th_moka'] = np.NAN
|
data['2th_moka'] = np.NAN
|
||||||
|
|
||||||
data['2th_moka'].loc[data['2th'] <= max_2th_moka] = 2*np.arcsin(moka/wavelength * np.sin((data['2th']/2) * np.pi/180)) * 180/np.pi
|
data['2th_moka'].loc[data['2th'] <= max_2th_moka] = 2*np.arcsin(moka/wavelength * np.sin((data['2th'].loc[data['2th'] <= max_2th_moka]/2) * np.pi/180)) * 180/np.pi
|
||||||
|
|
||||||
|
|
||||||
# Convert to other parameters
|
# Convert to other parameters
|
||||||
|
|
@ -537,7 +547,7 @@ def translate_wavelengths(data: pd.DataFrame, wavelength: float, to_wavelength=N
|
||||||
|
|
||||||
|
|
||||||
data['2th'] = np.NAN
|
data['2th'] = np.NAN
|
||||||
data['2th'].loc[data['2th_cuka'] <= max_2th] = 2*np.arcsin(to_wavelength/cuka * np.sin((data['2th_cuka']/2) * np.pi/180)) * 180/np.pi
|
data['2th'].loc[data['2th_cuka'] <= max_2th] = 2*np.arcsin(to_wavelength/cuka * np.sin((data['2th_cuka'].loc[data['2th_cuka'] <= max_2th]/2) * np.pi/180)) * 180/np.pi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -564,6 +574,22 @@ def find_wavelength_from_xy(path):
|
||||||
elif 'Wavelength' in line:
|
elif 'Wavelength' in line:
|
||||||
wavelength = float(line.split()[2])*10**10
|
wavelength = float(line.split()[2])*10**10
|
||||||
|
|
||||||
|
else:
|
||||||
|
wavelength = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return wavelength
|
||||||
|
|
||||||
|
|
||||||
|
def find_wavelength_from_poni(path):
|
||||||
|
|
||||||
|
with open(path, 'r') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if 'Wavelength' in line:
|
||||||
|
wavelength = float(line.split()[-1])*10**10
|
||||||
|
|
||||||
|
|
||||||
return wavelength
|
return wavelength
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import nafuma.xrd as xrd
|
||||||
import nafuma.auxillary as aux
|
import nafuma.auxillary as aux
|
||||||
import nafuma.plotting as btp
|
import nafuma.plotting as btp
|
||||||
|
|
||||||
|
|
||||||
def plot_diffractogram(data, options={}):
|
def plot_diffractogram(data, options={}):
|
||||||
''' Plots a diffractogram.
|
''' Plots a diffractogram.
|
||||||
|
|
||||||
|
|
@ -67,7 +66,14 @@ def plot_diffractogram(data, options={}):
|
||||||
if not 'diffractogram' in data.keys():
|
if not 'diffractogram' in data.keys():
|
||||||
# Initialise empty list for diffractograms and wavelengths
|
# Initialise empty list for diffractograms and wavelengths
|
||||||
data['diffractogram'] = [None for _ in range(len(data['path']))]
|
data['diffractogram'] = [None for _ in range(len(data['path']))]
|
||||||
data['wavelength'] = [None for _ in range(len(data['path']))]
|
|
||||||
|
# If wavelength is not manually passed it should be automatically gathered from the .xy-file
|
||||||
|
if 'wavelength' not in data.keys():
|
||||||
|
data['wavelength'] = [None for _ in range(len(data['path']))]
|
||||||
|
else:
|
||||||
|
# If only a single value is passed it should be set to be the same for all diffractograms passed
|
||||||
|
if not isinstance(data['wavelength'], list):
|
||||||
|
data['wavelength'] = [data['wavelength'] for _ in range(len(data['path']))]
|
||||||
|
|
||||||
for index in range(len(data['path'])):
|
for index in range(len(data['path'])):
|
||||||
diffractogram, wavelength = xrd.io.read_data(data=data, options=options, index=index)
|
diffractogram, wavelength = xrd.io.read_data(data=data, options=options, index=index)
|
||||||
|
|
@ -117,7 +123,7 @@ def plot_diffractogram(data, options={}):
|
||||||
options['reflections_data'] = [options['reflections_data']]
|
options['reflections_data'] = [options['reflections_data']]
|
||||||
|
|
||||||
# Determine number of subplots and height ratios between them
|
# Determine number of subplots and height ratios between them
|
||||||
if len(options['reflections_data']) >= 1:
|
if options['reflections_data'] and len(options['reflections_data']) >= 1:
|
||||||
options = determine_grid_layout(options=options)
|
options = determine_grid_layout(options=options)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -334,10 +340,10 @@ def plot_diffractogram_interactive(data, options):
|
||||||
'heatmap_default': {'min': xminmax['heatmap'][0], 'max': xminmax['heatmap'][1], 'value': [xminmax['heatmap'][0], xminmax['heatmap'][1]], 'step': 10}
|
'heatmap_default': {'min': xminmax['heatmap'][0], 'max': xminmax['heatmap'][1], 'value': [xminmax['heatmap'][0], xminmax['heatmap'][1]], 'step': 10}
|
||||||
},
|
},
|
||||||
'ylim': {
|
'ylim': {
|
||||||
'w': widgets.FloatRangeSlider(value=[yminmax['start'][2], yminmax['start'][3]], min=yminmax['start'][0], max=yminmax['start'][1], step=0.5, layout=widgets.Layout(width='95%')),
|
'w': widgets.FloatRangeSlider(value=[yminmax['start'][2], yminmax['start'][3]], min=yminmax['start'][0], max=yminmax['start'][1], step=0.01, layout=widgets.Layout(width='95%')),
|
||||||
'state': 'heatmap' if options['heatmap'] else 'diff',
|
'state': 'heatmap' if options['heatmap'] else 'diff',
|
||||||
'diff_default': {'min': yminmax['diff'][0], 'max': yminmax['diff'][1], 'value': [yminmax['diff'][2], yminmax['diff'][3]], 'step': 0.1},
|
'diff_default': {'min': yminmax['diff'][0], 'max': yminmax['diff'][1], 'value': [yminmax['diff'][2], yminmax['diff'][3]], 'step': 0.01},
|
||||||
'heatmap_default': {'min': yminmax['heatmap'][0], 'max': yminmax['heatmap'][1], 'value': [yminmax['heatmap'][0], yminmax['heatmap'][1]], 'step': 0.1}
|
'heatmap_default': {'min': yminmax['heatmap'][0], 'max': yminmax['heatmap'][1], 'value': [yminmax['heatmap'][0], yminmax['heatmap'][1]], 'step': 0.01}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -359,7 +365,12 @@ def plot_diffractogram_interactive(data, options):
|
||||||
w = widgets.interactive(btp.ipywidgets_update, func=widgets.fixed(plot_diffractogram), data=widgets.fixed(data), options=widgets.fixed(options),
|
w = widgets.interactive(btp.ipywidgets_update, func=widgets.fixed(plot_diffractogram), data=widgets.fixed(data), options=widgets.fixed(options),
|
||||||
scatter=widgets.ToggleButton(value=False),
|
scatter=widgets.ToggleButton(value=False),
|
||||||
line=widgets.ToggleButton(value=True),
|
line=widgets.ToggleButton(value=True),
|
||||||
xlim=options['widgets']['xlim']['w'])
|
heatmap=widgets.ToggleButton(value=options['heatmap']),
|
||||||
|
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=options['widgets']['ylim']['w'],
|
||||||
|
offset_y=widgets.BoundedFloatText(value=options['offset_y'], min=-5, max=5, step=0.01, description='offset_y'),
|
||||||
|
offset_x=widgets.BoundedFloatText(value=options['offset_x'], min=-1, max=1, step=0.01, description='offset_x'))
|
||||||
|
|
||||||
|
|
||||||
options['widget'] = w
|
options['widget'] = w
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue