Beispiel #1
0
def main(hotpotato):

    print("Running PRETO prepsubband.")
    t_prep_start = time.time()

    params_list = [
        'directory', 'rfi_dir', 'prep_dir', 'basename', 'prep_usemask',
        'downsample', 'prep_flags', 'prep_otherflags', 'filetype'
    ]
    print_params(params_list)

    # get/set file locations
    work_dir = get_value(hotpotato, 'directory')
    rfi_dir = get_value(hotpotato, 'rfi_dir')
    prep_dir = get_value(hotpotato, 'prep_dir')  # can change this
    basename = get_value(hotpotato, 'basename')
    fitslist = glob('%s/%s*.fits' % (rfi_dir, basename))
    fitslist.sort()
    fitsfiles = ' '.join(fitslist)

    # get de-dispersion parameters
    prep_usemask = get_value(hotpotato, 'prep_usemask')
    downsample = get_value(hotpotato, 'downsample')
    prep_flags = get_value(hotpotato, 'prep_flags')
    prep_otherflags = get_value(hotpotato, 'prep_otherflags')

    # run prepsubband command
    print("Dedispersing with 1st batch of DMs")
    orig_N = get_samples(fitslist, get_value(hotpotato, 'filetype'))
    numout = psr_utils.choose_N(orig_N) / downsample
    print(orig_N, numout)

    if prep_usemask == True:
        # make sure rfi_find has been run previously
        try:
            rfi_maskname = glob(rfi_dir + '/*.mask')[0]
        except IndexError:
            raise Exception("Could not access RFI_mask fits file. Please run PRESTO rfifind "\
                           "before generating masked dynamic spectrum.")

        cmd = 'prepsubband -o %s -numout %d %s %s -mask %s %s' % (
            basename, numout, prep_flags, prep_otherflags, rfi_maskname,
            fitsfiles)
    else:
        cmd = 'prepsubband -o %s %s %s %s' % (basename, numout, prep_flags,
                                              prep_otherflags, fitsfiles)

    try_cmd(cmd)

    # move output to prep_dir
    mv_cmd1 = 'mv %s %s' % (work_dir + '/*.dat', prep_dir)
    mv_cmd2 = 'mv %s %s' % (work_dir + '/*.inf', prep_dir)
    try_cmd(mv_cmd1)
    try_cmd(mv_cmd2)

    t_prep_end = time.time()
    prep_time = (t_prep_end - t_prep_start)
    print("PRESTO prepsubband took %f seconds." % (prep_time))

    return hotpotato
Beispiel #2
0
def run_prepsubband(basename, maskname, fitslist, dmlow=params.dmlow, \
                        ddm=params.ddm, ndm=params.dmspercall, \
                        downsample=params.downsample, nsub=params.nsub):
    t_prep_start = time.time()
    fitsfiles = ' '.join(fitslist) 
    print("Dedispersing with 1st batch of DMs")
    orig_N = readhdr.get_samples(fitslist, params.dat_type)
    numout = psr_utils.choose_N(orig_N)
    print(orig_N, numout)

    other_flags = params.prep_otherflags
    if params.use_mask:
        cmd = 'prepsubband -o %s -psrfits -nsub %d -numout %d -lodm %.6f -dmstep %.6f '\
            '-numdms %d -downsamp %d %s -mask %s %s' %(basename, nsub, numout/downsample, 
                                                                 dmlow, ddm, ndm, downsample,
                                                                 other_flags, maskname, fitsfiles)
    else:
        cmd = 'prepsubband -o %s -psrfits -nsub %d -numout %d -lodm %.6f -dmstep %.6f '\
            '-numdms %d -downsamp %d  %s %s' %(basename, nsub, numout/downsample,
                                                        dmlow, ddm, ndm, downsample,
                                                        other_flags, fitsfiles)

    try_cmd(cmd)

    t_prep_end = time.time()
    dt = t_prep_end - t_prep_start
    print "De-dispersion took %.2f hours.\n" %(dt/3600.)
    return dt
Beispiel #3
0
def multi_call_prepsubband(basename, maskname, fitslist, dmlow=params.dmlow, \
                               ddm=params.ddm, downsample=params.downsample, \
                               dmcalls=params.dmcalls, nsub=params.nsub,  \
                               dsubDM=params.dsubDM, \
                               dmspercall=params.dmspercall):
    t_prep_start = time.time()
    fitsfiles = ' '.join(fitslist)

    orig_N = readhdr.get_samples(fitslist, params.dat_type)
    numout = psr_utils.choose_N(orig_N)
    other_flags = params.prep_otherflags

    # Downsample organization as in PRESTO dedisp.py (why?)
    sub_downsample = downsample / 2
    dat_downsample = 2
    if downsample < 2: sub_downsample = dat_downsample = 1

    print("Dedispersing using %d calls on %d subbands\n" %(dmcalls, nsub))
    for ii in xrange(dmcalls):
        subDM = dmlow + (ii+0.5)*dsubDM
        # Make subband
        if params.use_mask:
            cmd_sub = "prepsubband -o %s -sub -subdm %.2f -nsub %d -downsamp %d %s -mask %s %s" \
                %(basename, subDM, nsub, sub_downsample, other_flags, maskname, fitsfiles)
        else:
            cmd_sub = "prepsubband -o %s -sub -subdm %.2f -nsub %d -downsamp %d %s %s" \
                %(basename, subDM, nsub, sub_downsample, other_flags, fitsfiles)
        try_cmd(cmd_sub)
        
        # Get dedispersed time series
        sub_dmlow = dmlow + ii*dsubDM
        subfiles =  basename+"_DM%.2f.sub[0-9]*" %subDM
        if params.use_mask:
            cmd_dat = "prepsubband -o %s -numout %d -lodm %.2f -dmstep %.2d "\
                "-numdms %d -downsamp %d %s -mask %s %s" \
                %(basename, numout/downsample, sub_dmlow, ddm, dmspercall, dat_downsample, other_flags, maskname, subfiles)
        else:
            cmd_dat = "prepsubband -o %s -numout %d -lodm %.2f -dmstep %.2d "\
                "-numdms %d -downsamp %d %s %s" \
                %(basename, numout/downsample, sub_dmlow, ddm, dmspercall, dat_downsample, other_flags, subfiles)
        try_cmd(cmd_dat)
    
    t_prep_end = time.time()
    dt = t_prep_end - t_prep_start
    print "De-dispersion took %.2f hours.\n" %(dt/3600.)
    return dt