IMAGE module

image is the pyvista module that implements some general image processing including basic image arithmetic, VISTA-style, and VISTA-style boxes

image functions:

class pyvista.image.BOX(n=None, nr=None, nc=None, sr=1, sc=1, cr=None, cc=None, xr=None, yr=None)[source]

Defines BOX class

set(xmin, xmax, ymin, ymax)[source]

Resets limits of a box

Parameters
  • xmin – lower x value

  • xmax – higher x value

  • ymin – lower y value

  • ymax – higher xyvalue

nrow()[source]

Returns number of rows in a box

Returns :

number of rows

ncol()[source]

Returns number of columns in a box

Returns :

number of columns

show(header=True)[source]

Prints box limits

mean(data)[source]

Returns mean of data in box

Args :

data : input data (Data or np.array)

Returns

mean of data in box

stdev(data)[source]

Returns standard deviation of data in box

Args :

data : input data (Data or np.array)

Returns

standard deviation of data in box

iqr(data)[source]

Returns IQR data in box

Args :

data : input data (Data or np.array)

Returns

IQR of data in box

max(data)[source]

Returns maximum of data in box

Args :

data : input data (Data or np.array)

Returns

maximum of data in box

min(data)[source]

Returns minimum of data in box

Args :

data : input data (Data or np.array)

Returns

minimum of data in box

median(data)[source]

Returns median of data in box

Args :

data : input data (Data or np.array)

Returns

median of data in box

setval(data, val)[source]

Sets data in box to specified value

setbit(data, val)[source]

Sets bit of data in box to specified value

getval(data)[source]

Returns data in box

Args :

data : input data (Data or np.array)

Returns

data in box

pyvista.image.abx(data, box)[source]

Returns dictionary with image statistics in box.

Args :

data : input data (Data or np.array) box : pyvista BOX

Returns :

dictionary with image statistics : ‘mean’, ‘stdev’, ‘min’, ‘max’, ‘peakx’, ‘peaky’

pyvista.image.gauss2d(X, amp, x0, y0, a, b, c, back, binned=False)[source]

Evaluate Gaussian 2D function

Form: amp*exp(-a(x-x0)**2 - b(x-x0)*(y-y0) - c(y-y0)**2) + const

Parameters
  • X (arraylike [2,npts]) – x,y positions to evaluate at

  • amp (float) – coefficients of function

  • x0 (float) – coefficients of function

  • y0 (float) – coefficients of function

  • a (float) – coefficients of function

  • b (float) – coefficients of function

  • c (float) – coefficients of function

  • back (float) – coefficients of function

pyvista.image.gh2d(X, gpars, hpars, back, binned=False)[source]

Evaluate Gauss-Hermite 2D function

Form: exp(-a(x-x0)**2 - b(x-x0)*(y-y0) - c(y-y0)**2) + const

Parameters
  • X (arraylike [2,npts]) – x,y positions to evaluate at

  • x0 (float) – coefficients of function

  • y0 (float) – coefficients of function

  • a (float) – coefficients of function

  • b (float) – coefficients of function

  • c (float) – coefficients of function

  • back (float) – coefficients of function

pyvista.image.abc2fwxfwytheta(a, b, c)[source]

Convert a,b,c, from gauss2d to xfwhm, yfwhm, theta

pyvista.image.fwxfwytheta2abc(xfwhm, yfwhm, theta)[source]

Convert xfwhm, yfwhm, theta to a,b,c for gauss2d

pyvista.image.gfit2d(data, x0, y0, size=5, fwhm=3.0, sub=True, plot=None, fig=1, scale=1, pafixed=False, astropy=True, binned=False)[source]

Does gaussian fit to input data given initial xcen,ycen

pyvista.image.ghfit2d_thread(pars)[source]

Wrapper for ghfit2d for multithreading, with just a single argument

pyvista.image.ghfit2d(data, x0, y0, size=5, fwhm=3.0, nherm=6, sub=True, plot=None, fig=1, scale=1, pafixed=False, binned=False, p0=None, bounds=None)[source]

Does 2D Gauss-Hermite fit to input data given initial xcen,ycen

pyvista.image.fit2d(X, Y, Z)[source]

Fit 2D quadratic surface

pyvista.image.mk2d(X, Y, coeff)[source]

Return 2D surface given input points and coefficients

pyvista.image.window(data, box, header=None)[source]

Reduce size of image and header accordingly

pyvista.image.stretch(a, ncol=None, nrow=None)[source]

Stretches a 1D image into a 2D image along rows or columns

pyvista.image.add(a, b, dc=0, dr=0, box=None)[source]

Adds b to a, paying attention to CNPIX

pyvista.image.sub(a, b, dc=0, dr=0, box=None)[source]

Subracts b from a, paying attention to CNPIX

pyvista.image.mul(a, b, dc=0, dr=0, box=None)[source]

Multiplies b by a, paying attention to CNPIX

pyvista.image.div(a, b, dc=0, dr=0, box=None)[source]

Divides a by b, paying attention to CNPIX

pyvista.image.clip(hd, min=None, max=None, vmin=None, vmax=None, box=None)[source]

Clipping tasks: sets all values above or below input values to specified values

Parameters

hd – input HDU

Keyword Arguments
  • min= (float) – clip values below min

  • vmin= (float) – values to clip min values to. If min= is not given clips values <vmin to vmin

  • max= (float) – clip values above max

  • vmax= (float) – values to clip max values to. If max= is not given clips values >vmax to vmax

pyvista.image.buf(hd)[source]

Display information about HDU

pyvista.image.rd(file, ext=0)[source]

Read file into HDU

pyvista.image.create(box=None, n=None, nr=None, nc=None, sr=1, sc=1, cr=None, cc=None, const=None)[source]

Creates a new HDU

pyvista.image.sky(im, box=None, max=None, min=None, plot=None)[source]

Estimate sky value in an image by fitting parabola to peak of histogram

Parameters

im (HDU or numpy array) – input image data

Keyword Arguments
  • box= – only use values within specified box (default=None)

  • min= – ignore values below min in sky computation (default=None)

  • max= – ignore values above max in sky computation (default=None)

  • plot= – matplotlib axes to view histogram and fit (default=None)

pyvista.image.xcorr(a, b, lags, medfilt=0, rad=3)[source]

Cross correlation function between two arrays, calculated at lags

If input images have the same number of rows, then calculate a single

cross-correlation in columns

If first image has one row, but the second has more, then calculate

a cross correlation for each row of the second images

Parameters
  • a – array_like reference array

  • b – array_like array to calculate shifts for

  • lags – array_like x-corrlation lags to use

  • medfilt – int, default=0 size of median filter for arrays

Returns :

fit peak of cross-correlation (quadratic fit) 1D cross-correlation function

pyvista.image.xcorr2d(a, b, lags=None, xlags=None, ylags=None)[source]

Two-dimensional cross correlation

Parameters
  • a – input Data frames

  • b – input Data frames

  • lags – array (1D) of x-corrlation lags

Returns

(x,y) position of cross correlation peak from quadratic fit to x-correlation 2D cross correlation function

pyvista.image.zap(hd, size, nsig=3, mask=False)[source]

Median filter array and replace values > nsig*uncertainty

pyvista.image.smooth(data, size, uncertainty=None, bitmask=None)[source]

Boxcar smooth image

pyvista.image.minmax(data, mask=None, low=3, high=10)[source]

Return min,max scaling factors for input data using median, and MAD

Parameters
  • img – input CCDData

  • low – number of MADs below median to return

  • high – number of MADs above median to retunr

Returns

low and high scaling factors

Return type

min,max

pyvista.image.transform(im0, im, lines0, xlags=range(-11, 12), ylags=range(-17, 18), rad=2, scale=20, hard=None, reject=1)[source]

Get geometric transformation between images based on point sources

Parameters
  • im0 (Data or array-like) – Reference image

  • im (Data or array-like) – Target image

  • lines0 (Table) – Table with reference object positions (‘x’ and ‘y’)

  • xlags (range) – Range of cross-correlation shifts to try, default is range(-11,12) and (-17,18)

  • ylags (range) – Range of cross-correlation shifts to try, default is range(-11,12) and (-17,18)

  • rad (float, default=2) – radius for automark

  • scale (integer, default=20) – scale for quiver plots

  • hard (None or char) – if char, make tranformation plots (’’ to display, otherwise save to specified file name)

pyvista.image.seq(files, box=None, size=None, red=None)[source]

Create montage image from a sequence

Parameters
  • files (array-like) – list of files to montage

  • box (box, default=None) – image.BOX to use to extract subregion

  • size (int, default=None) – if specified, extract region of given size around maximum pixel

  • red (Reducer, default=None) – imred.Reducer used to extract images, else use iio.imread