def make_summary(star, factor=2.5, clear=True): """ Update the database with a summary for the given star using the given factor. """ if clear: sql = "DELETE FROM summaries where factor = %f and ID = %d" % (factor, star) run_sql(sql) if len(get_summary_data(star, factor)) > 0: print "returning??" return points = make_radial_ratio_data(star) buckets = [[] for _ in range(int(360/factor))] for mag3, mag4, angle, radius, time in points: buckets[int(angle/factor)].append((mag3, mag4, radius)) for angle, bucket in enumerate(buckets): if bucket: bucket = recarray_wrap(bucket, names=["ratio3", "ratio4", "r"]) mags3 = bucket["ratio3"] mags4 = bucket["ratio4"] radii = bucket["r"] else: mags3, mags4, radii = [0], [0], [0] sql = "INSERT INTO summaries VALUES " + \ "(%d, %d, %f, %f, %f, %f, %f, %f, %f)" % \ (star, angle, factor, mean(mags3), std(mags3), mean(mags4), std(mags4), mean(radii), std(radii)) run_sql(sql)
def make_summary(star, factor=2.5, clear=True): """ Update the database with a summary for the given star using the given factor. """ if clear: sql = "DELETE FROM summaries where factor = %f and ID = %d" % (factor, star) run_sql(sql) if len(get_summary_data(star, factor)) > 0: print "returning??" return points = make_radial_ratio_data(star) buckets = [[] for _ in range(int(360 / factor))] for mag3, mag4, angle, radius, time in points: buckets[int(angle / factor)].append((mag3, mag4, radius)) for angle, bucket in enumerate(buckets): if bucket: bucket = recarray_wrap(bucket, names=["ratio3", "ratio4", "r"]) mags3 = bucket["ratio3"] mags4 = bucket["ratio4"] radii = bucket["r"] else: mags3, mags4, radii = [0], [0], [0] sql = "INSERT INTO summaries VALUES " + \ "(%d, %d, %f, %f, %f, %f, %f, %f, %f)" % \ (star, angle, factor, mean(mags3), std(mags3), mean(mags4), std(mags4), mean(radii), std(radii)) run_sql(sql)
def radial_data(data): """ Take a recarray of data with 'X' and 'Y' entries and return a recarray with 'r' and 'theta' entries representing the (X, Y) transformed to polar coordinates. """ x = data['X'] - c_x y = data['Y'] - c_y radius, angles = to_polar(x, y) angles = to_deg(angles) return recarray_wrap(zip(radius, angles), names=["r", "theta"])
def make_radial_ratio_data(star): """ Obtain radial coords and magnitude ratios for a given star. Returns a recarray with entries 'ratio3', 'ratio4', 'theta', 'r', 'time'. """ data = get_phot_data(star, ("Vmag", "smag", "mag3", "mag4", "X", "Y", "time"), ["mag3 < 100", "mag3 > 1"]) rad_data = radial_data(data) ratio3 = data['smag']#data['mag3']/data['Vmag'] ratio4 = data['mag4']/data['Vmag'] points = N.vstack((ratio3, ratio4, rad_data["theta"], rad_data["r"], data['time'])).T return recarray_wrap(points, names=["ratio3", "ratio4", "theta", "r", "time"])
def get_outliers(summary, points, factor): """ Calculate the outliers from a set of points. Returns a recarray of points with fields 'mag3', 'theta', 'r', 'time'. """ outliers = [] Z = 2.0 for mag3, mag4, angle, radius, time in points: avg_m = summary["AVG3"][int(angle/factor)] std_m = summary["STD3"][int(angle/factor)] if std_m == 0: std_m = 0.0001 if not (avg_m - Z*std_m <= mag3 <= avg_m + Z*std_m): outliers.append((mag3, angle, radius, time)) if len(points): print float(len(outliers))/len(points), len(outliers), len(points) return recarray_wrap(outliers, names=["mag3", "theta", "r", "time"])
def get_outliers(summary, points, factor): """ Calculate the outliers from a set of points. Returns a recarray of points with fields 'mag3', 'theta', 'r', 'time'. """ outliers = [] Z = 2.0 for mag3, mag4, angle, radius, time in points: avg_m = summary["AVG3"][int(angle / factor)] std_m = summary["STD3"][int(angle / factor)] if std_m == 0: std_m = 0.0001 if not (avg_m - Z * std_m <= mag3 <= avg_m + Z * std_m): outliers.append((mag3, angle, radius, time)) if len(points): print float(len(outliers)) / len(points), len(outliers), len(points) return recarray_wrap(outliers, names=["mag3", "theta", "r", "time"])
def make_radial_ratio_data(star): """ Obtain radial coords and magnitude ratios for a given star. Returns a recarray with entries 'ratio3', 'ratio4', 'theta', 'r', 'time'. """ data = get_phot_data(star, ("Vmag", "smag", "mag3", "mag4", "X", "Y", "time"), ["mag3 < 100", "mag3 > 1"]) rad_data = radial_data(data) ratio3 = data['smag'] #data['mag3']/data['Vmag'] ratio4 = data['mag4'] / data['Vmag'] points = N.vstack( (ratio3, ratio4, rad_data["theta"], rad_data["r"], data['time'])).T return recarray_wrap(points, names=["ratio3", "ratio4", "theta", "r", "time"])