run#
- crispy.image_ridge_find.run(image, h=1, eps=0.01, maxT=1000, thres=0.135, ordXYZ=True, crdScaling=None, converge_frac=99, ncpu=None, walkerThres=None, overmask=None, walkers=None, min_size=9, return_unconverged=True, f_h=5)[source]#
Identify density ridges in a gridded image using the SCMS algorithm.
This function serves as a wrapper for the SCMS algorithm to identify density ridges in FITS images or NumPy arrays. It supports configurable smoothing, convergence criteria, and walker initialization for ridge identification.
- Parameters:
image (str or ndarray) – Input image as a FITS file path or a NumPy array.
h (float, optional, default=1) – Smoothing bandwidth of the Gaussian kernel.
eps (float, optional, default=1e-2) – Convergence criteria for individual walkers. A smaller value increases precision.
maxT (int, optional, default=1000) – Maximum number of iterations allowed for the walkers to converge.
thres (float, optional, default=0.135) – Lower intensity threshold. Pixels below this threshold are ignored.
ordXYZ (bool, optional, default=True) – If True, reorders coordinates to XYZ format (native Python uses ZYX).
crdScaling (list of float, optional) – Scaling factors for each axis. Coordinates are scaled during processing and rescaled in the output.
converge_frac (float, optional, default=99) – Fraction of walkers that need to converge for the process to terminate, expressed as a percentage.
ncpu (int, optional) – Number of CPUs to use. If None, defaults to one less than the total number of CPUs.
walkerThres (float, optional) – Lower intensity threshold for placing walkers. Overrides the automated walker placement if provided.
overmask (ndarray of bool, optional) – Boolean mask specifying which pixels to include in ridge finding, in addition to the thres criteria.
walkers (ndarray, optional) – Custom initial positions for walkers. Overrides automated walker placement if provided.
min_size (int, optional, default=9) – Minimum size (in pixels) for structures to be considered. Smaller structures are removed.
return_unconverged (bool, optional, default=True) – If True, includes both converged and unconverged walkers in the output. Otherwise, only converged walkers are returned.
f_h (float, optional, default=5) – Filtering factor used to exclude data points based on their distance to all other points.
- Returns:
Coordinates of the density ridges. If return_unconverged is True, returns a tuple: (converged walkers, unconverged walkers). Otherwise, only the converged walkers are returned.
- Return type:
ndarray or tuple of ndarray
Notes
The image can be a 2D or 3D array. For 3D images, smoothing and walker placement apply to all axes equally unless crdScaling is provided.
If crdScaling is used, the coordinates are scaled back to their original values in the output.
This function is designed to work efficiently with gridded images and leverages multiprocessing.
Examples
Process a FITS image and retrieve density ridges:
>>> from crispy import image_ridge_find as irf >>> ridges = irf.run("input_image.fits", h=2, thres=0.2, maxT=500)
Use custom walkers for initialization:
>>> walkers = np.array([[10, 20], [15, 25], [20, 30]]) >>> ridges = irf.run("input_image.fits", walkers=walkers, maxT=200)