API Reference

Core module

taufactor.taufactor module

Main module.

class taufactor.taufactor.AnisotropicSolver(img, spacing, bc=(-0.5, 0.5), D_0=1, device=device(type='cuda', index=0))[source]

Bases: Solver

Anisotropic Solver e.g. for FIB-SEM datsets where spacing in cutting direction it different from pixel resolution

init_nn(img)[source]

Saves the number of conductive neighbours for flux calculation

solve(iter_limit=5000, verbose=True, conv_crit=0.02, plot_interval=10)[source]

run a solve simulation

Parameters

iter_limit – max iterations before aborting, will attemtorch double for the same no. iterations

if initialised as singles :param verbose: Whether to print tau. Can be set to ‘per_iter’ for more feedback :param conv_crit: convergence criteria, minimum percent difference between max and min flux through a given layer :return: tau

class taufactor.taufactor.BaseSolver(img, bc=(-0.5, 0.5), device=device(type='cuda'))[source]

Bases: object

check_rolling_mean(conv_crit)[source]
check_vertical_flux(conv_crit)[source]
crop(img, c=1)[source]

removes a layer from the volume edges

end_simulation(iter_limit, verbose, start)[source]
init_cb(img)[source]

Creates a chequerboard to ensure neighbouring pixels dont update, which can cause instability

pad(img, vals=[0, 0, 0, 0, 0, 0])[source]

Pads a volume with values

solve()[source]

Solve given PDE

class taufactor.taufactor.ElectrodeSolver(img, omega=1e-06, device=device(type='cuda'))[source]

Bases: object

Electrode Solver - solves the electrode tortuosity factor system (migration and capacitive current between current collector and solid/electrolyte interface) Once solve method is called, tau, D_eff and D_rel are available as attributes.

check_convergence()[source]
crop(img, c=1)[source]
end_simulation()[source]
init_cb(img)[source]
init_phi(img)[source]

Initialise phi field as zeros

Parameters

img (torch.array) – input image, with 1s conductive and 0s non-conductive

Returns

phi

Return type

torch.array

init_prefactor(img)[source]

Initialise prefactors -> (nn_cond+2j*omega*res*c(dims-nn_cond))**-1

Parameters

img (cp.array) – input image, with 1s conductive and 0s non-conductive

Returns

prefactor

Return type

cp.array

pad(img, vals=[0, 0, 0, 0, 0, 0])[source]
solve(iter_limit=100000, verbose=True, conv_crit=1e-05, conv_crit_2=0.001)[source]

run a solve simulation

Parameters

iter_limit – max iterations before aborting, will attemtorch double for the same no. iterations

if initialised as singles :param verbose: Whether to print tau. Can be set to ‘per_iter’ for more feedback :param conv_crit: convergence criteria - running standard deviation of tau_e :param conv_crit_2: convergence criteria - maximum difference between tau_e in consecutive omega solves :return: tau

sum_neighbours()[source]
tau_e_from_phi()[source]
class taufactor.taufactor.MultiPhaseSolver(img, cond={1: 1}, bc=(-0.5, 0.5), device=device(type='cuda', index=0))[source]

Bases: BaseSolver

Multi=phase solver for two phase images. Once solve method is called, tau, D_eff and D_rel are available as attributes.

calc_vertical_flux()[source]

Calculates the vertical flux through the volume

check_convergence(verbose, conv_crit)[source]
init_conc(img)[source]
init_nn(img)[source]
solve(iter_limit=5000, verbose=True, conv_crit=0.02)[source]

run a solve simulation

Parameters

iter_limit – max iterations before aborting, will attemtorch double for the same no. iterations

if initialised as singles :param verbose: Whether to print tau. Can be set to ‘per_iter’ for more feedback :param conv_crit: convergence criteria, minimum percent difference between max and min flux through a given layer :return: tau

class taufactor.taufactor.PeriodicSolver(img, bc=(-0.5, 0.5), D_0=1, device=device(type='cuda'))[source]

Bases: Solver

Solver with periodic boundary conditions in y and z direction. Only differences to the standard solver are the

  • neighbour matrix accounting for conductive neighbours on the other side and

  • the function to apply boundary conditions

Once solve method is called, tau, D_eff and D_rel are available as attributes.

apply_boundary_conditions()[source]
init_nn(img)[source]

Saves the number of conductive neighbours for flux calculation

class taufactor.taufactor.Solver(img, bc=(-0.5, 0.5), D_0=1, device=device(type='cuda'))[source]

Bases: BaseSolver

Default solver for two phase images. Once solve method is called, tau, D_eff and D_rel are available as attributes.

apply_boundary_conditions()[source]
calc_vertical_flux()[source]

Calculates the vertical flux through the volume

check_convergence(verbose, conv_crit, plot_interval)[source]
init_conc(img)[source]

Sets an initial linear field across the volume

init_nn(img)[source]

Saves the number of conductive neighbours for flux calculation

solve(iter_limit=5000, verbose=True, conv_crit=0.02, plot_interval=10)[source]

run a solve simulation

Parameters

iter_limit – max iterations before aborting, will attemtorch double for the same no. iterations

if initialised as singles :param verbose: Whether to print tau. Can be set to ‘per_iter’ for more feedback :param conv_crit: convergence criteria, minimum percent difference between max and min flux through a given layer :return: tau

Submodules

taufactor.metrics module

taufactor.metrics.crop_area_of_interest_numpy(array, labels)[source]
taufactor.metrics.crop_area_of_interest_torch(tensor, labels)[source]
taufactor.metrics.extract_through_feature(array, grayscale_value, axis, periodic=[False, False, False], connectivity=1, debug=False)[source]
taufactor.metrics.find_spanning_labels(labelled_array, axis)[source]

Find labels that appear on both ends along given axis

Returns:

set: Labels that appear on both ends of the first axis.

taufactor.metrics.gaussian_kernel_3d_numpy(size=3, sigma=1.0)[source]

Creates a 3D Gaussian kernel using NumPy

taufactor.metrics.gaussian_kernel_3d_torch(device, size=3, sigma=1.0)[source]

Creates a 3D Gaussian kernel using PyTorch

taufactor.metrics.label_periodic(field, grayscale_value, neighbour_structure, periodic, debug=False)[source]
taufactor.metrics.specific_surface_area(img, spacing=(1, 1, 1), phases={}, method='gradient', device=device(type='cuda'), smoothing=True, verbose=False)[source]

Calculate the specific surface area of all (specified) phases :param img: labelled microstructure where each integer value represents a phase :param spacing: voxel size in each dimension [dx,dy,dz] :param phases: dictionary of phases {‘name’: label, …}. If empty do all by default. :param method: string to indicate preferred method (face_counting, marching_cubes or gradient) :return: the surface area per unit volume

taufactor.metrics.triple_phase_boundary(img)[source]

Calculate triple phase boundary density i.e. fraction of voxel verticies that touch at least 3 phases

Args:

img (numpy array): image to calculate metric on

Returns:

float: triple phase boundary density

taufactor.metrics.volume_fraction(img, phases={})[source]

Calculates volume fractions of phases in an image :param img: segmented input image with n phases :param phases: a dictionary of phases to be calculated with keys as labels and phase values as values, default empty :return: list of volume fractions if no labels, dictionary of label: volume fraction pairs if labelled

taufactor.utils module

taufactor.utils.flux_direction(im, outpath=None)[source]

Plots the flux direction of the image and provides code for transposing the image to change the flux direction :param im: segmented input image with n phases :return: None

Module contents

Top-level package for TauFactor.