def doarcfitfunc(p,xdata,ydata,scidata,model,coeff): par = special_functions.build_coeff(p,coeff) scidata = scidata.astype(scipy.float64) z = special_functions.genfunc(xdata,ydata,par).astype(scipy.float64) z = z.reshape((1,scidata.size)) resample = ndimage.map_coordinates(model,z,output=scipy.float64,cval=-1) diff = (scidata - resample)/scipy.sqrt(abs(resample)) return diff
def myopt2(p, x, z, model, skyx, sky, skymodel, r, o): par = special_functions.unpack_coeff(p) coeff, ier = optimize.leastsq(skyarcfit, par, (x, z, model, skyx, sky, skymodel, p, r, o), maxfev=100000) par = special_functions.build_coeff(coeff, p) return par
def myoptimize(p, x, z, model, model2=None): par = special_functions.unpack_coeff(p) mask = ndimage.maximum_filter(z, 3) coeff, ier = optimize.leastsq(arcfitfunc, par, (x, z, model, p, model2, mask), maxfev=100000) par = special_functions.build_coeff(coeff, p) return par
def skyopt(p, x, data, model): par = special_functions.unpack_coeff(p).tolist() wave = special_functions.genfunc(x, 0, p).astype(scipy.float64) sky = interpolate.splev(wave, model).astype(scipy.float64) ratio = scipy.median(data) / scipy.median(sky) offset = 0. par.append(ratio) par.append(offset) coeff, ier = optimize.leastsq(skyfit, par, (x, data, model, p), maxfev=100000) return special_functions.build_coeff(coeff, p), coeff[-2], coeff[-1]
def skyfit(p, x, data, model, tmp): par = special_functions.build_coeff(p[:-2], tmp) """ Test for increasing function... """ tmp = special_functions.genfunc(x, 0., par).astype(scipy.float32) diff = signal.convolve(tmp, [1., -1.], mode='same')[10:-10].copy() if diff[diff < 0].size > 0: return scipy.ones(x.size) * 1.e9 data = data.astype(scipy.float64) z = special_functions.genfunc(x, 0, par).astype(scipy.float64) sky = interpolate.splev(z, model).astype(scipy.float64) sky *= p[-2] return (sky - data) / scipy.sqrt(abs(sky))
def arcfitfunc(p, x, data, model, tmp, model2=None, mask=None): par = special_functions.build_coeff(p, tmp) """ Test for increasing function... """ tmp = special_functions.genfunc(x, 0., par).astype(scipy.float32) diff = signal.convolve(tmp, [1., -1.], mode='same')[10:-10].copy() if diff[diff < 0].size > 0: return scipy.ones(x.size) * 1.e9 data = data.astype(scipy.float64) z = special_functions.genfunc(x, 0, par).astype(scipy.float64) mod = interpolate.splev(z, model).astype(scipy.float64) if model2 is not None: mod += interpolate.splev(z, model2).astype(scipy.float64) mod = mod * data.max() / mod.max() + scipy.median(data) diff = (data - mod) / scipy.sqrt(abs(mod)) return diff
def skyarcfit(p, x, data, model, skyx, sky, skymodel, tmp, r, o): par = special_functions.build_coeff(p, tmp) """ Test for increasing function... """ tmp = special_functions.genfunc(x, 0., par).astype(scipy.float32) diff = signal.convolve(tmp, [1., -1.], mode='same')[10:-10].copy() if diff[diff < 0].size > 0: return scipy.ones(x.size) * 1.e9 data = data.astype(scipy.float64) z = special_functions.genfunc(skyx, 0, par).astype(scipy.float64) skymod = interpolate.splev(z, skymodel).astype(scipy.float64) skymod = (skymod) * r # skymod = skymod*scipy.median(sky)/scipy.median(skymod) z = special_functions.genfunc(x, 0, par).astype(scipy.float64) mod = interpolate.splev(z, model).astype(scipy.float64) mod = mod * data.max() / mod.max() + scipy.median(data) diff1 = (data - mod) / scipy.sqrt(abs(mod)) # diff2 = (sky-skymod)/scipy.sqrt(abs(sky))**0.25 diff2 = (sky - skymod) return scipy.concatenate((diff1, diff2))
def arcfitfunc(p,x,data,scale,model,tmp,model2=None): par = special_functions.build_coeff(p,tmp) """ Test for increasing function... """ tmp = par['coeff'][1:].copy() for i in range(tmp.size): tmp[i] *= (i+1.) tmp = {'coeff':tmp.copy(),'type':par['type']} t = special_functions.genfunc(x,0,par).astype(scipy.float32) if t[t<0].size>0: return scipy.ones(x.size)*1.e9 data = data.astype(scipy.float64) z = special_functions.genfunc(x,0,par).astype(scipy.float64) mod = interpolate.splev(z,model).astype(scipy.float64) if model2 is not None: mod += interpolate.splev(z,model2).astype(scipy.float64) mod = mod*data.max()/mod.max() + scipy.median(data) diff = (data-mod)/scipy.sqrt(abs(mod)) return diff
def myoptimize(p,x,z,scale,model,model2=None): par = special_functions.unpack_coeff(p) coeff,ier = optimize.leastsq(arcfitfunc,par,(x,z,scale,model,p,model2),maxfev=100000) par = special_functions.build_coeff(coeff,p) return par
def arcfitfunc2(p,x,y,z,model): par = special_functions.unpack_coeff(p) coeff,ier = optimize.leastsq(doarcfitfunc,par,(x,y,z,model,p),maxfev=100000) return special_functions.build_coeff(coeff,p)