organoid_tracker.position_analysis.intensity_calculator module
Contains a lot of functions related to measuring intensity, averaged intensity and intensity derivatives.
- class organoid_tracker.position_analysis.intensity_calculator.IntensityOverTime(times_h: List[float], intensities: List[float])
Bases:
objectRepresents an intensity over time. The object holds the raw values, and statistics are calculated dynamically.
- organoid_tracker.position_analysis.intensity_calculator.add_ratiometric_intensity(experiment: Experiment, intensity_name: str, intensity_key_1: str, intensity_key_2: str) Callable[[Experiment], None]
Adds a ratiometric intensity to the experiment, which is the ratio of two regular intensities. Raises a ValueError if one (or both) of the intensity keys do not represent regular intensities, if the name is already in use for a regular intensity, or if both given keys are the same.
Returns an undo function that removes the ratiometric intensity again, and restores any previous state.
- organoid_tracker.position_analysis.intensity_calculator.get_intensities_for_ratiometric_intensity(experiment: Experiment, intensity_key: str) List[str] | None
Gets the regular intensity keys that make up the ratiometric intensity with the given key. Returns None if there is no ratiometric intensity with the given key, or there are not two strings stored.
- organoid_tracker.position_analysis.intensity_calculator.get_intensity_keys(experiment: Experiment) List[str]
Gets the keys of all stored intensities, both regular and ratiometric. Calling this function is equivalent to calling get_regular_intensity_keys and get_ratiometric_intensity_keys and concatenating the results.
- organoid_tracker.position_analysis.intensity_calculator.get_normalized_intensity(experiment: Experiment, position: Position, *, intensity_key: str = 'intensity', per_pixel: bool = False) float | None
Gets the normalized intensity of the position.
For regular intensities, it considers the raw intensity, the stored background per pixel for that intensity, and any stored multiplier (global, or z- or time-specific) for that intensity. If per_pixel is True, it also considers the volume of the position for that intensity.
For ratiometric intensities, it first calculates the two regular intensities that make up the ratio separately, using any stored normalization and multiplier like described above. Then it divides both. If the first intensity is zero, it returns zero, irrespective of the value of the second intensity. If any of the two intensities is missing or invalid (negative, or zero for the second intensity), it returns None. If both intensities have the same volume stored, it does not matter what the per_pixel parameter is, since the volume will cancel out in the ratio. However, if the two intensities have different volumes stored, note that the per_pixel parameter will affect the result. If False, the intensity sums are divided, otherwise the intensities per pixel.
- organoid_tracker.position_analysis.intensity_calculator.get_normalized_intensity_over_time(experiment: Experiment, around_position: Position, time_window_h: float, *, allow_incomplete: bool = False, intensity_key: str = 'intensity', per_pixel: bool = False) IntensityOverTime | None
Gets the slope and mean intensity over time given time span. Returns None if not enough data is available, which is the case if the track is too short or if some intensities are missing.
- organoid_tracker.position_analysis.intensity_calculator.get_ratiometric_intensity_keys(experiment: Experiment) List[str]
Gets the keys of all stored ratiometric intensities. These are global data that is a list of two regular intensity keys, and ends with “_ratio”. For example, you might have a ratiometric intensity “intensity_nad_nadh”. In the global data, there should then be a key “intensity_nad_nadh_ratio” with value [“intensity_nad”, “intensity_nadh”].
- organoid_tracker.position_analysis.intensity_calculator.get_raw_intensity(positions: PositionCollection, position: Position, *, intensity_key: str = 'intensity') float | None
Gets the raw intensity of the position. Note that ratiometric intensities are not supported, and will return None.
- organoid_tracker.position_analysis.intensity_calculator.get_regular_intensity_keys(experiment: Experiment) List[str]
Gets the keys of all stored regular intensities. These are position data that is numeric and has a “_volume” counterpart. For example, you might store intensities as “intensity_dapi” and the corresponding volumes as “intensity_dapi_volume”.
- organoid_tracker.position_analysis.intensity_calculator.perform_intensity_normalization(experiment: Experiment, *, background_correction: bool = True, z_correction: bool = False, time_correction: bool = False, intensity_key: str = 'intensity')
Performs intensity normalization for the given intensity key. The lowest found intensity in the experiment is used for setting the background, if background_correction is True. In addition, the intensities will be multiplied to obtain a median intensity of 1 at each z position if z_correction is True, or at every time point if time_correction is True. If both z_correction and time_correction are False, the intensities will be multiplied to obtain an overall median intensity of 1.
This method only works for regular intensities, not for ratiometric intensities. It will silently fail if no regular intensity with the given key is found.
- organoid_tracker.position_analysis.intensity_calculator.remove_intensities(experiment: Experiment, *, intensity_key: str = 'intensity')
Deletes the intensities with the given key.
- organoid_tracker.position_analysis.intensity_calculator.remove_intensity_normalization(experiment: Experiment, *, intensity_key: str = 'intensity')
Removes the normalization set by perform_intensity_normalization.
- organoid_tracker.position_analysis.intensity_calculator.remove_ratiometric_intensity(experiment: Experiment, intensity_key: str)
Removes the ratiometric intensity with the given key. Silently fails if there is no ratiometric intensity with that key.
- organoid_tracker.position_analysis.intensity_calculator.set_raw_intensities(experiment: Experiment, raw_intensities: Dict[Position, float], volumes: Dict[Position, int], *, intensity_key: str = 'intensity')
Registers the given intensities for the given positions. Both dicts must have the same keys.
Will overwrite any previous intensities saved under the given key.
Will also add this intensity to the intensity_keys of the experiment.
Also removes any previously set intensity normalization for that key.