def main():
    parser = argparse.ArgumentParser(
        description='----- find_stretch_all_runs.py ---------')
    parser.add_argument('vname', help='variable we want to look at, e.g. psf_sigma1,\
psf_sigma2, airmass, neff_psf, psf_nstar, psf_width')
    parser.add_argument('-pvfrac', type=float, default=0.1,
                        help='tolerance on peak-to-peak variation, \
default=0.1')
    parser.add_argument('-rmsfrac', type=float, default=0.05,
                        help='tolerance on RMS of the stretch, default=0.05')
    parser.add_argument('-fitsoff', help='w/o reading in data from fits files',
                        action='store_true')
    parser.add_argument('-tableoff', help='w/o creating the stretchTable',
                        action='store_true')
    args = parser.parse_args()

    start1 = time.time()

    objlist = np.loadtxt('data/Stripe82RunList.dat')

    sdss = sdssinst()

    outTable = 'output/stretchTable.txt'

    if (not args.tableoff):
        if os.path.isfile(outTable):
            os.remove(outTable)
        fz = open(outTable, 'ab')

        runcount = 0
        for line in objlist:

            start = time.time()
            run = int(line[0])
            runcount += 1
            print('-- running on run# %d (seq.# %d)---------' % (
                run, runcount))

            myRun = sdssrun(run)
            a3dfile = 'output/temp/run%d_%s.txt' % (myRun.runNo, args.vname)
            if (not args.fitsoff):
                a3d = myRun.getBCFtable(sdss, args.vname)
                myTools.savetxt3d(a3dfile, a3d)
            else:
                a3d = np.loadtxt(a3dfile)
                a3d = a3d.reshape(sdss.nBand, sdss.nCamcol, -1)
            stretchTable = myRun.findStretch(
                sdss, a3d, args.pvfrac, args.rmsfrac)
            np.savetxt(fz, stretchTable, fmt='%d')

            end = time.time()
            print('--- done with run# %d, time elapsed: %8.2fs---' % (
                run, (end - start)))
        fz.close()

    nrun = len(objlist)
    tableData = np.loadtxt(outTable)
    maxbyrun = np.zeros(nrun)
    runNo = objlist[:, 0].astype(int)
    for i in np.arange(nrun):
        # last column in tableTable is the length of the stretch
        maxbyrun[i] = np.max(tableData[tableData[:, 0] == runNo[i], -1])
    plt.plot(runNo, maxbyrun,  # label='',
             marker='o', color='r', markersize=10)
    plt.xlabel('Run No.')
    plt.ylabel('Longest Stretch')

    plt.savefig('output/maxStretch_%s.png' % (args.vname))
    for iRecord in range(0,2): #number of records to print out
        maxRow = np.where(tableData[:, -1] == np.max(tableData[:, -1]))
        runSeq = np.arange(1, nrun + 1)
        for irow in maxRow[0]:
            irun = tableData[irow, 0]
            print('longest stretch found in run %d (seq# %d), \
    field range = (%d, %d), %d runs' % (
                irun,
                runSeq[irun == runNo],
                tableData[irow, 1], tableData[irow, 2], tableData[irow, 3]))
        rmRow = np.where(tableData[:, 0] == irun)
        tableData[rmRow[0], -1] = 0
    # sys.exit()
    end1 = time.time()
    print('--- Total time elapsed: %8.2fs---' % ((end1 - start1)))
E.g. for some run
#  field  camCol  filter   FWHMvK    (other SDSS params)

"""
parser = argparse.ArgumentParser(
    description='-----makeMasterTXT_pool.py------')
parser.add_argument('-p', dest='numproc', default=1, type=int,
                    help='Number of Processors to use')
parser.add_argument('-run', dest='run', type=int, default=-1,
                    help='run number. use -1 to run over all runs. default=-1')
args = parser.parse_args()

objlist = np.loadtxt('data/Stripe82RunList.dat')
# objlist = objlist[0:3,:] #for test

sdss = sdssinst()

start = time.time()


def write1run(argList):

    sdss = argList[0]
    run = argList[1]
    runcount = argList[2]
    print('-- running on run# %d (seq.# %d)---------' % (run, runcount))
    myRun = sdssrun(run)
    txtfile = 'SDSSdata/masterTXT/run%d.txt' % (myRun.runNo)
    myRun.writeMasterTXT(sdss, txtfile)

Example #3
0
def main():

    parser = argparse.ArgumentParser(
        description='----- fwhm_check_eff.py ---------')
    parser.add_argument('vname', choices=('fwhmeff', 'neff'),
                        help='variable we want to look at')
    parser.add_argument('irun', type=int,
                        help='Run Number')
    args = parser.parse_args()

    objlist = np.loadtxt('data/Stripe82RunList.dat')

    sdss = sdssinst()

    runcount = 0

    f, ax1 = plt.subplots(sdss.nBand, sdss.nCamcol, sharex='col',
                          sharey='row', figsize=(12, 8))  # a plot is for a run

    for line in objlist:

        run = int(line[0])
        if run != args.irun:
            continue
        runcount += 1
        print('-- running on run# %d (seq.# %d)---------' % (run, runcount))
        myRun = sdssrun(run)

        txtfile = 'SDSSdata/masterTXT/run%d.txt' % (run)
        txtdata = np.loadtxt(txtfile)
        calc = np.zeros(txtdata.shape[0])
        if args.vname == 'fwhmeff':
            myv = txtdata[:, 4]
        else:
            myv = txtdata[:, 8]
        if (1):
            icount = 0
            # the loops below need to conform with masterTXT files
            # filter changes first, then field, then camcol
            for camcol in range(1, sdss.nCamcol + 1):
                print('running on camcol#%d' % camcol)
                datafile = myRun.fitsdir + \
                    "photoField-%06d-%d.fits" % (run, camcol)
                hdulist = fits.open(datafile)
                hdu1 = hdulist[1].data
                # for ifield in range(myRun.nfields-530): #for plotting tests
                for ifield in range(myRun.nfields):
                    if ifield % 100 == 0:
                        print('field No. = %d/%d' % (ifield, myRun.nfields))
                    for iBand in range(0, sdss.nBand):
                        data = hdu1[ifield]
                        sigG1 = data['psf_sigma1'][iBand]
                        sigG2 = data['psf_sigma2'][iBand]
                        b = data['psf_b'][iBand]
                        p0 = data['psf_p0'][iBand]
                        beta = data['psf_beta'][iBand]
                        sigP = data['psf_sigmap'][iBand]
                        pixScale = data['pixScale'][iBand]

                        #grid1d = np.linspace(-30, 30, 601)  # arcsec
                        grid1d = np.linspace(-50, 50, 1001)
                        x, y = np.meshgrid(grid1d, grid1d)
                        # for fits, radius must be in pixels
                        r2 = (x * x + y * y) * (1 / pixScale)**2
                        psfG1 = np.exp(-0.5 * r2 / (sigG1 * sigG1))
                        psfG2 = b * np.exp(-0.5 * r2 / (sigG2 * sigG2))
                        # note division by beta! below:
                        psfW = p0 * (1 + r2 / (sigP * sigP) / beta)**(-0.5 * beta)
                        psfG = psfG1 + psfG2
                        # normalized to 1 at r=0 by definition
                        psfModel = (psfG + psfW) / (1 + b + p0)
                        psfModel = psfModel / np.sum(psfModel)
                        neff = 1 / np.sum(psfModel**2) / (pixScale / 0.1)**2
                        if args.vname == 'neff':
                            calc[icount] = neff
                        elif args.vname == 'fwhmeff':
                            # 0.4 arcsec/pixel
                            calc[icount] = 0.664 * pixScale * np.sqrt(neff)
                        icount += 1

        for camcol in range(1, sdss.nCamcol + 1):

            for iBand in range(0, sdss.nBand):
                idx = (txtdata[:, 1] == camcol) & (txtdata[:, 2] == iBand) 
                ax1[iBand, camcol - 1].plot(myv[idx], calc[idx],
                                            'r', marker='.', linestyle='None')
                if iBand == 0 and runcount == 1:
                    ax1[iBand, camcol - 1].set_title('camcol=%d' % camcol)
                if args.vname == 'neff':
                    if camcol == 1 and runcount == 1:
                        text = 'band: %s' % sdss.band[iBand]
                        ax1[iBand, camcol -
                            1].text(30, 16, text, fontsize=15, ha='left',
                                    va='center')
                    ax1[iBand, camcol - 1].plot([0, 70], [0, 70],
                                                color='k', linestyle='-',
                                                linewidth=2)
                elif args.vname == 'fwhmeff':
                    if camcol == 1 and runcount == 1:
                        text = 'band: %s' % sdss.band[iBand]
                        ax1[iBand, camcol -
                            1].text(1.0, 0.8, text, fontsize=15, ha='left',
                                    va='center')
                    ax1[iBand, camcol - 1].plot([0.5, 2.5], [0.5, 2.5],
                                                color='k', linestyle='-',
                                                linewidth=2)
                ax1[iBand, camcol - 1].grid()
                if iBand == sdss.nBand - 1:
                    ax1[iBand, camcol - 1].set_xlabel(args.vname)
                if camcol == 1:
                    ax1[iBand, camcol - 1].set_ylabel('My calculation')

        # plt.suptitle('All units in arcsec ')
        plt.tight_layout()
        # plt.show()
        plt.savefig('output/run%d_check_%s.png' % (run, args.vname))
def main():
    parser = argparse.ArgumentParser(
        description='----- find_long_wild_runs.py ---------')
    parser.add_argument('vname', help='variable we want to look at, e.g. psf_sigma1,\
psf_sigma2, airmass, neff_psf, psf_nstar, psf_width')
    parser.add_argument('-fitsoff', help='w/o reading in data from fits files',
                        action='store_true')
    parser.add_argument('-tableoff', help='w/o creating the stretchTable',
                        action='store_true')
    args = parser.parse_args()

    start1 = time.time()

    objlist = np.loadtxt('data/Stripe82RunList.dat')

    sdss = sdssinst()

    outTable = 'output/longWildRuns.txt'

    if (not args.tableoff):
        if os.path.isfile(outTable):
            os.remove(outTable)
        fz = open(outTable, 'ab')

        runcount = 0
        for line in objlist:

            start = time.time()
            run = int(line[0])
            runcount += 1
            print('-- running on run# %d (seq.# %d)---------' % (
                run, runcount))

            myRun = sdssrun(run)
            a3dfile = 'output/temp/run%d_%s.txt' % (myRun.runNo, args.vname)
            if (not args.fitsoff):
                a3d = myRun.getBCFtable(sdss, args.vname)
                myTools.savetxt3d(a3dfile, a3d)
            else:
                a3d = np.loadtxt(a3dfile)
                a3d = a3d.reshape(sdss.nBand, sdss.nCamcol, -1)
            longWildTable = myRun.findLongWild(sdss, a3d)
            np.savetxt(fz, longWildTable, fmt='%d %d %d %d %9.6f %9.6f')

            end = time.time()
            print('--- done with run# %d, time elapsed: %8.2fs---' % (
                run, (end - start)))
        fz.close()

    nrun = len(objlist)
    tableData = np.loadtxt(outTable)
    prodbyrun = np.zeros(nrun)
    nfieldsbyrun = np.zeros(nrun)
    pvbyrun = np.zeros(nrun)
    rmsbyrun = np.zeros(nrun)
    runNo = objlist[:, 0].astype(int)
    for i in np.arange(nrun):
        idx = tableData[:, 0] == runNo[i]
        nfieldsbyrun[i] = np.mean(tableData[idx, 1])
        pvbyrun[i] = np.mean(tableData[idx, 4])
        rmsbyrun[i] = np.mean(tableData[idx, 5])
        prodbyrun[i] = nfieldsbyrun[i] * pvbyrun[i] * rmsbyrun[i]
    plt.plot(runNo, nfieldsbyrun,  label='nfields',
             marker='.', color='g', markersize=10)
    plt.plot(runNo, prodbyrun,  label='nfields*PV*RMS (arcsec$^2$)',
             marker='o', color='k', markersize=5)
    plt.plot(runNo, pvbyrun * 100,  label='PV (arcsec) x 100',
             marker='v', color='b', markersize=5)
    plt.plot(runNo, rmsbyrun * 100,  label='RMS (arcsec) x 100',
             marker='*', color='r', markersize=10)
    plt.xlabel('Run No.')
    plt.ylabel('runs & psf_width variations')
    plt.legend(loc="upper right", fontsize=10)

    plt.savefig('output/longWildRun_%s.png' % (args.vname))
    maxRun = runNo[np.where(prodbyrun == np.max(prodbyrun))]
    runSeq = np.arange(1, nrun + 1)
    for irun in maxRun:  # mostly likely there is only 1 number in maxRun
        idx = tableData[:, 0] == irun
        print('longest run with largest %s variation: run %d (seq# %d), \
        nfield = %d, \n\
        averaged over band and camcol: PV = %9.6f, RMS = %9.6f' % (
            args.vname,
            irun,
            runSeq[irun == runNo],
            np.mean(tableData[idx, 1]),
            np.mean(tableData[idx, 4]),
            np.mean(tableData[idx, 5])))
    # sys.exit()
    end1 = time.time()
    print('--- Total time elapsed: %8.2fs---' % ((end1 - start1)))
Example #5
0
def main():

    parser = argparse.ArgumentParser(description="----- fwhm_vk_psfwidth.py ---------")
    parser.add_argument(
        "run",
        type=int,
        default=94,
        help="run number; use -1 for all runs together;\
                        -9 for all runs individually",
    )
    args = parser.parse_args()

    runNo = args.run
    objlist = np.loadtxt("data/Stripe82RunList.dat")
    if runNo > 0:
        # remove all lines but one
        objlist = objlist[objlist[:, 0] == runNo, :]

    sdss = sdssinst()
    runcount = 0

    # vk = np.loadtxt('data/vonK1.0.txt', unpack='True')
    # vk = vk / np.sum(vk)
    # vkneff = 1 / np.sum(vk**2)
    # vkfwhm = 0.664 * 0.1 * np.sqrt(vkneff)
    f, ax1 = plt.subplots(sdss.nBand, sdss.nCamcol, sharex="col", sharey="row", figsize=(12, 8))  # a plot is for a run

    for line in objlist:

        run = int(line[0])
        runcount += 1
        print("-- running on run# %d (seq.# %d)---------" % (run, runcount))

        txtfile = "SDSSdata/masterTXT/run%d.txt" % (run)
        txtdata = np.loadtxt(txtfile)
        fwhmvk = txtdata[:, 3]
        psf_width = txtdata[:, 4]

        if runNo < -5:
            # a plot is for a run
            f, ax1 = plt.subplots(sdss.nBand, sdss.nCamcol, sharex="col", sharey="row", figsize=(12, 8))

        for camcol in range(1, sdss.nCamcol + 1):

            for iBand in range(0, sdss.nBand):
                idx = (txtdata[:, 1] == camcol) & (txtdata[:, 2] == iBand)
                ax1[iBand, camcol - 1].scatter(psf_width[idx], fwhmvk[idx], s=2, c="r", edgecolors="r")
                if iBand == 0 and runcount == 1:
                    ax1[iBand, camcol - 1].set_title("camcol=%d" % camcol)
                if camcol == 1 and runcount == 1:
                    text = "band: %s" % sdss.band[iBand]
                    ax1[iBand, camcol - 1].text(1.0, 0.8, text, fontsize=15, ha="left", va="center")
                ax1[iBand, camcol - 1].plot([0.5, 2.5], [0.5, 2.5], color="k", linestyle="-", linewidth=2)
                ax1[iBand, camcol - 1].grid()
                if iBand == sdss.nBand - 1:
                    ax1[iBand, camcol - 1].set_xlabel("psf_width")
                if camcol == 1:
                    ax1[iBand, camcol - 1].set_ylabel("FWHMvK")

        if runNo < -5:
            plt.tight_layout()
            plt.savefig("output/fwhmvk_psfwidth/run%d_fwhmvk_psfwidth.png" % (run))
            plt.close()
    if runNo > -5:
        plt.tight_layout()
        if runNo < 0:
            plt.savefig("output/fwhmvk_psfwidth/runAll_fwhmvk_psfwidth.png")
        else:
            plt.savefig("output/fwhmvk_psfwidth/run%d_fwhmvk_psfwidth.png" % (runNo))

        plt.close()
Example #6
0
def main():

    parser = argparse.ArgumentParser(
        description='----- fwhm_lambda.py ---------')
    parser.add_argument('run', type=int, default=94,
                        help='run number; -9 for all runs individually; \
                        makes no sense to plot all runs together')
    parser.add_argument('yscale', choices=(
        'log', 'linear'), help='yscale of the plots')
    parser.add_argument('-ugri', help='run ugri bands only; w/o z',
                        action='store_true')
    parser.add_argument('-startfield', dest='startfield', default=0, type=int,
                        help='field# to start with')
    parser.add_argument('-endfield', dest='endfield', default=99999, type=int,
                        help='field# to end with (note indexing \
                        starts from 0)')
    parser.add_argument('-doubleG', help='use psf_width from the double Gau fits',
                        action='store_true')
    args = parser.parse_args()

    if args.ugri == 1:
        bands = 'ugri'
    else:
        bands = 'ugriz'
    runNo = args.run
    objlist = np.loadtxt('data/Stripe82RunList.dat')
    if runNo > 0:
        # remove all lines but one
        objlist = objlist[objlist[:, 0] == runNo, :]

    sdss = sdssinst()
    runcount = 0

    nRow = 2
    nCol = np.uint8(np.ceil(sdss.nCamcol / nRow))
    f, ax1 = plt.subplots(nRow, nCol, sharex='col',
                          sharey='row', figsize=(12, 8))  # a plot is for a run
    if runNo < 0:
        outTXTfile = 'output/fwhm_lambda/power_%s.txt' % bands
        fidw = open(outTXTfile, 'w')
    xlambda = np.arange(300, 1000, 10)
    for line in objlist:

        run = int(line[0])
        runcount += 1
        print('-- running on run# %d (seq.# %d)---------' % (run, runcount))

        txtfile = 'SDSSdata/masterTXT/run%d.txt' % (run)
        txtdata = np.loadtxt(txtfile)
        idx = (txtdata[:, 0] >= args.startfield) & (
            txtdata[:, 0] < args.endfield)
        txtdata = txtdata[idx, :]
        if args.doubleG:
            fwhmStr = 'fwhm2G'
            fwhm = txtdata[:, 4]
        else:
            fwhmStr = 'fwhm'
            fwhm = txtdata[:, 3] / 1.222  # convert FWHMeff into FWHM
        airmass = txtdata[:, 5]
        fwhm = fwhm/airmass**0.6
        startfield = args.startfield
        endfield = np.uint16(np.max(txtdata[:, 0]))

        if runNo < 0:
            # a plot is for a run
            f, ax1 = plt.subplots(nRow, nCol, sharex='col',
                                  sharey='row', figsize=(12, 8))

        for camcol in range(1, sdss.nCamcol + 1):
            iRow = np.uint8(np.ceil(camcol / nCol)) - 1
            iCol = np.mod(camcol - 1, nCol)
            # print(iRow, iCol)

            # scanning order is r-i-u-z-g
            idx = (txtdata[:, 1] == camcol) & \
                (((txtdata[:, 2] == 0) & (txtdata[:, 0] > startfield + 3) & (
                    txtdata[:, 0] < endfield - 4)) |
                    ((txtdata[:, 2] == 1) & (txtdata[:, 0] < endfield - 8)) |
                 ((txtdata[:, 2] == 2) & (txtdata[:, 0] > startfield + 7)) |
                 ((txtdata[:, 2] == 3) & (txtdata[:, 0] > startfield + 5) & (
                     txtdata[:, 0] < endfield - 2)) |
                 ((txtdata[:, 2] == 4) & (txtdata[:, 0] > startfield + 1) & (
                     txtdata[:, 0] < endfield - 6)))
            if args.ugri == 1:
                idx = idx & (txtdata[:, 2] != 4)  # remove z band data
            fwhmfit = fwhm[idx]
            Leffnparray = np.array(sdss.Leff)
            Lefffit = Leffnparray[np.uint8(txtdata[idx, 2])]
            popt, pcov = optimize.curve_fit(
                lambda Leff, norm: fwhm_lambda_dep(Leff, norm, -0.2),
                Lefffit, fwhmfit, p0=[5])
            norm02 = popt[0]
            y02 = fwhm_lambda_dep(xlambda, norm02, -0.2)
            ax1[iRow, iCol].plot(xlambda, y02, '-b', label='power = -0.2')

            popt, pcov = optimize.curve_fit(
                lambda Leff, norm: fwhm_lambda_dep(Leff, norm, -0.3),
                Lefffit, fwhmfit, p0=[5])
            norm03 = popt[0]
            y03 = fwhm_lambda_dep(xlambda, norm03, -0.3)
            ax1[iRow, iCol].plot(xlambda, y03, '-g', label='power = -0.3')

            popt, pcov = optimize.curve_fit(
                fwhm_lambda_dep,
                Lefffit, fwhmfit, p0=[5, -0.25])
            normfit = popt[0]
            powerfit = popt[1]
            yfit = fwhm_lambda_dep(xlambda, normfit, powerfit)
            ax1[iRow, iCol].plot(xlambda, yfit, '-k',
                                 label='power (fit) = %5.2f' % powerfit)
            print('camcol=%d, power (fit) = %5.2f' % (camcol, powerfit))
            if runNo < 0:
                if camcol == 1:
                    fidw.write('%d\t' % run)
                fidw.write('%5.2f\t' % powerfit)
                if camcol == sdss.nCamcol:
                    fidw.write('\n')

            # scanning order is r-i-u-z-g
            for ufield in range(startfield + 4, endfield - 4 + 1):
                gfield = ufield - 4
                rfield = ufield + 4
                ifield = ufield + 2
                zfield = ufield - 2
                idxu = (txtdata[:, 0] == ufield) & (
                    txtdata[:, 1] == camcol) & (txtdata[:, 2] == 0)
                idxg = (txtdata[:, 0] == gfield) & (
                    txtdata[:, 1] == camcol) & (txtdata[:, 2] == 1)
                idxr = (txtdata[:, 0] == rfield) & (
                    txtdata[:, 1] == camcol) & (txtdata[:, 2] == 2)
                idxi = (txtdata[:, 0] == ifield) & (
                    txtdata[:, 1] == camcol) & (txtdata[:, 2] == 3)
                idxz = (txtdata[:, 0] == zfield) & (
                    txtdata[:, 1] == camcol) & (txtdata[:, 2] == 4)
                if args.ugri == 1:
                    fwhmt = np.hstack(
                        (fwhm[idxu], fwhm[idxg], fwhm[idxr], fwhm[idxi]))
                    ax1[iRow, iCol].plot(sdss.Leff[0:4], fwhmt, '-ro')
                else:
                    fwhmt = np.hstack((fwhm[idxu], fwhm[idxg], fwhm[
                                      idxr], fwhm[idxi], fwhm[idxz]))
                    ax1[iRow, iCol].plot(sdss.Leff, fwhmt, '-ro')
            ax1[iRow, iCol].grid()
            ax1[iRow, iCol].set_title('camcol=%d' % camcol)
            ax1[iRow, iCol].plot(xlambda, y02, '-b')
            ax1[iRow, iCol].plot(xlambda, y03, '-g')
            ax1[iRow, iCol].plot(xlambda, yfit, '-k')

            ax1[iRow, iCol].set_xlabel('Effective wavelength (nm)')
            ax1[iRow, iCol].set_ylabel(fwhmStr)
            ax1[iRow, iCol].legend(loc="upper right", fontsize=10)

            if args.yscale == 'log':
                ax1[iRow, iCol].set_yscale('log')
                ax1[iRow, iCol].set_xscale('log')
                ax1[iRow, iCol].set_xlim([300, 1000])
                ax1[iRow, iCol].set_ylim(
                    [np.min(fwhm) - 0.1, np.max(fwhm) + 0.3])

        if runNo < 0:
            # plt.tight_layout()
            plt.savefig('output/fwhm_lambda/run%d_%s_lambda_%s_%s.png' %
                        (run, fwhmStr, bands, args.yscale))
            plt.close()
    if runNo > 0:
        # plt.tight_layout()
        if (args.startfield == 0 and args.endfield == 99999):
            plt.savefig('output/fwhm_lambda/run%d_%s_lambda_%s_%s.png' %
                        (runNo, fwhmStr, bands, args.yscale))
        else:
            plt.savefig(
                'output/fwhm_lambda/run%d_%s_lambda_%s_%s_%d_%d.png' %
                (runNo, fwhmStr, bands, args.yscale, args.startfield, args.endfield))

        plt.close()

    if runNo < 0:
        fidw.close()
def main():

    parser = argparse.ArgumentParser(
        description='----- correlate_temporal.py ---------')
    parser.add_argument('run', type=int, default=94,
                        help='run number; -9 for all runs individually; \
                        makes no sense to plot all runs together')
    parser.add_argument('iBand', type=int, default=0, help='band, 0,1,2,3,4 for ugriz')                        
    parser.add_argument('-doubleG', help='use psf_width from the double Gau fits',
                        action='store_true')
    parser.add_argument('-startfield', dest='startfield', default=0, type=int,
                        help='field# to start with')
    parser.add_argument('-endfield', dest='endfield', default=99999, type=int,
                        help='field# to end with (note indexing \
                        starts from 0)')
    args = parser.parse_args()

    runNo = args.run
    objlist = np.loadtxt('data/Stripe82RunList.dat')
    if runNo > 0:
        # remove all lines but one
        objlist = objlist[objlist[:, 0] == runNo, :]

    sdss = sdssinst()
    runcount = 0
    for line in objlist:

        run = int(line[0])
        runcount += 1
        print('-- running on run# %d (seq.# %d)---------' % (run, runcount))

        txtfile = 'SDSSdata/masterTXT/run%d.txt' % (run)
        txtdata = np.loadtxt(txtfile)
        idx = (txtdata[:, 0] >= args.startfield) & (
            txtdata[:, 0] < args.endfield)
        txtdata = txtdata[idx, :]
        if args.doubleG:
            fwhmStr = 'fwhm2G'
            fwhm = txtdata[:, 4]
        else:
            fwhmStr = 'fwhm'
            fwhm = txtdata[:, 3]  # FWHMeff 
        airmass = txtdata[:, 5]
        fwhm = fwhm/airmass**0.6
        startfield = args.startfield
        endfield = np.uint16(np.max(txtdata[:, 0]))
        nfields = endfield - startfield + 1

        nRow = 2
        nCol = np.uint8(np.ceil(sdss.nCamcol / nRow))
        f, ax1 = plt.subplots(nRow, nCol, sharex='col',
                            sharey='row', figsize=(12, 8))  # a plot is for a run
        
        for camcol in range(1, sdss.nCamcol + 1):
            iRow = np.uint8(np.ceil(camcol / nCol)) - 1
            iCol = np.mod(camcol - 1, nCol)

            idx = (txtdata[:, 1] == camcol) & (txtdata[:, 2] == args.iBand)
            
            result = np.correlate(fwhm[idx], fwhm[idx], mode='full')
            autoCorr = result[result.size/2:]
            autoCorr = autoCorr/max(autoCorr)
            ax1[iRow, iCol].plot(autoCorr, marker='.')

            #SFFT = np.fft.fftshift(np.fft.fft(np.fft.fftshift(fwhm[idx])))
            #SFFT = abs(np.fft.fftshift(np.fft.fft(fwhm[idx])))
            #ax1[iRow, iCol].plot(SFFT, marker='.')

            #N = nfields
            ## sample spacing
            #T = 1.0 / N /2
            #x = np.linspace(0.0, N*T, N)
            #y = fwhm[idx]
            #yf = np.fft.fft(y)
            #xf = np.fft.fftfreq(N, T)
            #xf = np.fft.fftshift(xf)
            #yplot = np.fft.fftshift(yf)
            #ax1[iRow, iCol].semilogy(xf, 1.0/N * np.abs(yplot))

            #ax1[iRow, iCol].set_xlim(0, nfields+1)
            ax1[iRow, iCol].set_title('run%d, %s, %s, camcol=%s' %
                        (runNo, fwhmStr, sdss.band[args.iBand], camcol))
            ax1[iRow, iCol].set_xlabel('time (ifield)')
            #ax1[iRow, iCol].set_ylabel('Covariance (arcsec^2)')
            #ax1[iRow, iCol].set_ylabel('Correlation coefficients')
            ax1[iRow, iCol].set_ylabel('FFT')
            ax1[iRow, iCol].grid()
            #plt.show()
            
    # plt.tight_layout()
    if (args.startfield == 0 and args.endfield == 99999):
        plt.savefig('output/correlate_temporal/run%d_%s_%s.png' %
                    (runNo, fwhmStr, sdss.band[args.iBand]))
    else:
        plt.savefig(
            'output/correlate_temporal/run%d_%s_%s_fld_%d_%d.png' %
            (runNo, fwhmStr, sdss.band[args.iBand],args.startfield, args.endfield))

    plt.close()
Example #8
0
def main():

    parser = argparse.ArgumentParser(
        description='----- correlate_spatial.py ---------')
    parser.add_argument('run', type=int, default=94,
                        help='run number; -9 for all runs individually; \
                        makes no sense to plot all runs together')
    parser.add_argument('-doubleG', help='use psf_width from the double Gau fits',
                        action='store_true')
    parser.add_argument('-startfield', dest='startfield', default=0, type=int,
                        help='field# to start with')
    parser.add_argument('-endfield', dest='endfield', default=99999, type=int,
                        help='field# to end with (note indexing \
                        starts from 0)')
    args = parser.parse_args()

    runNo = args.run
    objlist = np.loadtxt('data/Stripe82RunList.dat')
    if runNo > 0:
        # remove all lines but one
        objlist = objlist[objlist[:, 0] == runNo, :]

    sdss = sdssinst()
    runcount = 0
    for line in objlist:

        run = int(line[0])
        runcount += 1
        print('-- running on run# %d (seq.# %d)---------' % (run, runcount))

        txtfile = 'SDSSdata/masterTXT/run%d.txt' % (run)
        txtdata = np.loadtxt(txtfile)
        idx = (txtdata[:, 0] >= args.startfield) & (
            txtdata[:, 0] < args.endfield)
        txtdata = txtdata[idx, :]
        if args.doubleG:
            fwhmStr = 'fwhm2G'
            fwhm = txtdata[:, 4]
        else:
            fwhmStr = 'fwhm'
            fwhm = txtdata[:, 3]  # FWHMeff 
        airmass = txtdata[:, 5]
        fwhm = fwhm/airmass**0.6
        startfield = args.startfield
        endfield = np.uint16(np.max(txtdata[:, 0]))
        nfields = endfield - startfield + 1

        nRow = 2
        nCol = 3
        f, ax1 = plt.subplots(nRow, nCol, sharex='col',
                            sharey='row', figsize=(12, 8))  # a plot is for a run
        
        for iBand in range(0, sdss.nBand):
            iRow = np.uint8(np.ceil((iBand+1) / nCol)) - 1
            iCol = np.mod(iBand, nCol)

            fwhmArray = np.zeros((nfields, sdss.nCamcol))
            for camcol in range(1, sdss.nCamcol + 1):
                idx = (txtdata[:, 1] == camcol) & (txtdata[:, 2] == iBand)
                fwhmArray[:, camcol-1] = fwhm[idx]
            #myCovSquare=np.cov(fwhmArray, rowvar=0)
            myCovSquare=np.corrcoef(fwhmArray, rowvar=0)
            myCov = np.zeros(15)
            mySep = np.zeros(15)
            i = 0
            for iCamcol in range(1, sdss.nCamcol + 1):
                for jCamcol in range(iCamcol+1, sdss.nCamcol + 1):
                    myCov[i] = myCovSquare[iCamcol-1, jCamcol-1]
                    mySep[i] = jCamcol - iCamcol
                    i += 1
            ax1[iRow, iCol].plot(mySep, myCov, 'xr',markersize=15)
            ax1[iRow, iCol].set_xlim(0, sdss.nCamcol)
            ax1[iRow, iCol].set_title('run%d, %s, %s' %
                        (runNo, fwhmStr, sdss.band[iBand]))
            ax1[iRow, iCol].set_xlabel('Spatial separation')
            #ax1[iRow, iCol].set_ylabel('Covariance (arcsec^2)')
            ax1[iRow, iCol].set_ylabel('Correlation coefficients')
            ax1[iRow, iCol].grid()
            #plt.show()
            
    # plt.tight_layout()
    if (args.startfield == 0 and args.endfield == 99999):
        plt.savefig('output/correlate_spatial/run%d_%s.png' %
                    (runNo, fwhmStr))
    else:
        plt.savefig(
            'output/correlate_spatial/run%d_%s_fld_%d_%d.png' %
            (runNo, fwhmStr, args.startfield, args.endfield))

    plt.close()