pyfli.simulator.calibration.sim_bridge#

Build the pyfli simulator config from calibrated quantities and run SimGenerator.

Functions

build_sim_config(priors, detector_type, dcr, ...)

Config dict for SimGenerator / PhotonCountSimulator / ContinuousSimulator.

draw_pixels(gen, n[, seed])

n calls of gen.simulate_once(), reproducible for a given seed: pixel i gets the engine seed seed * 1_000_003 + i and the global NumPy RNG is seeded once (and restored afterwards).

load_calibrated_generator(json_path)

Rebuild the calibrated SimGenerator from calibrated_sim_config.json (and the calibrated_irf.npy next to it). Use it as::.

make_generator(irf_cube, config, a_range, ...)

save_calibration(path, payload)

simulate_batch(irf_cube, config, a_range, ...)

Simulate n pixels; returns stacked decays and ground-truth parameters (stack_outputs()).

simulate_image(json_path[, shape, seed])

Simulate an (H, W) image with the calibrated simulator.

stack_outputs(outs)

Stack simulate_once outputs: decay / irf as (n, T), ground truth as (n,).

to_jsonable(obj)

Nested dicts / lists / tuples / NumPy values converted to JSON-serialisable Python types.

Classes

MultiIRFSimGenerator(irf_cube, config, ...)

SimGenerator whose IRF is drawn per pixel from a library: irf_cube[0, k] for k = 0..K-1, each with the usual OffsetGen shift a and baseline b.

TimeWindowedGenerator(generator, inactive_bins)

Wraps a SimGenerator and zeroes inactive_bins of every simulated decay: the time bins outside the detector's acquisition window (e.g. outside the TCSPC TAC range), which never record a count in the experiment.

build_sim_config(priors, detector_type, dcr, laser_freq_mhz, jitter=True)[source]#

Config dict for SimGenerator / PhotonCountSimulator / ContinuousSimulator.

Parameters:
Return type:

dict

class MultiIRFSimGenerator(irf_cube, config, a_range, b_range, weights=None, b_ranges=None, **kwargs)[source]#

Bases: SimGenerator

SimGenerator whose IRF is drawn per pixel from a library: irf_cube[0, k] for k = 0..K-1, each with the usual OffsetGen shift a and baseline b. Used for one config covering experiments recorded with different IRFs (e.g. two detector channels). The drawn index is returned as irf_index. b_ranges optionally gives each IRF its own baseline range (background belongs to the detector channel, like the IRF).

simulate_once()[source]#
class TimeWindowedGenerator(generator, inactive_bins)[source]#

Bases: object

Wraps a SimGenerator and zeroes inactive_bins of every simulated decay: the time bins outside the detector’s acquisition window (e.g. outside the TCSPC TAC range), which never record a count in the experiment. The pyfli simulator fills all bins, so without this step the simulated decays could not contain the experimental ones. Ground-truth photon_count stays the simulator’s expected photon number over the full period.

Parameters:

generator (SimGenerator)

property config: dict#
simulate_once()[source]#
Return type:

dict

make_generator(irf_cube, config, a_range, b_range, irf_weights=None, irf_b_ranges=None, inactive_bins=None)[source]#
Parameters:
draw_pixels(gen, n, seed=0)[source]#

n calls of gen.simulate_once(), reproducible for a given seed: pixel i gets the engine seed seed * 1_000_003 + i and the global NumPy RNG is seeded once (and restored afterwards). seed=None draws fresh random numbers.

Parameters:
Return type:

list[dict]

stack_outputs(outs)[source]#

Stack simulate_once outputs: decay / irf as (n, T), ground truth as (n,).

Parameters:

outs (list[dict])

Return type:

dict[str, ndarray]

simulate_batch(irf_cube, config, a_range, b_range, n, seed=0, irf_b_ranges=None, inactive_bins=None)[source]#

Simulate n pixels; returns stacked decays and ground-truth parameters (stack_outputs()).

Parameters:
Return type:

dict[str, ndarray]

to_jsonable(obj)[source]#

Nested dicts / lists / tuples / NumPy values converted to JSON-serialisable Python types.

save_calibration(path, payload)[source]#
Parameters:
Return type:

None

load_calibrated_generator(json_path)[source]#

Rebuild the calibrated SimGenerator from calibrated_sim_config.json (and the calibrated_irf.npy next to it). Use it as:

gen = load_calibrated_generator(".../calibrated_sim_config.json")
sample = gen.simulate_once()          # dict with decay, irf, tau1, tau2, alpha1, ...
Parameters:

json_path (str)

Return type:

SimGenerator

simulate_image(json_path, shape=(8, 8), seed=0)[source]#

Simulate an (H, W) image with the calibrated simulator. Returns the decay cube (H, W, T), the per-pixel IRF cube and (H, W) ground-truth maps (tau1, tau2, tau, alpha1, Efficiency, photon_count, h_shift, v_shift_bgp).

Parameters:
Return type:

dict[str, ndarray]