Esempio n. 1
0
def spoly_centroid(data, A, f, sigma):

    size = data.shape[0]
    zero = size / 2 + .5
    kernel = profile.makeGaussian(7, f, 0, np.array([3.5, 3.5]))

    image = signal.convolve2d(data, kernel, mode="same")

    bp = np.where(image == image.max())  #brightest pixel in the smoothed image
    cen = [bp[1][0], bp[0][0]]

    k = image[cen[1] - 1:cen[1] + 2, cen[0] - 1:cen[0] + 2]

    if (k.shape != (3, 3)):
        center = np.array([0., 0.])
        X = np.arange(6) * 0.
    else:
        C = cov(f, sigma)
        X = regression(A, C, k.flatten())

        a, b, c, d, e, f = X
        matrix = np.array([[2. * d, e], [e, 2. * f]])
        #matrix = matrix + (np.max(np.abs(matrix))/9.)*np.array([[1,0],[0,1]])
        matrix = matrix + (sigma / np.sqrt(4. * np.pi * f**2.)) * np.array(
            [[1, 0], [0, 1]])  #add maximum per pixel variance
        #of the smoothed image to the
        # diagonal elements of the curvature
        #matrix
        vector = np.array([-1. * b, -1. * c])
        center = np.dot(np.linalg.inv(matrix), vector)
        #center = (c*e - b*f)/(2.*d*f - 2.*e**2.) , (b*e - c*d)/(2.*d*f - 2.*e**2.)
    return np.array(cen) + np.array([.5, .5]) + center
Esempio n. 2
0
def sdss_centroid(data , f , sigma):

  """
     Inputs:  image = postage_stamp of star
              f = FWHM of smoothing kernel
              sigma = variance of the background Gaussian noise
     ------------------------------------------------------------

     Output:
              x & y coordinate of centroid

  """
  size = data.shape[0]
  zero = size/2 + .5
  kernel = profile.makeGaussian(17 , f , 0 , np.array([zero,zero]))
  
  smoothed_image = signal.convolve2d(data , kernel , mode = "same")
  
  image = smoothed_image/np.sum(smoothed_image)
  
  bp = np.where((image==image.max())) #brightest pixel in the smoothed image
  cen = [bp[0][0] , bp[1][0]]

  kk = image[cen[0]-1:cen[0]+2,cen[1]-1:cen[1]+2]
 
  if (kk.shape!= 3):
     cen = [size/2 , size/2]
     kk = image[cen[0]-1:cen[0]+2,cen[1]-1:cen[1]+2]
     
  xs = lupton_2d(kk , f , sigma)
     
  return xs
Esempio n. 3
0
def spoly_centroid(data , A , f , sigma):

  size = data.shape[0]
  zero = size/2 + .5
  kernel = profile.makeGaussian(7, f , 0 , np.array([3.5,3.5]))
  
  image = signal.convolve2d(data , kernel , mode = "same")
  
  
  
  bp = np.where(image==image.max()) #brightest pixel in the smoothed image
  cen = [bp[1][0] , bp[0][0]]
  
  k = image[cen[1]-1:cen[1]+2,cen[0]-1:cen[0]+2]
     
  if (k.shape!= (3,3)):
     center = np.array([0.,0.])
     X = np.arange(6)*0.
  else:
     C = cov(f , sigma)
     X = regression(A , C , k.flatten())
  
     a , b , c, d , e , f = X
     matrix = np.array([[2.*d , e],[e , 2.*f]])
     #matrix = matrix + (np.max(np.abs(matrix))/9.)*np.array([[1,0],[0,1]])
     matrix = matrix + (sigma/np.sqrt(4.*np.pi*f**2.))*np.array([[1,0],[0,1]]) #add maximum per pixel variance
                                                                               #of the smoothed image to the
                                                                               # diagonal elements of the curvature
                                                                               #matrix
     vector = np.array([-1.*b , -1.*c])
     center = np.dot(np.linalg.inv(matrix) , vector)
     #center = (c*e - b*f)/(2.*d*f - 2.*e**2.) , (b*e - c*d)/(2.*d*f - 2.*e**2.)   
  return np.array(cen) + np.array([.5,.5]) + center
Esempio n. 4
0
def sdss_centroid(data, f, sigma):
    """
     Inputs:  image = postage_stamp of star
              f = FWHM of smoothing kernel
              sigma = variance of the background Gaussian noise
     ------------------------------------------------------------

     Output:
              x & y coordinate of centroid

  """
    size = data.shape[0]
    zero = size / 2 + .5
    kernel = profile.makeGaussian(17, f, 0, np.array([zero, zero]))

    smoothed_image = signal.convolve2d(data, kernel, mode="same")

    image = smoothed_image / np.sum(smoothed_image)

    bp = np.where(
        (image == image.max()))  #brightest pixel in the smoothed image
    cen = [bp[0][0], bp[1][0]]

    kk = image[cen[0] - 1:cen[0] + 2, cen[1] - 1:cen[1] + 2]

    if (kk.shape != 3):
        cen = [size / 2, size / 2]
        kk = image[cen[0] - 1:cen[0] + 2, cen[1] - 1:cen[1] + 2]

    xs = lupton_2d(kk, f, sigma)

    return xs
Esempio n. 5
0
def sdss_centroid(data , f , sigma):

  """
     Inputs:  image = postage_stamp of star
              f = FWHM of smoothing kernel
              sigma = variance of the background Gaussian noise
     ------------------------------------------------------------

     Output:
              x & y coordinate of centroid

  """
  size = data.shape[0]
  zero = size/2 + .5
  kernel = profile.makeGaussian(7 , f , 0 , np.array([3.5,3.5]))
  
  smoothed_image = signal.convolve2d(data , kernel , mode = "same")
  
  image = smoothed_image#/np.sum(smoothed_image)
  
  bp = np.where((image==image.max())) #brightest pixel in the smoothed image
  cen = [bp[0][0] , bp[1][0]]

  kk = image[cen[0]-1:cen[0]+2 , cen[1]-1:cen[1]+2]
  
  if (kk.shape!= (3,3)):
     xs = np.array([0.,0.])
  else:
     xs = lupton_2d(kk , f , sigma)
     
  center_t = np.array(xs) + np.array([.5,.5]) + cen
  return np.array([center_t[1] , center_t[0]])
Esempio n. 6
0
def find_centroid(data , f , sigma):

  size = data.shape[0]
  zero = size/2 + .5
  kernel = profile.makeGaussian(7, f , 0 , np.array([3.5,3.5]))
  img = signal.convolve2d(data , kernel , mode = "same")
  xi, yi = np.unravel_index(np.argmax(img), img.shape)
    
  if (xi >= 1 and xi < img.shape[0] - 1 and yi >= 1 and yi < img.shape[1] - 1):
      ox, oy = fit_3x3(img[xi-1:xi+2, yi-1:yi+2] , sigma)
  else:
      ox , oy = 0. , 0.
  return xi + ox + .5 , yi + oy + .5
Esempio n. 7
0
def find_centroid(data , f , sigma):

  size = data.shape[0]
  zero = size/2 + .5
  kernel = profile.makeGaussian(17, f , 0 , np.array([8.5,8.5]))
  img = signal.convolve2d(data , kernel , mode = "same")
  xi, yi = np.unravel_index(np.argmax(img), img.shape)
    
  if (xi >= 1 and xi < img.shape[0] - 1 and yi >= 1 and yi < img.shape[1] - 1):
      ox, oy = fit_3x3(img[xi-1:xi+2, yi-1:yi+2] , sigma)
  else:
      ox , oy = 0. , 0.
  return xi + ox + .5 , yi + ox + .5
Esempio n. 8
0
def BP(data, f):

    size = data.shape[0]
    zero = size / 2 + .5
    kernel = profile.makeGaussian(size, f, 0, np.array([zero, zero]))
    smoothed_image = signal.convolve2d(data, kernel, mode="same")
    data = smoothed_image  #/np.sum(smoothed_image)

    bp = np.where((data == data.max()))  #brightest pixel in the smoothed image
    cen = [bp[0][0], bp[1][0]]

    #kk = data[cen[0]-1:cen[0]+2,cen[1]-1:cen[1]+2]

    return cen
Esempio n. 9
0
def BP(data , f):

  size = data.shape[0]
  zero = size/2 + .5
  kernel = profile.makeGaussian(size , f , 0 , np.array([zero,zero]))
  smoothed_image = signal.convolve2d(data , kernel , mode = "same")
  data = smoothed_image#/np.sum(smoothed_image)
  
  bp = np.where((data==data.max())) #brightest pixel in the smoothed image
  cen = [bp[0][0] , bp[1][0]]

  #kk = data[cen[0]-1:cen[0]+2,cen[1]-1:cen[1]+2]

  return cen
Esempio n. 10
0
def find_centroid(data, FWHM, sigma):

    size = data.shape[0]
    zero = size / 2 + .5

    ##q = np.int(2.*FWHM)
    ##Q = 2*q+1
    ##kernel = profile.makeGaussian(Q, FWHM , 0 , np.array([Q/2.,Q/2.]))
    """ incorporating referee's comment """

    kernel = profile.makeGaussian(size, FWHM, 0,
                                  np.array([size / 2., size / 2.]))
    img = signal.convolve2d(data, kernel, mode="same")
    xi, yi = np.unravel_index(np.argmax(img), img.shape)

    if (xi >= 1 and xi < img.shape[0] - 1 and yi >= 1
            and yi < img.shape[1] - 1):
        ox, oy = fit_3x3(img[xi - 1:xi + 2, yi - 1:yi + 2], sigma)
    else:
        ox, oy = 0., 0.
    return xi + ox + .5, yi + oy + .5
Esempio n. 11
0
def BP(data , f):
  """
     Inputs: data
     f = FWHM of the smoothing kernel
  """
  size = data.shape[0]
  zero = size/2 + .5
  kernel = profile.makeGaussian(17 , f , 0 , np.array([zero,zero]))
  smoothed_image = signal.convolve2d(data , kernel , mode = "same")
  data = smoothed_image#/np.sum(smoothed_image)
  
  bp = np.where((data==data.max())) #brightest pixel in the smoothed image
  cen = [bp[0][0] , bp[1][0]]

  #kk = data[cen[0]-1:cen[0]+2,cen[1]-1:cen[1]+2]
  
  """
  if (kk.shape!= 3):
     cen = [size/2 , size/2]
     kk = data[cen[0]-1:cen[0]+2,cen[1]-1:cen[1]+2]
     cen = [size/2 , size/2]
  """
  return cen
Esempio n. 12
0
import c3
import profile

y = profile.makeGaussian(33,6,0,(14.78,18.1))
print -16.5+14.78 , -16.5+18.1
print c3.find_centroid(y)
Esempio n. 13
0
import sampler
import profile
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

M , H = 25 , 3
y = profile.makeGaussian(H*M, H*M/6. ,0.1, (H*M/2.+0.83*H, H*M/2.+1.45*H))

hx, hy, hf = sampler.test_imatrix_new(M, H, -1.45, -0.83)
qw = hx.dot(y).dot(hy)
qq = y.flatten().dot(hf).reshape(M,M)



plt.subplot(1,3,1)
plt.imshow(y, interpolation = "None" , origin = "lower")
plt.colorbar()
plt.subplot(1,3,2)
plt.imshow(qw, interpolation = "None" , origin = "lower")
plt.colorbar()
plt.subplot(1,3,3)
plt.imshow(qq, interpolation = "None" , origin = "lower")
plt.colorbar()
plt.show()


M , H = 25 , 3

y = profile.makeGaussian(M, M/5. ,0.1, (M/2.+0.83, M/2.+1.45))
y /= y.sum() 
Esempio n. 14
0
C = np.kron(np.eye(m) , np.ones(n)).T

print D.shape , C.shape

s = np.dot(D,C)/n
w = np.dot(s,v)
print v
print w

print v.sum() , w.sum()


from scipy import ndimage
import profile
from matplotlib.colors import LogNorm
image = profile.makeGaussian(18 , 4. , 0.1 ,(8.1,7.8))

ii = ndimage.interpolation.zoom(image, 3, output=None, order=3)
def srmatrix(n,m):

  D = np.kron(np.eye(n) , np.ones(m).reshape(1,m).T).T 
  C = np.kron(np.eye(m) , np.ones(n).reshape(1,n)).T 
  return np.dot(D,C)#np.kron(np.dot(D,C) , np.dot(D,C))

from pylab import *

i = np.dot(srmatrix(54,18) , np.dot(image , srmatrix(54,18).T)) 
#i = np.dot(image,srmatrix(10,17).T).reshape(10,10)

imshow(image, interpolation ="None")
show()