IQCalc

class ginga.util.iqcalc.IQCalc(logger=None)[source]

Bases: object

Class to handle model fitting and FWHM calculations.

Parameters
loggerobj or None

Python logger. If not given, one will be created.

Attributes
lockthreading.RLock

For mutex around scipy.optimize, which seems to be non-threadsafe.

skylevel_magnification, skylevel_offsetfloat

For adjustments to sky background level.

Methods Summary

brightness(x, y, radius, medv, data)

Return the brightness value found in a region defined by input location and radius.

calc_fwhm(arr1d[, medv, method_name])

Calculate FWHM for the given input array.

calc_fwhm_gaussian(arr1d[, medv, gauss_fn])

FWHM calculation on a 1D array by using least square fitting of a Gaussian function on the data.

calc_fwhm_moffat(arr1d[, medv, moffat_fn])

FWHM calculation on a 1D array by using least square fitting of a Moffat function on the data.

centroid(data, xc, yc, radius)

Calculate centroid from center of mass.

cut_cross(x, y, radius, data)

Cut data vertically and horizontally at the given position with the given radius.

cut_region(x, y, radius, data)

Return a cut region.

encircled_energy(data)

Return a function of encircled energy across pixel indices.

ensquared_energy(data)

Return a function of ensquared energy across pixel indices.

evaluate_peaks(peaks, data[, bright_radius, ...])

Evaluate photometry for given peaks in data array.

find_bright_peaks(data[, threshold, sigma, ...])

Find bright peak candidates in in the given data.

fwhm_data(x, y, data[, radius, method_name])

Equivalent to get_fwhm().

gaussian(x, p)

Evaluate Gaussian function in 1D.

get_fwhm(x, y, radius, data[, medv, method_name])

Get the FWHM values of the object at the given coordinates and radius.

get_threshold(data[, sigma])

Calculate threshold for find_bright_peaks().

moffat(x, p)

Evaluate Moffat function in 1D.

objlist_select(objlist, width, height[, ...])

Filter output from evaluate_peaks().

pick_field(data[, peak_radius, ...])

Pick the first good object within the given field.

qualsize(image[, x1, y1, x2, y2, radius, ...])

Run pick_field() on the given image.

starsize(fwhm_x, deg_pix_x, fwhm_y, deg_pix_y)

Calculate average FWHM in arcseconds.

Methods Documentation

brightness(x, y, radius, medv, data)[source]

Return the brightness value found in a region defined by input location and radius. Region is cut using cut_region().

Parameters
x, yint

Indices of central pixel.

radiusint

Half-width in both X and Y directions.

medvfloat

Background to subtract off.

dataarray-like

Data array.

Returns
resfloat

Brightness.

calc_fwhm(arr1d, medv=None, method_name='gaussian')[source]

Calculate FWHM for the given input array.

Parameters
arr1darray-like

1D array cut in either X or Y direction on the object.

medvfloat or None

Median of the data. If not given, it is calculated from arr1d.

method_name{‘gaussian’, ‘moffat’}

Function to use for fitting.

Returns
resBunch

Fitting results.

calc_fwhm_gaussian(arr1d, medv=None, gauss_fn=None)[source]

FWHM calculation on a 1D array by using least square fitting of a Gaussian function on the data.

Parameters
arr1darray-like

1D array cut in either X or Y direction on the object.

medvfloat or None

Median of the data. If not given, it is calculated from arr1d.

gauss_fnfunc or None

Gaussian function for fitting. If not given, gaussian() is used.

Returns
resBunch

Fitting results.

Raises
IQCalcError

Fitting failed.

calc_fwhm_moffat(arr1d, medv=None, moffat_fn=None)[source]

FWHM calculation on a 1D array by using least square fitting of a Moffat function on the data.

Parameters
arr1darray-like

1D array cut in either X or Y direction on the object.

medvfloat or None

Median of the data. If not given, it is calculated from arr1d.

moffat_fnfunc or None

Moffat function for fitting. If not given, moffat() is used.

Returns
resBunch

Fitting results.

Raises
IQCalcError

Fitting failed.

centroid(data, xc, yc, radius)[source]

Calculate centroid from center of mass.

Parameters
dataarray-like

Data array.

xc, ycint

X and Y indices of the approximate center.

radiusfloat

Half-width of the region to consider around the given center.

Returns
x, yfloat

Centroid indices.

Raises
IQCalcError

Missing dependency.

cut_cross(x, y, radius, data)[source]

Cut data vertically and horizontally at the given position with the given radius.

Parameters
x, yint

Indices where vertical and horizontal cuts meet.

radiusfloat

Radius of both cuts.

dataarray-like

Data array to cut from.

Returns
x0array-like

Starting pixel of horizontal cut (in X).

y0array-like

Starting pixel of vertical cut (in Y).

xarrarray-like

Horizontal cut (in X).

yarrarray-like

Vertical cut (in Y).

cut_region(x, y, radius, data)[source]

Return a cut region.

Parameters
x, yint

Indices of central pixel.

radiusint

Half-width in both X and Y directions.

dataarray-like

Data array to cut from.

Returns
x0, y0int

Origin of the region.

arrarray-like

Cut region (a view, not copy).

encircled_energy(data)[source]

Return a function of encircled energy across pixel indices.

Ideally, data is already a masked array and is assumed to be centered.

ensquared_energy(data)[source]

Return a function of ensquared energy across pixel indices.

Ideally, data is already a masked array and is assumed to be centered.

evaluate_peaks(peaks, data, bright_radius=2, fwhm_radius=15, fwhm_method='gaussian', ee_total_radius=10, cb_fn=None, ev_intr=None)[source]

Evaluate photometry for given peaks in data array.

Parameters
peakslist of tuple

List of (x, y) tuples containing indices of peaks.

dataarray-like

Data array that goes with the given peaks.

bright_radiusint

This is not used.

fwhm_radius, fwhm_method

See get_fwhm().

ee_total_radiusfloat

Radius, in pixels, where encircled and ensquared energy fractions are defined as 1.

cb_fnfunc or None

If applicable, provide a callback function that takes a ginga.misc.Bunch.Bunch containing the result for each peak. It should not return anything.

ev_intrthreading.Event or None

For threading, if applicable.

Returns
objlistlist of ginga.misc.Bunch.Bunch

A list of successful results for the given peaks. Each result contains the following keys:

  • objx, objy: Fitted centroid from get_fwhm().

  • pos: A measure of distance from the center of the image.

  • oid_x, oid_y: Center-of-mass centroid from centroid().

  • fwhm_x, fwhm_y: Fitted FWHM from get_fwhm().

  • fwhm: Overall measure of fwhm as a single value.

  • fwhm_radius: Input FWHM radius.

  • brightness: Average peak value based on get_fwhm() fits.

  • elipse: A measure of ellipticity.

  • x, y: Input indices of the peak.

  • skylevel: Sky level estimated from median of data array and skylevel_magnification and skylevel_offset attributes.

  • background: Median of the input array.

  • ensquared_energy_fn: Function of ensquared energy for different pixel radii.

  • encircled_energy_fn: Function of encircled energy for different pixel radii.

find_bright_peaks(data, threshold=None, sigma=5, radius=5)[source]

Find bright peak candidates in in the given data.

Parameters
dataarray-like

Input data to find peaks from.

thresholdfloat or None

Detection threshold. Below this value, an object is not considered a candidate. If not given, a default is calculated using get_threshold() with the given sigma.

sigmafloat

Sigma for the threshold.

radiusfloat

Pixel radius for determining local maxima. If the desired objects are larger in size, specify a larger radius.

Returns
peakslist of tuple

A list of candidate object coordinate tuples (x, y) in data.

fwhm_data(x, y, data, radius=15, method_name='gaussian')[source]

Equivalent to get_fwhm().

gaussian(x, p)[source]

Evaluate Gaussian function in 1D. See calc_fwhm().

Parameters
xarray-like

X values.

ptuple of float

Parameters for Gaussian, i.e., (mean, stddev, amplitude).

Returns
yarray-like

Y values.

get_fwhm(x, y, radius, data, medv=None, method_name='gaussian')[source]

Get the FWHM values of the object at the given coordinates and radius.

Parameters
x, yint

Indices of the object location in data array.

radiusfloat

Radius of the region encompassing the object.

dataarray-like

Data array.

medv, method_name

See calc_fwhm().

Returns
fwhm_x, fwhm_yfloat

FWHM in X and Y, respectively.

ctr_x, ctr_yfloat

Center in X and Y, respectively.

x_res, y_resdict

Fit results from calc_fwhm() in X and Y, respectively.

get_threshold(data, sigma=5.0)[source]

Calculate threshold for find_bright_peaks().

Parameters
dataarray-like

Data array.

sigmafloat

Sigma for the threshold.

Returns
thresholdfloat

Threshold based on good data, its median, and the given sigma.

moffat(x, p)[source]

Evaluate Moffat function in 1D. See calc_fwhm().

Parameters
xarray-like

X values.

ptuple of float

Parameters for Moffat, i.e., (x_0, gamma, alpha, amplitude), where x_0 a.k.a. mean and gamma core width.

Returns
yarray-like

Y values.

objlist_select(objlist, width, height, minfwhm=2.0, maxfwhm=150.0, minelipse=0.5, edgew=0.01)[source]

Filter output from evaluate_peaks().

Parameters
objlistlist of ginga.misc.Bunch.Bunch

Output from evaluate_peaks().

width, heightint

Dimension of data array from which objlist was derived.

minfwhm, maxfwhmfloat

Limits for desired FWHM, where (minfwhm, maxfwhm).

minelipsefloat

Minimum value of desired ellipticity (not inclusive).

edgewfloat

Factor between 0 and 1 that determines if a location is too close to the edge or not.

Returns
resultslist of ginga.misc.Bunch.Bunch

Elements of objlist that contain desired FWHM, ellipticity, and not too close to the edge.

pick_field(data, peak_radius=5, bright_radius=2, fwhm_radius=15, threshold=None, minfwhm=2.0, maxfwhm=50.0, minelipse=0.5, edgew=0.01, ee_total_radius=10)[source]

Pick the first good object within the given field.

Parameters
dataarray-like

Data array of the field.

peak_radius, threshold

See find_bright_peaks().

bright_radius, fwhm_radius, ee_total_radius

See evaluate_peaks().

minfwhm, maxfwhm, minelipse, edgew

See objlist_select().

Returns
resultginga.misc.Bunch.Bunch

This is a single element of objlist as described in evaluate_peaks().

Raises
IQCalcError

No object matches selection criteria.

qualsize(image, x1=None, y1=None, x2=None, y2=None, radius=5, bright_radius=2, fwhm_radius=15, threshold=None, minfwhm=2.0, maxfwhm=50.0, minelipse=0.5, edgew=0.01, ee_total_radius=10)[source]

Run pick_field() on the given image.

Parameters
imageginga.AstroImage.AstroImage

Image to process.

x1, y1, x2, y2int

See ginga.BaseImage.BaseImage.cutout_data().

radius, threshold

See find_bright_peaks().

bright_radius, fwhm_radius, ee_total_radius

See evaluate_peaks().

minfwhm, maxfwhm, minelipse, edgew

See objlist_select().

Returns
qsginga.misc.Bunch.Bunch

This is a single element of objlist as described in evaluate_peaks().

starsize(fwhm_x, deg_pix_x, fwhm_y, deg_pix_y)[source]

Calculate average FWHM in arcseconds.

Parameters
fwhm_xfloat

FWHM in X (pixels).

deg_pix_xfloat

Plate scale from CDELT1 in degrees per pixel.

fwhm_yfloat

FWHM in Y (pixels).

deg_pix_yfloat

Plate scale from CDELT2 in degrees per pixel.

Returns
fwhmfloat

Average FWHM in arcseconds.