Exemple #1
0
def plant(image,psf,outfile,list,dtime):
    import pyfits,os 
    import numarray as N
    psf_f=pyfits.open(psf)
    psf_flux=psf_f[0].data.sum()
    psf_x_size=psf_f[0].header.get('NAXIS1',0)
    psf_y_size=psf_f[0].header.get('NAXIS2',0)
    psf_x=psf_f[0].header.get('PSF_X',0)
    psf_y=psf_f[0].header.get('PSF_Y',0)
    psf_mag=psf_f[0].header.get('PSFMAG',26.0)
    image_f=pyfits.open(image)
    xmax=image_f[0].header.get('NAXIS1',0)
    ymax=image_f[0].header.get('NAXIS2',0)
    exptime=image_f[0].header.get('EXPTIME',1)
    zeropoint=image_f[0].header.get('PHOT_C',26.5)

    import mop_files
    ahdu=mop_files.read(list)
    import string,math,re
    from numarray.nd_image.interpolation import shift as shift

    from string import atof
    for i in range(len(ahdu['data']['x'])):
        x=float(ahdu['data']['x'][i])
        y=float(ahdu['data']['y'][i])
        mag=float(ahdu['data']['mag'][i])
        rate=float(ahdu['data']['pix_rate'][i])/3600.0
        angle=float(ahdu['data']['angle'][i])
        x_shift_rate=rate*math.cos(angle/57.3)
        y_shift_rate=rate*math.sin(angle/57.3)
        #flux=exptime*10**((zeropoint-mag)/2.5)
        #scale=flux/psf_flux
        scale=10**((psf_mag-mag)/2.5)*exptime
        #print scale
        niter=int(rate*exptime)+1
        scale=scale/niter
        dt = exptime/niter
        #print x,y,mag,niter
        for i in range(niter):
            curtime = dtime+dt*i
            x=x+x_shift_rate*curtime
            y=y+y_shift_rate*curtime
            x1=int(max(0,x-psf_x))
            x2=int(min(xmax,x+psf_x_size-psf_x))
            y1=int(max(0,y-psf_y))
            y2=int(min(ymax,y+psf_y_size-psf_y))
            #print x2,x1,y2,y1
            px1=int((psf_x-(x-x1)))
            px2=int(px1+(x2-x1))
            py1=int(psf_y-(y-y1))
            py2=int(py1+(y2-y1))
            sec = psf_f[0].data[py1:py2,px1:px2].copy()
            sec = shift(sec,(y-int(y),x-int(x)),order=3)
            #print sec.shape,y2-y1,x2-x1
            #print "Adding @ ",x,y,mag,scale," data=> ",y1,y2,x1,x2," PSF=> ",py1,py2,px1,px2
            
            image_f[0].data[y1:y2,x1:x2]+=scale*sec

    image_f.writeto(outfile)
    image_f.close()
Exemple #2
0
def plant(image, psf, outfile, list, dtime):
    import pyfits, os
    import numarray as N
    psf_f = pyfits.open(psf)
    psf_flux = psf_f[0].data.sum()
    psf_x_size = psf_f[0].header.get('NAXIS1', 0)
    psf_y_size = psf_f[0].header.get('NAXIS2', 0)
    psf_x = psf_f[0].header.get('PSF_X', 0)
    psf_y = psf_f[0].header.get('PSF_Y', 0)
    psf_mag = psf_f[0].header.get('PSFMAG', 26.0)
    image_f = pyfits.open(image)
    xmax = image_f[0].header.get('NAXIS1', 0)
    ymax = image_f[0].header.get('NAXIS2', 0)
    exptime = image_f[0].header.get('EXPTIME', 1)
    zeropoint = image_f[0].header.get('PHOT_C', 26.5)

    import mop_files
    ahdu = mop_files.read(list)
    import string, math, re
    from numarray.nd_image.interpolation import shift as shift

    from string import atof
    for i in range(len(ahdu['data']['x'])):
        x = float(ahdu['data']['x'][i])
        y = float(ahdu['data']['y'][i])
        mag = float(ahdu['data']['mag'][i])
        rate = float(ahdu['data']['pix_rate'][i]) / 3600.0
        angle = float(ahdu['data']['angle'][i])
        x_shift_rate = rate * math.cos(angle / 57.3)
        y_shift_rate = rate * math.sin(angle / 57.3)
        #flux=exptime*10**((zeropoint-mag)/2.5)
        #scale=flux/psf_flux
        scale = 10**((psf_mag - mag) / 2.5) * exptime
        #print scale
        niter = int(rate * exptime) + 1
        scale = scale / niter
        dt = exptime / niter
        #print x,y,mag,niter
        for i in range(niter):
            curtime = dtime + dt * i
            x = x + x_shift_rate * curtime
            y = y + y_shift_rate * curtime
            x1 = int(max(0, x - psf_x))
            x2 = int(min(xmax, x + psf_x_size - psf_x))
            y1 = int(max(0, y - psf_y))
            y2 = int(min(ymax, y + psf_y_size - psf_y))
            #print x2,x1,y2,y1
            px1 = int((psf_x - (x - x1)))
            px2 = int(px1 + (x2 - x1))
            py1 = int(psf_y - (y - y1))
            py2 = int(py1 + (y2 - y1))
            sec = psf_f[0].data[py1:py2, px1:px2].copy()
            sec = shift(sec, (y - int(y), x - int(x)), order=3)
            #print sec.shape,y2-y1,x2-x1
            #print "Adding @ ",x,y,mag,scale," data=> ",y1,y2,x1,x2," PSF=> ",py1,py2,px1,px2

            image_f[0].data[y1:y2, x1:x2] += scale * sec

    image_f.writeto(outfile)
    image_f.close()
Exemple #3
0
    ### import import import
    import os,re, string
    import numarray as N
    from numarray.ma  import *
    import numarray.image.combine as nic
    from string import lstrip
    from numarray.nd_image.interpolation import shift as shift
    from numarray.nd_image import label
    from math import floor

    ### get the list of psf stars.
    ### expected to be step0jmp bright.psf format.
    if not os.access(opt.stars,os.R_OK):
        sys.exit("failed trying to open input star list: "+opt.stars)
    import mop_files
    psf_stars=mop_files.read(opt.stars)



    ### open the output psf file... must not exist at start
    outfile=opt.outfile
    if os.access(outfile,os.W_OK):
        sys.exit("Output file "+outfile+" already exists")

    if opt.verbose:
        print "Creating output image "+outfile

    ## fitsobj is a list of fits HDUs.
    fitsobj = pyfits.HDUList()

    ### s is the 'structure' what we call linked objects.