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.get_bg(img, clip_iter=None, sigma_lower=100.0, sigma_upper=5.0)[source]
Measure the background in an image.
- Parameters
img (array) – 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, threshold=None, bg=None, sig=None, clip_iter=10, sigma_lower=100.0, sigma_upper=3.0)[source]
- 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