def getAverageMagnitude(m, me, idx): if len(idx) > 1: m_good = m[idx] m_weight = 1.0 / me[idx]**2 flux_tmp = 10**(m_good/-2.5) flux_avg = statsWeighted.mean_wgt(flux_tmp, m_weight) flux_std = statsWeighted.std_wgt(flux_tmp, m_weight) m_avg = -2.5 * math.log10(flux_avg) me_avg = 2.5 * math.log10(math.e) * flux_std / flux_avg # Use the input magnitude errors if they are larger than # the spread in the magnitude measurements. This is because # we have so few measurements for some stars, there is a # reasonable change that the photometric errors are underestimated. # This is the conservative thing to do I think. magerr_avg = me[idx].mean() if magerr_avg > me_avg: me_avg = magerr_avg if len(idx) == 1: m_avg = m[idx[0]] me_avg = me[idx[0]] if len(idx) == 0: m_avg = 0.0 me_avg = 0.0 return m_avg, me_avg
def getAveragePosition(p, pe, idx): if (len(idx) > 1): p_good = p[idx] p_weight = 1.0 / pe[idx]**2 # Handle a rare case where pe == 0 due to not enough decimals in # our files. zeros = np.where(pe[idx] == 0)[0] non_zeros = np.where(pe[idx] != 0)[0] if len(zeros) > 0: min_err = pe[idx[non_zeros]].min() p_weight[zeros] = 1.0 / (min_err * 0.5) # for positions, get the weighted average # for errors, get the straight average p_avg = statsWeighted.mean_wgt(p_good, p_weight) #pe_avg = statsWeighted.std_wgt(p_good, p_weight) pe_avg = pe[idx].mean() # ------------------- # JLu had this next part originally, but we are already using # the average error, so not needed...for now ## Use the input magnitude errors if they are larger than ## the spread in the magnitude measurements. This is because ## we have so few measurements for some stars, there is a ## reasonable chance that the photometric errors are underestimated. ## This is the conservative thing to do I think. #poserr_avg = pe[idx].mean() #if poserr_avg > pe_avg: # pe_avg = poserr_avg # ------------------- if len(idx) == 1: p_avg = p[idx[0]] pe_avg = pe[idx[0]] if len(idx) == 0: p_avg = 0.0 pe_avg = 0.0 return p_avg, pe_avg
def makeNewRefList(alignRoot, refList, starPrefix='ep0'): print 'Making new reference list', refList s = starset.StarSet(alignRoot) # Get the zeropoint offset to convert to magRef = s.getArrayFromEpoch(0, 'mag') magLis = s.getArrayFromEpoch(1, 'mag') idx = np.where((magRef != 0) & (magLis != 0))[0] # Only use the first 10 stars if len(idx) > 10: idx = idx[0:10] zp = (magRef[idx] - magLis[idx]).mean() print 'Zeropoint for %s is %.2f' % (starPrefix, zp) _out = open(refList, 'w') for star in s.stars: inRef = False inLis = False if star.e[0].x > -999: inRef = True if star.e[1].x > -999: inLis = True if inRef and inLis: name = star.e[0].name # Rename new stars from the mosaiced images. # Don't rename reference list sources, so we can reject # them later on. if name.startswith('star') and starPrefix != None: name = star.e[1].name.replace('star', starPrefix) # get errors and combine them # centroid, distortion, and residual distortion xe0 = star.e[0].xpixerr_p ye0 = star.e[0].ypixerr_p # centroid, distortion, and residual distortion xe1 = star.e[1].xpixerr_p ye1 = star.e[1].ypixerr_p # align error xea = star.e[1].xpixerr_a yea = star.e[1].ypixerr_a # add the alignment error in quadrature to the frame's other errors xe1_tot = np.hypot(xe1, xea) ye1_tot = np.hypot(ye1, yea) m = star.e[1].mag + zp # get original and aligned positions, then take weighted ave # weight by each field's errors (which contain centroid, # distortion, and residual distortion errors already) x0 = star.e[0].xpix y0 = star.e[0].ypix x1 = star.e[1].xpix y1 = star.e[1].ypix xwt0 = 1. / xe0**2 ywt0 = 1. / ye0**2 xwt1 = 1. / xe1_tot**2 ywt1 = 1. / ye1_tot**2 x = statsWeighted.mean_wgt(np.array([x0,x1]), np.array([xwt0,xwt1])) y = statsWeighted.mean_wgt(np.array([y0,y1]), np.array([ywt0,ywt1])) # For the next reference list's new positional error, we'll # take the average error of the ref and lis errors xerr = (xe0 + xe1_tot) / 2.0 yerr = (ye0 + ye1_tot) / 2.0 else: if inRef: name = star.e[0].name x = star.e[0].xpix y = star.e[0].ypix xe = star.e[0].xpixerr_p ye = star.e[0].ypixerr_p m = star.e[0].mag # just maintain the frame's (centroid+distortion+residual) # errors xerr = xe yerr = ye if inLis: name = star.e[1].name # Rename new stars from the narrow camera stuff. # Don't rename wide camera sources, so we can reject # them later on. if name.startswith('star') and starPrefix != None: name = name.replace('star', starPrefix) x = star.e[1].xpix y = star.e[1].ypix xe = star.e[1].xpixerr_p ye = star.e[1].ypixerr_p xea = star.e[1].xpixerr_a yea = star.e[1].ypixerr_a m = star.e[1].mag + zp # just maintain the frame's (centroid+distortion+residual) # errors. xerr = xe yerr = ye date = star.years[0] _out.write('%-13s %6.3f %9.4f %11.5f %11.5f %8.5f %8.5f 1 1 1 1\n' % (name, m, date, x, y, xerr, yerr)) _out.close()