In [21]:
import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib as mpl
mpl.rcParams['figure.figsize'] = (10, 9)

In [22]:
file = '/Users/schriste/heroespy/data/HEROES_20130910_X-ray_alignment_repeat2/Detector0/position1/Det00_position1_s.evt'

In [23]:
from astropy.io import fits
f = fits.open(file)

In [24]:
f[0].header


Out[24]:
SIMPLE  =                    T / file does conform to FITS standard             
BITPIX  =                    8 / number of bits per data pixel                  
NAXIS   =                    0 / number of data axes                            
EXTEND  =                    T / FITS dataset may contain extensions            
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 

In [25]:
f[1].header['DETECTOR']


Out[25]:
0

In [26]:
f[1].data[1][2]


Out[26]:
12

In [27]:
data = f[1].data

In [28]:
len(data)


Out[28]:
92143

In [29]:
data[0]


Out[29]:
(235003080.69599998, 317429378, 19, 458, 1134, 1233, 532, 431, 890, 1208, 754, 720, 310.93207, 350.40454, array([False, False, False, False, False, False, False, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False, False, False, False], dtype=bool))

In [30]:
f[1].header


Out[30]:
XTENSION= 'BINTABLE'           / binary table extension                         
BITPIX  =                    8 / 8-bit bytes                                    
NAXIS   =                    2 / 2-dimensional binary table                     
NAXIS1  =                   46 / width of table in bytes                        
NAXIS2  =                92143 / number of rows in table                        
PCOUNT  =                    0 / size of special data area                      
GCOUNT  =                    1 / one data group (required keyword)              
TFIELDS =                   15 / number of fields in each row                   
TTYPE1  = 'STIME   '           / label for field   1                            
TFORM1  = '1D      '           / data format of field: 8-byte DOUBLE            
TUNIT1  = 'sec     '           / physical unit of field                         
TTYPE2  = 'TICKS   '           / label for field   2                            
TFORM2  = '1J      '           / data format of field: 4-byte INTEGER           
TUNIT2  = 'tics    '           / physical unit of field                         
TTYPE3  = 'LPEAK   '           / label for field   3                            
TFORM3  = '1I      '           / data format of field: 2-byte INTEGER           
TTYPE4  = 'CX1     '           / label for field   4                            
TFORM4  = '1I      '           / data format of field: 2-byte INTEGER           
TUNIT4  = 'adu     '           / physical unit of field                         
TTYPE5  = 'CX2     '           / label for field   5                            
TFORM5  = '1I      '           / data format of field: 2-byte INTEGER           
TUNIT5  = 'adu     '           / physical unit of field                         
TTYPE6  = 'CX3     '           / label for field   6                            
TFORM6  = '1I      '           / data format of field: 2-byte INTEGER           
TUNIT6  = 'adu     '           / physical unit of field                         
TTYPE7  = 'CX4     '           / label for field   7                            
TFORM7  = '1I      '           / data format of field: 2-byte INTEGER           
TUNIT7  = 'adu     '           / physical unit of field                         
TTYPE8  = 'CY1     '           / label for field   8                            
TFORM8  = '1I      '           / data format of field: 2-byte INTEGER           
TUNIT8  = 'adu     '           / physical unit of field                         
TTYPE9  = 'CY2     '           / label for field   9                            
TFORM9  = '1I      '           / data format of field: 2-byte INTEGER           
TUNIT9  = 'adu     '           / physical unit of field                         
TTYPE10 = 'CY3     '           / label for field  10                            
TFORM10 = '1I      '           / data format of field: 2-byte INTEGER           
TUNIT10 = 'adu     '           / physical unit of field                         
TTYPE11 = 'CY4     '           / label for field  11                            
TFORM11 = '1I      '           / data format of field: 2-byte INTEGER           
TUNIT11 = 'adu     '           / physical unit of field                         
TTYPE12 = 'PHA     '           / label for field  12                            
TFORM12 = '1J      '           / data format of field: 4-byte INTEGER           
TUNIT12 = 'adu     '           / physical unit of field                         
TTYPE13 = 'RAWX    '           / label for field  13                            
TFORM13 = '1E      '           / data format of field: 4-byte REAL              
TUNIT13 = 'pixel   '           / physical unit of field                         
TTYPE14 = 'RAWY    '           / label for field  14                            
TFORM14 = '1E      '           / data format of field: 4-byte REAL              
TUNIT14 = 'pixel   '           / physical unit of field                         
TTYPE15 = 'STATUS  '           / label for field  15                            
TFORM15 = '32X     '           / data format of field: BIT                      
EXTNAME = 'EVENTS  '           / name of this binary table extension            
TELESCOP= 'HERO    '           / Instrument                                     
INSTRUME= 'GSPC    '           / Instrument                                     
DETECTOR=                    0 / Detector number                                
DETNAM  = 'DET0    '           / Detector name                                  
CPU     =                   16 / CPU ID                                         
MJDREF  =          5.38260E+04 / MJD zero point for times                       
MJD-OBS =          5.65450E+04 / MJD of observation                             
DATE-OBS= '2013-09-10'         / Observation start                              
HDUNAME = 'EVENTS  '           / Instrument                                     
HDUCLASS= 'OGIP    '           / Instrument                                     
TIMEREF = 'LOCAL   '           / Time reference                                 
METHOD  = 'Tap_fit '           / How tap values are used                        
DATE    = '2013-09-11T16:56:21' / file creation date (YYYY-MM-DDThh:mm:ss UT)   
IONEOFF =                    0 / new file, new offset                           
TAPEC1  =                1.000 / Tap correction (energy)                        
TAPPC1  =                1.000 / Tap correction (position)                      
TAPEC2  =                1.000 / Tap correction (energy)                        
TAPPC2  =                1.000 / Tap correction (position)                      
TAPEC3  =                1.000 / Tap correction (energy)                        
TAPPC3  =                1.000 / Tap correction (position)                      
TAPEC4  =                1.000 / Tap correction (energy)                        
TAPPC4  =                1.000 / Tap correction (position)                      
TAPEC5  =                1.000 / Tap correction (energy)                        
TAPPC5  =                1.000 / Tap correction (position)                      
TAPEC6  =                1.000 / Tap correction (energy)                        
TAPPC6  =                1.000 / Tap correction (position)                      
TAPEC7  =                1.000 / Tap correction (energy)                        
TAPPC7  =                1.000 / Tap correction (position)                      
TAPEC8  =                1.000 / Tap correction (energy)                        
TAPPC8  =                1.000 / Tap correction (position)                      
TLMIN3  =          1.00000E+00                                                  
TLMAX3  =          1.00000E+02                                                  
TLMIN4  =          1.00000E+00                                                  
TLMAX4  =          1.02400E+03                                                  
TLMIN5  =          1.00000E+00                                                  
TLMAX5  =          1.02400E+03                                                  
TLMIN6  =          1.00000E+00                                                  
TLMAX6  =          1.02400E+03                                                  
TLMIN7  =          1.00000E+00                                                  
TLMAX7  =          1.02400E+03                                                  
TLMIN8  =          1.00000E+00                                                  
TLMAX8  =          1.02400E+03                                                  
TLMIN9  =          1.00000E+00                                                  
TLMAX9  =          1.02400E+03                                                  
TLMIN10 =          1.00000E+00                                                  
TLMAX10 =          1.02400E+03                                                  
TLMIN11 =          1.00000E+00                                                  
TLMAX11 =          1.02400E+03                                                  
TLMIN12 =          1.00000E+00                                                  
TLMAX12 =          1.02400E+03                                                  
TLMIN13 =          1.00000E+00                                                  
TLMAX13 =          6.00000E+02                                                  
TLMIN14 =          1.00000E+00                                                  
TLMAX14 =          6.00000E+02                                                  
HISTORY TASK: FSELECT on FILENAME: position1.evt                                
HISTORY fselect4.4 at 2013-09-11T16:56:29                                       
HISTORY Expression: status.EQ.bx000000                                          

In [31]:
data['RAWX']


Out[31]:
array([ 310.93206787,  459.74182129,  366.43600464, ...,  216.54396057,
        450.3961792 ,  462.48812866], dtype=float32)

In [32]:
data['RAWY']


Out[32]:
array([ 350.40454102,  356.94439697,  400.99206543, ...,  101.45124817,
        628.03509521,  610.44775391], dtype=float32)

In [33]:
import numpy as np
img, xedges, yedges = np.histogram2d(data['RAWX'], data['RAWY'], bins=200)

In [34]:
plt.imshow(img)


Out[34]:
<matplotlib.image.AxesImage at 0x10737e310>

In [35]:
import skimage
print(skimage.__version__)
from skimage import data, filter, color
from skimage.transform import hough_circle
from skimage.feature import peak_local_max
from skimage.draw import circle_perimeter
from skimage.util import img_as_ubyte


0.10.1

In [36]:
print(img.max())
image = img_as_ubyte(img.astype(np.uint8))
edges = filter.canny(image, sigma=1)


91.0

In [37]:
plt.imshow(edges)


Out[37]:
<matplotlib.image.AxesImage at 0x10ad06290>

In [38]:
hough_radii = np.arange(15, 30, 2)
hough_res = hough_circle(edges, hough_radii)

In [39]:
centers = []
accums = []
radii = []

for radius, h in zip(hough_radii, hough_res):
    # For each radius, extract two circles
    peaks = peak_local_max(h, num_peaks=2)
    centers.extend(peaks)
    accums.extend(h[peaks[:, 0], peaks[:, 1]])
    radii.extend([radius, radius])

fig, ax = plt.subplots()
plt.imshow(image, cmap=plt.cm.gray)
collection = []
for idx in np.argsort(accums)[::-1][:5]:
    center_x, center_y = centers[idx]
    radius = radii[idx]
    circle = plt.Circle((center_y, center_x), radius, color='r', fill=False)
    ax.add_patch(circle)
plt.show()