def grabdata(resultsdir, outfile): files = os.listdir(os.path.join(resultsdir, 'lightcurves')) smpfiles = [] for f in files: if '.smp' in f: smpfiles.append(os.path.join(resultsdir, 'lightcurves', f)) print "Found " + str(len(smpfiles)) + " .smp files" if not os.path.exists(os.path.join(resultsdir, 'Summary')): os.makedirs(os.path.join(resultsdir, 'Summary')) #outfile = os.path.join(resultsdir,'Summary','sumdata.npz') bigdata = {'fitmag': [], 'fiterr': [], 'catmag': [], 'fitzpt': []} for f in smpfiles: data = dt.readcol(f) try: print len(data['FLUX']), len(data['FLUXERR']), len( data['FAKEMAG']), len(data['ZPT']), (data['FAKEZPT']) bigdata['Flux'].extend(data['FLUX']) bigdata['Fluxerr'].extend(data['FLUXERR']) bigdata['FakeMag'].extend(data['FAKEMAG']) bigdata['FitZPT'].extend(data['ZPT']) bigdata['FakeZPT'].extend(data['FAKEZPT']) print f, 'read in' except: print 'Columns missing in file ' + f fakef = f.split('/')[-1][:17] filt = f.split('/')[-1][18] fakefile = os.path.join(fakedir, fakef + '.dat') ff = open(fakefile, 'r').readlines() print 'fileter', filt hostmag = -999 #raw_input() for l in ff: key = l.split(':')[0] if key == 'HOSTGAL_SB_FLUXCAL': if filt == 'r': hostmag = 27.5 - 2.5 * np.log10(float(l.split()[2])) print 'hostmag', hostmag bigdata['HostMag'].extend(data['FLUX'] * 0 + hostmag) #raw_input() print 'saving to cachfile' np.savez(outfile, **bigdata) print 'saved' #tmpwriter.savez(outfile,*bigdata) return bigdata
def grabdata(resultsdir,outfile): files = os.listdir(os.path.join(resultsdir, 'lightcurves')) smpfiles = [] for f in files: if '.smp' in f: smpfiles.append(os.path.join(resultsdir, 'lightcurves', f)) print "Found " + str(len(smpfiles)) + " .smp files" if not os.path.exists(os.path.join(resultsdir,'Summary')): os.makedirs(os.path.join(resultsdir,'Summary')) #outfile = os.path.join(resultsdir,'Summary','sumdata.npz') bigdata = {'fitmag':[],'fiterr':[],'catmag':[],'fitzpt':[]} for f in smpfiles: data = dt.readcol(f) try: print len(data['FLUX']),len(data['FLUXERR']),len(data['FAKEMAG']),len(data['ZPT']),(data['FAKEZPT']) bigdata['Flux'].extend(data['FLUX']) bigdata['Fluxerr'].extend(data['FLUXERR']) bigdata['FakeMag'].extend(data['FAKEMAG']) bigdata['FitZPT'].extend(data['ZPT']) bigdata['FakeZPT'].extend(data['FAKEZPT']) print f,'read in' except: print 'Columns missing in file '+f fakef = f.split('/')[-1][:17] filt = f.split('/')[-1][18] fakefile = os.path.join(fakedir,fakef+'.dat') ff = open(fakefile,'r').readlines() print 'fileter',filt hostmag = -999 #raw_input() for l in ff: key = l.split(':')[0] if key == 'HOSTGAL_SB_FLUXCAL': if filt == 'r': hostmag = 27.5 - 2.5 * np.log10(float(l.split()[2])) print 'hostmag',hostmag bigdata['HostMag'].extend(data['FLUX']*0 + hostmag) #raw_input() print 'saving to cachfile' np.savez(outfile,**bigdata) print 'saved' #tmpwriter.savez(outfile,*bigdata) return bigdata
# pass #print 'DOES EXIST',smpfile #print lcfile pkmjd = open(lcfile).readlines()[10].split()[1] if filt == 'g': fi = 1 if filt == 'r': fi = 2 if filt == 'i': fi = 3 if filt == 'z': fi = 4 hostsbfluxcal = open(lcfile).readlines()[20].split()[fi] #print pkmjd #raw_input() inplace = False #if i > 0: inplace = True sndata = dt.readcol(smpfile, 1, 2) try: a = sndata['MJD'] except: print 'could not grab mjd ' * 100 continue #print sndata['FLUX'].shape mjd.extend(sndata['MJD']) flux.extend(sndata['FLUX']) fluxerr.extend(sndata['FLUXERR']) zpt.extend(sndata['ZPT']) zpterr.extend(sndata['ZPTERR']) rmsaddin.extend(sndata['RMSADDIN']) chi2.extend(sndata['CHI2']) sky.extend(sndata['SKY'])
# pass #print 'DOES EXIST',smpfile #print lcfile pkmjd = open(lcfile).readlines()[10].split()[1] if filt == 'g': fi = 1 if filt == 'r': fi = 2 if filt == 'i': fi = 3 if filt == 'z': fi = 4 hostsbfluxcal = open(lcfile).readlines()[20].split()[fi] #print pkmjd #raw_input() inplace = False #if i > 0: inplace = True sndata = dt.readcol(smpfile,1,2) try: a = sndata['MJD'] except: print 'could not grab mjd '*100 continue #print sndata['FLUX'].shape mjd.extend(sndata['MJD']) flux.extend(sndata['FLUX']) fluxerr.extend(sndata['FLUXERR']) zpt.extend(sndata['ZPT']) zpterr.extend(sndata['ZPTERR']) rmsaddin.extend(sndata['RMSADDIN']) chi2.extend(sndata['CHI2']) sky.extend(sndata['SKY'])