1

I mark the bad pixels on an image with a boolean array. A bad pixel has a value of True and a good one a value of False. I use this routine for various images, none with the same dimensions. The code I use is:

image = pyfits.getdata(image_loc)
background=np.median(image)
ndimg.filters.minimum_filter(image,size=(2,2),output=image)
print background
raw_stars = pys.run(image,params=['X_IMAGE','Y_IMAGE'],conf_args={'ANALYSIS_THRESH':3,'FILTER':'Y','FILTER_NAME':'default.conv','DETECT_TYPE':'CCD','DEBLEND_NTHRESH':32,'DEBLEND_MINCONT':0.005,'CLEAN':'Y','CLEAN_PARAM':1.0,'MASK_TYPE':'CORRECT','SEEING_FWHM':'1.2','STARNNW_NAME':'default.nnw','BACK_SIZE':32,'BACK_FILTERSIZE':3,'GAIN':5.0,'DETECT_THRESH':10,'PIXEL_SCALE':0.453,'THRESH_TYPE':'RELATIVE','DETECT_MINAREA':det_area})
starsx=raw_stars[0].tonumpy()
starsy=raw_stars[1].tonumpy()

fringe = np.empty(np.shape(image),dtype=bool)
for m in range(np.shape(image)[0]):
    for n in range(np.shape(image)[1]):
        if ( image[m,n] < np.sqrt(background) ):
            fringe[m,n] = True
x=np.linspace(0,m,m)
y=np.linspace(0,n,n)
z = np.empty(np.shape(image),dtype=bool)
for clean in range(10):
    z = np.copy(fringe)
    print z
    fringe=sp.interpolate.griddata(x,y,z,method='linear',fill_value=True)

Here x and y have the dimensions of the distinctive axis. Ons some images it wors great, on others though I get:

fringe=scipy.interpolate.griddata(x,y,z,method='linear',fill_value=True)
File "/usr/lib64/python2.7/site-packages/scipy/interpolate/ndgriddata.py", line 176, in griddata
values = values[idx]
IndexError: index 1556 is out of bounds for size 1556

I have tried interpolate.interp2d also but it demands a square array. What may be the solution?

  • Your code sample is not really clear. What are the sizes of the arrays x,y and z when this works and when it fails? Are they all equal? – C Mars Oct 09 '13 at 11:30
  • You are most likely using it wrong, in particular `griddata(x,y,z,...)` is likely not the correct way to call it; based on your code example it's difficult to tell what you are doing. See the documentation. – pv. Oct 09 '13 at 17:30
  • What I initially do is I read data from a fits file into a numpy array 'image'. Then I create boolean array 'fringe' with the same dimentions and mark all of the bad pixels as 'True'. I then assign vector x and y to the first row and column values of the array. On each iteration the interpolated array is assigned to z. – user2739303 Oct 10 '13 at 12:44
  • can you post some runnable code that will reproduce this with some example data? – C Mars Oct 10 '13 at 14:17
  • I put in the complete extract surrounding the interpolation – user2739303 Oct 14 '13 at 07:07

0 Answers0