exponential_growth module
Define exponential growth model as well as fitting function.
Note
Other models that I tried:
I dropped them as with too much unkowns, any model can fit anything.
- exp_growth(time, n_0, alpha, t_0=0.0, **kwargs)[source]
Exponential growth factor function.
\[N(t) = N_0 \mathrm{e}^{\alpha (t-t_0)}\]- Parameters:
- Returns:
population – Modelled population evolution. It is filled with NaN for times before
t_0.- Return type:
np.ndarray
- exp_growth_log(time, n_0, alpha, t_0=0.0, **kwargs)[source]
Exponential growth factor function, in log form.
\[\log{N(t)} = \log{N_0} + \alpha (t-t_0)\]In general, better results for the fit process than the classic
exp_growth().- Parameters:
- Returns:
log_population – Log of modelled population evolution. It is filled with NaN for times before
t_0.- Return type:
np.ndarray
- fit_alpha(time, population, fitting_range, period, running_mean=True, log_fit=True, minimum_final_number_of_electrons=0, bounds=([1e-10, -10.0], [inf, 10.0]), initial_values=[0.0, 0.0], minimum_number_of_points=5, min_points_per_period=5, **kwargs)[source]
Perform the exponential growth fitting.
- Parameters:
time (np.ndarray) – Time in \(\mathrm{ns}\).
population (np.ndarray) – Evolution of electron population with time.
fitting_range (float) – Time over which the exp growth is searched. Longer is better, but you do not want to start the fit before the exp growth starts.
running_mean (bool, optional) – To tell if you want to average the number of particles over one period. Highly recommended. The default is True.
log_fit (bool, optional) – To perform the fit on
exp_growth_log()rather thanexp_growth(). The default is True, as it generally shows better convergence.minimum_final_number_of_electrons (int, optional) – Under this final number of electrons, we do no bother finding the exp growth factor and return a
NaN.bounds (tuple[list[float], list[float]], optional) – Upper bound and lower bound for the two variables: initial number of electrons, exp growth factor.
initial_values (list[float | None], optional) – Initial values for the two variables: initial number of electrons, exp growth factor.
minimum_number_of_points (
int, default:5) – Minimum number of fitting points; under this limit, a warning is issued. For CST, should be at least 10 or 20. With SPARK3D, there are two points per RF period so a value of 2 or 4 should be enough.min_points_per_period (
int, default:5) – Minimum number of points per period. In SPARK3D, we only have two points per RF period so this number should be lower to avoid unnecessary warnings.kwargs – Other keyword arguments passed to the
curve_fitfunction.period (
float)
- Returns:
exp_growth_parameters – Holds the fit parameters.
- Return type:
- _to_fit(time, population, fitting_range, log_fit=True, minimum_number_of_points=5)[source]
Determine the
x,f(x)arrays as well asffor the fit.- Parameters:
time (np.ndarray) – Full array of times.
population (np.ndarray) – Corresponding population evolution,
fitting_range (float) – Time over which the exp growth is searched. Longer is better, but you do not want to start the fit before the exp growth starts.
log_fit (bool, optional) – To perform the fit on
exp_growth_log()rather thanexp_growth(). The default is True, as it generally shows better convergence.minimum_number_of_points (
int, default:5) – Minimum number of fitting points; under this limit, a warning is issued. For CST, should be at least 10 or 20. With SPARK3D, there are two points per RF period so a value of 2 or 4 should be enough.
- Return type:
- Returns:
fit_func (Callable) – The
fwe want to retrieve parameters.fit_time (np.ndarray) – The
xvalues for the fit.fit_pop (np.ndarray) – The
f(x)we will try to retrieve.
- _indexes_for_fit(time, population, fitting_range, minimum_number_of_points=5)[source]
Determine the indexes on which the fit should be performed.
The fit is performed over
fitting_range, ending at the last non-zero population count (first zero-population count is excluded to avoid messing with log(population)).
- _n_points_in_a_period(time, period, min_points_per_period=5)[source]
Get the number of data points in a single RF period.
Print a warning if the number of points is lower than
min_points_per_period.
- _design_space(log_fit, fit_pop, bounds=([1e-10, -10.0], [inf, 10.0]), initial_values=[0.0, 0.0])[source]
Set initial value and bounds.
As for now, only set the initial value of
n_0to the population count at the start of the fit.Note
n_0is the actual population count, not the log of the pop count.
- _smoothen(population, width)[source]
Smooth data (running mean).
Used to compensate the periodic population oscillations (period: RF period).
See also: https://stackoverflow.com/a/43200476/12188681
Todo
Better unit testing for this function.