Graphical FrontEnd

Graphical frontend for fitting photo-current spectra.

class pypec.Analyse_PEC.Analyse_PEC(master=None)[source]

Construct a frame widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, takefocus, visual, width.

Methods

update_nb_runs()

Update the number of cpu and run per process on the graphical interface.

AddFiles_cb

Fit_cb

ask_quit

autoscale

create_fit_lines

get_progress

on_Run_Fit

on_hv_limits

on_start_workers

on_stop_button

plot_Graph

plot_Re_Im

plot_fit_lines

plot_ligne_V

prm_binary

process_queue

remove_fit_folder

remove_fit_lines

start

update_figure

update_legend

update_nb_fit_in_run

AddFiles_cb()[source]
Fit_cb()[source]
ask_quit()[source]
autoscale(chart)[source]
create_fit_lines()[source]
get_progress(run=1, fit=0)[source]
on_Run_Fit()[source]
on_hv_limits(*args)[source]
on_start_workers()[source]
on_stop_button()[source]
plot_Graph()[source]
plot_Re_Im()[source]
plot_fit_lines(*args)[source]
plot_ligne_V()[source]
prm_binary()[source]
process_queue()[source]
remove_fit_folder()[source]
remove_fit_lines()[source]
start()[source]
update_figure()[source]
update_legend(axes, run=1, fit=0, location='upper left')[source]
update_nb_fit_in_run()[source]
update_nb_runs()[source]

Update the number of cpu and run per process on the graphical interface.

class pypec.Analyse_PEC.ParameterTable(master, prm, last_prm_folder, **kwargs)[source]

Construct a frame widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, takefocus, visual, width.

class pypec.Analyse_PEC.ParameterWindow(master, prm_init, last_prm_folder)[source]

Construct a toplevel widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, menu, relief, screen, takefocus, use, visual, width.

Methods

get_paths

get_prm

get_paths()[source]
get_prm()[source]
class pypec.Analyse_PEC.ScrolledFrame(master, **kwargs)[source]

Construct a frame widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, takefocus, visual, width.

Iph Functions

Modules - Iph Functions

This module contains functions requiered for computing and optimizing the photo-current values from input parameters i.e. triplets (K_i, \theta_i, Eg_i) and experimental data for each semi-conductive phase [1].

pypec.iph_functions.get_Iph_calc(hv, prm_array, phi_N)[source]

Compute the complex values of Iph based on the values and states of the triplets (K_i, \theta_i, Eg_i) [1].

Iph^{\ast} = \frac{Iph}{\Phi_{N}}

Parameters:
hv: 1d array

Vector of energies for which the complex Iph has to be computed.

prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

phi_N: 1d array

Represents the values of the normalized photon flux to the maximum value. If nphf is a unity vector, the true photo-current is returned otherwise the as-measured photo-current is returned.

Returns:
iph_calc_complex: 1d array

Vector of the computed complex values of Iph.

pypec.iph_functions.get_LCC(iph_exp_complex, iph_calc_complex)[source]
pypec.iph_functions.get_distance(iph_exp_complex, iph_calc_complex)[source]

Compute the distance D between Iph_{exp} and Iph_{calc}. The distance is computed by multiplying the distances on real and imaginary parts of Iph:

\Delta Re & = Re \, Iph_{exp} - Re \, Iph_{calc} \\
\Delta Im & = Im \, Iph_{exp} - Im \, Iph_{calc} \\
D_{Re} & = \sqrt{\sum{\Delta Re ^2}}\\
D_{Im} & = \sqrt{\sum{\Delta Im ^2}}\\
D & = D_{Re} \cdot D_{Im}

Parameters:
iph_exp_complex: 1d numpy array

Contains the complex values of the Iph_{exp}.

iph_calc_complex: 1d numpy array

Contains the complex values of the Iph_{calc}.

Returns:
D: float

The computed distance on real and imaginary parts of Iph:.

pypec.iph_functions.get_exp_data(filepath)[source]

Get the data array of data files according to their extension.

Supported files are .dot files recorded by PECLab software and .data files were the first three columns represent h\nu, \left | Iph^{\ast} \right |, \theta.

Parameters:
filepath: string

Path to the data file.

Returns:
data_array: 2d array

Experimental data.

Find the number of lines in header and footer in .dot files.

Parameters:
filepath: path to the dot file
Returns:
skip_header: int

number of lines in header

skip_footer: int

number of lines in footer

nbpoints: int

number of data lines

pypec.iph_functions.get_random_prm_values(prm_array, K_bound=(1e-12, 0.1), theta_bound=(-180.0, 180.0), Eg_bound=(0.1, 6.2), phase_flag=True)[source]

Generates random values for the triplets (K_i, \theta_i, Eg_i) to be fitted based on the states given by the prm_array.

By default, the limits are:

  • K_i: [10^{-12},10^{-1}]

  • \theta _i: [-\pi,+\pi]

  • Eg_i: [0.1, 6.0]

Parameters:
prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

K_bound:tuple

Contains the lower and upper limits for the K_i values.

theta_bound: tuple

Contains the lower and upper limits for the \theta _i values.

Eg_bound:tuple

Contains the lower and upper limits for the Eg_i values.

phase_flag: bool

Indicates if the values of \theta _i have to be randomized.

Returns:
random_prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

pypec.iph_functions.get_results_array(hv, iph_exp_complex, iph_calc_complex)[source]

Build the data array of the experimental and calculated data: h\nu, \left| Iph_{exp} \right|, \theta _{exp}, \left| Iph_{calc} \right| and \theta _{calc}

Parameters:
hv: 1d numpy array

Contains the energy vector.

iph_exp_complex: 1d array

Contains the complex values of Iph_{exp}.

iph_calc_complex: 1d array

Contains the complex values of Iph_{calc}.

Returns:
data_array: 2d array

Array containing the .

pypec.iph_functions.get_summary(fit_folder)[source]

List result files for the triplets (K_i, \theta_i, Eg_i) at the end and the minimum of each run.

Compute the distance, the LCCs for the energy interval that was used for minimizing the the triplets (K_i, \theta_i, Eg_i).

The results are saved in 4 files: .SumEnd, .SumEndEg, *.SumMin, *.SumMinEg.

Parameters:
fit_folder: string

Path of the fit folder.

pypec.iph_functions.import_prm_file(filepath)[source]

Import the triplets (K_i, \theta_i, Eg_i) from text file where each line represents a contributing semi-conductive phase.

Parameters:
filepath: string

Absolute or relative file path to the text file.

Returns:
prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

pypec.iph_functions.minimize(hv, iph_exp_complex, phi_N, weights, prm_array, Ki_log_flag=True, maxiter=None, maxfun=None, xtol=1e-11, ftol=1e-23, full_output=True, retall=False, disp=False, callback=None)[source]

Execute the Nelder-Mead algorithm based on parameter values given by prm_array and energy vector h\nu.

First, the prm_array is flattened and the parameters (K_i, \theta_i,
Eg_i) to be fitted are extracted and sent to the target_function() through the Nelder-Mead algorithm.

Once the parameters were computed by the Nelder-Mead algorithm, the prm_array is updated with the new values.

Parameters:
hv: 1d numpy array

Contains the energy vector.

iph_exp_complex: 1d numpy array

Contains the complex values of the experimental photo-current.

phi_N: 1d array

Contains the normalized photon spectrum.

weights: 1d array

Contains the weights of the data.

prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

Ki_log_flag: bool

Indicates if the K_i values are in logarithmic space.

maxiterint, optional

Maximum number of iterations to perform.

maxfunnumber, optional

Maximum number of function evaluations to make.

xtolfloat, optional

Relative error in xopt acceptable for convergence.

ftolnumber, optional

Relative error in func(xopt) acceptable for convergence.

full_outputbool, optional

Set to True if fopt and warnflag outputs are desired.

retallbool, optional

Set to True to return list of solutions at each iteration.

dispbool, optional

Set to True to print convergence messages.

callbackcallable, optional

Called after each iteration, as callback(xk), where xk is the current parameter vector.

Returns:
prm_array: 2d array

Represents the updated values and states of the triplets (K_i, \theta_i, Eg_i).

foptfloat

Value of function at minimum: fopt = func(xopt).

pypec.iph_functions.plot_summary(fit_folder)[source]

Plot the result files that were created by the get_summary() for he triplets (K_i, \theta_i, Eg_i) at the end and the minimum of each run.

The results are saved in 2 files: -0-End.pdf, -0-Min.pdf.

Parameters:
fit_folder: string

Path of the fit folder.

pypec.iph_functions.save_pdf(filepath, hv, iph_exp_complex, iph_calc_complex, mask, all_results)[source]
pypec.iph_functions.save_results(run, process_id, fit_folder, datafilepath, suffix, hv, mask, iph_exp_complex, phi_N, prm_min_run, prm_end_run, distance_min_run, distance_end_run, minimization_results, header_minimization_results)[source]
pypec.iph_functions.scatter_logpolar(ax, theta, r_, ticks=5, bullseye=0.0, **kwargs)[source]
pypec.iph_functions.shift_phase(prm_array, theta_bound=(-180.0, 180.0))[source]

Compute the modulo of \theta _i values with 2\pi and then shift the values of \theta _i by the amplitude of the boundaries in order to be in between the boundaries.

By default, the boundaries for \theta _i are set to [-\pi,+\pi].

Parameters:
prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

theta_bound: tuple

Contains the lower and upper limits for the :math`theta _i` values.

Returns:
prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i) where the \theta _i values were shifted.

pypec.iph_functions.sort_prm_Eg(prm_array)[source]

Sort the prm_array based on values of Eg_i.

Parameters:
prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

Returns:
prm_array: 2d array

Represents the sorted values and states of the triplets (K_i, \theta_i, Eg_i).

pypec.iph_functions.target_func(p, hv, prm_array, iph_exp_complex, phi_N, weights, Ki_log_flag=True)[source]

Update the triplets (K_i, \theta_i, Eg_i) from the flattened parameter vector p sent by the optimization algorithm. The prm_array will be flattened and the indexes of the parameters to be fitted will be updated with p vector.

The calculated complex values of Iph will be sent along the experimental values to the get_distance() function. The value of the distance between the experimental and calculated data will sent back to the optimization algorithm.

Parameters:
p: 1d array

Parameter vector sent by the optimization algorithm which is always. flattened.

hv: 1d array

Vector of energies for which the complex values of Iph have to be calculated.

prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

iph_exp_complex: 1d numpy array

Contains the complex values of the experimental Iph.

phi_N: 1d array

Represents the values of the normalized photon flux to the maximum value.

weights: 1d array

Contains the values of the data weights.

Ki_log_flag: bool

Indicates if the K_i values are in logarithmic space.

Returns:
distance: float

Calculated distance between experimental and calculated data values. See the get_distance() function.

pypec.iph_functions.validate_prm(prm_array, K_bound=(1e-12, 0.1), Eg_bound=(0.1, 6.2))[source]

Check if the values of K_i and Eg_i are within the boundaries.

Parameters:
prm_array: 2d array

Represents the values and states of the triplets (K_i, \theta_i, Eg_i).

K_bound:tuple

Contains the lower and upper limits for the K_i values.

Eg_bound:tuple

Contains the lower and upper limits for the Eg_i values.

Returns:
valid: bool

Set to True if value of K_i or Eg_i is out of the boundaries.

Parallel Processes

Module for controlling the parallel processes running during the fitting procedure

class pypec.Parallel_Process.MinimizationProcess(output_queue, name, prm_init, nb_run, nb_SC, init_type, random_loops, hv, iph_exp_complex, iph_exp_complex_CI, phi_N, phi_N_CI, weights, hv_limits, nb_fit_in_run, fit_folder, filepath, suffix, NelderMead_options=(1e-11, 1e-23, 200, 200), ParameterConstraints=((1e-12, 0.1), (-180, 180), (0.1, 6.2), True), update_every=5)[source]

Methods

run()

Method to be run in sub-process; can be overridden in sub-class

shutdown

run()[source]

Method to be run in sub-process; can be overridden in sub-class

shutdown()[source]
class pypec.Parallel_Process.PlotSummaryProcess(fit_folder)[source]
Parameters:
fit_folder: str

Path to the folder where the summary files will be saved.

Attributes:
fit_folder: str

Path to the folder where the summary files will be saved.

Methods

run()

Method to be run in sub-process; can be overridden in sub-class

run()[source]

Method to be run in sub-process; can be overridden in sub-class

pypec.Parallel_Process.get_cpu_number()[source]

DocString

pypec.Parallel_Process.get_queue()[source]

DocString

pypec.Parallel_Process.initialize_processes(n, daemon=True, **kwargs)[source]

Create N processes as daemons and return them in a list.

Parameters:
n: int

Number of processes to be created.

daemon: bool

Flag for creating daemon process.

kwargs: dict

See MinimizationProcess

pypec.Parallel_Process.start_processes(workers)[source]
Parameters:
workers: subprocess workers
Returns:
0: return integer