Open beamline data straight from raw file
This commit is contained in:
parent
1126809c5a
commit
ebb98debff
2 changed files with 29 additions and 26 deletions
|
|
@ -23,15 +23,14 @@ def get_image_headers(path):
|
||||||
return image.header
|
return image.header
|
||||||
|
|
||||||
|
|
||||||
def integrate_1d(calibrant, bins, path=None, image=None, options=None):
|
def integrate_1d(data, options={}):
|
||||||
''' Integrates an image file to a 1D diffractogram.
|
''' Integrates an image file to a 1D diffractogram.
|
||||||
|
|
||||||
Input:
|
Required content of data:
|
||||||
calibrant: path to .poni-file
|
calibrant (str): path to .poni-file
|
||||||
bins: Number of bins to divide image into
|
nbins (int): Number of bins to divide image into
|
||||||
path (optional): path to image file - either this or image must be specified. If both is passed, image is prioritsed
|
path (str) (optional): path to image file - either this or image must be specified. If both is passed, image is prioritsed
|
||||||
image (optional): image array (Numpy) as extracted from get_image_array
|
image (str) (optional): image array (Numpy) as extracted from get_image_array
|
||||||
options (optional): dictionary of options
|
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
df: DataFrame contianing 1D diffractogram if option 'return' is True
|
df: DataFrame contianing 1D diffractogram if option 'return' is True
|
||||||
|
|
@ -56,15 +55,15 @@ def integrate_1d(calibrant, bins, path=None, image=None, options=None):
|
||||||
options[option] = default_options[option]
|
options[option] = default_options[option]
|
||||||
|
|
||||||
|
|
||||||
if not image:
|
if 'image' not in data.keys():
|
||||||
image = get_image_array(path)
|
data['image'] = get_image_array(data['path'])
|
||||||
|
|
||||||
ai = pyFAI.load(calibrant)
|
ai = pyFAI.load(data['calibrant'])
|
||||||
|
|
||||||
|
|
||||||
if not options['filename']:
|
if not options['filename']:
|
||||||
if path:
|
if data['path']:
|
||||||
filename = os.path.join(options['save_folder'], os.path.split(path)[-1].split('.')[0] + options['extension'])
|
filename = os.path.join(options['save_folder'], os.path.split(data['path'])[-1].split('.')[0] + options['extension'])
|
||||||
else:
|
else:
|
||||||
filename = os.path.join(options['save_folder'], 'integrated.dat')
|
filename = os.path.join(options['save_folder'], 'integrated.dat')
|
||||||
|
|
||||||
|
|
@ -84,9 +83,8 @@ def integrate_1d(calibrant, bins, path=None, image=None, options=None):
|
||||||
os.makedirs(options['save_folder'])
|
os.makedirs(options['save_folder'])
|
||||||
|
|
||||||
|
|
||||||
res = ai.integrate1d(image, bins, unit=options['unit'], filename=filename)
|
res = ai.integrate1d(data['image'], data['nbins'], unit=options['unit'], filename=filename)
|
||||||
|
|
||||||
if options['return']:
|
|
||||||
return read_diffractogram(filename)
|
return read_diffractogram(filename)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -245,16 +243,23 @@ def read_diffractogram(path):
|
||||||
return diffractogram
|
return diffractogram
|
||||||
|
|
||||||
|
|
||||||
def read_data(path, kind, options=None):
|
def read_data(data, options={}):
|
||||||
|
|
||||||
if kind == 'beamline':
|
if data['plot_kind'] == 'beamline':
|
||||||
diffractogram = read_diffractogram(path)
|
|
||||||
|
|
||||||
elif kind == 'recx':
|
beamline = ['mar3450', 'edf', 'cbf']
|
||||||
diffractogram = read_brml(path, options=options)
|
|
||||||
|
|
||||||
elif kind == 'image':
|
if data['path'].split('.')[-1] in beamline:
|
||||||
diffractogram = get_image_array(path)
|
diffractogram = integrate_1d(data=data, options=options)
|
||||||
|
|
||||||
|
else:
|
||||||
|
diffractogram = read_diffractogram(data['path'])
|
||||||
|
|
||||||
|
elif data['plot_kind'] == 'recx':
|
||||||
|
diffractogram = read_brml(data['path'], options=options)
|
||||||
|
|
||||||
|
elif data['plot_kind'] == 'image':
|
||||||
|
diffractogram = get_image_array(data['path'])
|
||||||
|
|
||||||
|
|
||||||
return diffractogram
|
return diffractogram
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ def plot_diffractogram(plot_data, options={}):
|
||||||
plot_data (dict): Must include path = string to diffractogram data, and plot_kind = (recx, beamline, image)'''
|
plot_data (dict): Must include path = string to diffractogram data, and plot_kind = (recx, beamline, image)'''
|
||||||
|
|
||||||
# Update options
|
# Update options
|
||||||
required_options = ['x_vals', 'y_vals', 'ylabel', 'xlabel', 'xunit', 'yunit', 'line', 'scatter',
|
required_options = ['x_vals', 'y_vals', 'ylabel', 'xlabel', 'xunit', 'yunit', 'line', 'scatter', 'xlim', 'ylim',
|
||||||
'reflections_plot', 'reflections_indices', 'reflections_data', 'plot_kind', 'palettes', 'interactive', 'rc_params', 'format_params']
|
'reflections_plot', 'reflections_indices', 'reflections_data', 'plot_kind', 'palettes', 'interactive', 'rc_params', 'format_params']
|
||||||
|
|
||||||
default_options = {
|
default_options = {
|
||||||
|
|
@ -59,8 +59,6 @@ def plot_diffractogram(plot_data, options={}):
|
||||||
if len(options['reflections_data']) >= 1:
|
if len(options['reflections_data']) >= 1:
|
||||||
options = determine_grid_layout(options=options)
|
options = determine_grid_layout(options=options)
|
||||||
|
|
||||||
print(options['format_params']['nrows'])
|
|
||||||
|
|
||||||
|
|
||||||
# Prepare plot, and read and process data
|
# Prepare plot, and read and process data
|
||||||
|
|
||||||
|
|
@ -84,7 +82,7 @@ def plot_diffractogram(plot_data, options={}):
|
||||||
colours = btp.generate_colours(options['palettes'])
|
colours = btp.generate_colours(options['palettes'])
|
||||||
|
|
||||||
|
|
||||||
diffractogram = xrd.io.read_data(path=plot_data['path'], kind=plot_data['plot_kind'], options=options)
|
diffractogram = xrd.io.read_data(data=plot_data)
|
||||||
|
|
||||||
|
|
||||||
if options['line']:
|
if options['line']:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue