SimulatedPhotometryGenerator
A class for simulating photometry data with advanced support for photobleaching and custom event dynamics.
Generator for simulated fiber photometry data.
Simulated data is generated with the following layers
1) event-driven neural signals rendered from timestamped events 2) B: photobleaching curve, modeled with a 5-param negative bi-exponetial 3) M: movement attenuation artifacts 4) noise_dependent(_exp & _iso): Gaussian noise that scales with photobleaching, calculated seperately for experimental and isosbestic signal 5) noise_independent(_exp & _iso): Gaussian noise that is independent of photobleaching, calculated seperately for experimental and isosbestic signal
Experimental signal = (B + event_signal_exp + noise_exp) * M Isosbestic signal = (B + event_signal_iso + noise_iso) * M
Outputs (attributes): t: time points F_exp, F_iso: experimental and isosbestic signals neural_true, neural_norm: true and null-Z normalized experimental event signals event_times_sec: times of the base neural events events: mapping of event labels to timestamps event_peak_specs: per-label peak-generation parameters B, M: photobleaching curve and movement attenuation
Build simulated photometry data.
Parameters:
-
T_sec(float, default:1000) –Amount of seconds in data.
-
fs(float, default:30.0) –Sampling frequency in Hz.
-
n_events(int, default:100) –Number of base neural events.
-
event_dur_sec(float, default:3.0) –How long a base neural event is in seconds.
-
A_neural(float, default:0.02) –Magnitude of the base event signal.
-
tau_p_sec(float, default:0.6) –Exponential param for neural signal generation.
-
shape_k(int, default:3) –Controls the skewness of neural signal, must be >= 2.
-
buffer_sec(float, default:5) –Minimum number of seconds between a base neural event and end of time series.
-
n_artifacts(int, default:60) –Number of attenuation artifacts.
-
artifact_tau_sec(float, default:0.8) –Exponential param for attenuation generation.
-
artifact_depth_range(Tuple[float, float], default:(0.02, 0.15)) –Fractional bounds for attenuation magnitude.
-
dependent_sigma_exp(float, default:0.0001) –Magnitude of intensity-proportional noise in experimental signal.
-
independent_sigma_exp(float, default:1e-05) –Magnitude of intensity-independent noise in experimental signal.
-
dependent_sigma_iso(float, default:0.0001) –Magnitude of intensity-proportional noise in isosbestic signal.
-
independent_sigma_iso(float, default:1e-05) –Magnitude of intensity-independent noise in isosbestic signal.
-
bleach_params(dict, default:dict(a1=50, a2=20, tau1=300, tau2=10000, b0=1)) –Params for the negative bi-exponential photobleaching model.
-
artifact_mask(ndarray | None, default:None) –Optional multiplicative attenuation mask of shape (N,).
Returns:
-
–
None
Source code in pyFiberPhotometry/utils/sim.py
add_event(time_range, overall_prob, choices, choice_probs, peak_specs=None, relative_to='event', allow_out_of_bounds=False)
Add stochastic event timestamps relative to an existing event stream and rebuild the simulated signal so the new events contribute peaks.
Parameters:
-
time_range(tuple[float, float]) –Relative time bounds around each anchor event.
-
overall_prob(float) –Probability that an event occurs for each anchor event.
-
choices(list[str]) –Event labels to assign to generated timestamps.
-
choice_probs(list[float]) –Relative probabilities for each label in
choices. -
peak_specs(dict[str, dict] | None, default:None) –Optional per-label peak settings. Each label-specific dict can include
amplitude,event_dur_sec,tau_p_sec,shape_k,channel('exp', 'iso', or 'both'), andscale_with_bleach. -
relative_to(str, default:'event') –Existing event label used as the anchor event.
-
allow_out_of_bounds(bool, default:False) –If False, drop generated events outside the session time bounds.
Returns:
dict[str, np.ndarray]: Updated timestamp arrays for the labels in choices.