Crossfit

class crossfit.Alpha(triDData, laser_pwr, params=None, func=None, info={})[source]

Class for working with planar LIF measurements of fluorescence vs. laser power.

Attributes:

func: default is \(\alpha E_L/(1 + \beta E_L)\). The fit() method assumes only this form and works with linearized version for inverted values of laser power. Changing this attribute is currently pointless, but might become useful in future versions.

M: (float) the smaller this number, the shorter range of values is
permitted for refit(). For decent data M=2 can lead to cca 20% overestimation of alpha and M = 1 to cca 10% overestimation. Underestimation is unlikely.
beta_Imax()[source]

Calculate and return the 2D map of values beta(y,x) * max(laser_power(y,x)). Served for checking the condition of weak saturation.

delta_beta(y, x)[source]

Calculate and retun the estimate of standard deviation of the beta parameter from the fit at pixel given by y,x coordinate.

delta_beta_map(relative=True)[source]

Runs delta_beta for each pixel and returns a 2D map of standard deviations.

Args:
relative: (bool) defaults to True, in which case returns the relative standard deviation in percent. Otherwise the absolute values in units of inverted laser power are returned.
fit()[source]

Fitting the measured fluorescence vs. laser power data pixelwise. Assumes the dependence fluorescence = alpha * pwr / (1 + beta*pwr). No additive offset is allowed. The results of the fit are stored in the dictionary self.result with keys ‘alpha’, ‘beta’, ‘delta_alpha’. The values of delta_beta (estimate of standard deviation of beta) can be obtained by the method delta_beta(y, x) (single value) or delta_beta_map() (a 2D array for all pixels)

Returns:
alpha: 2D numpy array of the alpha parameters
invert(data)[source]
Calculate inverse of given array and mark values that are invalid
(i.e. == np.nan, == np.inf or < 0).
Args:
data: numpy array
Returns:
(tuple) inverted, mask inverted: inverted VALID data. The invalid values are omitted mask: a boolean array of the shape of the original data that can be used to filter arrays of the same size according to the invalid values in the original data.
print_result(y, x)[source]

Returns a formatted string with the values of alpha +/- delta_alpha and beta +/- delta_beta at pixel given by coordinates y,x

refit(M=1, betamedx=True)[source]

Advised to run after Alpha.fit(). Re-runs the fit with the limitation that the laser_power * median(self.result[‘beta’]) < M, (i.e., restricts the used values of laser power and ignores the large ones) to force obeying the condition of weak saturation.

Args:

M: (float) the upper limit of fitting range, i.e. only values with beta*pwr < M are permitted

betamedx: (bool) determines the method to extract beta. If True (default), median of all valid betas is used. If False, the beta on the particular pixel is used.

show_refit(y, x, save_to_file=None, draw=False, betax=True, show=True)[source]

Similar to show fit in the parent Crossfit class, but highlights the values really used in refit() method.

Args:

y, x: pixel coordinates

betax: (bool) if False, the x-axis of the plot is in the units of laser power. If True (default), the x-axis is multiplied by beta.

save_to_file: If a string is given, it represents the name of the file the figure will be saved to. If None (default), no file is written.

xlabel, ylabel: (strings) passed directly to matplotlib

draw: if True, matplotlib.draw() and clear() are called. May be used in a loop to create an animation.

show: if True (default), matplotlib.show() is called.

Returns:
matplotlib.figure object.
class crossfit.Crossfit(triDData, independet_variable, func=None, info={})[source]

Parent class for fitting planar LIF data. Expects series of 2D images (triDData) and some x-axis (x) that enables fitting of function (func) to the measured data for each pixel.

Attributes:
data: (3D numpy array) a series of 2D images (triDData) independent_variable: (numpy array) the independent variable for fitting. May be 1D with the length equal to the number of frames of data, 2D with the first dimension equal to the first dimension of self.data and the second dimension equal to the second or third dimension of self.data or 3D with the same shape as self.data
default_func()[source]

To be provided in inherited classes...

dfunc_from_keys()[source]

To be provided in inherited classes...

fit(keys='all')[source]

call self.fit_at_yx() for each pixel in a loop.

fit_at_yx(y, x, keys='all')[source]

Find the best estimate of parameters of self.default_func for data at (y, x) with scipy.optimize.curve_fit().

Args:

y, x: (int) pixel coordinates

keys: (list) of keywords describing the argument to be optimized or simply ‘all’. The keywords should be provided by inherited classes in their definition.

format_x(y, x)[source]
Automatically determine the x-axis for eventual fitting at position (y, x).
Args:
y, x: (int) coordinates of a pixel
Returns:
x_ax: (1D numpy array)
func_from_keys()[source]

To be provided in inherited classes...

get_corr_matrix(y, x)[source]

return matrix of correlation coefficients. See result[‘cov_order’] for assignign to the right variables.

get_covariance_matrix(y, x)[source]

calculates and returns the real variance-covariance matrix from the scipu.optimize.curve_fit’s output by multiplying it with (len(data)-len(parameters)) / sum_of_squares

get_params(y, x)[source]

To be provided in inherited classes...

independent_var_to_plot(y, x, numpoints=100)[source]
Returns linspace(xmin, xmax, numpoints), where xmin, xmax are the
minimum and maximum of the independent_variable at position y, x. Intended to yield x-axis values for theoretical data form the fits.
Args:
y, x: pixel coordinates numpoints: (integer) defaults to 100. Number of equally spaced points to be returned
Returns:
1D numpy array from numpy.linspace
show_fit(y, x, save_to_file=None, xlabel='', ylabel='', draw=False, show=True)[source]

Method for plotting the the cross-section of triDData at position y, x vs. the independent_variable for that particular position, together with fitted funcion.

Args:

y, x: pixel coordinates

save_to_file: If a string is given, it represents the name of the file the figure will be saved to. If None (dafault), no file will be written.

xlabel, ylabel: (strings) passed directly to matplotlib

draw: defaults to False. if True, matplotlib.draw() will be called to show the figure. May be used in loop to create an animation, as ax.clear() is also called.

show: defaults to True - the figure will be shown by matplotlib.show()

Returns: matplotlib.figure object.

class crossfit.FluoVsPwr(triDData, laser_pwr, params=None, info={})[source]

Replacement of ALpha with more rigorous function. Is not very practical for real-world fitting.

class crossfit.Tau(triDData, time, params=None, func=None, dfunc_dict=None, info={})[source]

Class for working with planar LIF measurements of lfuorescence vs. delay after the laser pulse.

Attributes:

func: a function used to fit the measured dependent. Defaults to \(A {\rm e}^{(-t/ \tau)} + C\).

dfunc_dict: dictionary of derivatives of func with respect to its parameters. The keys should be ‘amplitude’, ‘tau’ and ‘offset’ and the values should be the respective functions taking the arguments (time_axis, amplitude, tau) and returning an array with the same shape as the time_axis.

params: initial guess of the respective values. If left to None, the default values of amplitude = 1e3, tau = 10 and offset = 1e3 are filled from start to the self.result arrays

result: dictionary with keys ‘amplitude’, ‘tau’, ‘offset’ (fit results), ‘damplitude’, ‘dtau’, ‘doffset’ (standard error estimates), (‘cov’, (y, x)) storing “covariance matrices” returned by scipy.optimize.curve_fit and ‘cov_order’ storing the order of the parameters used to calculate the “covariance matrices”.

class crossfit.WaitingCorr(tau_map, delta_tau_map=None, **kwargs)[source]

Calculate correction for the fact that the detection begins after the laser pulse. The fluorescence temporal shape is calculated as a convolution of single-exponential and a*t**b * exp(-c*t).

crossfit.read_lifbase_table(filename)[source]

Read database file exported from LIFBASE.

Args:
filename: (str) path to the file created by LIFBASE to be read
Returns:
dictionary of coefficients with keys N P1 P2 Q1 Q2 R1 R2 O12 Q12 P12 R21 Q21 S21

Example of use:

coefs = read_lifbase_table('abs_00.txt')

print coefs['R1'][coefs['N']==4]

Previous topic

Introduction

This Page