from astropy.io import fits
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import glob
import ntpath
import math as m
from scipy import stats
import operator

BLACK = 0
WHITE=2**16
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
   result = 0
   for x in range(xsize):
      for y in range(ysize):
         if temp[x,y] >= Threshold:
            result += 1
            fill(temp, xsize, ysize, x, y)
   plt.imshow(temp, cmap=plt.cm.binary)         
   return result

def fill(pic, xsize, ysize, x, y):
   if pic[x, y] != Threshold:
      pic[x,y] = WHITE
      return 
   pic[x,y] = BLACK
   if x>0: fill(pic, xsize, ysize, x-1, y)
   if x < (xsize-1): fill(pic, xsize, ysize, x+1, y)
   if y > 0: fill(pic, xsize, ysize, x, y-1)
   if y < (ysize-1): fill(pic, xsize, ysize, x, y+1)




pic = OpenImage("C:\\Users\\Blake\\Dropbox\\Msci_project\\Alpha\\alpha_persei.fit")
Threshold = pic.mean()+(np.std(pic)/20)
plt.figure(1)
plt.imshow(pic)
plt.figure(2)
print count(pic)

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: r1 - 27 Oct 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