fiberlab.contour module
- class fiberlab.contour.Circle(x, y)[source]
Bases:
objectFit the center and radius of a circle fit to a set of data.
- Parameters:
x (array) – The Cartesian x coordinates of the circle
y (array) – The Cartesian y coordinates of the circle
- class fiberlab.contour.Ellipse(x, y)[source]
Bases:
objectFit an ellipse to a set of coordinates.
Equations are:
- Parameters:
x (array) – The Cartesian x coordinates of the polygon to model.
y (array) – The Cartesian y coordinates of the polygon to model.
- fiberlab.contour.atleast_one_decade(lim)[source]
Increase a provided set of limits so that they span at least one decade.
- Parameters:
lim (array-like) – A two-element object with, respectively, the lower and upper limits on a range.
- Returns:
The adjusted lower and upper limits on the range.
- Return type:
list
- fiberlab.contour.convert_radius(r, pixelsize=None, distance=None, inverse=False)[source]
Convert radius coordinates from pixels to mm or degrees.
- Parameters:
r (numpy.ndarray) – Radius in pixels for the forward operation. For the reverse operation (see
inverse), the radius should be in degrees if bothpixelsizeanddistanceare provided, or in mm if onlypixelsizeis provided.pixelsize (
float, optional) – Size of the image pixels in mm.distance (
float, optional) – Distance from the fiber output to the detector in mm.inverse (
bool, optional) – Perform the inverse operation; i.e., convert radius coordinates from mm or degrees to pixels.
- Returns:
A string with the radius units and the updated radius values converted to either mm in the detector plane or output angle in degrees with respect to the fiber face normal vector. For the reverse (see
inverse) operation, the returned units should be pixels.- Return type:
tuple
- fiberlab.contour.fit_bg(img, degree, sigma_lower=30.0, sigma_upper=3.0, maxclipiters=10, cenfunc='median', fititer=1)[source]
- fiberlab.contour.get_bg(img, clip_iter=None, sigma_lower=100.0, sigma_upper=5.0)[source]
Measure the background in an image.
- Parameters:
img (numpy.ndarray, numpy.ma.MaskedArray) – 2D array with image data.
clip_iter (
int, optional) – Number of clipping iterations. If None, no clipping is performed.sigma_lower (
float, optional) – Sigma level for clipping. Clipping only removes negative outliers. Ignored if clip_iter is None.sigma_upper (
float, optional) – Sigma level for clipping. Clipping only removes positive outliers. Ignored if clip_iter is None.
- Returns:
Returns the background level, the standard deviation in the background, and the number of rejected values excluded from the computation.
- Return type:
tuple
- fiberlab.contour.get_contour(img, level=None, threshold=None, bg=None, sig=None, clip_iter=10, sigma_lower=100.0, sigma_upper=3.0)[source]
Return a single coherent contour of an image that contains the most number of contour points (as a proxy for the one that covers the most area).
If
sigandbgare None,imgis used withget_bg()to get both (using the clipping arguments provided). Ifsigis None, butbgis provided, it must be a numpy.ndarray andget_bg()is used to determinesigand a constant background. If bothsigandbgare provided,bgis subtracted directly fromimg.- Parameters:
img (numpy.ndarray) – Image to contour
level (float, optional) – The exact level to contour. If provided, all other keyword values are ignored.
threshold (float, optional) – The threshold in units of background sigma used to set the contour level.
bg (float, numpy.ndarray, optional) – A background level to subtract. It can be anything that broadcasts to the shape of
img.sig (float, optional) – The (assumed) constant noise level in the background of the image.
clip_iter (int, optional) – Number of clipping iterations to use when measuring the background and noise level. This is only used if sig or bg is None. See
get_bg().sigma_lower (float, optional) – Lower sigma rejection limit. This is only used if sig or bg is None. See
get_bg().sigma_upper (float, optional) – Upper sigma rejection limit. This is only used if sig or bg is None. See
get_bg().
- Returns:
The contour level, the contour coordinates, the noise level, and the background level. The noise level will be None if the level is provided directly.
- Return type:
tuple
- fiberlab.contour.growth_lim(a, lim, fac=1.0, midpoint=None, default=[0.0, 1.0])[source]
Set the plots limits of an array based on two growth limits.
- Parameters:
a (array-like) – Array for which to determine limits.
lim (
float) – Fraction of the total range of the array values to cover. Should be in the range [0, 1].fac (
float, optional) – Factor to contract/expand the range based on the growth limits. Default is no change.midpoint (
float, optional) – Force the midpoint of the range to be centered on this value. If None, set to the median of the data.default (
list, optional) – Default range to return if a has no data.
- Returns:
Lower and upper limits for the range of a plot of the data in a.
- Return type:
list
- fiberlab.contour.iterative_filter(data, window_length, polyorder, clip_iter=None, sigma=3.0, **kwargs)[source]
Iteratively filter and reject 1D data.
kwargs are passed directly to scipy.signal.savgol_filter.
- fiberlab.contour.rotate_y_ticks(ax, rotation, va)[source]
Rotate all the existing y tick labels by the provided rotation angle (deg) and reset the vertical alignment.
- Parameters:
ax (matplotlib.axes.Axes) – Rotate the tick labels for this Axes object. The object is edited in place.
rotation (
float) – Rotation angle in degreesva (
str) – Vertical alignment for the tick labels.
- fiberlab.contour.sigma_clip_stdfunc_mad(data, **kwargs)[source]
A simple wrapper for scipy.stats.median_abs_deviation that omits NaN values and rescales the output to match a normal distribution for use in astropy.stats.sigma_clip.
- Parameters:
data (numpy.ndarray) – Data to clip.
**kwargs – Passed directly to scipy.stats.median_abs_deviation.
- Returns:
- Return type:
scalar-like, numpy.ndarray