Beispiel #1
0
Datei: frame.py Projekt: dfm/kpsf
 def initialize(self, **kwargs):
     if not np.any(self.mask):
         self.coords = []
         return
     tmp = np.array(self.img)
     tmp[~(self.mask)] = np.median(tmp[self.mask])
     self.coords = simplexy(tmp, **kwargs)
Beispiel #2
0
def source_extract(image_data, srcext=None):

    x, y, flux, sigma = simplexy(
        image_data,
        dpsf=dpsf,
        plim=plim,
        dlim=dlim,
        saddle=saddle,
        maxper=maxper,
        maxnpeaks=maxnpeaks,
        maxsize=maxsize,
        halfbox=halfbox,
    )

    print "simplexy: shapes", x.shape, y.shape

    cx = pyfits.Column(name="X", format="E", array=x, unit="pix")
    cy = pyfits.Column(name="Y", format="E", array=y, unit="pix")
    cflux = pyfits.Column(name="FLUX", format="E", array=flux)

    tbhdu = pyfits.new_table([cx, cy, cflux])
    h = tbhdu.header
    h.add_comment("Parameters used in source extraction")
    h.update("dpsf", dpsf, "Gaussian psf width")
    h.update("plim", plim, "Significance to keep")
    h.update("dlim", dlim, "Closest two peaks can be")
    h.update("saddle", saddle, "Saddle in difference (in sig)")
    h.update("maxper", maxper, "Max num of peaks per object")
    h.update("maxpeaks", maxnpeaks, "Max num of peaks total")
    h.update("maxsize", maxsize, "Max size of extended objects")
    h.update("halfbox", halfbox, "Half-size of sliding sky window")
    if srcext != None:
        h.update("srcext", i, "Extension number in src image")
    h.update("estsigma", sigma, "Estimated source image variance")
    h.add_comment("The X and Y points are specified assuming 1,1 is ")
    h.add_comment("the center of the leftmost bottom pixel of the ")
    h.add_comment("image in accordance with the FITS standard.")
    h.add_comment("Extracted by image2xy.py")
    h.add_comment("on %s %s" % (time.ctime(), time.tzname[0]))
    cards = tbhdu.header.ascardlist()
    cards["TTYPE1"].comment = "X coordinate"
    cards["TTYPE2"].comment = "Y coordinate"
    cards["TTYPE3"].comment = "Flux of source"

    return tbhdu
Beispiel #3
0
def source_extract(image_data, srcext=None):

    x, y, flux, sigma = simplexy(image_data,
                                 dpsf=dpsf,
                                 plim=plim,
                                 dlim=dlim,
                                 saddle=saddle,
                                 maxper=maxper,
                                 maxnpeaks=maxnpeaks,
                                 maxsize=maxsize,
                                 halfbox=halfbox)

    print 'simplexy: shapes', x.shape, y.shape

    cx = pyfits.Column(name='X', format='E', array=x, unit='pix')
    cy = pyfits.Column(name='Y', format='E', array=y, unit='pix')
    cflux = pyfits.Column(name='FLUX', format='E', array=flux)

    tbhdu = pyfits.new_table([cx, cy, cflux])
    h = tbhdu.header
    h.add_comment('Parameters used in source extraction')
    h.update('dpsf', dpsf, 'Gaussian psf width')
    h.update('plim', plim, 'Significance to keep')
    h.update('dlim', dlim, 'Closest two peaks can be')
    h.update('saddle', saddle, 'Saddle in difference (in sig)')
    h.update('maxper', maxper, 'Max num of peaks per object')
    h.update('maxpeaks', maxnpeaks, 'Max num of peaks total')
    h.update('maxsize', maxsize, 'Max size of extended objects')
    h.update('halfbox', halfbox, 'Half-size of sliding sky window')
    if srcext != None:
        h.update('srcext', i, 'Extension number in src image')
    h.update('estsigma', sigma, 'Estimated source image variance')
    h.add_comment('The X and Y points are specified assuming 1,1 is ')
    h.add_comment('the center of the leftmost bottom pixel of the ')
    h.add_comment('image in accordance with the FITS standard.')
    h.add_comment('Extracted by image2xy.py')
    h.add_comment('on %s %s' % (time.ctime(), time.tzname[0]))
    cards = tbhdu.header.ascardlist()
    cards['TTYPE1'].comment = 'X coordinate'
    cards['TTYPE2'].comment = 'Y coordinate'
    cards['TTYPE3'].comment = 'Flux of source'

    return tbhdu
def source_extract(image_data, srcext=None):


    x,y,flux,sigma = simplexy(image_data, dpsf=dpsf, plim=plim,
                              dlim=dlim, saddle=saddle, maxper=maxper,
                              maxnpeaks=maxnpeaks, maxsize=maxsize,
                              halfbox=halfbox)

    print 'simplexy: shapes',x.shape, y.shape

    cx = pyfits.Column(name='X', format='E', array=x, unit='pix')
    cy = pyfits.Column(name='Y', format='E', array=y, unit='pix')
    cflux = pyfits.Column(name='FLUX', format='E', array=flux)

    tbhdu = pyfits.new_table([cx, cy, cflux])
    h = tbhdu.header
    h.add_comment('Parameters used in source extraction')
    h.update('dpsf',     dpsf, 'Gaussian psf width')
    h.update('plim',     plim, 'Significance to keep')
    h.update('dlim',     dlim, 'Closest two peaks can be')
    h.update('saddle',   saddle, 'Saddle in difference (in sig)')
    h.update('maxper',   maxper, 'Max num of peaks per object')
    h.update('maxpeaks', maxnpeaks, 'Max num of peaks total')
    h.update('maxsize',  maxsize, 'Max size of extended objects')
    h.update('halfbox',  halfbox, 'Half-size of sliding sky window')
    if srcext != None:
        h.update('srcext', i, 'Extension number in src image')
    h.update('estsigma', sigma, 'Estimated source image variance')
    h.add_comment('The X and Y points are specified assuming 1,1 is ')
    h.add_comment('the center of the leftmost bottom pixel of the ')
    h.add_comment('image in accordance with the FITS standard.')
    h.add_comment('Extracted by image2xy.py')
    h.add_comment('on %s %s' % (time.ctime(), time.tzname[0]))
    cards = tbhdu.header.ascardlist()
    cards['TTYPE1'].comment = 'X coordinate'
    cards['TTYPE2'].comment = 'Y coordinate'
    cards['TTYPE3'].comment = 'Flux of source'

    return tbhdu
Beispiel #5
0
Datei: test2.py Projekt: dfm/kpsf
assert 0

img = flux_images[-1000]
img[img == 0.0] = np.nan
frame = Frame(img)
frame.initialize()
print(frame.coords)

assert 0

obs = flux[-1000]
pixel_mask = np.isfinite(obs)
pixel_mask[pixel_mask] *= (obs[pixel_mask] > 0.0)
tmp = np.array(obs)
tmp[~pixel_mask] = np.median(obs[pixel_mask])
coords = simplexy(tmp)

mu = np.median(tmp)
sig = np.sqrt(np.median((tmp - mu)**2))

vmin, vmax = mu - sig, mu + 100 * sig

shape = obs.shape
x, y = np.meshgrid(range(shape[0]), range(shape[1]), indexing="ij")
x = np.array(x[pixel_mask], dtype=np.float64)
y = np.array(y[pixel_mask], dtype=np.float64)

psfpars = np.array([0.25, 0.25, 0.0] + [
    v for j in range(2)
    for v in [-2.0 - 100 * j, 0.0, 0.0, 2.0 + j, 2.0 + j, -0.5]
])
Beispiel #6
0
import numpy as np
import matplotlib.pyplot as pl
from simplexy import simplexy

cx, cy = 3.0, 3.0
x, y = np.meshgrid(range(50), range(10), indexing="ij")
r2 = (x - cx) ** 2 + (y - cy) ** 2
img = np.exp(-0.5 * r2)

pl.imshow(img, cmap="gray", interpolation="nearest")
pl.savefig("sup.png")

print(simplexy(img)["flux"])
Beispiel #7
0
Datei: test2.py Projekt: dfm/kpsf
img = flux_images[-1000]
img[img == 0.0] = np.nan
frame = Frame(img)
frame.initialize()
print(frame.coords)

assert 0



obs = flux[-1000]
pixel_mask = np.isfinite(obs)
pixel_mask[pixel_mask] *= (obs[pixel_mask] > 0.0)
tmp = np.array(obs)
tmp[~pixel_mask] = np.median(obs[pixel_mask])
coords = simplexy(tmp)

mu = np.median(tmp)
sig = np.sqrt(np.median((tmp - mu) ** 2))

vmin, vmax = mu - sig, mu + 100 * sig

shape = obs.shape
x, y = np.meshgrid(range(shape[0]), range(shape[1]), indexing="ij")
x = np.array(x[pixel_mask], dtype=np.float64)
y = np.array(y[pixel_mask], dtype=np.float64)

psfpars = np.array([0.25, 0.25, 0.0]
                   + [v for j in range(2)
                      for v in [-2.0 - 100 * j, 0.0, 0.0, 2.0+j, 2.0+j, -0.5]])
norm = compute_psf(psfpars, 0.0, 0.0)