qumas.MicrolensingMaps.micro_maps_tracks_func module
- bresenham_line(r0, c0, r1, c1)[source]
Classic Bresenham line between (r0, c0) and (r1, c1), inclusive. Returns arrays rr, cc of same length.
- Parameters:
r0 (int)
c0 (int)
r1 (int)
c1 (int)
- Return type:
Tuple[ndarray, ndarray]
- generate_random_tracks(shape, lengths, *, n_tracks=None, seed=None, max_attempts=5000, extent=None, avoid_overlap=False)[source]
Generate straight tracks (Bresenham lines) with exact pixel lengths.
Angles are no longer biased: endpoints are sampled uniformly on the Chebyshev perimeter { (dr,dc): max(|dr|,|dc|)=L-1 }, which admits all lattice directions including true 45° diagonals and guarantees a Bresenham path of length L (unless border clipping occurs, in which case we retry).
- Parameters:
shape ((H, W))
lengths (list[int] or int) – If int, you must also pass n_tracks (all tracks same length). If list, its length is the number of tracks and each entry is the pixel length.
n_tracks (int | None) – Number of tracks if lengths is an int.
seed (int | None) – RNG seed.
max_attempts (int) – Max attempts per track to find a valid line of exact length.
extent ((xmin, xmax, ymin, ymax) | None) – If provided, data coords (p0, p1) and data-space angle will be included.
avoid_overlap (bool) – If True, tries to avoid reusing pixels used by previous tracks.
- Returns:
tracks –
- Each dict has:
’pix0’: (r0, c0)
’pix1’: (r1, c1)
’rr’: array of row indices (Bresenham path)
’cc’: array of col indices (Bresenham path)
’length’: int (number of pixels)
’angle_deg’: float (pixel-space, y-down convention, [0,360))
’p0’: (x0, y0) [only if extent provided]
’p1’: (x1, y1) [only if extent provided]
’angle_deg_data’: float [only if extent provided]
’coords’: ((r0,c0),(r1,c1))
’coords_pix’: (rr,cc)
- Return type:
list of dict