maxID = np.max(maxID)

# Crop off some of the early junky observations
minMJD = 56900
minID,mjd = sb.allSkyDB(0,'select min(ID) from dates where mjd > %i;' % minMJD, dtypes='int')

altLimit = 10. # Degrees
sunAltLimit = np.radians(-20.)

maxID = 3000
step = 5

for dateID in np.arange(minID.max(),minID.max()+maxID+1, step):
    sqlQ = 'select stars.ra, stars.dec, stars.ID, obs.starMag_inst, obs.starMag_err,obs.sky, obs.filter from obs, stars, dates where obs.starID = stars.ID and obs.dateID = dates.ID and obs.filter = "%s" and obs.dateID = %i and obs.starMag_err != 0 and dates.sunAlt < %f and obs.starMag_inst > %f;' % (filt,dateID,sunAltLimit, starBrightLimit)

    # Note that RA,Dec are in degrees
    data,mjd = sb.allSkyDB(dateID, sqlQ=sqlQ, dtypes=dtypes)
    if data.size > nStarLimit:
        alt,az,pa = _altAzPaFromRaDec(np.radians(data['ra']), np.radians(data['dec']),
                                      telescope.lon, telescope.lat, mjd)
        for i,nside in enumerate(nsides):
            tempMap = healbin(az,alt, az*0+1, nside=nside, reduceFunc=np.size)[hpIndices[i]]
            ratio = np.size(np.where(tempMap > 0)[0])/float(np.size(tempMap))
            mapFractions[i].append(ratio)


print 'nside, resolution (deg), fraction of healpixes populated'
for mf,nside in zip(mapFractions,nsides):
    resol = hp.nside2resol(nside, arcmin=True)/60.
    print ' %i,  %f, %f' % (nside, resol,np.median(mf))
altLimit = 10.  # Degrees
sunAltLimit = np.radians(-20.)

maxID = 3000
step = 5

for dateID in np.arange(minID.max(), minID.max() + maxID + 1, step):
    sqlQ = 'select stars.ra, stars.dec, stars.ID, obs.starMag_inst, obs.starMag_err,obs.sky, obs.filter from obs, stars, dates where obs.starID = stars.ID and obs.dateID = dates.ID and obs.filter = "%s" and obs.dateID = %i and obs.starMag_err != 0 and dates.sunAlt < %f and obs.starMag_inst > %f;' % (
        filt, dateID, sunAltLimit, starBrightLimit)

    # Note that RA,Dec are in degrees
    data, mjd = sb.allSkyDB(dateID, sqlQ=sqlQ, dtypes=dtypes)
    if data.size > nStarLimit:
        alt, az, pa = _altAzPaFromRaDec(np.radians(data['ra']),
                                        np.radians(data['dec']), telescope.lon,
                                        telescope.lat, mjd)
        for i, nside in enumerate(nsides):
            tempMap = healbin(az,
                              alt,
                              az * 0 + 1,
                              nside=nside,
                              reduceFunc=np.size)[hpIndices[i]]
            ratio = np.size(np.where(tempMap > 0)[0]) / float(np.size(tempMap))
            mapFractions[i].append(ratio)

print 'nside, resolution (deg), fraction of healpixes populated'
for mf, nside in zip(mapFractions, nsides):
    resol = hp.nside2resol(nside, arcmin=True) / 60.
    print ' %i,  %f, %f' % (nside, resol, np.median(mf))
예제 #3
0
starsFit = np.load('solvedStar.npz')['result']
trueStars = fastRead('starInfo.dat', dtype=list(zip(['starID','TrueMag', 'ra','dec'],
                                               [int,float,float,float])),
                                               delimiter=',')
trueStars.sort(order='starID')

# Remove any stars that were observed but not fit
mask = np.in1d(trueStars['starID'], starsFit['starID'], assume_unique=True)
trueStars = trueStars[mask]

resid = starsFit['fitMag'] - trueStars['TrueMag']

resid = resid-np.median(resid)

print('median fitMag - TrueMag = %f'%np.median(resid))
print('std (fitMag - TrueMag) = %f'%np.std(resid))
print('robust RMS = %f'%robustRMS(resid))
rrms = robustRMS(resid)

plt.hist(resid, bins=100, range=(-4*rrms,4*rrms))
plt.xlabel('Fit-True (mags)')
plt.ylabel('#')

plt.savefig('resid_hist.png')

healmap = healbin(np.radians(trueStars['ra']), np.radians(trueStars['dec']), resid)
hp.mollview(healmap, min =-4*rrms, max=4*rrms, unit='Residuals (mag)')
plt.savefig('resid_map.png')

예제 #4
0
zp = 12.11

#zps = []
counter = 0
maxI = np.size(dateIDs)
for i, dateID in enumerate(dateIDs):

    skydata, mjd = sb.allSkyDB(dateID, filt=band)  #2744
    airmass = 1. / np.cos(np.radians(90. - skydata['alt']))
    skydata = skydata[np.where((airmass < 2.1) & (airmass >= 1.))]

    alt, az, pa = altAzPaFromRaDec(np.radians(skydata['ra']),
                                   np.radians(skydata['dec']), telescope.lon,
                                   telescope.lat, mjd)

    skyhp = healplots.healbin(az, alt, skydata['sky'], nside=nside)

    sm.setRaDecMjd(np.radians(skydata['ra']),
                   np.radians(skydata['dec']),
                   mjd,
                   degrees=False)
    if sm.sunAlt < np.radians(-12.):
        sm.computeSpec()
        mags = sm.computeMags(canonDict[band])

        good = np.where(mags > 0)
        if np.size(good[0]) > 10:
            modelhp = healplots.healbin(az[good],
                                        alt[good],
                                        mags[good],
                                        nside=nside)
예제 #5
0
zp = 12.11

#zps = []
counter = 0
maxI = np.size(dateIDs)
for i,dateID in enumerate(dateIDs):

    skydata, mjd = sb.allSkyDB(dateID , filt=band)#2744
    airmass = 1./np.cos(np.radians(90.-skydata['alt']))
    skydata = skydata[np.where((airmass < 2.1) & (airmass >= 1.))]

    alt,az,pa =  altAzPaFromRaDec(np.radians(skydata['ra']), np.radians(skydata['dec']),
                                  telescope.lon, telescope.lat, mjd)

    skyhp = healplots.healbin(az, alt, skydata['sky'], nside=nside)

    sm.setRaDecMjd(np.radians(skydata['ra']), np.radians(skydata['dec']), mjd, degrees=False)
    if sm.sunAlt < np.radians(-12.):
        sm.computeSpec()
        mags = sm.computeMags(canonDict[band])

        good = np.where(mags > 0)
        if np.size(good[0]) > 10:
            modelhp = healplots.healbin(az[good], alt[good], mags[good], nside=nside)
            zp = np.median(mags[good] - skydata['sky'][good])
            #zps.append(zp)
            fig = plt.figure(num=1)
            hp.mollview(skyhp+zp, rot=(0,90), sub=(2,1,1), fig=1, title='Cannon '+band+' mjd=%0.2f'%sm.mjd,
                        min=cmin, max=cmax)
            hp.mollview(modelhp, rot=(0,90), sub=(2,1,2), fig=1,
예제 #6
0
        for j, (le, ri, mjd) in enumerate(zip(left, right, umjd)):
            Observatory.date = mjd2djd(mjd)
            sun.compute(Observatory)
            alt, az, pa = altAzPaFromRaDec(data['ra'][le:ri],
                                           data['dec'][le:ri], telescope.lon,
                                           telescope.lat, mjd)
            az = wrapRA(az - sun.az)
            altaz['alt'][le:ri] += alt
            altaz['az'][le:ri] += az
            moon.compute(Observatory)
            moonAlt[le:ri] += moon.alt

        print 'making maps'
        good = np.where(moonAlt < 0)
        magMap[:, i] = healbin(altaz['az'][good],
                               altaz['alt'][good],
                               data['sky'][good],
                               nside=nside,
                               reduceFunc=np.median)
        rmsMap[:, i] = healbin(altaz['az'][good],
                               altaz['alt'][good],
                               data['sky'][good],
                               nside=nside,
                               reduceFunc=robustRMS)

    print 'saving maps'
    np.savez('TwilightMaps/twiMaps_%s.npz' % filterName,
             magMap=magMap,
             rmsMap=rmsMap,
             sunAlts=sunAlts)
예제 #7
0
    if read:
        data = np.load('Plots/valAr_%s.npz' % filterName)
        validationArr = data['validationArr'].copy()
    else:
        for i, indx in enumerate(indices):
            skydata, mjd = sb.allSkyDB(dateData[indx]['dateID'],
                                       filt=filterName)
            if skydata.size > starLimit:
                airmass = 1. / np.cos(np.radians(90. - skydata['alt']))
                skydata = skydata[np.where((airmass < amMax)
                                           & (airmass >= 1.))]
                alt, az, pa = _altAzPaFromRaDec(np.radians(skydata['ra']),
                                                np.radians(skydata['dec']),
                                                telescope.lon, telescope.lat,
                                                mjd)
                skyhp = healplots.healbin(az, alt, skydata['sky'], nside=nside)
                skyhp[np.isnan(skyhp)] = hp.UNSEEN

                good = np.where(skyhp != hp.UNSEEN)
                sm.setRaDecMjd(hpra[good],
                               hpdec[good],
                               mjd,
                               degrees=False,
                               azAlt=True)
                sm.computeSpec()
                modelhp = np.zeros(npix, dtype=float) + hp.UNSEEN
                modelhp[good] = sm.computeMags(canonDict[filterName])
                validationArr['frameZP'][i] = np.median(modelhp[good] -
                                                        skyhp[good])

                notnan = np.where(skyhp != hp.UNSEEN)
예제 #8
0
hpdec = np.pi/2.-lat


for filterName in filters:
    if read:
        data = np.load('Plots/valAr_%s.npz' % filterName)
        validationArr = data['validationArr'].copy()
    else:
        for i,indx in enumerate(indices):
            skydata,mjd = sb.allSkyDB(dateData[indx]['dateID'], filt=filterName)
            if skydata.size > starLimit:
                airmass = 1./np.cos(np.radians(90.-skydata['alt']))
                skydata = skydata[np.where((airmass < amMax) & (airmass >= 1.))]
                alt,az,pa =  _altAzPaFromRaDec(np.radians(skydata['ra']), np.radians(skydata['dec']),
                                               telescope.lon, telescope.lat, mjd)
                skyhp = healplots.healbin(az,alt, skydata['sky'], nside=nside)
                skyhp[np.isnan(skyhp)] = hp.UNSEEN

                good = np.where(skyhp != hp.UNSEEN)
                sm.setRaDecMjd(hpra[good], hpdec[good], mjd, degrees=False, azAlt=True)
                sm.computeSpec()
                modelhp = np.zeros(npix,dtype=float)+hp.UNSEEN
                modelhp[good] = sm.computeMags(canonDict[filterName])
                validationArr['frameZP'][i] = np.median(modelhp[good]-skyhp[good] )

                notnan = np.where(skyhp != hp.UNSEEN)
                validationArr['obsDarkestHP'][i] = np.where(skyhp == skyhp[notnan].max() )[0].min()
                validationArr['obsBrightestHP'][i] = np.where(skyhp == skyhp[notnan].min() )[0].min()
                notnan =np.where(modelhp != hp.UNSEEN)
                validationArr['modelDarkestHP'][i]  = np.where(modelhp == modelhp[notnan].max() )[0]
                validationArr['modelBrightestHP'][i]  = np.where(modelhp == modelhp[notnan].min() )[0]
        umjd = np.unique(data['mjd'])

        left = np.searchsorted(data['mjd'], umjd)
        right = np.searchsorted(data['mjd'], umjd, side='right')

        altaz = np.zeros(data.size, dtype=zip(['alt','az'], [float]*2))
        moonAlt = np.zeros(data.size, dtype=float)

        print 'computing alts and azs'

        for j, (le, ri, mjd) in enumerate(zip(left,right,umjd)):
            Observatory.date = mjd2djd(mjd)
            sun.compute(Observatory)
            alt, az, pa = altAzPaFromRaDec(data['ra'][le:ri], data['dec'][le:ri],
                                           telescope.lon, telescope.lat, mjd)
            az = wrapRA(az - sun.az)
            altaz['alt'][le:ri] += alt
            altaz['az'][le:ri] += az
            moon.compute(Observatory)
            moonAlt[le:ri] += moon.alt

        print 'making maps'
        good = np.where(moonAlt < 0)
        magMap[:,i] = healbin(altaz['az'][good],altaz['alt'][good], data['sky'][good],
                              nside=nside, reduceFunc=np.median)
        rmsMap[:,i] = healbin(altaz['az'][good],altaz['alt'][good],data['sky'][good],
                              nside=nside, reduceFunc=robustRMS)

    print 'saving maps'
    np.savez('TwilightMaps/twiMaps_%s.npz' % filterName, magMap=magMap, rmsMap=rmsMap, sunAlts=sunAlts)
예제 #10
0
trueStars = fastRead('starInfo.dat',
                     dtype=list(
                         zip(['starID', 'TrueMag', 'ra', 'dec'],
                             [int, float, float, float])),
                     delimiter=',')
trueStars.sort(order='starID')

# Remove any stars that were observed but not fit
mask = np.in1d(trueStars['starID'], starsFit['starID'], assume_unique=True)
trueStars = trueStars[mask]

resid = starsFit['fitMag'] - trueStars['TrueMag']

resid = resid - np.median(resid)

print('median fitMag - TrueMag = %f' % np.median(resid))
print('std (fitMag - TrueMag) = %f' % np.std(resid))
print('robust RMS = %f' % robustRMS(resid))
rrms = robustRMS(resid)

plt.hist(resid, bins=100, range=(-4 * rrms, 4 * rrms))
plt.xlabel('Fit-True (mags)')
plt.ylabel('#')

plt.savefig('resid_hist.png')

healmap = healbin(np.radians(trueStars['ra']), np.radians(trueStars['dec']),
                  resid)
hp.mollview(healmap, min=-4 * rrms, max=4 * rrms, unit='Residuals (mag)')
plt.savefig('resid_map.png')