def readLcs2Fits(imgPath, imgFile, apSize, innSize, outSize, savePath): """ """ IM = ReadImgFITS(imgPath) IM._getFileName(imgFile) priHeader = IM.temp[0].header snapShot = IM.temp[0].data numFibre = priHeader['FIBREACT'] expTime = priHeader['EXPTIME'] timeZero = 0.0 cols_ext = [] for index in range(numFibre): fibre = priHeader['EXTEN_{:02}'.format(index + 1)] print('{}: fibre {}...'.format(imgFile, fibre)) imgCube = IM._getImage(fibre) # excute photometry frame, srcFlux, xCentre, yCentre, srcPixl, mSkyValue, quality = apPhotometry( imgCube, apSize, innSize, outSize) time = frame * expTime col1 = pf.Column(name='Time (sec)', format='E', array=time) col2 = pf.Column(name='SrcFlux (count)', format='E', array=srcFlux) col3 = pf.Column(name='XCentre (pixel)', format='E', array=xCentre) col4 = pf.Column(name='YCentre (pixel)', format='E', array=yCentre) col5 = pf.Column(name='SrcArea (pixel)', format='E', array=srcPixl) col6 = pf.Column(name='AvgSky (count)', format='E', array=mSkyValue) col7 = pf.Column(name='Quality (bool)', format='E', array=quality) cols = pf.ColDefs([col1, col2, col3, col4, col5, col6, col7]) tbhdu = pf.new_table(cols) cols_ext.append(tbhdu) IM.close() hdu = pf.PrimaryHDU(snapShot, priHeader) thdulist = pf.HDUList([hdu] + cols_ext) # Update extension header for jndex in range(numFibre): extTable = thdulist[jndex + 1] extTable.header.update('FIBRE', priHeader['EXTEN_{:02}'.format(jndex + 1)]) extTable.header.update('RA', priHeader['RA_{:02}'.format(jndex + 1)]) extTable.header.update('DEC', priHeader['DEC_{:02}'.format(jndex + 1)]) extTable.header.update('MAG', priHeader['MAG_{:02}'.format(jndex + 1)]) extTable.header.update('EQUINOX', priHeader['EQUINOX']) extTable.header.update('APERTURE', apSize, 'aperture radius in pixels') extTable.header.update('SKYRADIN', innSize, 'inner sky radius in pixels') extTable.header.update('SKYRADOU', outSize, 'outer sky radius in pixels') thdulist.writeto( '{}/{}'.format(savePath, imgFile), output_verify='fix' ) # pyfits 3.0.3 changes the behaviour of verify (default to 'exception'), but is reversed to 'fix' in 3.0.4
def testGfit(imgPath, imgFile, fibre, frame=0): """ """ IM = ReadImgFITS(imgPath) IM._getFileName(imgFile) imgCube = IM._getImage(fibre) IM.close() AP = Apphot(imgCube) AP._getInitPosition() iyPos, ixPos = AP.yPosition, AP.xPosition roughLevel = np.median(AP.imageCube[frame]) iHeight = AP.height - roughLevel mCrosX = np.mean(AP.imageCube[frame], axis=0) - roughLevel # bring the floor to ~ zero xAxis = np.arange(0, AP.xsize, 1) AP.oneDGaussianFit([iHeight, ixPos, 1.0], mCrosX, xAxis) fxPos, xS = AP.gMu, AP.gSigma CrosXFit = AP._gPeval(xAxis, [AP.gHeight, AP.gMu, AP.gSigma]) mCrosY = np.mean(AP.imageCube[frame], axis=1) - roughLevel # bring the floor to ~ zero yAxis = np.arange(0, mCrosY.size, 1) AP.oneDGaussianFit([iHeight, iyPos, 1.0], mCrosY, yAxis) fyPos, yS = AP.gMu, AP.gSigma CrosYFit = AP._gPeval(yAxis, [AP.gHeight, AP.gMu, AP.gSigma]) plt.figure(20) plt.clf() plt.subplot(1, 2, 1) plt.plot(mCrosX, 'k+') plt.plot(CrosXFit, 'r-') plt.text(fxPos, 80, '[{:.1f}, {:.1f}]'.format(fxPos, xS), horizontalalignment='center') plt.xlim(0, 40) plt.ylim(-20, 100) plt.title('From image in \n{}/{} f#{}'.format(imgFile, fibre, frame)) plt.subplot(1, 2, 2) plt.plot(mCrosY, 'k+') plt.plot(CrosYFit, 'r-') plt.text(fyPos, 80, '[{:.1f}, {:.1f}]'.format(fyPos, yS), horizontalalignment='center') plt.xlim(0, 40) plt.ylim(-20, 100) plt.show()
def readLcs2Fits(imgPath, imgFile, apSize, innSize, outSize, savePath): """ """ IM = ReadImgFITS(imgPath) IM._getFileName(imgFile) priHeader = IM.temp[0].header snapShot = IM.temp[0].data numFibre = priHeader['FIBREACT'] expTime = priHeader['EXPTIME'] timeZero = 0.0 cols_ext = [] for index in range(numFibre): fibre = priHeader['EXTEN_{:02}'.format(index+1)] print('{}: fibre {}...'.format(imgFile, fibre)) imgCube = IM._getImage(fibre) # excute photometry frame, srcFlux, xCentre, yCentre, srcPixl, mSkyValue, quality = apPhotometry(imgCube, apSize, innSize, outSize) time = frame*expTime col1 = pf.Column(name='Time (sec)', format='E', array=time) col2 = pf.Column(name='SrcFlux (count)', format='E', array=srcFlux) col3 = pf.Column(name='XCentre (pixel)', format='E', array=xCentre) col4 = pf.Column(name='YCentre (pixel)', format='E', array=yCentre) col5 = pf.Column(name='SrcArea (pixel)', format='E', array=srcPixl) col6 = pf.Column(name='AvgSky (count)', format='E', array=mSkyValue) col7 = pf.Column(name='Quality (bool)', format='E', array=quality) cols = pf.ColDefs([col1, col2, col3, col4, col5, col6, col7]) tbhdu = pf.new_table(cols) cols_ext.append(tbhdu) IM.close() hdu = pf.PrimaryHDU(snapShot, priHeader) thdulist = pf.HDUList([hdu] + cols_ext) # Update extension header for jndex in range(numFibre): extTable = thdulist[jndex+1] extTable.header.update('FIBRE', priHeader['EXTEN_{:02}'.format(jndex+1)]) extTable.header.update('RA', priHeader['RA_{:02}'.format(jndex+1)]) extTable.header.update('DEC', priHeader['DEC_{:02}'.format(jndex+1)]) extTable.header.update('MAG', priHeader['MAG_{:02}'.format(jndex+1)]) extTable.header.update('EQUINOX', priHeader['EQUINOX']) extTable.header.update('APERTURE', apSize, 'aperture radius in pixels') extTable.header.update('SKYRADIN', innSize, 'inner sky radius in pixels') extTable.header.update('SKYRADOU', outSize, 'outer sky radius in pixels') thdulist.writeto('{}/{}'.format(savePath, imgFile), output_verify='fix') # pyfits 3.0.3 changes the behaviour of verify (default to 'exception'), but is reversed to 'fix' in 3.0.4
def testGfit(imgPath, imgFile, fibre, frame=0): """ """ IM = ReadImgFITS(imgPath) IM._getFileName(imgFile) imgCube = IM._getImage(fibre) IM.close() AP = Apphot(imgCube) AP._getInitPosition() iyPos, ixPos = AP.yPosition, AP.xPosition roughLevel = np.median(AP.imageCube[frame]) iHeight = AP.height - roughLevel mCrosX = np.mean(AP.imageCube[frame], axis=0) - roughLevel # bring the floor to ~ zero xAxis = np.arange(0, AP.xsize, 1) AP.oneDGaussianFit([iHeight, ixPos, 1.0], mCrosX, xAxis) fxPos, xS = AP.gMu, AP.gSigma CrosXFit = AP._gPeval(xAxis, [AP.gHeight, AP.gMu, AP.gSigma]) mCrosY = np.mean(AP.imageCube[frame], axis=1) - roughLevel # bring the floor to ~ zero yAxis = np.arange(0, mCrosY.size, 1) AP.oneDGaussianFit([iHeight, iyPos, 1.0], mCrosY, yAxis) fyPos, yS = AP.gMu, AP.gSigma CrosYFit = AP._gPeval(yAxis, [AP.gHeight, AP.gMu, AP.gSigma]) plt.figure(20) plt.clf() plt.subplot(1,2,1) plt.plot(mCrosX, 'k+') plt.plot(CrosXFit, 'r-') plt.text(fxPos, 80, '[{:.1f}, {:.1f}]'.format(fxPos, xS), horizontalalignment='center') plt.xlim(0,40) plt.ylim(-20, 100) plt.title('From image in \n{}/{} f#{}'.format(imgFile, fibre, frame)) plt.subplot(1,2,2) plt.plot(mCrosY, 'k+') plt.plot(CrosYFit, 'r-') plt.text(fyPos, 80, '[{:.1f}, {:.1f}]'.format(fyPos, yS), horizontalalignment='center') plt.xlim(0,40) plt.ylim(-20, 100) plt.show()