Ejemplo n.º 1
0
def extract_standard(name, filter):
    images = glob.glob(dataDir + name + '_' + filter + '/c????.fits')
    imageRoots = [ii.replace('.fits', '') for ii in images]

    if filter == 'h':
        aperture = 160
        skyannul = 200
        skywidth = 50

    if filter == 'kp':
        aperture = 130
        skyannul = 170
        skywidth = 50

    if filter == 'lp2':
        aperture = 20
        skyannul = 100
        skywidth = 200

    for image in imageRoots:
        (r, f, m, me) = run_phot(image,
                                 silent=True,
                                 apertures=[aperture],
                                 sky_annulus=skyannul,
                                 sky_dannulus=skywidth)
Ejemplo n.º 2
0
def extract_standard(name, filter):
    images = glob.glob(dataDir + name + '_' + filter + '/c????.fits')
    imageRoots = [ii.replace('.fits', '') for ii in images]

    aperture = findap.standard_aperture[filter]
    skyannul = findap.sky_annulus_start[filter]
    skywidth = findap.sky_annulus_width[filter]

    for image in imageRoots:
        (r, f, m, me) = run_phot(image, silent=False,
                                 apertures=[aperture],
                                 sky_annulus=skyannul,
                                 sky_dannulus=skywidth)
Ejemplo n.º 3
0
def extract_standard(name, filter):
    images = glob.glob(dataDir + name + '_' + filter + '/c????.fits')
    imageRoots = [ii.replace('.fits', '') for ii in images]

    aperture = findap.standard_aperture[filter]
    skyannul = findap.sky_annulus_start[filter]
    skywidth = findap.sky_annulus_width[filter]

    for image in imageRoots:
        (r, f, m, me) = run_phot(image,
                                 silent=False,
                                 apertures=[aperture],
                                 sky_annulus=skyannul,
                                 sky_dannulus=skywidth)
Ejemplo n.º 4
0
def extract_standard(name, filter):
    images = glob.glob(dataDir + name + '_' + filter + '/c????.fits')
    imageRoots = [ii.replace('.fits', '') for ii in images]

    if filter == 'h':
        aperture = 160
        skyannul = 200
        skywidth = 50
        
    if filter == 'kp':
        aperture = 130
        skyannul = 170
        skywidth = 50

    if filter == 'lp2':
        aperture = 20
        skyannul = 100
        skywidth = 200

    for image in imageRoots:
        (r, f, m, me) = run_phot(image, silent=True,
                                 apertures=[aperture],
                                 sky_annulus=skyannul,
                                 sky_dannulus=skywidth)
Ejemplo n.º 5
0
def test_sky(suffix):
    dataDir = '/u/jlu/data/w51/10aug14/clean/' + suffix + '/'

    images = glob.glob(dataDir + 'c????.fits')
    imageRoots = [ii.replace('.fits', '') for ii in images]

    # Use a fixed aperture and vary the sky annuli
    aperture = range(10, 201, 5)
    sky_a = range(150, 251, 20)
    sky_da = range(25, 101, 25)

    mag = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)
    merr1 = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)
    merr2 = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)
    flux = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)
    ferr = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)

    aper = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=int)
    skya = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=int)
    skyda = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=int)

    imcnt = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=int)

    for sa in range(len(sky_a)):
        for sd in range(len(sky_da)):
            print 'Sky Annulus = %d + %d' % (sky_a[sa], sky_da[sd])

            iflux = np.zeros((len(imageRoots), len(aperture)), dtype=float)
            imag = np.zeros((len(imageRoots), len(aperture)), dtype=float)
            imerr = np.zeros((len(imageRoots), len(aperture)), dtype=float)

            # Loop through all the images and get the mean magnitude
            # and the standard deviation of the magnitude.
            for ii in range(len(imageRoots)):
                (r, f, m, me) = run_phot(imageRoots[ii],
                                         silent=True,
                                         apertures=aperture,
                                         sky_annulus=sky_a[sa],
                                         sky_dannulus=sky_da[sd])
                iflux[ii] = f
                imag[ii] = m
                imerr[ii] = me

            for aa in range(len(aperture)):
                idx = np.where(iflux[:, aa] != 0)[0]

                flux[aa, sa, sd] = iflux[idx, aa].mean()
                ferr[aa, sa, sd] = iflux[idx, aa].std()
                mag[aa, sa, sd] = imag[idx, aa].mean()
                merr1[aa, sa, sd] = imerr[idx, aa].mean()
                merr2[aa, sa,
                      sd] = 1.0857 * ferr[aa, sa, sd] / flux[aa, sa, sd]

                aper[aa, sa, sd] = aperture[aa]
                skya[aa, sa, sd] = sky_a[sa]
                skyda[aa, sa, sd] = sky_da[sd]

                imcnt[aa, sa, sd] = len(imageRoots)

    pfile = open('test_sky_' + suffix + '.dat', 'w')
    pickle.dump(flux, pfile)
    pickle.dump(ferr, pfile)
    pickle.dump(mag, pfile)
    pickle.dump(merr1, pfile)
    pickle.dump(merr2, pfile)
    pickle.dump(aper, pfile)
    pickle.dump(skya, pfile)
    pickle.dump(skyda, pfile)
    pickle.dump(imcnt, pfile)
Ejemplo n.º 6
0
def curve_of_growth(star, filter):
    """
    Make a plot of the radius of growth for each of the stars.
    Plot all the associated images for that star on top of each other.
    """
    dataDir = '/u/jlu/data/w51/10aug14/clean/'
    dir = star + '_' + filter

    images = glob.glob(dataDir + dir + '/c????.fits')
    imageRoots = [ii.replace('.fits', '') for ii in images]

    aperture = range(6, 201, 2)

    sky_a = sky_annulus_start[filter]
    sky_da = sky_annulus_width[filter]

    mag = np.zeros((len(aperture), len(imageRoots)), dtype=float)
    merr = np.zeros((len(aperture), len(imageRoots)), dtype=float)
    diff = np.zeros((len(aperture), len(imageRoots)), dtype=float)

    for ii in range(len(imageRoots)):
        (r, f, m, me) = run_phot(imageRoots[ii],
                                 silent=True,
                                 apertures=aperture,
                                 sky_annulus=sky_a,
                                 sky_dannulus=sky_da)

        mag[:, ii] = m
        merr[:, ii] = me
        diff[1:, ii] = mag[1:, ii] - mag[:-1, ii]

    # Clean up arrays
    idx = np.where(mag == 0)
    mag[idx] = np.nan
    merr[idx] = np.nan
    diff[idx] = np.nan

    py.figure(2, figsize=(6, 8))
    py.clf()
    py.subplots_adjust(left=0.15, bottom=0.08, top=0.95, right=0.95)

    py.subplot(2, 1, 1)
    for ii in range(len(imageRoots)):
        py.plot(aperture, mag[:, ii], '--')
    py.plot(aperture, mag.mean(axis=1), 'k-', linewidth=2)
    py.xlabel('Aperture (pix)')
    py.ylabel('Magnitude')
    py.title('Star = %s, Filter = %s, Sky = %d + %d pix' %
             (star, filter, sky_a, sky_da))
    py.xlim(aperture[0], aperture[-1])

    py.subplot(2, 1, 2)
    for ii in range(len(imageRoots)):
        py.plot(aperture[1:], diff[1:, ii], '--')
    py.plot(aperture[1:], diff[1:, :].mean(axis=1), 'k-', linewidth=2)
    lims = py.axis()
    py.plot([lims[0], lims[1]], [0, 0], 'b-')
    py.xlabel('Aperture (pix)')
    py.ylabel('Delta-Magnitude')
    py.xlim(aperture[0], aperture[-1])
    py.ylim(-0.1, 0.05)

    py.savefig('curve_of_growth_' + star + '_' + filter + '.png')
Ejemplo n.º 7
0
def calc_aperture_corrections():
    """
    Calculate aperture correction curves from all the standard
    stars. Store the curves (mean + errors) so that they can be 
    read in later for getting the specific aperture correction for
    a given inner and outer aperture.
    """
    stars = ['fs140', 'fs147', 'fs148']
    filters = ['h', 'kp', 'lp2']
    sky_ann = sky_annulus_start
    sky_da = sky_annulus_width
    big_ap = standard_aperture

    # Calculate Curve of Growth for each filter
    for filter in filters:
        skya = sky_ann[filter]
        skyda = sky_da[filter]
        #outer = big_ap[filter]
        outer = sky_ann[filter]

        aperture = range(5, outer)
        growthCurves = []

        # Loop through all the stars and gather up the growth-curves
        for star in stars:
            dataDir = '/u/jlu/data/w51/10aug14/clean/'
            dir = star + '_' + filter

            images = glob.glob(dataDir + dir + '/c????.fits')
            imageRoots = [ii.replace('.fits', '') for ii in images]

            apCnt = len(aperture)
            imCnt = len(imageRoots)

            mag = np.zeros((apCnt, imCnt), dtype=float)
            merr = np.zeros((apCnt, imCnt), dtype=float)
            diff = np.zeros((apCnt, imCnt), dtype=float)

            for ii in range(len(imageRoots)):
                # run_phot can only handle 100 apertures at a time
                for aa in range(int(math.ceil(apCnt / 100.))):
                    apStart = aa * 100
                    apStop = (aa + 1) * 100

                    if (apStop > apCnt):
                        apStop = apCnt

                    (r, f, m,
                     me) = run_phot(imageRoots[ii],
                                    silent=True,
                                    apertures=aperture[apStart:apStop],
                                    sky_annulus=skya,
                                    sky_dannulus=skyda)
                    mag[apStart:apStop, ii] = m
                    merr[apStart:apStop, ii] = me

                diff[1:, ii] = mag[1:, ii] - mag[:-1, ii]

                # Cut it out if it is really really discrepant.
                # In our case, discrepant means a delta-mag in the first
                # differenced bin of < -0.3
                if (diff[:, ii].min() < -0.25):
                    continue

                # Clean up arrays
                idx = np.where(m == 0)
                mag[idx, ii] = np.nan
                merr[idx, ii] = np.nan
                diff[idx, ii] = np.nan

                growthCurves.append(diff[:, ii])

        ####################
        # All the growth curves for this filter (combine the stars)
        ####################
        growthCurves = np.array(growthCurves)
        aperture = np.array(aperture)

        py.clf()
        for ii in range(len(growthCurves)):
            py.plot(aperture[1:], growthCurves[ii, 1:], '--')
        py.plot(aperture[1:],
                growthCurves[:, 1:].mean(axis=0),
                'k-',
                linewidth=2)
        lims = py.axis()
        py.plot([lims[0], lims[1]], [0, 0], 'b-')
        py.xlabel('Aperture (pix)')
        py.ylabel('Delta-Magnitude')
        py.xlim(aperture[0], aperture[-1])
        py.ylim(-0.25, 0.01)
        py.savefig('curve_of_growth_' + filter + '.png')

        ##########
        # Save off to a file for later retrieval
        ##########
        pfile = open('curve_of_growth_' + filter + '.dat', 'w')
        pickle.dump(aperture, pfile)
        pickle.dump(growthCurves, pfile)
        pfile.close()
Ejemplo n.º 8
0
def test_sky(suffix):
    dataDir = '/u/jlu/data/w51/10aug14/clean/' + suffix + '/'

    images = glob.glob(dataDir + 'c????.fits')
    imageRoots = [ii.replace('.fits', '') for ii in images]

    # Use a fixed aperture and vary the sky annuli
    aperture = range(10, 201, 5)
    sky_a = range(150, 251, 20)
    sky_da = range(25, 101, 25)

    mag = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)
    merr1 = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)
    merr2 = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)
    flux = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)
    ferr = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=float)

    aper = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=int)
    skya = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=int)
    skyda = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=int)

    imcnt = np.zeros((len(aperture), len(sky_a), len(sky_da)), dtype=int)

    for sa in range(len(sky_a)):
        for sd in range(len(sky_da)):
            print 'Sky Annulus = %d + %d' % (sky_a[sa], sky_da[sd])

            iflux = np.zeros((len(imageRoots), len(aperture)), dtype=float)
            imag = np.zeros((len(imageRoots), len(aperture)), dtype=float)
            imerr = np.zeros((len(imageRoots), len(aperture)), dtype=float)
            
            # Loop through all the images and get the mean magnitude
            # and the standard deviation of the magnitude.
            for ii in range(len(imageRoots)):
                (r, f, m, me) = run_phot(imageRoots[ii], silent=True,
                                         apertures=aperture,
                                         sky_annulus=sky_a[sa], 
                                         sky_dannulus=sky_da[sd])
                iflux[ii] = f
                imag[ii] = m
                imerr[ii] = me

            for aa in range(len(aperture)):
                idx = np.where(iflux[:,aa] != 0)[0]

                flux[aa, sa, sd] = iflux[idx,aa].mean()
                ferr[aa, sa, sd] = iflux[idx,aa].std()
                mag[aa, sa, sd] = imag[idx,aa].mean()
                merr1[aa, sa, sd] = imerr[idx,aa].mean()
                merr2[aa, sa, sd] = 1.0857 * ferr[aa,sa,sd] / flux[aa,sa,sd]

                aper[aa, sa, sd] = aperture[aa]
                skya[aa, sa, sd] = sky_a[sa]
                skyda[aa, sa, sd] = sky_da[sd]

                imcnt[aa, sa, sd] = len(imageRoots)

                
    pfile = open('test_sky_' + suffix + '.dat', 'w')
    pickle.dump(flux, pfile)
    pickle.dump(ferr, pfile)
    pickle.dump(mag, pfile)
    pickle.dump(merr1, pfile)
    pickle.dump(merr2, pfile)
    pickle.dump(aper, pfile)
    pickle.dump(skya, pfile)
    pickle.dump(skyda, pfile)
    pickle.dump(imcnt, pfile)
Ejemplo n.º 9
0
def curve_of_growth(star, filter):
    """
    Make a plot of the radius of growth for each of the stars.
    Plot all the associated images for that star on top of each other.
    """
    dataDir = '/u/jlu/data/w51/10aug14/clean/'
    dir = star + '_' + filter

    images = glob.glob(dataDir + dir + '/c????.fits')
    imageRoots = [ii.replace('.fits', '') for ii in images]

    aperture = range(6, 201, 2)

    sky_a = sky_annulus_start[filter]
    sky_da = sky_annulus_width[filter]

    mag = np.zeros((len(aperture), len(imageRoots)), dtype=float)
    merr = np.zeros((len(aperture), len(imageRoots)), dtype=float)
    diff = np.zeros((len(aperture), len(imageRoots)), dtype=float)

    for ii in range(len(imageRoots)):
        (r, f, m, me) = run_phot(imageRoots[ii], silent=True,
                                 apertures=aperture,
                                 sky_annulus=sky_a, sky_dannulus=sky_da)

        mag[:,ii] = m
        merr[:,ii] = me
        diff[1:,ii] = mag[1:,ii] - mag[:-1,ii]

    # Clean up arrays
    idx = np.where(mag == 0)
    mag[idx] = np.nan
    merr[idx] = np.nan
    diff[idx] = np.nan
        
    py.figure(2, figsize=(6,8))
    py.clf()
    py.subplots_adjust(left=0.15, bottom=0.08, top=0.95, right=0.95)

    py.subplot(2, 1, 1)
    for ii in range(len(imageRoots)):
        py.plot(aperture, mag[:,ii], '--')
    py.plot(aperture, mag.mean(axis=1), 'k-', linewidth=2)
    py.xlabel('Aperture (pix)')
    py.ylabel('Magnitude')
    py.title('Star = %s, Filter = %s, Sky = %d + %d pix' % 
             (star, filter, sky_a, sky_da))
    py.xlim(aperture[0], aperture[-1])

    py.subplot(2, 1, 2)
    for ii in range(len(imageRoots)):
        py.plot(aperture[1:], diff[1:,ii], '--')
    py.plot(aperture[1:], diff[1:,:].mean(axis=1), 'k-', linewidth=2)
    lims = py.axis()
    py.plot([lims[0], lims[1]], [0, 0], 'b-')
    py.xlabel('Aperture (pix)')
    py.ylabel('Delta-Magnitude')
    py.xlim(aperture[0], aperture[-1])
    py.ylim(-0.1, 0.05)

    py.savefig('curve_of_growth_' + star + '_' + filter + '.png')
Ejemplo n.º 10
0
def calc_aperture_corrections():
    """
    Calculate aperture correction curves from all the standard
    stars. Store the curves (mean + errors) so that they can be 
    read in later for getting the specific aperture correction for
    a given inner and outer aperture.
    """
    stars = ['fs140', 'fs147', 'fs148']
    filters = ['h', 'kp', 'lp2']
    sky_ann = sky_annulus_start
    sky_da = sky_annulus_width
    big_ap = standard_aperture

    # Calculate Curve of Growth for each filter
    for filter in filters:
        skya = sky_ann[filter]
        skyda = sky_da[filter]
        #outer = big_ap[filter]
        outer = sky_ann[filter]

        aperture = range(5, outer)
        growthCurves = []

        # Loop through all the stars and gather up the growth-curves
        for star in stars:
            dataDir = '/u/jlu/data/w51/10aug14/clean/'
            dir = star + '_' + filter

            images = glob.glob(dataDir + dir + '/c????.fits')
            imageRoots = [ii.replace('.fits', '') for ii in images]

            apCnt = len(aperture)
            imCnt = len(imageRoots)

            mag = np.zeros((apCnt, imCnt), dtype=float)
            merr = np.zeros((apCnt, imCnt), dtype=float)
            diff = np.zeros((apCnt, imCnt), dtype=float)

            for ii in range(len(imageRoots)):
                # run_phot can only handle 100 apertures at a time
                for aa in range(int(math.ceil(apCnt / 100.))):
                    apStart = aa*100
                    apStop = (aa+1)*100

                    if (apStop > apCnt):
                        apStop = apCnt

                    (r, f, m, me) = run_phot(imageRoots[ii], silent=True,
                                             apertures=aperture[apStart:apStop],
                                             sky_annulus=skya, 
                                             sky_dannulus=skyda)
                    mag[apStart:apStop,ii] = m
                    merr[apStart:apStop,ii] = me
                    
                diff[1:,ii] = mag[1:,ii] - mag[:-1,ii]


                # Cut it out if it is really really discrepant.
                # In our case, discrepant means a delta-mag in the first
                # differenced bin of < -0.3
                if (diff[:,ii].min() < -0.25):
                    continue
                
                # Clean up arrays
                idx = np.where(m == 0)
                mag[idx,ii] = np.nan
                merr[idx,ii] = np.nan
                diff[idx,ii] = np.nan

                growthCurves.append(diff[:,ii])
            
        ####################
        # All the growth curves for this filter (combine the stars)
        ####################
        growthCurves = np.array(growthCurves)
        aperture = np.array(aperture)

        py.clf()
        for ii in range(len(growthCurves)):
            py.plot(aperture[1:], growthCurves[ii,1:] , '--')
        py.plot(aperture[1:], growthCurves[:,1:].mean(axis=0), 'k-', 
                linewidth=2)
        lims = py.axis()
        py.plot([lims[0], lims[1]], [0, 0], 'b-')
        py.xlabel('Aperture (pix)')
        py.ylabel('Delta-Magnitude')
        py.xlim(aperture[0], aperture[-1])
        py.ylim(-0.25, 0.01)
        py.savefig('curve_of_growth_' + filter + '.png')
        
        ##########
        # Save off to a file for later retrieval
        ##########
        pfile = open('curve_of_growth_' + filter + '.dat', 'w')
        pickle.dump(aperture, pfile)
        pickle.dump(growthCurves, pfile)
        pfile.close()