iq_fit – image quality fitting

Image quality fit.

Fits the point-like continuum detections with the 2D Moffat distribution integrated over the fibers of the reconstructed IFU image.

Warning

The module does run, but it is not tested. Should not be used before proper tests are implemented

Reconstruct the IFU head and fit the 2D Moffat

pyhetdex.tools.astro.iq_fit.fit_image_quality(dither_file, ifucen_file, stars=None, fe_prefix='', fextract=None, wmin=None, wmax=None, Sampler=<class 'pyhetdex.tools.astro.iq_fit.GridSampler'>, n_points=10000)[source]

Fit the image quality on the reconstructed IFU defined by the dither and IFU center files.

Parameters:

dither_file : string

name of the file defining the relative dither position, illumination and image quality

ifucen_file : string

name of the file with the position and throughput of the fibers on the IFU head

stars : None or list of 2-tuples, optional

If none, auto-detect stars on the reconstructed IFU (not implemented). Otherwise must be a list of (x, y) positions of stars on the IFU head to use for the fit

fextract : None or list of fits files, optional

if the name of the files to use for the reconstruction is not the same as the basenames in the dither file

fe_prefix : string, optional

when getting the names from the dither file, prepend fe_prefix to the basename

wmin, wmax : float, optional

min and max wavelength to use when doing the reconstruction. If None: use the min and/or max from the file

Sampler : _BaseSampler child instance, optional

type of sampler to use

n_points : int, optional

number of points to created in the sampler

Returns:

best_fits : list of numpy arrays

best fit parameters from the moffat, plus FWHM. One list entry of each of the fitted stars in the IFU head [np.array(amplitude, x_0, y_0, gamma, alpha, FWHM),]

Raises:

NotImplementedError

if stars is None

The fitter

class pyhetdex.tools.astro.iq_fit.MonteCarlo_Moffat2D[source]

Bases: astropy.modeling.functional_models.Moffat2D

The model is the 2D Moffat distribution integrated in circles.

The integration is done in a Montecarlo like approach using the points provided by the sampler instance.

Parameters:

sampler : instance child of _BaseSampler

sampling of a unit circle centered in (0, 0)

radius : float

fiber radius

amplitude : float

Amplitude of the model

x_0 : float

x position of the maximum of the Beta model

y_0 : float

y position of the maximum of the Beta model

gamma : float

Core width of the Beta model

alpha : float

Power index of the beta model

Attributes

sampler  
radius  
area (float) area of the fiber
__call__(x, y, model_set_axis=None)

Evaluate this model using the given input(s) and the parameter values that were specified when the model was instantiated.

evaluate(x, y, amplitude, x_0, y_0, gamma, alpha)[source]

Evaluate the model in x and y given the parameters. Integrates the Moffat with a Montecarlo like approach using the points from the sampler. Assumes that the sampler samples the correct radius

Parameters:

x, y : array-like or numeric value

input coordinate values

amplitude : float

Amplitude of the model

x_0 : float

x position of the maximum of the Beta model

y_0 : float

y position of the maximum of the Beta model

gamma : float

Core width of the Beta model

alpha : float

Power index of the beta model

Returns:

z : array-like or numeric value

same type of the input x and y containing the integral of the Moffat distribution

pyhetdex.tools.astro.iq_fit.montecarlo_2d(func, x, y, area, *args, **kwargs)[source]

Compute the 2 dimensional integral of function func using a simple montecarlo-like integration.

Parameters:

func : callable

2-dimensional function to evaluate : f(x, y, *params)

x, y : nd-arrays

x and y coordinates of the points to use to compute the integral

area : float

area sampled by (x, y)

args : list

parameters to pass to the function

kwargs : dictionary

keyword parameter to pass to the function

Returns:

I : float

integral

sI : float

error on the integral

The sampler

class pyhetdex.tools.astro.iq_fit._BaseSampler(n_points)[source]

Bases: object

Sample a circle and returns the samples of a circle centered in (x, y) and with radius r.

This is the base class and doesn’t do the sampling. It provides a get_samples() that returns the list of points for a given circle center and radius.

Parameters:

n_points : int

number of points to sample

Notes

Private attributes _xs and _ys should be appropriately defined in the derived classes

get_samples(x, y, r=1.0)[source]

Get the sample point for the circle centered in (x, y) with radius r

Parameters:

x, y : floats

center of the circle

r : float

radius of the circle

Returns:

xs, ys : ndarray

points sampling the circle

class pyhetdex.tools.astro.iq_fit.RandomSampler(n_points)[source]

Bases: pyhetdex.tools.astro.iq_fit._BaseSampler

Randomly sample the circle

Creates about n_points random (x, y) coordinates that sample the circle (x=0, y=0, r=1). It first creates a square with side=2*r and then removes the points outside the circle.

Parameters:

n_points : int

approximate number of points

class pyhetdex.tools.astro.iq_fit.GridSampler(n_points)[source]

Bases: pyhetdex.tools.astro.iq_fit._BaseSampler

Regular grid sample the circle

Creates about n_points (x, y) coordinates in a regular grid that samples the unit circle (x=0, y=0, r=1). It first creates a unit square (a=2) and then removes the points outside the circle. The actual number of points is going to be almost: round(sqrt(n_points * 4/pi)) ** 2

Parameters:

n_points : int

approximate number of points

Utilities

pyhetdex.tools.astro.iq_fit.get_fwhm(gamma, alpha)[source]

Compute the fwhm given gamma and alpha

Parameters:

gamma, alpha : floats or nd arrays

parameters

Returns:

float or nd array

full width half max