Add change modes in interactive mode
This commit is contained in:
parent
6f2d96005d
commit
a96210cf07
2 changed files with 43 additions and 48 deletions
|
|
@ -69,8 +69,8 @@ def integrate_1d(data, options={}):
|
||||||
|
|
||||||
res = ai.integrate1d(data['image'], data['nbins'], unit=options['unit'], filename=filename)
|
res = ai.integrate1d(data['image'], data['nbins'], unit=options['unit'], filename=filename)
|
||||||
|
|
||||||
diff_data = {'path': filename}
|
data['path'] = filename
|
||||||
diffractogram = read_xy(data=diff_data, options=options)
|
diffractogram = read_xy(data=data, options=options)
|
||||||
|
|
||||||
if not options['save']:
|
if not options['save']:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
@ -175,24 +175,17 @@ def view_integrator(calibrant):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def read_brml(path, options=None):
|
def read_brml(data, options={}):
|
||||||
|
|
||||||
|
|
||||||
required_options = ['extract_folder', 'save_folder']
|
required_options = ['extract_folder', 'save_folder']
|
||||||
default_options = {
|
default_options = {
|
||||||
'extract_folder': 'temp',
|
'extract_folder': 'tmp',
|
||||||
'save_folder': None
|
'save_folder': None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if not options:
|
options = aux.update_options(options=options, required_options=required_options, default_options=default_options)
|
||||||
options = default_options
|
|
||||||
|
|
||||||
else:
|
|
||||||
for option in required_options:
|
|
||||||
if option not in options.keys():
|
|
||||||
options[option] = default_options[option]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not os.path.isdir(options['extract_folder']):
|
if not os.path.isdir(options['extract_folder']):
|
||||||
|
|
@ -200,7 +193,7 @@ def read_brml(path, options=None):
|
||||||
|
|
||||||
|
|
||||||
# Extract the RawData0.xml file from the brml-file
|
# Extract the RawData0.xml file from the brml-file
|
||||||
with zipfile.ZipFile(path, 'r') as brml:
|
with zipfile.ZipFile(data['path'], 'r') as brml:
|
||||||
for info in brml.infolist():
|
for info in brml.infolist():
|
||||||
if "RawData" in info.filename:
|
if "RawData" in info.filename:
|
||||||
brml.extract(info.filename, options['extract_folder'])
|
brml.extract(info.filename, options['extract_folder'])
|
||||||
|
|
@ -223,21 +216,26 @@ def read_brml(path, options=None):
|
||||||
if scantype.text == 'StillScan':
|
if scantype.text == 'StillScan':
|
||||||
|
|
||||||
if chain.get('Description') == 'Originally measured data.':
|
if chain.get('Description') == 'Originally measured data.':
|
||||||
for data in chain.findall('Datum'):
|
for scandata in chain.findall('Datum'):
|
||||||
data = data.text.split(',')
|
scandata = scandata.text.split(',')
|
||||||
data = [float(i) for i in data]
|
scandata = [float(i) for i in scandata]
|
||||||
twotheta, intensity = float(data[2]), float(data[3])
|
twotheta, intensity = float(scandata[2]), float(scandata[3])
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if chain.get('Description') == 'Originally measured data.':
|
if chain.get('Description') == 'Originally measured data.':
|
||||||
for data in chain.findall('Datum'):
|
for scandata in chain.findall('Datum'):
|
||||||
data = data.text.split(',')
|
scandata = scandata.text.split(',')
|
||||||
twotheta, intensity = float(data[2]), float(data[3])
|
twotheta, intensity = float(scandata[2]), float(scandata[3])
|
||||||
|
|
||||||
if twotheta > 0:
|
if twotheta > 0:
|
||||||
diffractogram.append({'2th': twotheta, 'I': intensity})
|
diffractogram.append({'2th': twotheta, 'I': intensity})
|
||||||
|
|
||||||
|
|
||||||
|
if 'wavelength' not in data.keys():
|
||||||
|
for chain in root.findall('./FixedInformation/Instrument/PrimaryTracks/TrackInfoData/MountedOptics/InfoData/Tube/WaveLengthAlpha1'):
|
||||||
|
data['wavelength'] = float(chain.attrib['Value'])
|
||||||
|
|
||||||
diffractogram = pd.DataFrame(diffractogram)
|
diffractogram = pd.DataFrame(diffractogram)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -253,10 +251,10 @@ def read_brml(path, options=None):
|
||||||
return diffractogram
|
return diffractogram
|
||||||
|
|
||||||
|
|
||||||
def read_xy(data, options):
|
def read_xy(data, options={}):
|
||||||
|
|
||||||
if 'wavelength' not in data.keys():
|
if 'wavelength' not in data.keys():
|
||||||
find_wavelength(data=data, file_ext='xy')
|
find_wavelength_from_xy(data=data)
|
||||||
|
|
||||||
with open(data['path'], 'r') as f:
|
with open(data['path'], 'r') as f:
|
||||||
position = 0
|
position = 0
|
||||||
|
|
@ -294,6 +292,9 @@ def read_data(data, options={}):
|
||||||
elif file_extension in['xy', 'xye']:
|
elif file_extension in['xy', 'xye']:
|
||||||
diffractogram = read_xy(data=data, options=options)
|
diffractogram = read_xy(data=data, options=options)
|
||||||
|
|
||||||
|
|
||||||
|
diffractogram = translate_wavelengths(diffractogram=diffractogram, wavelength=data['wavelength'])
|
||||||
|
|
||||||
return diffractogram
|
return diffractogram
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -361,30 +362,23 @@ def translate_wavelengths(diffractogram, wavelength):
|
||||||
diffractogram['q4'] = diffractogram['q']**4
|
diffractogram['q4'] = diffractogram['q']**4
|
||||||
|
|
||||||
|
|
||||||
|
return diffractogram
|
||||||
def find_wavelength(data, file_ext):
|
|
||||||
|
|
||||||
# Find from EVA-exports (.xy)
|
|
||||||
if file_ext == 'xy':
|
|
||||||
wavelength_dict = {'Cu': 1.54059, 'Mo': 0.71073}
|
|
||||||
|
|
||||||
with open(data['path'], 'r') as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
if 'Anode' in line:
|
|
||||||
anode = line.split()[8].strip('"')
|
|
||||||
data['wavelength'] = wavelength_dict[anode]
|
|
||||||
|
|
||||||
|
|
||||||
# Find from .poni-file
|
|
||||||
if file_ext in ['mar3450', 'edf', 'cbf']:
|
|
||||||
if 'calibrant' in data.keys():
|
|
||||||
with open(data['calibrant'], 'r') as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
|
|
||||||
for line in lines:
|
def find_wavelength_from_xy(data):
|
||||||
if 'Wavelength' in line:
|
|
||||||
data['wavelength'] = float(line.split[-1])
|
|
||||||
|
|
||||||
|
|
||||||
|
wavelength_dict = {'Cu': 1.54059, 'Mo': 0.71073}
|
||||||
|
|
||||||
|
with open(data['path'], 'r') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if 'Anode' in line:
|
||||||
|
anode = line.split()[8].strip('"')
|
||||||
|
data['wavelength'] = wavelength_dict[anode]
|
||||||
|
|
||||||
|
elif 'Wavelength' in line:
|
||||||
|
data['wavelength'] = float(line.split()[2])*10**10
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,8 @@ def plot_diffractogram_interactive(data, options):
|
||||||
line=widgets.ToggleButton(value=True),
|
line=widgets.ToggleButton(value=True),
|
||||||
reflections_plot=widgets.ToggleButton(value=True),
|
reflections_plot=widgets.ToggleButton(value=True),
|
||||||
reflections_indices=widgets.ToggleButton(value=False),
|
reflections_indices=widgets.ToggleButton(value=False),
|
||||||
xlim=widgets.IntRangeSlider(value=options['xlim'], min=options['xlim'][0], max=options['xlim'][1], step=1, description='xlim', layout=widgets.Layout(width='1000px')))
|
x_vals=widgets.Dropdown(options=['2th', 'd', '1/d', 'q', 'q4', 'q4', '2th_cuka', '2th_moka'], value='2th', description='X-values'),
|
||||||
|
xlim=widgets.FloatRangeSlider(value=options['xlim'], min=options['xlim'][0], max=options['xlim'][1], step=1, description='xlim', layout=widgets.Layout(width='1000px')))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
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),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue