def make_blanks(gal, header, cubefilename, clobber=True): lrange = gal.l.deg.min()+15/3600.,gal.l.deg.max()+15/3600. brange = gal.b.deg.min()+15/3600.,gal.b.deg.max()+15/3600. print "Map extent: %0.2f < l < %0.2f, %0.2f < b < %0.2f" % (lrange[0], lrange[1], brange[0], brange[1]) pixsize = 5*u.arcsec naxis1 = (lrange[1]-lrange[0])/(pixsize.to(u.deg).value) naxis2 = (brange[1]-brange[0])/(pixsize.to(u.deg).value) restfreq = (header['RESTF']*u.MHz) bmaj = (1.22*10*u.m / restfreq.to(u.m,u.spectral()))*u.radian makecube.generate_header(np.mean(lrange), np.mean(brange), naxis1=naxis1, naxis2=naxis2, naxis3=4096, coordsys='galactic', ctype3='VELO-LSR', bmaj=bmaj.to(u.deg).value, bmin=bmaj.to(u.deg).value, pixsize=pixsize.to(u.arcsec).value, cunit3='km/s', output_flatheader='header.txt', output_cubeheader='cubeheader.txt', cd3=header['VRES'], crval3=-1*header['VRES']*header['RCHAN'], crpix3=1, clobber=True, bunit="K", restfreq=restfreq.to(u.Hz).value, radio=True) makecube.make_blank_images(cubefilename, clobber=clobber)
def make_blanks_merge(cubefilename, lowhigh='low', clobber=True): pixsize = 5*u.arcsec naxis1 = 950 naxis2 = 300 restfreq = 218222.192*u.MHz bmaj = (1.22*10*u.m / restfreq.to(u.m,u.spectral()))**-1*u.radian cd3 = ((1*u.km/u.s)/constants.c * 218.2*u.GHz).to(u.Hz).value naxis3 = int(np.ceil(((1.0*u.GHz / (218.2*u.GHz) * constants.c) / (u.km/u.s)).decompose().value)) makecube.generate_header(0.35, -0.075, naxis1=naxis1, naxis2=naxis2, naxis3=naxis3, coordsys='galactic', bmaj=bmaj.to(u.deg).value, bmin=bmaj.to(u.deg).value, pixsize=pixsize.to(u.arcsec).value, cunit3='Hz', ctype3='FREQ', output_flatheader='header.txt', output_cubeheader='cubeheader.txt', cd3=cd3, crval3=216.8e9 if lowhigh=='low' else 218e9, crpix3=1, clobber=True, bunit="K", restfreq=restfreq.to(u.Hz).value, radio=True) makecube.make_blank_images(cubefilename, clobber=clobber)
def make_blanks_freq(gal, header, cubefilename, clobber=True): """ complete freq covg """ lrange = gal.l.deg.min()+15/3600.,gal.l.deg.max()+15/3600. brange = gal.b.deg.min()+15/3600.,gal.b.deg.max()+15/3600. print "Map extent: %0.2f < l < %0.2f, %0.2f < b < %0.2f" % (lrange[0], lrange[1], brange[0], brange[1]) pixsize = 5*u.arcsec naxis1 = int((lrange[1]-lrange[0])/(pixsize.to(u.deg).value)+10) naxis2 = int((brange[1]-brange[0])/(pixsize.to(u.deg).value)+10) restfreq = (header['RESTF']*u.MHz) bmaj = (1.22*10*u.m / restfreq.to(u.m,u.spectral()))*u.radian rchan = header['RCHAN'] #scalefactor = 1./downsample_factor #crpix3 = (rchan-1)*scalefactor+0.5+scalefactor/2. makecube.generate_header(np.mean(lrange), np.mean(brange), naxis1=naxis1, naxis2=naxis2, naxis3=header['NCHAN'], coordsys='galactic', bmaj=bmaj.to(u.deg).value, bmin=bmaj.to(u.deg).value, pixsize=pixsize.to(u.arcsec).value, cunit3='Hz', ctype3='FREQ', output_flatheader='header.txt', output_cubeheader='cubeheader.txt', cd3=header['FRES']*1e6, crval3=restfreq.to(u.Hz).value, crpix3=rchan, clobber=True, bunit="K", restfreq=restfreq.to(u.Hz).value, radio=True) makecube.make_blank_images(cubefilename, clobber=clobber)
import astropy.io.fits as pyfits from astropy import units as u import itertools import sys from sdpy import makecube,make_off_template,calibrate_map_scans import numpy as np from paths import outpath # to ignore div-by-zero errors? np.seterr(all='ignore') cubename = os.path.join(outpath,'CMZ_East_H2CO22_cube') # 0.5x0.2 deg = 30x12' makecube.generate_header(0.466, -0.025, naxis1=200, naxis2=150, pixsize=15, naxis3=800, cd3=0.5, clobber=True, cunit3='km/s', crval3=0.0, restfreq=14.48848e9) makecube.make_blank_images(cubename,clobber=True) files = [os.path.join(outpath,x) for x in ( '15B_129_1_19to76_H1_5_F2.fits', '15B_129_1_77to134_H1_5_F2.fits', '15B_129_1_149to194_H1_5_F2.fits', '15B_129_1_196to242_H1_5_F2.fits', '15B_129_1_248to305_H1_5_F2.fits', '15B_129_1_306to352_H1_5_F2.fits', '15B_129_1_19to76_H2_5_F2.fits', '15B_129_1_77to134_H2_5_F2.fits', '15B_129_1_149to194_H2_5_F2.fits', '15B_129_1_196to242_H2_5_F2.fits', '15B_129_1_248to305_H2_5_F2.fits', '15B_129_1_306to352_H2_5_F2.fits',
for species in all_species: for name,shape in zip(names,shapes): cubename = os.path.join(outpath,'cube_{name}_{species}'.format(name=name, species=species)) print name,shape,cubename naxis3 = (max(velocityrange)-min(velocityrange)) / cd3 crval3 = (max(velocityrange)+min(velocityrange)) / 2. makecube.generate_header(shape[0], shape[1], naxis1=shape[2], naxis2=shape[3], pixsize=15, naxis3=naxis3, cd3=cd3, clobber=True, restfreq=all_species[species], crpix3=naxis3/2., crval3=crval3, cunit3='km/s', output_cubeheader="{name}_{species}_cubeheader.txt".format(name=name, species=species), output_flatheader="{name}_{species}_header.txt".format(name=name, species=species), bmaj=28/3600., bmin=28/3600.) makecube.make_blank_images(cubename,clobber=True, cubeheader="{name}_{species}_cubeheader.txt".format(name=name, species=species), flatheader="{name}_{species}_header.txt".format(name=name, species=species), ) log.info("Completed blank making {0}".format(species)) for scan,name,session in zip(scans,names,sessions): cubename = os.path.join(outpath,'cube_{name}_{species}'.format(name=name, species=species)) for sm,fd in samplers_feeds_mapping.items(): if sampler_lines[sm] != species: print "Skipping {0} because it's not in this map. ({1},{2}): {3}".format(species, sm, fd, sampler_lines[sm]) continue else: print name,cubename fn = os.path.join(outpath, "{prefix}_{scan1}to{scan2}_{sampler}_{feed}.fits".format(scan1=scan[0],
-0.025, naxis1=200, naxis2=150, pixsize=15, naxis3=naxis3, cd3=cdelt3, cunit3=cunit3, clobber=True, ctype3=ctype3, crval3=restfreq if ctype3 == "FREQ" else 0.0, output_flatheader=cubename + "flatheader.txt", output_cubeheader=cubename + "cubeheader.txt", restfreq=restfreq, ) makecube.make_blank_images( cubename, flatheader=cubename + "flatheader.txt", cubeheader=cubename + "cubeheader.txt", clobber=True ) files = [ x for obsrun in scanranges for scan1, scan2 in scanranges[obsrun] for x in [ os.path.join( outpath, fntemplate.format(scan1, scan2, samplers[ii], sampler_feeds[samplers[ii][0]], obsrun=obsrun) ) for ii in range(len(samplers)) ] ] iterator = makecube.freq_iterator if ctype3 == "FREQ" else makecube.velo_iterator
cubename_supersampled = "/Users/adam/work/h2co/maps/w51/W51_H213CO11_cube_supersampled" makecube.generate_header( glon, glat, naxis1=naxis1, naxis2=naxis2, pixsize=15, naxis3=int(naxis3), cd3=cd3, crval3=crval3, clobber=True, restfreq=linefreq, author="Adam Ginsburg", ) makecube.make_blank_images(cubename_supersampled, clobber=True) files = [ "W51_h213coW_spectra_0910.fits", "W51_h213coW_spectra_0911.fits", "W51_h213coW_spectra_0912.fits", "W51_h213coW_spectra_0915.fits", ] for fn in files: fullfn = fix_TDIM_in_header(prefix + fn) makecube.add_file_to_cube( fullfn, cubename_supersampled + ".fits", add_with_kernel=True, kernel_fwhm=20.0 / 3600.0,
# dumb debug stuff vels = crval3 + cd3 * (np.arange(naxis3) + 1 - naxis3 / 2 - 1) # this will probably cause an error but I must insist.. #if velocityrange[0]<=vels.min() or velocityrange[1]>=vels.max(): # raise ValueError("Add more points. Something's going to be out of range for stupid star stupid link") makecube.generate_header(49.209553, -0.277137, naxis1=192, naxis2=128, pixsize=24, naxis3=naxis3, cd3=cd3, crval3=crval3, clobber=True, restfreq=14.488479e9) makecube.make_blank_images(cubename_lores, clobber=True) for fn in [filename]: print "Adding file %s" % fn fullfn = fn makecube.add_file_to_cube(fullfn, cubename_lores + ".fits", add_with_kernel=True, kernel_fwhm=50. / 3600., nhits=cubename_lores + "_nhits.fits", diagnostic_plot_name=fullfn.replace( '.fits', '_data_scrubbed.png'), velocityrange=velocityrange, excludefitrange=[40, 75], noisecut=1.0) # more aggressive noisecut