def find_ccd_limits_interp(self, write=False): # TODO SHOULD THIS BE A WAVEFUNC METHOD ? n = self.orders.size det_wl_lim = np.empty([self.ndet*2, n]) # detector x positions in mm # NOTE does not take detector tilt into account x_det = np.array( [self.xdl_le, self.xdl_re, self.xdm_le, self.xdm_re, self.xdr_le, self.xdr_re]) log.debug("Detector edges = %s mm", x_det) for i in xrange(n): m = self.orders[i] # fn = os.path.splitext(codevparsed_path % (self.band, self.echang, m))[0] + ".npy" _m, wl, xbot, xmid, xtop, yb, ymid, yt, slitheight, phi = get_codev_files(self, m) inds = np.argsort(wl) wl = wl[inds] xbot = xbot[inds] xmid = xmid[inds] xtop = xtop[inds] fxbot = InterpolatedUnivariateSpline(xbot, wl) fxmid = InterpolatedUnivariateSpline(xmid, wl) fxtop = InterpolatedUnivariateSpline(xtop, wl) wlpbot = fxbot(x_det) wlpmid = fxmid(x_det) wlptop = fxtop(x_det) wlp = wlpmid det_wl_lim[:, i] = wlp log.info("Wavelength limits for order %s found.", m) self.det_wl_lim = det_wl_lim self.wmin = self.det_wl_lim.min() self.wmax = self.det_wl_lim.max() if write: # WRITE TO ETC OUTPUT FILE pass pass
def interp(self, m, waves, slit_x, slit_y): # fn = os.path.join(codevparsednpy_path % (self.band, self.echang, m)) # log.info("Loading '%s'", fn) _m, wl, xb, xmid, xt, yb, ymid, yt, slitheight, phi = get_codev_files(self, m) inds = np.argsort(wl) wl = wl[inds] xbot = xb[inds] xmid = xmid[inds] xtop = xt[inds] ybot = yb[inds] ymid = ymid[inds] ytop = yt[inds] phi = phi[inds] buff = 2.0 * np.median(np.diff(wl)) # interpolation limit buffer log.info("Extending interpolation boundaries by %s Ang", buff) # EXTEND BOUNDARIES TO AVOID GSL INTERPOLATION ERROR fxb = InterpolatedUnivariateSpline(wl, xbot) fxm = InterpolatedUnivariateSpline(wl, xmid) fxt = InterpolatedUnivariateSpline(wl, xtop) fyb = InterpolatedUnivariateSpline(wl, ybot) fym = InterpolatedUnivariateSpline(wl, ymid) fyt = InterpolatedUnivariateSpline(wl, ytop) fphi = InterpolatedUnivariateSpline(wl, phi) # APPEND NEW ENDPOINTS wmin = np.concatenate((wl, waves)).min() - buff wmax = np.concatenate((wl, waves)).max() + buff wl = np.insert(wl, 0, wmin) wl = np.append(wl, wmax) xbot = np.insert(xbot, 0, fxb(wmin)) xbot = np.append(xbot, fxb(wmax)) xmid = np.insert(xmid, 0, fxm(wmin)) xmid = np.append(xmid, fxm(wmax)) xtop = np.insert(xtop, 0, fxt(wmin)) xtop = np.append(xtop, fxt(wmax)) ybot = np.insert(ybot, 0, fyb(wmin)) ybot = np.append(ybot, fyb(wmax)) ymid = np.insert(ymid, 0, fym(wmin)) ymid = np.append(ymid, fym(wmax)) ytop = np.insert(ytop, 0, fyt(wmin)) ytop = np.append(ytop, fyt(wmax)) phi = np.insert(phi, 0, fphi(wmin)) phi = np.append(phi, fphi(wmax)) # SEND TO C FUNCTION nxpix = self.det_dims[1] nypix = self.det_dims[0] dpix = self.dpix slit_ratio = self.slit_ratio n = slit_x.size cn = wl.size xdl_0 = self.xdl_0 xdm_0 = self.xdm_0 xdr_0 = self.xdr_0 ydl_0 = self.ydl_0 ydm_0 = self.ydm_0 ydr_0 = self.ydr_0 tau_dl = self.tau_dl tau_dm = self.tau_dm tau_dr = self.tau_dr func = ci.raytrace.raytrace_interp_bin func.argtypes = [ ct.c_int, # nxpix ct.c_int, # nypix ct.c_double, # dpix ct.c_double, # xdl_0 ct.c_double, # xlm_0 ct.c_double, # xdr_0 ct.c_double, # ydl_0 ct.c_double, # ydm_0 ct.c_double, # ydr_0 ct.c_double, # tau_dl ct.c_double, # tau_dm ct.c_double, # tau_dr ct.c_double, # slit_ratio ct.c_ulong, # nslit ct.c_uint, # cn ci.array_1d_double, # cwl ci.array_1d_double, # cxb ci.array_1d_double, # cxm ci.array_1d_double, # cxt ci.array_1d_double, # cyb ci.array_1d_double, # cym ci.array_1d_double, # cyt ci.array_1d_double, # cphi ci.array_1d_double, # waves ci.array_1d_double, # slit_x ci.array_1d_double, # slit_y ci.array_2d_uint, # outarr ci.array_2d_double] # outwaves Hmm.... func.restype = None log.info("Raytracing order %s...", m) func(nxpix, nypix, dpix, xdl_0, xdm_0, xdr_0, ydl_0, ydm_0, ydr_0, tau_dl, tau_dm, tau_dr, slit_ratio, n, cn, wl, xbot, xmid, xtop, ybot, ymid, ytop, phi, waves, slit_x, slit_y, self.outarr, self.outwaves)