pyfli.simulator.sim_workflow#

Functions

concat_sim_data(*datasets)

Concatenate multiple sim.sample() output dicts along the batch axis (axis=0).

make_simulator(simulate_fn, num_samples)

Run simulate_fn num_samples times and stack each output key along a new leading axis.

Classes

BatchSimulator()

Run repeated FLI/FLIM simulations across parameter sets.

SimGenerator(irf_data, config[, a_range, ...])

Wraps IRF shifting + a MacroSimulator/ContinuousSimulator/TCSPCSimulator/ PhotonCountSimulator engine + SimOutputWithIRFOffset for a single config.

SimOutput(simulator)

SimOutputWithIRFOffset(simulator, irf_1d)

WeightedConfigSimGenerator(irf_data, ...[, ...])

Wraps one SimGenerator per config combination and, on every simulate_once() call, draws a fresh combination according to probs before delegating to it.

concat_sim_data(*datasets)[source]#

Concatenate multiple sim.sample() output dicts along the batch axis (axis=0). Assumes all datasets share identical keys and per-sample shapes.

class SimOutput(simulator)[source]#

Bases: object

run()[source]#
class SimOutputWithIRFOffset(simulator, irf_1d)[source]#

Bases: SimOutput

run()[source]#
class SimGenerator(irf_data, config, a_range=(-20, 100), b_range=(0, 10), pixel=(0, 0), family='separate', sensor_type='discrete')[source]#

Bases: object

Wraps IRF shifting + a MacroSimulator/ContinuousSimulator/TCSPCSimulator/ PhotonCountSimulator engine + SimOutputWithIRFOffset for a single config. Only accepts one config dict — raises if given a list/tuple of configs.

Engine selection has two independent axes:

  • sensor_type (physics): config["sensor_type"] if present, otherwise the sensor_type constructor argument. "continuous" samples from an intensity/ADC-scaled engine; "discrete" samples from a photon-by-photon TCSPC engine.

  • family (implementation): "separate" (default) uses ContinuousSimulator/PhotonCountSimulator; "combined" uses MacroSimulator/TCSPCSimulator.

Parameters:
  • family (str) – Which implementation family to sample from — “separate” (default) or “combined”. See SIMULATOR_TYPES.

  • sensor_type (str) – Fallback “continuous”/”discrete” engine choice used only when config doesn’t already set sensor_type. Defaults to “discrete”.

simulate_once()[source]#
class WeightedConfigSimGenerator(irf_data, configs, probs, a_range=(-20, 100), b_range=(0, 10), pixel=(0, 0), family='separate', sensor_type='discrete', seed=None)[source]#

Bases: object

Wraps one SimGenerator per config combination and, on every simulate_once() call, draws a fresh combination according to probs before delegating to it.

This lets a single simulator built from this class (e.g. via bayesflow.make_simulator([lambda: gen.simulate_once()])) produce draws sampled from a mixture of configs — such as the (configs, probs) pair returned by combination_table() — with no change needed to code downstream that only ever calls simulate_once().

Parameters:
  • irf_data (np.ndarray) – Full IRF cube, forwarded to each per-combination SimGenerator.

  • configs (Sequence[dict]) – One config dict per combination.

  • probs (Sequence[float]) – Sampling probability for each entry in configs (same order, same length). Renormalized if it doesn’t already sum to 1.

  • a_range – Forwarded to every per-combination SimGenerator.

  • b_range – Forwarded to every per-combination SimGenerator.

  • pixel – Forwarded to every per-combination SimGenerator.

  • family – Forwarded to every per-combination SimGenerator.

  • sensor_type – Forwarded to every per-combination SimGenerator.

  • seed (int | None) – Seed for the combination-selection RNG (independent of each SimGenerator’s own internal randomness).

simulate_once()[source]#

Picks one config combination per the weighted probabilities, then delegates to it.

make_simulator(simulate_fn, num_samples)[source]#

Run simulate_fn num_samples times and stack each output key along a new leading axis.

class BatchSimulator[source]#

Bases: object

Run repeated FLI/FLIM simulations across parameter sets. The class is a convenience layer for generating batches of synthetic datasets for validation or model training.

Unlike make_simulator()/concat_sim_data() (which batch the flattened per-sample dict produced by SimOutput), these methods batch the raw nested {"raw_data": {...}, "results": {"maps": {...}, "TR_maps": {...}}} dict returned directly by a simulator’s __call__ (e.g. MacroSimulator, ContinuousSimulator).

sim_BI(sim_funcs, num_list)[source]#

Generates a simplified batch dictionary with specific parameters. Returns data as a dictionary of NumPy arrays.

Parameters:
Return type:

Any

generate_batch(sim_func_list, num_list)[source]#

Generate batch.

Parameters:
  • sim_func_list (np.ndarray) – Simulator functions used to generate a batch.

  • num_list (int) – Number of samples generated for each simulator function.

Returns:

Object produced by generate batch.

Return type:

Any

generate_batch2D(sim_funcs, num_list, shape=(10, 10))[source]#

Generate batch2 d.

Parameters:
  • sim_funcs (np.ndarray) – Simulator functions used to generate a two-dimensional batch.

  • num_list (int) – Number of samples generated for each simulator function.

  • shape (tuple[int, ]) – Output shape requested for generated simulation batches.

Returns:

Object produced by generate batch2d.

Return type:

Any