def fit_edge_poly(xposs, xposs_missing, yposs, order): ''' fit_edge_poly fits a polynomial to the measured slit edges. This polynomial is used to extract spectra. fit_edge_poly computes a parabola, and fills in missing data with a parabola input- xposs, yposs [N]: The x and y positions of the slit edge [pix] order: the polynomial order ''' # First fit low order polynomial to fill in missing data fun = np.poly1d(Fit.polyfit_clip(xposs, yposs, 2)) xposs = np.append(xposs, xposs_missing) yposs = np.append(yposs, fun(xposs_missing)) # Remove any fits that deviate wildly from the 2nd order polynomial ok = np.abs(yposs - fun(xposs)) < 1 if not ok.any(): error("Flat is not well illuminated? Cannot find edges") raise Exception("Flat is not well illuminated? Cannot find edges") # Now refit to user requested order fun = np.poly1d(Fit.polyfit_clip(xposs[ok], yposs[ok], order)) yposs_ok = yposs[ok] res = fun(xposs[ok]) - yposs[ok] sd = np.std(res) ok = np.abs(res) < 2*sd # Check to see if the slit edge funciton is sane, # if it's not, then we fix it. pix = np.arange(2048) V = fun(pix) if np.abs(V.max() - V.min()) > 10: info ("Forcing a horizontal slit edge") print("Forcing a horizontal slit edge") tmp = yposs_ok[ok] fun = np.poly1d(np.median(tmp)) #fun = np.poly1d(np.median(yposs[ok])) return (fun, res, sd, ok)
def fit_edge_poly(xposs, xposs_missing, yposs, order): ''' fit_edge_poly fits a polynomial to the measured slit edges. This polynomial is used to extract spectra. fit_edge_poly computes a parabola, and fills in missing data with a parabola input- xposs, yposs [N]: The x and y positions of the slit edge [pix] order: the polynomial order ''' # First fit low order polynomial to fill in missing data fun = np.poly1d(Fit.polyfit_clip(xposs, yposs, 2)) xposs = np.append(xposs, xposs_missing) yposs = np.append(yposs, fun(xposs_missing)) # Remove any fits that deviate wildly from the 2nd order polynomial ok = np.abs(yposs - fun(xposs)) < 1 if not ok.any(): error("Flat is not well illuminated? Cannot find edges") raise Exception("Flat is not well illuminated? Cannot find edges") # Now refit to user requested order fun = np.poly1d(Fit.polyfit_clip(xposs[ok], yposs[ok], order)) yposs_ok = yposs[ok] res = fun(xposs[ok]) - yposs[ok] sd = np.std(res) ok = np.abs(res) < 2 * sd # Check to see if the slit edge funciton is sane, # if it's not, then we fix it. pix = np.arange(2048) V = fun(pix) if np.abs(V.max() - V.min()) > 10: info("Forcing a horizontal slit edge") print("Forcing a horizontal slit edge") tmp = yposs_ok[ok] fun = np.poly1d(np.median(tmp)) #fun = np.poly1d(np.median(yposs[ok])) return (fun, res, sd, ok)
print "Skipping: %i" % (x+delt*i) return map(np.array, (xposs, yposs, widths)) def fit_edge_poly(xposs, yposs, widths, order): ''' fit_edge_poly fits a polynomial to the measured slit edges. This polynomial is used to extract spectra. input- xposs, yposs [N]: The x and y positions of the slit edge [pix] widths [N]: the offset from end of one slit to beginning of another [pix] order: the polynomial order ''' fun = np.poly1d(Fit.polyfit_clip(xposs, yposs, order)) wfun = np.poly1d(Fit.polyfit_clip(xposs, widths, order)) res = fun(xposs) - yposs sd = np.std(res) ok = np.abs(res) < 2*sd return (fun, wfun, res, sd, ok) def data_quality_plots(results): y = 2028 toc = 0 slits = []