Lightcurves¶
Lightcurve clustering¶
We have minimal support for costructing the light curves from a sets of per-frame measurements of many objects, by applying simple spatial clusering to their positions. It is implemented in the stdpipe.lcs.LCs container that stores per-detection vectors (e.g. RA/Dec/flux) and can group them into spatial clusters using a KDTree radius search. Results are stored in self.lcs with centroid coordinates and member indices.
lcs = LCs()
lcs.add(ra=ra, dec=dec, flux=flux, time=time1)
# Can be called repeatedly, e.g. to append per-image chunks
lcs.add(ra=ra2, dec=dec2, flux=flux2, time=time2)
lcs.cluster(sr=1/3600, min_length=3)
# Cluster centroids (degrees) and sizes
print(lcs.lcs['ra'], lcs.lcs['dec'], lcs.lcs['N'])
# Show the lightcurve for first object
ids = lcs.lcs['ids'][0]
plt.plot(lcs.time[ids], lcs.flux[ids], 'o--')
The clustering results include:
x,y,z: centroid unit-vector coordinatesra,dec: centroid sky coordinates in degreesN: number of points per clusterids: list of index arrays for member pointskd: KDTree built from centroid vectors
You can pass an analyze= callback to compute per-cluster diagnostics. The callable
should return a mapping; each value is appended to self.lcs under its key.
def analyze(lcs, ids):
return {'mean_flux': np.mean(lcs.flux[ids])}
lcs.cluster(sr=1/3600, analyze=analyze)
print(lcs.lcs['mean_flux'])
Key parameters include sr (radius in degrees) and min_length (minimum number of
detections required to keep a cluster).
- class stdpipe.lcs.LCs[source]
Container for light-curve data vectors with spatial clustering utilities.
Stores user-provided per-detection vectors (e.g., ra/dec/flux/time) and groups detections into spatial clusters using a KDTree radius search. Clustering returns per-cluster centroids and member indices in
self.lcs.Methods
add(**kwargs)Add per-detection vectors to the container.
cluster([sr, min_length, col_ra, col_dec, ...])Spatially cluster the data vectors using ra/dec values stored in
col_raandcol_dec.Notes
add()broadcasts scalars to the length of the longest input vector.cluster()refines centroids and can call ananalyze(self, ids)callback per cluster.Coordinate jitter is applied when building the KDTree to avoid degeneracy from repeated positions.
Clustering results are stored in
self.lcswith keys: -x,y,z: centroid unit-vector coordinates. -ra,dec: centroid sky coordinates in degrees. -N: number of points per cluster. -ids: list of index arrays for member points in the container. -kd: KDTree built from centroid vectors for fast queries.
- add(**kwargs)[source]
Add per-detection vectors to the container.
Each keyword defines a stored vector. Scalars are broadcast to the length of the longest input vector, and missing values are filled with None. This method may be called repeatedly to append new chunks of measurements (e.g., per-image batches) to the existing vectors.
Examples
>>> lcs = LCs() >>> lcs.add(ra=[1, 2], dec=[3, 4], flux=10.0)
- cluster(sr=0.0002777777777777778, min_length=None, col_ra='ra', col_dec='dec', verbose=True, analyze=None, N=1000, max_refine_iter=1)[source]
Spatially cluster the data vectors using ra/dec values stored in
col_raandcol_dec.- Parameters:
- srfloat, optional
Clustering radius in degrees.
- min_lengthint or None, optional
Minimum number of points required to keep a cluster.
- col_rastr, optional
Name of the RA column in stored vectors.
- col_decstr, optional
Name of the Dec column in stored vectors.
- verbosebool or callable, optional
Logging control, can be a print-like function.
- analyzecallable or None, optional
Optional callback
analyze(self, ids)called per accepted cluster. Any returned mapping entries are appended intoself.lcsunder their respective keys (one entry per cluster).- Nint, optional
Progress update interval in points.
- max_refine_iterint, optional
Maximum number of centroid refinement iterations (default 1).