Simulate Foci
Simulate Foci Reference#
simulate_foci.py#
This file contains the necessary classes and functions to simulate foci dynamics in space, particularly within cell simulations.
Author: Baljyot Singh Parmar
Classes:#
- Track_generator: A class to generate tracks of foci movements in a cell space with or without transitions.
Functions:#
- get_lengths: Generates an array of track lengths based on a chosen distribution.
- create_condensate_dict: Creates a dictionary of condensates for simulation.
- tophat_function_2d: Defines a circular top-hat probability distribution in 2D.
- generate_points: Generates random points following a given probability distribution.
- generate_points_from_cls: Generates 3D points using the accept/reject method based on a given distribution.
- generate_radial_points: Generates uniformly distributed points in a circle.
- generate_sphere_points: Generates uniformly distributed points in a sphere.
- radius_spherical_cap: Computes the radius of a spherical cap given the sphere's radius and a z-slice.
- get_gaussian: Returns a 2D Gaussian distribution over a given domain.
- axial_intensity_factor: Computes the axial intensity factor based on axial position.
- generate_map_from_points: Generates a spatial map from given points and intensities.
Track_generator
#
A class to generate tracks of foci movements in a simulated cell space.
Parameters:#
cell : BaseCell Cell object defining the space for track generation oversample_motion_time : int | float Time for oversampling motion in milliseconds.
Source code in SMS_BP/simulate_foci.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
track_generation_constant(track_length, initials, start_time)
#
Generate a constant track (no movement).
Parameters:#
track_length : int mean track length, in this case the track length is constant with this mean initials : array-like [[x,y,z]] coordinates of the initial positions of the track starting_time : int time at which the track start (this is not the frame, and needs to be converted to the frame using the exposure time and interval time and the oversample motion time)
Returns:#
dict-like with format: {"xy":xyz,"times":times,"diffusion_coefficient":diffusion_coefficient,"hurst":hurst_exponent,"initial":initial}
Source code in SMS_BP/simulate_foci.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | |
track_generation_no_transition(diffusion_coefficient, hurst_exponent, track_length, initials, start_time)
#
Simulates the track generation with no transition between the diffusion coefficients and the hurst exponents namely, this means each track has a unique diffusion coefficient and hurst exponent This simulation is confined to the cell space and the axial range of the cell
Parameters:#
diffusion_coefficient : float diffusion coefficient for the track hurst_exponent : float hurst exponent for the track track_length : int track_length for the track initials : array-like [[x,y,z]] coordinates of the initial positions of the track start_time : int time at which the track start (this is not the frame, and needs to be converted to the frame using the exposure time and interval time and the oversample motion time) Returns:
dict-like with format: {"xy":xyz,"times":times,"diffusion_coefficient":diffusion_coefficient,"hurst":hurst_exponent,"initial":initial}
Source code in SMS_BP/simulate_foci.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
track_generation_with_transition(diffusion_transition_matrix, hurst_transition_matrix, diffusion_parameters, hurst_parameters, diffusion_state_probability, hurst_state_probability, track_length, initials, start_time)
#
Genereates the track data with transition between the diffusion coefficients and the hurst exponents
Parameters:#
diffusion_transition_matrix : array-like transition matrix for the diffusion coefficients hurst_transition_matrix : array-like transition matrix for the hurst exponents diffusion_parameters : array-like diffusion coefficients for the tracks hurst_parameters : array-like hurst exponents for the tracks diffusion_state_probability : array-like probabilities for the diffusion coefficients hurst_state_probability : array-like probabilities for the hurst exponents track_length : int track_length for the track initials : array-like [[x,y,z]] coordinates of the initial positions of the track start_time : int time at which the track start (this is not the frame, and needs to be converted to the frame using the exposure time and interval time and the oversample motion time)
Returns:#
dict-like with format: {"xy":xyz,"times":times,"diffusion_coefficient":diffusion_coefficient,"hurst":hurst_exponent,"initial":initial}
Source code in SMS_BP/simulate_foci.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
axial_intensity_factor(abs_axial_pos, detection_range, **kwargs)
#
Docstring Calculate the factor for the axial intensity of the PSF given the absolute axial position from the 0 position of the focal plane. This is the factor that is multiplied by the intensity of the PSF
For now this is a negative exponential decay i.e: I = I_0e^(-|z-z_0|) This function returns the factor e^(-|z-z_0|2 / (22.2**2)) only.
Parameters:#
abs_axial_pos : float|np.ndarray absolute axial position from the 0 position of the focal plane detection_range : float detection range of the function. This is the standard deviation of the gaussian function describing the axial intensity decay assuming a gaussian function. kwargs : dict
Returns:#
float|np.ndarray factor for the axial intensity of the PSF
Source code in SMS_BP/simulate_foci.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
generate_map_from_points(points, point_intensity, map, movie, base_noise, psf_sigma)
#
Generates a 2D spatial map from a set of points and their intensities.
Parameters:#
points : np.ndarray Array of points of shape (total_points, 2). point_intensity : float | np.ndarray Intensity of the points. map : np.ndarray Pre-defined space map to update. If None, a new map is generated. movie : bool If True, noise is added to the whole image at once; otherwise, noise is added per point. base_noise : float Base noise level to add to the spatial map. psf_sigma : float Sigma of the PSF (in pixel units).
Returns:#
tuple[np.ndarray, np.ndarray] The updated spatial map and the points.
Source code in SMS_BP/simulate_foci.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
generate_points(pdf, total_points, min_x, max_x, center, radius, bias_subspace_x, space_prob, density_dif)
#
Generates random (x, y) points using the accept/reject method based on a given distribution.
Parameters:#
pdf : callable Probability density function to sample from. total_points : int Number of points to generate. min_x : float Minimum x value for sampling. max_x : float Maximum x value for sampling. center : np.ndarray Coordinates of the center of the top-hat distribution. radius : float Radius of the top-hat region. bias_subspace_x : float Probability at the top of the top-hat. space_prob : float Probability outside the top-hat region. density_dif : float Scaling factor for density differences.
Returns:#
np.ndarray Array of generated points.
Source code in SMS_BP/simulate_foci.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
generate_points_from_cls(pdf, total_points, volume, bounds, density_dif)
#
Generates random (x, y, z) points using the accept/reject method based on a given distribution.
Parameters:#
pdf : callable Probability density function to sample from. total_points : int Number of points to generate. bound : list with the following min_x : float Minimum x value for sampling. max_x : float Maximum x value for sampling. min_y : float Minimum y value for sampling. max_y : float Maximum y value for sampling. min_z : float Minimum z value for sampling. max_z : float Maximum z value for sampling. volume : float, volume of region sampling density_dif : float Scaling factor for density differences.
Returns:#
np.ndarray Array of generated (x, y, z) points.
Source code in SMS_BP/simulate_foci.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
generate_radial_points(total_points, center, radius)
#
Generates uniformly distributed points in a circle of a given radius.
Parameters:#
total_points : int Number of points to generate. center : np.ndarray Coordinates of the center of the circle. radius : float Radius of the circle.
Returns:#
np.ndarray Array of generated (x, y) coordinates.
Source code in SMS_BP/simulate_foci.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
generate_sphere_points(total_points, center, radius)
#
Generates uniformly distributed points in a sphere of a given radius.
Parameters:#
total_points : int Number of points to generate. center : np.ndarray Coordinates of the center of the sphere. radius : float Radius of the sphere.
Returns:#
np.ndarray Array of generated (x, y, z) coordinates.
Source code in SMS_BP/simulate_foci.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
get_gaussian(mu, sigma, domain=[list(range(10)), list(range(10))])
#
Generates a 2D Gaussian distribution over a given domain.
Parameters:#
mu : np.ndarray Center position of the Gaussian (x, y). sigma : float | np.ndarray Standard deviation(s) of the Gaussian. domain : list[list[int]], optional Domain over which to compute the Gaussian (default is 0-9 for x and y).
Returns:#
np.ndarray 2D array representing the Gaussian distribution over the domain.
Source code in SMS_BP/simulate_foci.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
get_lengths(track_distribution, track_length_mean, total_tracks)
#
Returns track lengths based on the specified distribution.
Parameters:#
track_distribution : str The distribution of track lengths. Options are "exponential", "uniform", and "constant". track_length_mean : int The mean length of the tracks. total_tracks : int The total number of tracks to generate.
Returns:#
np.ndarray An array of track lengths (shape: (total_tracks,)).
Raises:#
ValueError If the distribution type is not recognized.
Source code in SMS_BP/simulate_foci.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
radius_spherical_cap(R, center, z_slice)
#
Calculates the radius of a spherical cap at a given z-slice.
Parameters:#
R : float Radius of the sphere. center : np.ndarray [x, y, z] coordinates of the center of the sphere. z_slice : float Z-coordinate of the slice relative to the sphere's center.
Returns:#
float Radius of the spherical cap at the given z-slice.
Raises:#
ValueError If the z-slice is outside the sphere.
Source code in SMS_BP/simulate_foci.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | |
tophat_function_2d(var, center, radius, bias_subspace, space_prob, **kwargs)
#
Defines a circular top-hat probability distribution in 2D.
Parameters:#
var : np.ndarray [x, y] coordinates for sampling the distribution. center : np.ndarray [c1, c2] coordinates representing the center of the top-hat region. radius : float Radius of the circular top-hat. bias_subspace : float Probability at the center of the top-hat. space_prob : float Probability outside the top-hat region.
Returns:#
float The probability value at the given coordinates.
Source code in SMS_BP/simulate_foci.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |