def generate_v_header(hdu, inhead, params): """ """ today = datetime.datetime.today() hdu.header = inhead.copy() hdu.header.set('ORIGIN', 'rmsynthesis.py', 'Origin of the data set') hdu.header.set('DATE', str(today), 'Date when the file was created') hdu.header.set('NAXIS', 3, 'Number of axes in the data array, must be 3') hdu.header.set('NAXIS3', params.nu.size, 'Length of the Frequency axis') # In FITS, the first pixel is 1, not 0!!! hdu.header.set('CRPIX3', 1, 'Reference pixel') hdu.header.set('CRVAL3', params.nu[0]) hdu.header.set('CDELT3', params.dnu) hdu.header.add_history('RMSYNTH: Stokes V cube generated by ' + 'rmsynthesis.py version ' + str(VERSION) + '.') hdu.header.add_history(' WARNING! The frequency axis is not linear. ' + 'Look in the') hdu.header.add_history(' accompanying _freqlist.txt file for ' + 'frequency axis information') # Get the reference pixel for the new image cpix_ra = (params.ra_lim[1] - params.ra_lim[0]) / 2. + 1. cpix_dec = (params.dec_lim[1] - params.dec_lim[0]) / 2. + 1. # Get the index of the new reference pixel in the old image cpix_ra_old = params.ra_lim[0] + cpix_ra - 1 cpix_dec_old = params.dec_lim[1] - cpix_dec + 1 # Find its sky coordinate wcs = WCS(inhead) if inhead['NAXIS'] == 4: crval_ra = wcs.wcs_pix2sky([[cpix_ra_old, cpix_dec_old, 0, 0]], 0)[0][0] crval_dec = wcs.wcs_pix2sky([[cpix_ra_old, cpix_dec_old, 0, 0]], 0)[0][1] if inhead['NAXIS'] == 3: crval_ra = wcs.wcs_pix2sky([[cpix_ra_old, cpix_dec_old, 0]], 0)[0][0] crval_dec = wcs.wcs_pix2sky([[cpix_ra_old, cpix_dec_old, 0]], 0)[0][1] hdu.header.set('NAXIS1', params.ra_lim[1] - params.ra_lim[0]) hdu.header.set('CRVAL1', crval_ra) hdu.header.set('CRPIX1', cpix_ra) hdu.header.set('NAXIS2', params.dec_lim[1] - params.dec_lim[0]) hdu.header.set('CRVAL2', crval_dec) hdu.header.set('CRPIX2', cpix_dec) try: hdu.header.__delitem__('NAXIS4') hdu.header.__delitem__('CTYPE4') hdu.header.__delitem__('CRVAL4') hdu.header.__delitem__('CRPIX4') hdu.header.__delitem__('CDELT4') hdu.header.__delitem__('CUNIT4') except: pass
def main(srcMaps=None, expCube=None, binnedExpMap=None, outname=None, IRFs='CALDB', index=2): if srcMaps is None: srcMaps = env['ccube'] expCube = env['lvtime'] binnedExpMap = env['bexpcube'] outname = env.get('mdlmap', 'modelcube.fits').replace('.fits', '_ps.fits') IRFs = env.get('irfs', 'CALDB') obs = BinnedObs(srcMaps=srcMaps, expCube=expCube, binnedExpMap=binnedExpMap, irfs=IRFs) with pyfits.open(srcMaps) as f: w = WCS(f[0].header) cpix = int(f[0].header['NAXIS1']) / 2 RA, DEC, e = w.wcs_pix2sky([[cpix, cpix, 0]], 0)[0] xmlfile = outname.replace('.fits', '') + '.xml' with open(xmlfile, 'w') as f: f.write(content_xml % (index, RA, DEC)) like1 = BinnedAnalysis(obs, xmlfile, optimizer='') os.remove(xmlfile) print 'creating Model Map...' like1.writeModelMap(outname) print 'Done!'
def generate_header(hdu, inhead, params): """ """ today = datetime.datetime.today() hdu.header = inhead.copy() hdu.header.set('ORIGIN', 'rmsynthesis.py', 'Origin of the data set') hdu.header.set('DATE', str(today), 'Date when the file was created') hdu.header.set('NAXIS', 3, 'Number of axes in the data array, must be 3') hdu.header.set('NAXIS3', params.nphi, 'Length of the Faraday depth axis') hdu.header.set('CTYPE3', 'Phi', 'Axis type') hdu.header.set('CUNIT3', 'rad/m/m', 'Axis units') # In FITS, the first pixel is 1, not 0!!! hdu.header.set('CRPIX3', 1, 'Reference pixel') hdu.header.set('CRVAL3', params.phi_min, 'Reference value') hdu.header.set('CDELT3', params.dphi, 'Size of pixel bin') # Get the reference pixel for the new image cpix_ra = (params.ra_lim[1] - params.ra_lim[0]) / 2. + 1. cpix_dec = (params.dec_lim[1] - params.dec_lim[0]) / 2. + 1. # Get the index of the new reference pixel in the old image cpix_ra_old = params.ra_lim[0] + cpix_ra - 1 cpix_dec_old = params.dec_lim[1] - cpix_dec + 1 # Find its sky coordinate wcs = WCS(inhead) if inhead['NAXIS'] == 4: crval_ra = wcs.wcs_pix2sky([[cpix_ra_old, cpix_dec_old, 0, 0]], 0)[0][0] crval_dec = wcs.wcs_pix2sky([[cpix_ra_old, cpix_dec_old, 0, 0]], 0)[0][1] if inhead['NAXIS'] == 3: crval_ra = wcs.wcs_pix2sky([[cpix_ra_old, cpix_dec_old, 0]], 0)[0][0] crval_dec = wcs.wcs_pix2sky([[cpix_ra_old, cpix_dec_old, 0]], 0)[0][1] hdu.header.set('CRVAL1', crval_ra) hdu.header.set('CRPIX1', cpix_ra) hdu.header.set('NAXIS1', params.ra_lim[1] - params.ra_lim[0]) hdu.header.set('CRVAL2', crval_dec) hdu.header.set('CRPIX2', cpix_dec) hdu.header.set('NAXIS2', params.dec_lim[1] - params.dec_lim[0]) C2 = 8.98755179e16 nus = numpy.sort(params.nu) dnu = params.dnu delta_l2 = C2 * (nus[0]**(-2) - nus[len(nus) - 1]**(-2)) l2min = 0.5 * C2 * ((nus[len(nus) - 1] + dnu)**(-2) + (nus[len(nus) - 1] - dnu)**(-2)) rmsf = 2. * math.sqrt(3) / delta_l2 maxscale = numpy.pi / l2min hdu.header.set('TFFWHM', round(rmsf, 2), 'Theoretical FWHM of the RMSF ' + ', rad/m/m') hdu.header.set('MAXSCL', round(maxscale, 2), 'Maximum scale in ' + 'Faraday depth rad/m/m') hdu.header.add_history('RMSYNTH: RM Synthesis performed by ' + 'rmsynthesis.py version ' + str(VERSION) + '.') if params.do_clean: hdu.header.add_history(' RM Clean performed. niter=' + str(params.niter) + ', gain=' + str(params.gain) + ', cutoff=' + str(params.cutoff)) else: hdu.header.add_history(' No RM Clean performed.') hdu.header.add_history(' See the accompanying _rmsf.txt for ' + 'RMSF information.') try: hdu.header.__delitem__('NAXIS4') hdu.header.__delitem__('CTYPE4') hdu.header.__delitem__('CRVAL4') hdu.header.__delitem__('CRPIX4') hdu.header.__delitem__('CDELT4') hdu.header.__delitem__('CUNIT4') except: pass
def dg_coords(self, hdr): pw = WCS(header=hdr) _x, _y = pw.wcs_pix2sky(self.xlist, self.ylist, 1) return zip(list(_x), list(_y))
nxpix = int(env['npix3']) nypix = int(env['npix3']) delta = float(env['binszts']) proj = env['proj'] Npix = int(env['Npix']) if nxpix % Npix != 0 or nypix % Npix != 0: print 'invalid pixel number!!' exit(1) option = env.get('option', ',24h').split(',') if len(option) != 2: exit(1) w = WCS(naxis=2) w.wcs.crpix = [(nxpix + 1) / 2., (nypix + 1) / 2.] w.wcs.cdelt = np.array([-delta, delta]) w.wcs.crval = [ra, dec] w.wcs.ctype = ['RA---%s' % proj, 'DEC--%s' % proj] w.wcs.equinox = 2000.0 head = w.to_header() x = np.array([Npix * (i + 0.5) - 0.5 for i in range(nxpix / Npix)]) y = np.array([Npix * (i + 0.5) - 0.5 for i in range(nypix / Npix)]) XX, YY = np.meshgrid(x, y) NN = nxpix * nypix / Npix**2