def selfid(data, sdata, ystart='middlerow', rstep=3): """Create a wavelength identification and rectification based on the data itself. The first step is to extract the line itself and then run specidentify on the data """ # setup the fiducial line if ystart == 'middlerow': ystart = int(0.5 * len(data)) else: ystart = int(ystart) sfluxes = sdata[ystart, :] xarr = np.arange(len(data[0])) function = 'polynomial' order = 2 blank = 0 inttype = 'interp' ws = WavelengthSolution.WavelengthSolution(xarr, xarr, function=function, order=order) ws.fit() ndstep = 50 nw_arr = xarr for j in range(0, ystart): dcoef = [2.0, 0.0, 0.0] nws = st.findxcor(xarr, sdata[j, :], xarr, sfluxes, ws, dcoef=dcoef, ndstep=ndstep, best=False, inttype=inttype, debug=False) data[j, :] = zeroshift(data[j, :], xarr, nws, blank=blank, inttype=inttype) for j in range(ystart, len(data) - 1): dcoef = [2.0, 0.0, 0.0] nws = st.findxcor(xarr, sdata[j, :], xarr, sfluxes, ws, dcoef=dcoef, ndstep=ndstep, best=False, inttype=inttype, debug=False) data[j, :] = zeroshift(data[j, :], xarr, nws, blank=blank, inttype=inttype) return data
def findzpd(self): """Find the zeropoint and dispersion for the source and plot of the new value """ dc=0.5*self.rms*self.ndstep #fixed at 0.1 of the dispersion dd=0.1*self.ws.coef[1] #set upt he docef values dcoef=self.ws.coef*0.0 dcoef[0]=dc dcoef[1]=dd self.ws=st.findxcor(self.xarr, self.farr, self.swarr, self.sfarr, self.ws, dcoef=dcoef, ndstep=self.ndstep, best=False, inttype='interp') self.plotArt() self.redraw_canvas()
def arcstraight(data, xarr, istart, ws=None, function='poly', order=3, rstep=1, nrows=1, dcoef=None, ndstep=50, log=None, verbose=True): """For a given image, assume that the line given by istart is the fiducial and then calculate the transformation between each line and that line in order to straighten the arc returns Wavlenght solution """ ImageSolution = {} # extract the central row oxarr = xarr.copy() ofarr = data[istart] print function, order ws = WavelengthSolution.WavelengthSolution(xarr, xarr, function, order) ws.fit() print ws.coef ImageSolution[istart] = ws if dcoef is None: docef = ws.coef * 0.0 dcoef[0] = 10.0 else: dcoef = np.array(dcoef) print dcoef data = nd.gaussian_filter(data, 3) # now step around the central row for i in range(rstep, int(0.5 * len(data)), rstep): for k in [istart - i, istart + i]: lws = getwsfromIS(k, ImageSolution) xarr = np.arange(len(data[k])) farr = apext.makeflat(data, k, k + nrows) nws = st.findxcor( xarr, farr, oxarr, ofarr, lws, dcoef=dcoef, ndstep=ndstep, best=True, inttype='interp', debug=False) ImageSolution[k] = nws print k, nws.coef return ImageSolution
def auto_arc_lens(arc_image, dbfile='wav.db', ndstep=20, logfile='salt.log'): """Automatically process an arc image for the SALT Lens project """ hdu = fits.open(arc_image) hdr = hdu[0].header if hdr['LAMPID'] == 'Xe' and hdr['GRATING'] == 'PG0900' and hdr['GRTILT'] == 15.875: print('Automatically processing arc image') data = hdu[1].data ystart = int(0.5 * len(data)) xarr = np.arange(len(data[ystart]), dtype='int64') farr = data[ystart] lampfile = os.path.dirname(__file__)+'/data/Xe.lens' guessfile = os.path.dirname(__file__)+'/data/lens.db' slines, sfluxes = st.readlinelist(lampfile) spectrum = Spectrum.Spectrum( slines, sfluxes, dw=0.1, stype='line', sigma=6) swarr = spectrum.wavelength sfarr = spectrum.flux * farr.max() / spectrum.flux.max() soldict = readsolascii(guessfile, {}) soldict = (soldict[soldict.keys()[0]]) ws = WavelengthSolution.WavelengthSolution( xarr, xarr, function=soldict[7], order=soldict[8]) ws.func.func.domain = soldict[11] ws.set_coef(soldict[10][2]) # start the pre processing dcoef = ws.coef * 0.0 dcoef[0] = 0.05 * ndstep dcoef[1] = 0.01 * ws.coef[1] ws = st.findxcor(xarr, farr, swarr, sfarr, ws, dcoef=dcoef, ndstep=ndstep, best=False, inttype='interp') xp, wp = st.crosslinematch(xarr, farr, slines, sfluxes, ws, res=6, mdiff=20, wdiff=10, sections=3, sigma=5, niter=5) ws = st.findfit(np.array(xp), np.array(wp), ws=ws, thresh=ws.thresh) print(ws) with logging(logfile, True) as log: iws = ai.AutoIdentify(xarr, data, slines, sfluxes, ws, farr=farr, method='Matchlines', rstep=100, istart=ystart, nrows=1, res=6, dres=0.25, mdiff=20, sigma=5, smooth=3, niter=5, dc=5, ndstep=ndstep, oneline=False, log=log, verbose=True) # get the basic information about the spectrograph dateobs = saltkey.get('DATE-OBS', hdu[0]) try: utctime = saltkey.get('UTC-OBS', hdu[0]) except SaltError: utctime = saltkey.get('TIME-OBS', hdu[0]) instrume = saltkey.get('INSTRUME', hdu[0]).strip() grating = saltkey.get('GRATING', hdu[0]).strip() grang = saltkey.get('GR-ANGLE', hdu[0]) grasteps = saltkey.get('GRTILT', hdu[0]) arang = saltkey.get('AR-ANGLE', hdu[0]) arsteps = saltkey.get('CAMANG', hdu[0]) rssfilter = saltkey.get('FILTER', hdu[0]) specmode = saltkey.get('OBSMODE', hdu[0]) masktype = saltkey.get('MASKTYP', hdu[0]).strip().upper() slitname = saltkey.get('MASKID', hdu[0]) slit = st.getslitsize(slitname) xbin, ybin = saltkey.ccdbin(hdu[0], arc_image) writeIS(iws, dbfile, dateobs=dateobs, utctime=utctime, instrume=instrume, grating=grating, grang=grang, grasteps=grasteps, arsteps=arsteps, arang=arang, rfilter=rssfilter, slit=slit, xbin=xbin, ybin=ybin, objid=None, filename=arc_image, log=log, verbose=True) print(iws) #self.findfit() else: lamp = hdr['LAMPID'] lampfile=iraf.osfn("pysalt$data/linelists/%s.salt" % lamp) lampfile = 'Xe.lens' specidentify(arc_image, lampfile, dbfile, guesstype='rss', guessfile=None, automethod='Matchlines', function='legendre', order=3, rstep=100, rstart='middlerow', mdiff=20, thresh=5, niter=5, smooth=3, inter=True, clobber=True, preprocess=True, logfile=logfile, verbose=True) print("Running specidenity in interactive mode")
def selfid(data, sdata, ystart='middlerow', rstep=3): """Create a wavelength identification and rectification based on the data itself. The first step is to extract the line itself and then run specidentify on the data """ # setup the fiducial line if ystart == 'middlerow': ystart = int(0.5 * len(data)) else: ystart = int(ystart) sfluxes = sdata[ystart, :] xarr = np.arange(len(data[0])) function = 'polynomial' order = 2 blank = 0 inttype = 'interp' ws = WavelengthSolution.WavelengthSolution( xarr, xarr, function=function, order=order) ws.fit() ndstep = 50 nw_arr = xarr for j in range(0, ystart): dcoef = [2.0, 0.0, 0.0] nws = st.findxcor( xarr, sdata[ j, :], xarr, sfluxes, ws, dcoef=dcoef, ndstep=ndstep, best=False, inttype=inttype, debug=False) data[ j, :] = zeroshift( data[ j, :], xarr, nws, blank=blank, inttype=inttype) for j in range(ystart, len(data) - 1): dcoef = [2.0, 0.0, 0.0] nws = st.findxcor( xarr, sdata[ j, :], xarr, sfluxes, ws, dcoef=dcoef, ndstep=ndstep, best=False, inttype=inttype, debug=False) data[ j, :] = zeroshift( data[ j, :], xarr, nws, blank=blank, inttype=inttype) return data