romanimpreprocess.utils.sky

Utilities for simple sky estimation.

Functions

binkxk

Bin-averaging utility for 2D array, kxk.

smooth_mode

Find the mode of the smoothed histogram.

medfit

Fits a low-order polynomial to a 2D array.

Functions

binkxk(arr, k)

Bin-averaging utility for 2D array, kxk.

smooth_mode(arr[, pc, pksmooth, niter])

Find the mode of the smoothed histogram.

medfit(arr[, N, order])

Fits a low-order polynomial to a 2D array.

Module Contents

binkxk(arr, k)[source]

Bin-averaging utility for 2D array, kxk.

Parameters:
  • arr (np.array) – 2D array

  • k (int) – Bin every k pixels on both axes.

Returns:

2D array, reduced by a factor of k on each axis. The “remainder” pixels (if any) are ignored.

Return type:

np.array of float

smooth_mode(arr, pc=25.0, pksmooth=0.5, niter=3)[source]

Find the mode of the smoothed histogram.

Ignores nans.

Parameters:
  • arr (np.array) – The image from which we want to take the mode.

  • pc (float, optional) – Percentile cut for the histogram.

  • pksmooth (float, optional) – Number of sigmas to smooth.

  • niter (int, optional) – Number of peak-finding iterations.

Returns:

Best fit mode and width of weighting function.

Return type:

(float, float)

medfit(arr, N=8, order=2)[source]

Fits a low-order polynomial to a 2D array.

Inputs

arrnp.array

The 2D image.

Nint, optional

Number of regions to break into on each dimension (so total is N^2).

orderint, optional

Order of polynomial to fit.

returns:
  • coef (np.array) – The flattened array of polynomial coefficients (see Notes for ordering).

  • arrmed (np.array) – The fit to the median (same shape as arr).

Notes

The polynomial fit is of the form (in pseudocode):

u = 2*x/nx-1
v = 2*y/ny-1
arrmed[y,x] = sum coef_ij P_i(u) P_j(v)

(so u and v are scaled to the range -1 to +1).

The ordering in coef is:

0,0   0,1   0,2   ...   0,order-1   0,order
1,0   1,1   1,2   ...   1,order-1
...
order,0

The total number of coefficients is (order+1)*(order+2)//2.