Iguape package#
Submodules#
Iguape.Monitor module#
This is Monitor Class. It was built to track and read a given Folder for new XRD Data. It’s dependent on the iguape_fileslist.txt text file. It was built to work only for Paineira XRD Data, but it can easily be adjusted for other situations.
- class Iguape.Monitor.FolderMonitor(folder_path, fit_interval=None)[source]#
Bases:
QThreadThe Folder Monitor operates by tracking new or exiting data in a specified folder.
This class inherits the QThread class from PyQt. By reading the ‘iguape_filelist.txt’ file, it can track new or existing data files in the specified folder. Later, it reads the data and stores it in a pandas DataFrame. If a fitting interval is specified, it fits the data to a desired model and stores the fitting parameters in another DataFrame.
- Parameters:
(str) (folder_path)
(list) (fit_interval)
- __init__(folder_path, fit_interval=None)[source]#
The constructor for the FolderMonitor class. It defines all the flags necessary for the class to work, like the folder path, the fit interval, the fit model and the DataFrames.
- Parameters:
(str) (folder_path)
(list (fit_interval)
optional) (2theta interval selected to perform. Default is None)
- new_data_signal#
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- run()[source]#
The run method is the main method of the FolderMonitor class. It reads the ‘iguape_filelist.txt’ file tracking all the XRD data in the folder. Then it reads the data and stores it as DataFrames. I also performs the peak fit, if a fit interval is specified.
- set_distance(distance)[source]#
Method for defining the minimum distance between the two peak centers. Only used when the model is Split PseduoVoigt.
- Parameters:
(float) (distance)
- Iguape.Monitor.calculate_q_vector(wavelength: float, two_theta: ndarray)[source]#
- Converts 2theta values into Q vector (Scattering vector).
- \[Q = \frac{4\pi}{\lambda} \sin{\theta}\]
- Parameters:
wavelength (float) – wavelength in Angstroms
two_theta (np.ndarray) – 2theta values array
- Returns:
Q-vector
- Return type:
Q-vector values array
- Iguape.Monitor.counter()[source]#
Counter function. It counts the number of XRD data and returns its index.
- Returns:
_Index of the XRD data
- Return type:
int
- Iguape.Monitor.data_read(path)[source]#
Data reading function.
It reads the data from a given path and returns the 2theta and Intensity arrays, Temperature and Kelvin Signal tag.
- Parameters:
(str) (path)
- Returns:
x (np.array) (2theta array.)
y (np.array) (Intensity array.)
temp (float) (Temperature.)
kelvin_signal (bool) (Kelvin Signal tag.)
- Iguape.Monitor.normalize_array(array: array)[source]#
Normalizes (by the maximum) and array
- Parameters:
array (np.array) – Array to be normalized
- Returns:
Normalized (by maximum) array
- Return type:
np.array
- Iguape.Monitor.peak_fit(theta, intensity, interval, id, bkg='Linear', pars=None)[source]#
Peak fitting function for the PseudoVoigt model. Given a set of 2theta and Intensity arrays, it fits the data to the PseudoVoigt model and 2theta interval selected. It returns the fitting parameters.
- Parameters:
(np.array) (intensity)
(np.array)
(list) (interval)
(str (bkg)
optional) (Background model. Default is 'Linear'.)
- Returns:
dois_theta_0 (float) (Peak center.)
fwhm (float) (Full Width at Half Maximum.)
area (float) (Area under the peak.)
r_squared (float) (R-squared value of the fit.)
out (lmfit.ModelResult) (ModelResult. Inherited from the lmfit package.)
comps (dict) (Fitting components such as the backgroud and model function. Inherited from the lmfit package.)
theta_fit (np.array) (2theta array for the fitting interval.)
- Iguape.Monitor.peak_fit_split_gaussian(theta, intensity, interval, id, bkg='Linear', height=1000000000.0, distance=35, prominence=50, pars=None)[source]#
Peak fitting function for the Split PseudoVoigt model. Given a set of 2theta and Intensity arrays, it fits the data to the Split PseudoVoigt model and 2theta interval selected. It returns the fitting parameters.
- Parameters:
theta (np.array) – 2theta array.
intensity (np.array) – Intensity array.
interval (list) – 2theta interval for the peak fitting
id (str) – String with the index and temperature of the XRD data.
bkg (str, optional) – Background Model, defaults to ‘Linear’
height (float, optional) – Minimum height of the peaks, defaults to 1e+09
distance (int, optional) – Minimum distance bewtween the peaks, defaults to 35
prominence (int, optional) – Minimum prominence of the peaks, defaults to 50
pars (dict, optional) – Parameters dictionary (as described by lmfit), defaults to None
- Returns:
tuple with fit results
- Return type:
tuple
- Iguape.Monitor.pseudo_voigt(x, amplitude, center, sigma, eta)[source]#
PseudoVoigt function, a linear combination of a Gaussian and a Lorentzian function.
- Parameters:
(np.array) (x)
(float) (eta)
(float)
(float)
(float)
- Returns:
np.array
- Return type:
PseudoVoigt function.
Notes
- The PseudoVoigt function is defined as:
- \[PV(x; A, \mu, \sigma, \eta) = \eta L(x; A, \mu, \sigma) + (1 - \eta) G(x; A, \mu, \sigma)\]\[L(x; A, \mu, \sigma) = \frac{A}{\pi} \left[ \frac{\sigma}{(x-\mu)^2 + \sigma^{2}} \right]\]\[G(x; A, \mu, \sigma) = \frac{A}{\sigma\sqrt{2\pi}}e^{\left[ \frac{-(x - \mu)^{2}}{2\sigma^{2}} \right]}\]
- Iguape.Monitor.split_pseudo_voigt(x, amp1, cen1, sigma1, eta1, amp2, cen2, sigma2, eta2)[source]#
Split PseudoVoigt function, a linear combination of two PseudoVoigt functions.
- Parameters:
x (np.array) – 2theta array
amp1 (np.array) – Peak amplitude for the first peak
cen1 (float) – Peak center for the first peak.
sigma1 (float) – Sigma value or standard deviation for the first peak.
eta1 (float) – Eta value for the first peak (mixing parameter).
amp2 (float) – Peak amplitude for the second peak.
cen2 (float) – Peak center for the second peak.
sigma2 (float) – Sigma value or standard deviation for the second peak.
eta2 (float) – Eta value for the second peak (mixing parameter).
- Returns:
Split PseudoVoigt function
- Return type:
np.array
- Notes
- The Split PseudoVoigt function is defined as:
- \[SPV(x; A1, \mu1, \sigma1, \eta1, A2, \mu2, \sigma2, \eta2) = PV1(x; A1, \mu1, \sigma1, \eta1) + PV2(x; A2, \mu2, \sigma2, \eta2)\]
Iguape.iguape module#
This is the main script for the excution of the Paineira Graphical User Interface, a GUI for visualization and data processing during in situ experiments at Paineira. In this script, both GUIs used by the program are called and all of the backend functions and processes are defined.
- class Iguape.iguape.CustomListViewModel(data=None, unit=None)[source]#
Bases:
QAbstractListModelCustom QListView made to display the data correctly.
- Parameters:
QAbstractListModel (QAbstractListModel) – QAbstractListModel from PyQt5
- __init__(data=None, unit=None)[source]#
Constructor
- Parameters:
data (pd.DataFrame, optional) – pandas DataFrame containing the names of the XRD data files. Defaults to None.. Defaults to None.
unit (str, optional) – Temperature unit. Defaults to None.
- data(index, role=0)[source]#
- Parameters:
index (QModelIndex) – PyQt5 index for each item
role (Qt.DisplayRolde, optional) – PyQt5 Display Role for each item
- Return type:
QVariant
- flags(index)[source]#
Defines the properties of each item
- Parameters:
index (QIndexModel) – PyQt5 index for each item
- Returns:
_description_
- Return type:
_type_
- class Iguape.iguape.ExportWindow(figure: Figure, parent=None)[source]#
Bases:
QDialog,Ui_Export_FigureCustom QDialog for managing Figure export.
- Parameters:
QDialog (QDialog) – QDialog class from PyQt5
Ui_Export_Figure (_type_) – Custom QDialog mode with QDesigner
- __init__(figure: Figure, parent=None)[source]#
Constructor
- Parameters:
figure (matplotlib.figure.Figure) – matplotlib Figure class
parent (_type_, optional) – Defaults to None.
- on_change_font_comboBox(font)[source]#
Changes the label and tick font.
- Parameters:
font (str) – Font for label and ticks
- on_change_label_size_spinBox(value)[source]#
Changes the label font size
- Parameters:
value (int) – Font size
- on_change_label_style_comboBox(style)[source]#
Changes the label style
- Parameters:
style (str) – Label style (italic/bold/normal)
- on_change_tick_size_spinBox(value)[source]#
Changes the tick font size
- Parameters:
value (int) – Font size
- class Iguape.iguape.FilterWindow(data=None, kelvin_signal=None, parent=None)[source]#
Bases:
QDialog,Ui_Filter_Dialog_summary_
- Parameters:
QDialog (QDialog) – QDialog class from PyQt5
Ui_Filter_Dialog (QDialog) – Custom QDialog class made from QtDesigner
- __init__(data=None, kelvin_signal=None, parent=None)[source]#
Constructor This method will initialize the QDialog and render a QListView() in the QDialog Window.
- Parameters:
data (pd.DataFrame, optional) – pandas DataFrame containing the names of the XRD data files. Defaults to None.
kelvin_signal (Bool, optional) – Defines if the temperature unit is K or °C. Defaults to None.
parent (_type_, optional) – _description_. Defaults to None.
- mask#
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- class Iguape.iguape.FitWindow(parent=None)[source]#
Bases:
QDialog,Ui_pk_windowQDialog Window to manage the Peak Fitting options.
- Parameters:
QDialog (QDialog) – QDialog from PyQt5
Ui_pk_window (QDialog) – Custom QDialog made with QDesigner
- onChanged_bkg_combo_box(text)[source]#
Changes the Background model. Currently only Linear model is applied.
- Parameters:
text (_type_) – _description_
- onChanged_distance_spinbox(value)[source]#
Sets the distance to value. Only valid for Spli PseudoVoigt model
- Parameters:
value (int) – Minimum distance (in experimental points) between peaks.
- onChanged_height_spinbox(value)[source]#
Sets the height to value (x1e09). Only valid for Spli PseudoVoigt model
- Parameters:
value (float) – Minimum height of peaks. This float is multiplied by 1e09.
- onChanged_pk_combo_box(text)[source]#
Routine for selecting the Peak Fitting Model via the ComboBox.
- Parameters:
(str) (text)
- onChanged_prominence_spinbox(value)[source]#
Sets the prominence to value. Only valid for Spli PseudoVoigt model
- Parameters:
value (int) – Prominence of peaks. Prominence is the difference between the maximum value of the peak and the background of the measure.
- onChanged_xrd_combo_box(text)[source]#
Adds a new XRD difractogram to the Figure. If there’s already two plotted, it will ask to user to clear the canvas.
- Parameters:
text (str) – Text from the QComboBox. It identifies the XRD data.
- onselect(xmin, xmax)[source]#
Sets the selected fit interval as [xmin, xmax]. It also draws a rectangle spaning the interval (axvspan)
- Parameters:
xmin (float) – Lower bound of the interval
xmax (flat) – Upper bound of the interval
- peak_fitting_error(error_message)[source]#
Shows QMessageBox if there’s been an error during peak fitting.
- Parameters:
error_message (str) – Error message
- class Iguape.iguape.GarbageCollector[source]#
Bases:
QThreadGarbage Collector class. Inherits a QThread and calls, every 3 seconds, the collect method of python’s garbage collector. The matpltolib Figures are updated using for loops. This consumes a lot of RAM memory. This method frees up some memory space.
- Parameters:
QThread (QThread) – QThread class from PyQt5
- class Iguape.iguape.Window(parent=None)[source]#
Bases:
QMainWindow,Ui_MainWindowClass for IGUAPE main window. It inherits QMainWindow from PyQt5 and Ui_MainWindow from GUI.iguape_GUI
- Parameters:
QMainWindow (QMainWindow) – QMainWindow from PyQt5
Ui_MainWindow (QMainWindow) – Ui_MainWindow from GUI.iguape_GUI
- __init__(parent=None)[source]#
Constructor for Window class
- Parameters:
parent (optional) – Defaults to None.
- _create_double_peak_dataframe()[source]#
Method for creating a DataFrame with the results of a Split-PseudoVoigt peak fitting. :returns: pandas DataFrame with fitting parameters from a Split-PseudoVoigt peak fit. :rtype: pd.DataFrame
- _create_single_peak_dataframe()[source]#
Method for creating a DataFrame with the results of a PseudoVoigt peak fitting. :returns: pandas DataFrame with fitting parameters from a PseudoVoigt single peak fit. :rtype: pd.DataFrame
- _get_mask(i: int)[source]#
Method for getting the \(2\theta\) mask, given the selection of interval by SpanSelector in the XRD Data tab.
- Parameters:
i (int) – index of the XRD pattern
- Returns:
slice object as a mask.
- Return type:
slice
- _open_url(url: str)[source]#
Uses QDesktopServices to open URL from logos.
- Parameters:
url (str) – url to websites (as strings)
- _plot_double_peak()[source]#
Hidden method to call
Window._plot_parameter()in order to plot fitting parameters of a double peak.
- _plot_fitting_parameters()[source]#
This method calls
Window._plot_single_peak()orWindow._plot_double_peak(), according to the profile model selected.
- _plot_parameter(ax, x, y, ylabel, xlabel, label=None, color=None, marker='o', yerr=None)[source]#
Generic routine to plot xy data in a given axes. :param ax: A matplotlib Axes object :type ax: matplotlib.axes.Axes :param x: x-axis data :type x: list :param y: y-axis data :type y: list :param ylabel: y-axis label :type ylabel: str :param xlabel: x-axis label :type xlabel: str :param label: Displays label. Accepts True or False. Defaults to None. :type label: bool, optional :param color: matplotlib color. Defaults to None. :type color: str, optional :param marker: matplotlib marker. Defaults to ‘o’. :type marker: str, optional :param yerr: y-axis error. Defaults to None. :type yerr: list, optional
- _plot_single_peak()[source]#
Hidden method to call
Window._plot_parameter()in order to plot fitting parameters of a single peak.
- _update_main_figure()[source]#
Routine to update XRD Data Tab graph. This calls other methods such as update_colormap and plots the selected XRD measures in the main figure.
- apply_filter()[source]#
Initializes the
FilterWindowclass.
- apply_temp_mask(mask)[source]#
Method for applying a temperature mask in the XRD measures. Recieves an array of booleans. The array has a length equal to the number of XRD data read by the
Iguape.Monitor.FolderMonitor. :param mask: numpy array with booleans as entries :type mask: np.array
- create_graphs_layout()[source]#
Routine to initialize and connect UI elements. All parameters and flags are initiated and UI element’s signals are connected to its functions.
- eventFilter(source: QLabel, event: QEvent)[source]#
eventFilter method for logo QLabel. It tracks a mouse press event and calls the
Window._open_url()- Parameters:
source (QLabel) – Object name of logo in IGUAPE UI (QLabel)
event (QEvent) – QEvent to track mouse click
- Returns:
Boolean value that determines the excution of
Window._open_url()- Return type:
Bool
- export_figure()[source]#
Method for initializing the ExportWindow class. This Window has the elements that control the fitting parameters.
- handle_new_data(new_data)[source]#
This method is connected to the signal emited by
Iguape.Monitor.FolderMonitor, which delivers a pd.DataFrame containing the XDR data.- Parameters:
new_data (pd.DataFrame) – pandas DataFrame to be concatenated with the existing one
- measure_order_index(checked)[source]#
Method connected to the measure order QCheckBox. This method will change the colormaps that identify the XRD data. All of the Figures are updated accordingly.
- Parameters:
checked (bool) – True or False
- on_change_color_pallete(index)[source]#
Sets the current item in the QComboBox.
- Parameters:
index (int) – Integer representing the index of item in the Color pallete QComboBox.
- on_change_vline_checkbox()[source]#
This method enables a Vertical Line cursor in the XRD Data Tab Figure.
- on_mouse_move(event)[source]#
This method is connected to the canvas in the XRD Data Tab graph. It shows the temperature/index of the closest XRD difractogram.
- Parameters:
event (str) – matplotlib FigureCanvas event.
- on_toggle_2theta_action()[source]#
This is triggred when the 2theta visualization option is selected by the user. This is the default visualization mode. The method updates the graphs to plot as function of 2theta.
- on_toggle_Q_vector_action()[source]#
This is triggred when the Q vector visualization option is selected by the user. This renders a QDialog for user input of the wavelength and than updates the graphs to plot as function of Q.
- onselect(xmin, xmax)[source]#
This method is passed as argument for the SpanSelector in the XRD Data Tab Graph. It sets the selected interval for visualization based on the min/max value received for 2theta.
- Parameters:
xmin (float) – minimum 2theta value of the interval selected in the XRD Data graph
xmax (float) – maximum 2theta value of the interval selected in the XRD Data graph
- read_data(path, normalize=False, Q=False)[source]#
Reads the XRD data using pandas read_csv function. Comments are identified by “#” and the header is identified by the first line.
- Parameters:
path (str)
normalize (bool, optional) – If True the XRD intensities will be normalized. Defaults to False.
Q (bool, optional) – If True the XRD x-axis will be converted from 2theta to the scattering vector Q. Defaults to False.
- Returns:
2theta and Intensity numpy arrays read from the XRD data.
- Return type:
(theta, intensity)
- save_data_frame()[source]#
This method calls two hidden method that generates the DataFrame to be saved. It also writes comments (“#”) on the top of the csv file.
- select_fit_interval()[source]#
Method for initializing the FitWindow class. This Window has the elements that control the fitting parameters.
- select_folder()[source]#
Method for selecting a folder conatining the XRD data. In order for IGUAPE to read and monitor the folder, the file iguape_filelist.txt must be present.
- temp_index(checked)[source]#
Method connected to the measure order QCheckBox. This method will change the colormaps that identify the XRD data. All of the Figures are updated accordingly.
- Parameters:
checked (bool) – True or False
- update_colormap(color_map_type: str, label: str)[source]#
Routine for updating the colormaps and norm used in the XRD Data and PeakFit tabs.
- Parameters:
color_map_type (str) – Column label of XRD patterns DataFrame. It can be temp or file_index
label (str) – _description_
- update_graphs()[source]#
Method to update Main Figure (XRD Data tab) and Plotting Parameters Figure (Peak Fitting tab).
- validate_temp(min_value, max_value)[source]#
Method for validating the temperature value entered in the temperature QDoubleSpinBox. It returns the closest available temperature from the Monitor’s DataFrame
- Parameters:
min_value (float) – Minimum temperature
max_value (float) – Maximum temperature
- Returns:
(min_temp, max_temp) tuple with the closest min/max available temperature
- Return type:
tuple
- class Iguape.iguape.Worker(interval)[source]#
Bases:
QThreadQThread that performs peak fitting in the selected XRD data. :param QThread: QThread class from PyQt5 :type QThread: QThread
- __init__(interval)[source]#
Constructor for the peak fitting thread.
- Parameters:
interval (list) – List in the form [\(2\theta_{i}\), \(2\theta_{f}\)] where \(2\theta_{i}\) and \(2\theta_{f}\) are, respectively,
fitting. (the initial and final values of the 2theta interval selected to perfor peak)
- error#
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- finished#
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
- progress#
int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- Type:
str = …, revision
Iguape.launcher module#
Execution script. It goes to the directory where Iguape is installed and it executes the program (iguape.py)
Module contents#
This is the main script for the excution of the Paineira Graphical User Interface, a GUI for visualization and data processing during in situ experiments at Paineira. In this script, both GUIs used by the program are called and all of the backend functions and processes are defined.