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)
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)))
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)))
def write1run(sdss, run, runcount): print("-- running on run# %d (seq.# %d)---------" % (run, runcount)) myRun = sdssrun(run) txtfile = "SDSSdata/masterTXT/run%d.txt" % (myRun.runNo) myRun.writeMasterTXT(sdss, txtfile)