makecube.calibrate_cube_data(datapfits,
            outpath+'13B_031_%ito%i_%s_F1.fits' %
            (ref1,ref2,sampler),scanrange=scanrange,refscan1=ref1,refscan2=ref2,
            feednum=feed, refscans=refscans, sampler=sampler, filepyfits=filepyfits,
            datapfits=datapfits, tau=tau, dataarr=dataarr, obsmode=obsmode,
            sourcename=sourcename, off_template=off_template)






cubename='NGC1333_H2CO22_cube'
# 15' x 12 ' 
makecube.generate_header(52.256025, 31.257809, coordsys='radec', naxis1=30, naxis2=30, pixsize=20,
        naxis3=2000, cd3=0.1, crval3=7.5, clobber=True, restfreq=14.488479e9)
makecube.make_blank_images(cubename,clobber=True)

files = ['/Users/adam/observations/gbt/NGC1333map/13B_031_33to57_A13_F1.fits',
         '/Users/adam/observations/gbt/NGC1333map/13B_031_33to57_A9_F1.fits',
        '/Users/adam/observations/gbt/NGC1333map/13B_031_33to57_C25_F2.fits',
        '/Users/adam/observations/gbt/NGC1333map/13B_031_33to57_C29_F2.fits',
         #'/Users/adam/observations/gbt/NGC1333map/13B_031_22to32_A13_F1.fits',
         #'/Users/adam/observations/gbt/NGC1333map/13B_031_22to32_A9_F1.fits',
         ]

for fn in files:
    makecube.add_file_to_cube(fn,
        cubename+'.fits',nhits=cubename+'_nhits.fits',wcstype='V',
        velocityrange=[-100,100],excludefitrange=exclude_velo,coordsys='galactic') # removed smoothto kwd
import sys
sys.path.append('/Users/adam/repos/casaradio/branches/python/ginsburg/')
import makecube

cubename='NGC1333_H2CO11_cube'
makecube.generate_header(52.25625, 31.257809, coordsys='radec', naxis1=60, naxis2=60, pixsize=20,
        naxis3=2000, cd3=0.1, crval3=7.5, clobber=True, restfreq=14.488479e9)
makecube.make_blank_images(cubename,clobber=True)
for ii in xrange(4):
    makecube.add_file_to_cube('/Users/adam/observations/arecibo/20130913/NGC1333_spectra_0913_%i.fits' % ii,
        cubename+'.fits',nhits=cubename+'_nhits.fits',wcstype='V',
        velocityrange=[-50,50],excludefitrange=[4,10], coordsys='radec')

makecube.make_flats(cubename,vrange=[4,10],noisevrange=[-20,0])