def calibrate_session(filename, mapnames, ifnum=0,
        gbtpath='/Users/adam/observations/gbt/', sessionnumber=None,
        refscans_list=None, scanranges=None, tau=0.02, 
        obsmodes=None, sourcenames=None):

    root = filename
    while root != os.path.splitext(root)[0]:
        root = os.path.splitext(root)[0]

    if sessionnumber is None:
        sessionnumber = int(root[-2:])

    filepyfits = pyfits.open(filename,memmap=True)
    datapfits = filepyfits[1].data
    dataarr = datapfits.DATA
    if datapfits.DATA[-1,:].sum() == 0:
        log.warn("READING USING PFITS")
        import pfits
        datapfits = pfits.FITS(filename).get_hdus()[1].get_data()
        dataarr = numpy.reshape(datapfits['DATA'],datapfits['DATA'].shape[::-1])

    for feed in (1,2):
        for sampler in samplers[ifnum]:
            OK = (datapfits['FEED'] == feed) * (datapfits['SAMPLER'] == sampler)
            if OK.sum() > 0:
                pl.plot(datapfits['LST'][OK],
                        dataarr[OK,1000:2000].mean(axis=1), ',',
                        label='Feed %i Sampler %s' % (feed,sampler))
    pl.savefig(root+'_secondhalf_continuum_nolimits.png')
    pl.gca().set_ylim(1,5)
    pl.savefig(root+'_secondhalf_continuum.png')

    if scanranges is None:
        scanranges = [(min(r)+1,max(r)-1) for r in refscans_list]
    if obsmodes is None:
        obsmodes = [None for r in refscans_list]
    if sourcenames is None:
        sourcenames = [None for r in refscans_list]

    for refscans, scanrange, mapname, obsmode, sourcename in zip(refscans_list,
                                                                 scanranges,
                                                                 mapnames,
                                                                 obsmodes,
                                                                 sourcenames):
        outpath = '%s%smap/' % (gbtpath,mapname)
        ref1,ref2 = min(refscans),max(refscans)
        for sampler,feednum in zip(samplers[ifnum],feeds[ifnum]):
            calibrate_map_scans.calibrate_cube_data(filename,
                    outpath+'Session%i_%ito%i_%s_F%i.fits' %
                    (sessionnumber,ref1,ref2,sampler,feednum),
                    scanrange=scanrange, feednum=feednum, sampler=sampler,
                    filepyfits=filepyfits, datapfits=datapfits, tau=tau,
                    dataarr=dataarr, refscans=refscans, sourcename=sourcename,
                    obsmode=obsmode)
                        extension=1, exclude_spectral_ends=10)
            elif sampler in ["B18","B22","D34","D38"]: # h2c18o
                off_template = make_off_template.make_off(filename, scanrange=scanrange,
                        #exclude_velo=[-10,70], interp_vrange=[-150,250],
                        interp_polyorder=10, sampler=sampler,
                        feednum=feednum,
                        sourcename=sourcename,
                        savefile=savefile,
                        clobber=True,
                        extension=1, exclude_spectral_ends=10)
            else:
                off_template = None

            outfn = outpath+'14A_110_2_%ito%i_%s_F%i.fits' % (ref1,ref2,sampler,feednum)
            calibrate_map_scans.calibrate_cube_data(filename,
                                                    outfn,
                                                    scanrange=scanrange,
                                                    #min_scale_reference=10,
                                                    feednum=feednum,
                                                    refscans=refscans,
                                                    sampler=sampler,
                                                    filepyfits=filepyfits,
                                                    datapfits=datapfits,
                                                    tau=0.03,
                                                    dataarr=dataarr,
                                                    obsmode=obsmode,
                                                    sourcename=sourcename,
                                                    off_template=off_template)


        elif sampler in ('D33','D37'): # H110a
            off_template = make_off_template.make_off(filename,
                                                      scanrange=scanrange,
                                                      obsmode=obsmode,
                                                      exclude_velo=[-50,150],
                                                      interp_vrange=[-150,250],
                                                      interp_polyorder=10,
                                                      sampler=sampler,
                                                      savefile=savefile,
                                                      clobber=True,
                                                      exclude_spectral_ends=10)
        else:
            off_template = None

        print "Sanity check.  Off_template: ",off_template

        calibrate_map_scans.calibrate_cube_data(filename,
                                                outpath+'12B_221_%ito%i_%s_F1.fits' % (ref1,ref2,sampler),
                                                scanrange=scanrange,
                                                feednum=1,
                                                refscans=refscans,
                                                sampler=sampler,
                                                filepyfits=filepyfits,
                                                datapfits=datapfits, tau=0,
                                                dataarr=dataarr,
                                                obsmode=obsmode,
                                                exclude_spectral_ends=10.,
                                                min_scale_reference=10,
                                                sourcename=sourcename,
                                                off_template=off_template)
Esempio n. 4
0
            )
           ):

            s1,s2 = scanrange

            savefile = os.path.join(paths.AGBT15B_129_3_path,
                                    "AGBT15B_129_03_{0}_fd{1}_if{2}_sr{3}-{4}"
                                    .format(sampler,feednum,ifnum,s1,s2))
            log.info(savefile)

            outfn = os.path.join(paths.outpath,
                                 '15B_129_3_%ito%i_%s_F%i.fits' % (s1,s2,sampler,feednum))
            calibrate_map_scans.calibrate_cube_data(filename,
                                                    outfn,
                                                    scanrange=scanrange,
                                                    #min_scale_reference=10,
                                                    feednum=feednum,
                                                    refscans=refscans,
                                                    sampler=sampler,
                                                    filepyfits=filepyfits,
                                                    datapfits=datapfits,
                                                    # ignored b/c gain tau=0.50,
                                                    #tsys=np.median(tsys[gainsOK]),
                                                    #gain=gain_dict,
                                                    dataarr=dataarr,
                                                    obsmode=obsmode,
                                                    sourcename=sourcename,
                                                    highfreq=False,
                                                    verbose=True,
                                                   )