Esempio n. 1
0
    def getBCFtable(self, sdss, vname):
        if vname == 'fwhmvk':
            vdata = np.loadtxt('data/r_vonK_Kolm.txt',
                               unpack='True')
            radius = vdata[0]
            vonK = vdata[1]
            vonK1arcsec = np.vstack((radius, vonK))

        a3d = np.zeros((sdss.nBand, sdss.nCamcol, self.nfields))
        for camcol in range(1, sdss.nCamcol + 1):
            print('running on camcol#%d' % camcol)
            datafile = self.fitsdir + \
                "photoField-%06d-%d.fits" % (self.runNo, camcol)

            hdulist = fits.open(datafile)
            hdu1 = hdulist[1].data
            for ifield in range(0, self.nfields):
                if ifield % 100 == 0:
                    print('field No. = %d/%d' % (ifield, self.nfields))
                for iBand in range(0, sdss.nBand):
                    if vname == 'fwhmvk':
                        psf = sdsspsf(hdu1, ifield, iBand, self.runNo, camcol)
                        psf.fit2vonK_curve_fit(vonK1arcsec)
                        if psf.scaleR < -1:
                            psf.fit2vonK_fmin(vonK1arcsec)
                        a3d[iBand, camcol - 1, ifield] = psf.scaleR
                    else:
                        # a3d[iBand, camcol - 1, ifield] =
                        # getattr(psf, args.vname)
                        a3d[iBand, camcol - 1,
                            ifield] = hdu1[ifield][vname][iBand]
        return a3d
Esempio n. 2
0
    def writeMasterTXT(self, sdss, filename):

        vdata = np.loadtxt('data/r_vonK_Kolm.txt',
                           unpack='True')
        radius = vdata[0]
        vonK = vdata[1]
        vonK1arcsec = np.vstack((radius, vonK))

        fid = open(filename, 'w')
        fid.write('#field \t camCol  filter FWHMvK ')
        otherParams = [['psf_width', '%5.3f'],
                       ['airmass', '%5.3f'],
                       ['mjd\t\t', '%12.6f'],
                       ['psf_nstar ', '%d'],
                       ['neff_psf\t', '%7.3f'],
                       ['sky_frames\t', '%5.3f']]
        for i in range(len(otherParams)):
            fid.write('%s ' % otherParams[i][0])
        fid.write('\n')

        for camcol in range(1, sdss.nCamcol + 1):
            print('running on camcol#%d' % camcol)
            datafile = self.fitsdir + \
                "photoField-%06d-%d.fits" % (self.runNo, camcol)

            hdulist = fits.open(datafile)
            hdu1 = hdulist[1].data
            for ifield in range(0, self.nfields):
                if ifield % 100 == 0:
                    print('field No. = %d/%d' % (ifield, self.nfields))
                for iBand in range(0, sdss.nBand):
                    psf = sdsspsf(hdu1, ifield, iBand, self.runNo, camcol)
                    psf.fit2vonK_curve_fit(vonK1arcsec)
                    if psf.scaleR < -1:
                        psf.fit2vonK_fmin(vonK1arcsec)

                    # fwhmeff of the vonK1arcsec = 1.222 arcsec
                    fid.write('%d \t %d \t %d \t %5.3f \t' % (
                        ifield, camcol, iBand, psf.scaleR * 1.222))
                    for i in range(len(otherParams)):
                        fid.write('%s \t' % otherParams[i][1] % (
                            hdu1[ifield][otherParams[i][0].strip()][iBand]))
                    fid.write('\n')
        fid.close()
Esempio n. 3
0
def main():
    parser = argparse.ArgumentParser(
        description='----- changing_shape.py ---------')
    parser.add_argument('yscale', choices=(
        'log', 'linear', 'logzoom'), help='yscale of the plots')
    parser.add_argument('-run', dest='irun', type=int, default=3388,
                        help='run number. default=3388, based on find_long_wild_runs.py')
    args = parser.parse_args()

    start = time.time()
    objlist = np.loadtxt('data/Stripe82RunList.dat')
    if args.irun not in objlist[:, 0]:
        print('run# %d is not in Stripe82RunList.dat\n' % args.irun)
        sys.exit()

    rootName = "SDSSdata"

    nBand = 5
    nCamcol = 6
    # show which band
    band = {}
    band[0] = "u"
    band[1] = "g"
    band[2] = "r"
    band[3] = "i"
    band[4] = "z"
    color = {}
    color[0] = "r"
    color[1] = "b"
    
    vdata = np.loadtxt('data/r_vonK_Kolm.txt',
                       unpack='True')
    radius = vdata[0]
    vonK = vdata[1]
    vonK1arcsec = np.vstack((radius, vonK))

    run = args.irun
    print('------ running on run# %d ---------' % run)
    f, ax1 = plt.subplots(nBand, nCamcol, sharex='col',
                          sharey='row', figsize=(12, 8))  # a plot is for a run

    datadir = "%s/%d/" % (rootName, run)
    fieldlist = np.zeros((nCamcol, 2))
    for camcol in range(1, nCamcol + 1):
        print('running on camcol#%d' % camcol)
        datafile = datadir + "photoField-%06d-%d.fits" % (run, camcol)

        hdulist = fits.open(datafile)
        nfields = hdulist[0].header['NFIELDS']
        hdu1 = hdulist[1].data

        fieldlist[camcol-1, 0]= np.where(np.max(hdu1[:]['psf_width'])==hdu1[:]['psf_width'])[0][0]
        fieldlist[camcol-1, 1]= np.where(np.min(hdu1[:]['psf_width'])==hdu1[:]['psf_width'])[0][0]
        print('field with max seeing: %d, min seeing: %d'%(fieldlist[camcol-1, 0], fieldlist[camcol-1, 1]))
        for i in range(2):            
            for iBand in range(0, nBand):
                psf = sdsspsf(hdu1, fieldlist[camcol-1, i], iBand, run, camcol)
                psf.fit2vonK_curve_fit(vonK1arcsec)
                if psf.scaleR < -1:
                    psf.fit2vonK_fmin(vonK1arcsec)

                if args.yscale == 'log' or args.yscale == 'logzoom':
                    ax1[iBand, camcol -
                        1].plot(radius * psf.scaleR, np.log10(vonK * psf.scaleV),
                                'b')
                    ax1[iBand, camcol - 1].errorbar(psf.OKprofRadii, psf.OKprofile,
                                                    psf.OKprofileErr, fmt='ok')
                    if args.yscale == 'log':
                        ax1[iBand, camcol - 1].set_xlim(0, 30.0)
                        ax1[iBand, camcol - 1].set_ylim(-6, 0.5)
                        if camcol == 1:
                            text = 'band: %s' % band[iBand]
                            ax1[iBand, camcol -
                                1].text(10, -2, text, fontsize=15, ha='left',
                                        va='center')
                    elif args.yscale == 'logzoom':
                        ax1[iBand, camcol - 1].set_xlim(0, 2)
                        ax1[iBand, camcol - 1].set_ylim(-1.5, 0.1)
                elif args.yscale == 'linear':
                    ax1[iBand, camcol -
                        1].plot(radius * psf.scaleR, vonK * psf.scaleV, color[i])
                    ax1[iBand, camcol - 1].errorbar(psf.OKprofRadii,
                                                    psf.OKprofileLinear,
                                                    psf.OKprofileErrLinear,
                                                    fmt='ok')
                    ax1[iBand, camcol - 1].set_xlim(0, 2.)
                    ax1[iBand, camcol - 1].grid()
                    if camcol == 1:
                        text = 'band: %s' % band[iBand]
                        ax1[iBand, camcol -
                            1].text(0.8, 0.8, text, fontsize=15, ha='left',
                                    va='center')

                if iBand == 0:
                    ax1[iBand, camcol - 1].set_title('camcol=%d' % camcol)
        if camcol ==1:
            titleStr = 'run %d, field %d/%d' % (run, fieldlist[camcol-1, 0], fieldlist[camcol-1, 1])
        else:
            titleStr = '%s, %d/%d' % (titleStr, fieldlist[camcol-1, 0], fieldlist[camcol-1, 1])

    plt.suptitle(titleStr)
    # plt.tight_layout()
    # plt.show()
    plt.savefig('output/run%d_changing_shape_%s.png' % (run, args.yscale))
    end = time.time()
    print('time = %8.2fs' % (end - start))
    sys.exit()
def main():
    parser = argparse.ArgumentParser(
        description='----- draw_1run_1field_vK_2G.py ---------')
    parser.add_argument('yscale', choices=(
        'log', 'linear', 'logzoom'), help='yscale of the plots')
    parser.add_argument('irun', type=int,
                        help='Run Number')
    parser.add_argument('ifield', type=int,
                        help='Field Number')
    args = parser.parse_args()

    start = time.time()
    objlist = np.loadtxt('data/Stripe82RunList.dat')
    if args.irun not in objlist[:, 0]:
        print('run# %d is not in Stripe82RunList.dat\n' % args.irun)
        sys.exit()

    rootName = "SDSSdata"

    nBand = 5
    nCamcol = 6
    # show which band
    band = {}
    band[0] = "u"
    band[1] = "g"
    band[2] = "r"
    band[3] = "i"
    band[4] = "z"

    vdata = np.loadtxt('data/r_vonK_Kolm.txt',
                       unpack='True')
    radius = vdata[0]
    vonK = vdata[1]
    vonK1arcsec = np.vstack((radius, vonK))

    run = args.irun
    print('------ running on run# %d ---------' % run)
    f, ax1 = plt.subplots(nBand, nCamcol, sharex='col',
                          sharey='row', figsize=(12, 8))  # a plot is for a run

    outdir = "%s/%d/" % (rootName, run)
    for camcol in range(1, nCamcol + 1):
        print('running on camcol#%d' % camcol)
        datafile = outdir + "photoField-%06d-%d.fits" % (run, camcol)

        hdulist = fits.open(datafile)
        nfields = hdulist[0].header['NFIELDS']
        if args.ifield > nfields:
            print('given field# = %d is too big\n' % args.ifield)
            print('run# %d has %d fields in total\n' % args.irun)
            sys.exit()
        hdu1 = hdulist[1].data

        for iBand in range(0, nBand):

            psf = sdsspsf(hdu1, args.ifield, iBand, run, camcol)
            psf.fit2vonK_curve_fit(vonK1arcsec)
            if psf.scaleR < -1:
                psf.fit2vonK_fmin(vonK1arcsec)
            print('chi2=%4.1f/%4.1f, chi2lr = %4.1f/%4.1f, chi2hr=%4.1e/%4.1e' %(
                psf.chi2, psf.G2chi2, psf.chi2lr, psf.G2chi2lr, psf.chi2hr, psf.G2chi2hr))

            if args.yscale == 'log' or args.yscale == 'logzoom':
                ax1[iBand, camcol -
                    1].plot(radius * psf.scaleR, np.log10(vonK * psf.scaleV),
                            'b')
                ax1[iBand, camcol -
                    1].plot(psf.r, psf.LpsfModel + np.log10(psf.scaleV), 'r')
                ax1[iBand, camcol - 1].errorbar(psf.OKprofRadii, psf.OKprofile,
                                                psf.OKprofileErr, fmt='ok')
                if args.yscale == 'log':
                    ax1[iBand, camcol - 1].set_xlim(0, 30.0)
                    ax1[iBand, camcol - 1].set_ylim(-6, 0.5)
                    if camcol == 1:
                        text = 'band: %s' % band[iBand]
                        ax1[iBand, camcol -
                            1].text(10, -2, text, fontsize=15, ha='left',
                                    va='center')
                elif args.yscale == 'logzoom':
                    ax1[iBand, camcol - 1].set_xlim(0, 2)
                    ax1[iBand, camcol - 1].set_ylim(-1.5, 0.1)
            elif args.yscale == 'linear':
                ax1[iBand, camcol -
                    1].plot(radius * psf.scaleR, vonK * psf.scaleV, 'b')
                ax1[iBand, camcol - 1].plot(psf.r,
                                            psf.psfModel * psf.scaleV, 'r')
                ax1[iBand, camcol - 1].errorbar(psf.OKprofRadii,
                                                psf.OKprofileLinear,
                                                psf.OKprofileErrLinear,
                                                fmt='ok')
                ax1[iBand, camcol - 1].set_xlim(0, 2.)
                ax1[iBand, camcol - 1].grid()
                if camcol == 1:
                    text = 'band: %s' % band[iBand]
                    ax1[iBand, camcol -
                        1].text(0.8, 0.8, text, fontsize=15, ha='left',
                                va='center')

            if iBand == 0:
                ax1[iBand, camcol - 1].set_title('camcol=%d' % camcol)

    plt.suptitle('run %d, field %d, blue: vK, Red: 2G ' % (run, args.ifield))
    # plt.tight_layout()
    # plt.show()
    plt.savefig('output/run%d_fld%d_psf_vK_2G_%s.png' %
                (run, args.ifield, args.yscale))
    end = time.time()
    print('time = %8.2fs' % (end - start))
    sys.exit()
Esempio n. 5
0
for line in objlist:
    run = int(line[0])
    plt.suptitle('run %d' % run)
    print('------ running on run# %d ---------' % run)
    outdir = "%s/%d/" % (rootName, run)
    for camcol in range(1, nCamcol + 1):
        print('running on camcol#%d' % camcol)
        datafile = outdir + "photoField-%06d-%d.fits" % (run, camcol)

        hdulist = fits.open(datafile)
        hdu1 = hdulist[1].data

        for iBand in range(0, nBand):
            kk = iBand * nCamcol + camcol

            psf = sdsspsf(hdu1, 0, iBand, run, camcol)
            ax1[iBand, camcol - 1].plot(psf.r, psf.LpsfG, 'b')
            ax1[iBand, camcol - 1].plot(psf.r, psf.LpsfW, 'g')
            ax1[iBand, camcol - 1].plot(psf.r, psf.LpsfModel, 'r')
            ax1[iBand, camcol - 1].errorbar(psf.OKprofRadii, psf.OKprofile,
                                            psf.OKprofileErr, fmt='ok')

            ax1[iBand, camcol - 1].set_xlim(0, 30.0)
            ax1[iBand, camcol - 1].set_ylim(-6, 0.5)
            if iBand == 0:
                ax1[iBand, camcol - 1].set_title('camcol=%d' % camcol)
            if camcol == 1:
                text = 'band: %s' % band[iBand]
                ax1[iBand, camcol -
                    1].text(10, -2, text, fontsize=15, ha='left', va='center')