Skip to content

Script Mode demo

Qingteng Zhang edited this page Apr 22, 2022 · 2 revisions

Import pyXpcsViewer:

from xpcs_viewer import XpcsFile as xf

Read XPCS result file:

a = xf('my_file_name', cwd = './my_file_path')

Here a is a python object whose attributes correspond to various SAXS and XPCS quantities.

Examples are:

a.saxs_2d           # 2D SAXS pattern
a.saxs_1d["Iq"]     # 1D SAXS pattern (I vs. Q)
a.ql_sta            # List of Q values for I vs. Q (Q values for static ROI)

a.ql_dyn            # List of Q values for g2 (Q values for dynamic ROIs)
a.t_el              # Time axis of Multitau g2
a.g2                # g2 values at different dynamic ROIs
a.g2_err            # g2 error values at different dynamic ROIs

a.get_twotime_c2('exchange', ii)        # Two-time correlation function at dynamic ROI index of ii

Here ROI stands for 'Regions of Interests', i.e. Different regions on the 2D detector, within which the pixels are considered to have the same Q values and the SAXS and XPCS results can be averaged to improve the statistics.

All variables are 1D or 2D numpy arrays.

Fit g2

a also contains class methods for basic XPCS result processing. For example:

g2_fit = a.fit_g2(q_range = [0, 0.0092], 
                  t_range = [1e-8, 1e1], 
                  bounds = [[0.14, 1e-6, 1, 0.95], [0, 1, 0, 1.05]], 
                  fit_flag=[False, True, False, True])

returns a python dictionary g2_fit that contains the fitting parameters and the fitted g2 values. Specifically:

g2_fit["fit_val"][i,j,k]

is a 3D numpy array where:

  • i is the index of the dynamic ROI;
  • j = 0 for fit values, j=1 for errors;
  • k = 0, 1 ,2, 3 for different fitting parameters.

And

g2_fit["fit_line"]["fit_x"]
g2_fit["fit_line"]["fit_y"]

are two 2D numpy arrays that correspond to the x and y axes of the fitted g2 at different Q.

Fit τ vs. Q

Similar to the fit of g2:

tauq_fit = a.fit_tauq(q_range=[0.003, 0.0055], 
                      bounds=[[1e-12, -2], [1e-3, -2]], 
                      fit_flag=[True, False])

returns a python dictionary tauq_fit that contains the fitting parameters and the fitted τ vs. Q values. Specifically:

tauq_fit["tauq_q"] 
tauq_fit["tauq_tau"]
tauq_fit["tauq_tau_err"]

are the Q and τ values for the fit as well as the fit errors, and

tauq_fit["tauq_fit_val"]
tauq_fit["tauq_fit_line"]

are the fitted values of the τ vs. Q plot.

Averaging XPCS results

Similar as in the GUI, the averaging can be performed using the script mode. The syntax is:

from xpcs_viewer.module.average_toolbox import do_average

do_average(flist, 
           work_dir=None, save_path=None, 
           avg_window=3, avg_qindex=0, avg_blmin=0.95, avg_blmax=1.05,
           fields=['saxs_2d', 'saxs_1d', 'g2', 'g2_err']

flist is a python list containing the names of the file to be averaged;
work_dir is the full path of the result files;
save_path is the full path and name the average file will be saved to.

Clone this wiki locally