def galfit_getcentralcoordinate(modelfile,coordorigin=1,verbose=True):
"""
Return the central coordinates of a GALFIT model extracted using the reference image WCS and the FITSECT keyword
--- INPUT ---
modelfile Path and name to GALFIT model fits file to retrieve central coordinates for
coordorigin Origin of coordinates in reference image to use when converting pixels to degrees (skycoord)
verbose Toggle verbosity
--- EXAMPLE OF USE ---
fileG = '/Volumes/DATABCKUP2/TDOSEextractions/models_cutouts/model8685multicomponent/model_acs_814w_candels-cdfs-02_cut_v1.0_id8685_cutout7p0x7p0arcsec.fits' # Gauss components
fileS = '/Volumes/DATABCKUP2/TDOSEextractions/models_cutouts/model8685multicomponent/model_acs_814w_candels-cdfs-02_cut_v1.0_id9262_cutout2p0x2p0arcsec.fits' # Sersic components
xpix, ypix, ra_model, dec_model = tu.galfit_getcentralcoordinate(fileG,coordorigin=1)
"""
if verbose: print ' - Will extract central coordinates from '+modelfile
refimg_hdr = pyfits.open(modelfile)[1].header
model_hdr = pyfits.open(modelfile)[2].header
imgwcs = wcs.WCS(tu.strip_header(refimg_hdr.copy()))
fit_region = model_hdr['FITSECT']
cutrange_low_x = int(float(fit_region.split(':')[0].split('[')[-1]))
cutrange_low_y = int(float(fit_region.split(',')[-1].split(':')[0]))
xsize = model_hdr['NAXIS1']
ysize = model_hdr['NAXIS2']
xpix = cutrange_low_x + int(xsize/2.)
ypix = cutrange_low_y + int(ysize/2.)
if verbose: print ' - Converting pixel position to coordinates using a pixel origin='+str(coordorigin)
skycoord = wcs.utils.pixel_to_skycoord(xpix,ypix,imgwcs,origin=coordorigin)
ra_model = skycoord.ra.value
dec_model = skycoord.dec.value
return xpix,ypix,ra_model,dec_model
# = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
评论列表
文章目录