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 os
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',
shapes = ([0.20298, -0.03243,40,40],
          [-0.01221,-0.07189,40,40],
          [0.20298, -0.03243,40,40])

# nothing below here needs editing

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])
    if linefreq == 0:
        continue
        
    # 7/29/2014: remove non-superresolution maps
    # 1/10/2014: add "superresolution" maps
    vmin = 30
    vmax = 90
    velocityrange = [-50,150]

    #makecube.generate_header(49.523158,-0.34987466,naxis1=96,naxis2=96,pixsize=20,naxis3=1600,cd3=0.5,clobber=True,restfreq=4.8296594e9)
    #makecube.generate_header(49.353568,-0.2982199,naxis1=144,naxis2=96,pixsize=20,naxis3=1600,cd3=0.5,clobber=True,restfreq=4.8296594e9)
    # reduced to CD3 = 1.0, naxis3 = 350 because of size and because the arecibo spectra looked artificially smoothed
    cd3 = 1.0
    crval3 = 50.0
    naxis3 = int((velocityrange[1]-velocityrange[0]) / cd3)
    makecube.generate_header(49.209553,-0.277137,naxis1=308,naxis2=205,pixsize=15,naxis3=int(naxis3),cd3=cd3,crval3=crval3,clobber=True,
                             restfreq=linefreq, author='Adam Ginsburg')
    cubename = '/Users/adam/work/h2co/maps/w51/W51_%slpha_cube_supersampled' % linename
    makecube.make_blank_images(cubename,clobber=True)

    for date in ('0910','0911','0912','0915',):
        fn = '/Users/adam/observations/arecibo/2012{date}/W51_{line}_spectra_{date}.fits'.format(line=linename,date=date)
        if not os.path.exists(fn):
            fn = '/Users/adam/observations/arecibo/20120910/W51_{line}_spectra_{date}.fits'.format(line=linename,date=date)
        log.info(" ".join([str(x) for x in (fn, velocityrange, linename, linefreq)]))
        if os.path.exists(fn):
            makecube.add_file_to_cube(fn,
                                      cubename+'.fits',
                                      add_with_kernel=True,
                                      kernel_fwhm=20./3600.,
                                      nhits=cubename+'_nhits.fits',
                                      velocityrange=velocityrange,
    ),
    ("CMZ_East_H2C18O_cube", 13.16596e9, ["A1_7", "A2_7", "E1_7", "E2_7"], "km/s", "VRAD", 800, 0.5),
    ("CMZ_East_13.0_cube", 13.0e9, ["C1_0", "C2_0", "G2_0", "G1_0"], "Hz", "FREQ", 15000, 1e5),
    ("CMZ_East_14.5_cube", 14.5e9, ["C1_0", "C2_0", "G2_0", "G1_0"], "Hz", "FREQ", 15000, 1e5),
):

    cubename = os.path.join(outpath, cubename)

    makecube.generate_header(
        0.466,
        -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]
Example #8
0
filename = '/Users/adam/observations/gbt/W51map/Session17_111to186_D37_F2.fits'

cubename_lores = 'test'
velocityrange=[-50,150]
cd3 = 1.0
#cd3 = 1.0 # Arecibo is limited to 0.64 because one of the receivers went bad at hi-res mode once
#naxis3 = int(np.ceil((velocityrange[1]-velocityrange[0])/cd3))+4 # +4 is BAD!  don't do that.
naxis3 = int((velocityrange[1]-velocityrange[0]) / cd3) + 1 # +1 is good: include -50
crval3 = 50.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
from fix_tdim import fix_TDIM_in_header
from sdpy import makecube
from makecube_pars import glon, glat, naxis1, naxis2, naxis3, vels, crval3, cd3, vmin, vmax, velocityrange

prefix = "/Users/adam/observations/arecibo/20120910/"

linefreq = 4.59309e9

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",
]
import os
import astropy.io.fits as pyfits
from astropy.io import fits
import itertools
import sys
from sdpy import makecube
import numpy as np
np.seterr(all='ignore')
from paths import outpath

cubename=outpath+'LimaBean_H2CO11_cube'
#cubename_discrete='LimaBean_H2CO11_cube_discrete'
# 15' x 12 '
#makecube.generate_header(0.256, 0.0220, naxis1=24, naxis2=24, pixsize=60,
#        naxis3=2400, cd3=1.0, clobber=True, restfreq=4.8296594e9)
makecube.generate_header(0.256, 0.0220, naxis1=100, naxis2=100, pixsize=15,
                         naxis3=800, cd3=1.0, clobber=True, restfreq=4.8296594e9)
makecube.make_blank_images(cubename,clobber=True)
#makecube.make_blank_images(cubename_discrete,clobber=True)

files = [outpath+'12B_221_6to21_A13_F1.fits',
         outpath+'12B_221_6to21_A9_F1.fits',
         # there was one noisy scan, so the whole damned thing gets commented out
         #outpath+'12B_221_22to32_A13_F1.fits',
         #outpath+'12B_221_22to32_A9_F1.fits',
         ]

for fn in files:
    makecube.add_file_to_cube(fn,
                              cubename+'.fits', nhits=cubename+'_nhits.fits',
                              wcstype='V', 
                              chmod=True,
pfx = 'W51_TSPEC_kband'
prefilter = True
if prefilter:
    cubefilename = pfx+"_cube_filtered.fits"
    nhitsfilename = pfx+"_cube_filtered_nhits.fits"
else:
    cubefilename = pfx+"_cube.fits"
    nhitsfilename = pfx+"_cube_nhits.fits"

# Allison: Check these parameters.  Make sure the cube is big enough.
# Let's start with making just K-band, so 20300 - 24300
makecube.generate_header(290.94251, 14.4748, naxis1=400, naxis2=400,
                         naxis3=4648, coordsys='radec', ctype3='WAVE',
                         crval3=22300,
                         cd3=1.0,
                         cunit3='Angstrom',
                         pixsize=1, bunit='erg/s/cm2/AA',
                         output_cubeheader='cube.hdr',
                         output_flatheader='flat.hdr',clobber=True)

if True: # not os.path.exists(cubefilename):
    cubeheader = pyfits.Header.fromtextfile('cube.hdr',endcard=False)
    cubewcs = wcs.WCS(cubeheader)

    cubeshape = [cubeheader['NAXIS%i' % i] for i in (3,2,1)]
    print "Making blank cube with size ",cubeshape
    blankcube = np.zeros(cubeshape,dtype='float32')

    cubefitsfile = pyfits.PrimaryHDU(data=blankcube, header=cubeheader)
    print "Writing blank cube to disk"
    cubefitsfile.writeto(cubefilename, clobber=True)
outdir = '/Users/adam/work/h2co/maps/w51/'
cubename_supersampled = outdir+'W51_h77a_pyproc_cube_supersampled'
velocityrange=[-50,150]
cd3 = 1.0
#cd3 = 1.0 # Arecibo is limited to 0.64 because one of the receivers went bad at hi-res mode once
#naxis3 = int(np.ceil((velocityrange[1]-velocityrange[0])/cd3))+4 # +4 is BAD!  don't do that.
naxis3 = int((velocityrange[1]-velocityrange[0]) / cd3) + 1 # +1 is good: include -50
crval3 = 50.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 starlink")
makecube.generate_header(49.209553, -0.277137, naxis1=308, naxis2=205,
                         pixsize=15, naxis3=naxis3, cd3=cd3, crval3=crval3,
                         clobber=True, restfreq=14.12861587343394e9)
makecube.make_blank_images(cubename_supersampled,clobber=True)


for fn in filelist+filelist2:
    log.info("Adding file %s" % fn)
    fullfn = '/Users/adam/observations/gbt/W51map/'+fn
    d = fits.getdata(fullfn)
    pl.clf()
    pl.imshow(d['DATA'],norm=asinh_norm.AsinhNorm())
    pl.savefig(fullfn.replace(".fits","_data.png"))
    pl.clf()
    dsub = d['DATA']-np.median(d['DATA'],axis=1)[:,None]
    pl.imshow(dsub)
    pl.savefig(fullfn.replace(".fits","_data_subbed.png"))
import os
import astropy.io.fits as pyfits
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,'LimaBean_H2CO33_cube')
# 8' x 8'
makecube.generate_header(0.256, 0.0220, naxis1=100, naxis2=100, pixsize=10,
                         naxis3=500, cd3=1.0, clobber=True, restfreq=28.9748e9,
                         crval3=0.0, cunit3='km/s',
                         bmaj=28/3600., bmin=28/3600.)
makecube.make_blank_images(cubename,clobber=True)

files = [os.path.join(outpath,x) for x in
         ['14A_110_2_29to79_A9_F1.fits',
          '14A_110_2_29to79_A13_F2.fits',
          '14A_110_2_80to96_A9_F1.fits',
          '14A_110_2_80to96_A13_F2.fits',
          '14A_110_3_11to35_A9_F1.fits',
          '14A_110_3_11to35_A13_F2.fits',
          '14A_110_3_35to75_A9_F1.fits',
          '14A_110_3_35to75_A13_F2.fits',
          '14A_110_3_76to102_A9_F1.fits',
          '14A_110_3_76to102_A13_F2.fits',
          '14A_110_3_102to142_A9_F1.fits',
          '14A_110_3_102to142_A13_F2.fits',
Example #14
0
cd3 = 1.0
#cd3 = 1.0 # Arecibo is limited to 0.64 because one of the receivers went bad at hi-res mode once
#naxis3 = int(np.ceil((velocityrange[1]-velocityrange[0])/cd3))+4 # +4 is BAD!  don't do that.
naxis3 = int(
    (velocityrange[1] - velocityrange[0]) / cd3) + 1  # +1 is good: include -50
crval3 = 50.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(