BLACK = 0
WHITE=5000

def OpenImage(FileName):
    """Opens a FIT image and puts pixel ADU values into an array"""
    image = fits.getdata(FileName)
    return image

def OpenDirectory(Directory):
    filenames = glob.glob(Directory+"*.fit")
    return filenames


def count(pic):
   xsize, ysize = np.shape(pic)
   temp = pic
   clust = []
   for x in range(xsize):
      for y in range(ysize):
         if temp[x,y] >= Threshold and temp[x,y] != WHITE:
            
            clust.append((fill(temp, xsize, ysize, x, y)))

   plt.imshow(temp, cmap='gray_r', origin='lower',interpolation='none', vmin=WHITE - 1,vmax=WHITE)         
   
   return clust

def fill(pic, xsize, ysize, x, y):
   
   if pic[x, y] < Threshold:
      return

   thisClustList = []

   queue = [(x, y)]
   while len(queue) != 0:
      next = queue.pop()
      if pic[next[0], next[1]] >= Threshold and pic[next[0], next[1]] != WHITE:
         pic[next[0], next[1]] = WHITE
         thisClustList.append((next[0], next[1]))
         if x > 0: queue.append((x-1, y))
         if x < (xsize-1): queue.append((x+1, y))
         if y > 0: queue.append((x, y-1))
         if y < (ysize-1): queue.append((x, y+1))
   return thisClustList

pic = OpenImage("C:\\Users\\Blake\\Dropbox\\Msci_project\\Alpha\\alpha_persei_10.fit")

Threshold = pic.mean()+(np.std(pic))

plt.figure(1)

plt.imshow(pic, cmap='gray', origin='lower',interpolation='none', vmin=np.median(pic),vmax=np.median(pic)*2.2)
plt.colorbar()
plt.figure(2)
stars = count(pic)
print stars
print len(stars)
count(pic)
plt.colorbar()


plt.show()


<\verbatim>



-- Public.LunaBorella - 27 Oct 2017
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...

Physics WebpagesRHUL WebpagesCampus Connect • Royal Holloway, University of London, Egham, Surrey TW20 0EX; Tel/Fax +44 (0)1784 434455/437520

Topic revision: r2 - 09 Nov 2017 - LunaMarieBorella1

 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback