Пример #1
0
def __set_pm__(L, window, taps, fwidth):
    global pm
    if pm['L'] == L and pm['taps'] == taps and \
       pm['fwidth'] == fwidth:
        if type(window) == str and pm['window_name'] == window: return
        elif window is pm['window']: return
    else:
        pm['L'] = L
        pm['taps'] = taps
        pm['fwidth'] = fwidth
        def sinx_x(x):
            t = n.pi * taps * fwidth * (x/float(L) - .5)
            v = n.where(t != 0, t, 1)
            return n.where(t != 0, n.sin(v) / v, 1)
        pm['sinx_x'] = n.fromfunction(sinx_x, (L,))
    if type(window) == str: 
        wf = {}
        wf['blackman'] = lambda x: .42-.5*n.cos(2*n.pi*x/(L-1))+.08*n.cos(4*n.pi*x/(L-1))
        wf['blackman-harris'] = lambda x: .35875 - .48829*n.cos(2*n.pi*x/(L-1)) + .14128*n.cos(4*n.pi*x/(L-1)) - .01168*n.cos(6*n.pi*x/(L-1))
        wf['gaussian0.4'] = lambda x: n.exp(-0.5 * ((x - (L-1)/2)/(0.4 * (L-1)/2))**2)
        wf['kaiser2'] = lambda x: i0(n.pi * 2 * n.sqrt(1-(2*x/(L-1) - 1)**2)) / i0(n.pi * 2)
        wf['kaiser3'] = lambda x: i0(n.pi * 3 * n.sqrt(1-(2*x/(L-1) - 1)**2)) / i0(n.pi * 3)
        wf['hamming'] = lambda x: .54 - .46 * n.cos(2*n.pi*x/(L-1))
        wf['hanning'] = lambda x: .5 - .5 * n.cos(2*n.pi*x/(L-1))
        wf['parzen'] = lambda x: 1 - n.abs(L/2. - x) / (L/2.)
        wf['none'] = lambda x: 1
        pm['window'] = n.fromfunction(wf[window], (L,))
        pm['window_name'] = window
    else: 
        pm['window'] = window
        pm['window_name'] = None
    pm['window_sinx_x'] = pm['window'] * pm['sinx_x']
Пример #2
0
def __set_pm__(L, window, taps, fwidth):
    global pm
    if pm['L'] == L and pm['taps'] == taps and \
       pm['fwidth'] == fwidth:
        if type(window) == str and pm['window_name'] == window: return
        elif window is pm['window']: return
    else:
        pm['L'] = L
        pm['taps'] = taps
        pm['fwidth'] = fwidth

        def sinx_x(x):
            t = n.pi * taps * fwidth * (x / float(L) - .5)
            v = n.where(t != 0, t, 1)
            return n.where(t != 0, n.sin(v) / v, 1)

        pm['sinx_x'] = n.fromfunction(sinx_x, (L, ))
    if type(window) == str:
        wf = {}
        wf['blackman'] = lambda x: .42 - .5 * n.cos(2 * n.pi * x / (
            L - 1)) + .08 * n.cos(4 * n.pi * x / (L - 1))
        wf['blackman-harris'] = lambda x: .35875 - .48829 * n.cos(
            2 * n.pi * x /
            (L - 1)) + .14128 * n.cos(4 * n.pi * x /
                                      (L - 1)) - .01168 * n.cos(6 * n.pi * x /
                                                                (L - 1))
        wf['gaussian0.4'] = lambda x: n.exp(-0.5 * ((x - (L - 1) / 2) /
                                                    (0.4 * (L - 1) / 2))**2)
        wf['kaiser2'] = lambda x: i0(n.pi * 2 * n.sqrt(1 - (2 * x / (
            L - 1) - 1)**2)) / i0(n.pi * 2)
        wf['kaiser3'] = lambda x: i0(n.pi * 3 * n.sqrt(1 - (2 * x / (
            L - 1) - 1)**2)) / i0(n.pi * 3)
        wf['hamming'] = lambda x: .54 - .46 * n.cos(2 * n.pi * x / (L - 1))
        wf['hanning'] = lambda x: .5 - .5 * n.cos(2 * n.pi * x / (L - 1))
        wf['parzen'] = lambda x: 1 - n.abs(L / 2. - x) / (L / 2.)
        wf['none'] = lambda x: 1
        pm['window'] = n.fromfunction(wf[window], (L, ))
        pm['window_name'] = window
    else:
        pm['window'] = window
        pm['window_name'] = None
    pm['window_sinx_x'] = pm['window'] * pm['sinx_x']
Пример #3
0
import numpy as n
from aipy._cephes import i0
from _dsp import *

WINDOW_FUNC = {
    'blackman': lambda x,L: .42-.5*n.cos(2*n.pi*x/(L-1))+.08*n.cos(4*n.pi*x/(L-1)),
    'blackman-harris': lambda x,L: .35875 - .48829*n.cos(2*n.pi*x/(L-1)) + .14128*n.cos(4*n.pi*x/(L-1)) - .01168*n.cos(6*n.pi*x/(L-1)),
    'gaussian0.4': lambda x,L: n.exp(-0.5 * ((x - (L-1)/2)/(0.4 * (L-1)/2))**2),
    'kaiser2': lambda x,L: i0(n.pi * 2 * n.sqrt(1-(2*x/(L-1) - 1)**2)) / i0(n.pi * 2),
    'kaiser3': lambda x,L: i0(n.pi * 3 * n.sqrt(1-(2*x/(L-1) - 1)**2)) / i0(n.pi * 3),
    'hamming': lambda x,L: .54 - .46 * n.cos(2*n.pi*x/(L-1)),
    'hanning': lambda x,L: .5 - .5 * n.cos(2*n.pi*x/(L-1)),
    'parzen': lambda x,L: 1 - n.abs(L/2. - x) / (L/2.),
    'none': lambda x,L: 1,
}

def gen_window(L, window='hamming'):
    '''Return the specified window (see WINDOW_FUNC) for a length L.'''
    return n.fromfunction(lambda x: WINDOW_FUNC[window](x,L), (L,))
Пример #4
0
o.add_option('--nchan', dest='nchan', default=1024, type='int',
    help='Number of channels in simulated data if no input data to mimic.  Default is 1024')
o.add_option('--sfreq', dest='sfreq', default=.100, type='float',
    help='Start frequency (GHz) in simulated data if no input data to mimic.  Default is 0.100')
o.add_option('--sdf', dest='sdf', default=.100/1024, type='float',
    help='Channel spacing (GHz) in simulated data if no input data to mimic.  Default is .100/1024')
o.add_option('--inttime', dest='inttime', default=10, type='float',
    help='Integration time (s) in simulated data if no input data to mimic.  Default is 10')
o.add_option('--startjd', dest='startjd', default=2455600., type='float',
    help='Julian Date to start observation if no input data to mimic.  Default is 2454600')
o.add_option('--endjd', dest='endjd', default=2455601., type='float',
    help='Julian Date to end observation if no input data to mimic.  Default is 2454601')
opts,args = o.parse_args(sys.argv[1:])

NCHAN = opts.nchan
kaiser3 = lambda x: i0(n.pi * 3 * n.sqrt(1-(2*x/(NCHAN-1) - 1)**2)) / i0(n.pi * 3)
times = n.arange(opts.startjd, opts.endjd, opts.inttime/a.const.s_per_day)

aa = a.cal.get_aa(opts.cal, opts.sdf, opts.sfreq, opts.nchan)
srclist,cutoff,catalogs = a.scripting.parse_srcs(opts.src, opts.cat)
cat = a.cal.get_catalog(opts.cal, srclist, cutoff, catalogs)
pols = ['yy']
afreqs = aa.get_afreqs()
dlys = n.fft.fftfreq(NCHAN, d=afreqs[1]-afreqs[0])

def recenter(d, cen): return n.concatenate([d[cen:], d[:cen]])
def sim(tau): return n.exp(-2j*n.pi*afreqs*tau)

w = n.fromfunction(kaiser3, (opts.nchan,))
FOOTPRINT = 30 
SUBSAMPLE = 64
Пример #5
0
    help=
    'Julian Date to start observation if no input data to mimic.  Default is 2454600'
)
o.add_option(
    '--endjd',
    dest='endjd',
    default=2455601.,
    type='float',
    help=
    'Julian Date to end observation if no input data to mimic.  Default is 2454601'
)
opts, args = o.parse_args(sys.argv[1:])

NCHAN = opts.nchan
kaiser3 = lambda x: i0(n.pi * 3 * n.sqrt(1 -
                                         (2 * x /
                                          (NCHAN - 1) - 1)**2)) / i0(n.pi * 3)
times = n.arange(opts.startjd, opts.endjd, opts.inttime / a.const.s_per_day)

aa = a.cal.get_aa(opts.cal, opts.sdf, opts.sfreq, opts.nchan)
srclist, cutoff, catalogs = a.scripting.parse_srcs(opts.src, opts.cat)
cat = a.cal.get_catalog(opts.cal, srclist, cutoff, catalogs)
pols = ['yy']
afreqs = aa.get_afreqs()
dlys = n.fft.fftfreq(NCHAN, d=afreqs[1] - afreqs[0])


def recenter(d, cen):
    return n.concatenate([d[cen:], d[:cen]])

Пример #6
0
import numpy as np
from aipy._cephes import i0
from _dsp import *

WINDOW_FUNC = {
    'blackman':
    lambda x, L: .42 - .5 * np.cos(2 * np.pi * x /
                                   (L - 1)) + .08 * np.cos(4 * np.pi * x /
                                                           (L - 1)),
    'blackman-harris':
    lambda x, L: .35875 - .48829 * np.cos(2 * np.pi * x / (L - 1)) + .14128 *
    np.cos(4 * np.pi * x / (L - 1)) - .01168 * np.cos(6 * np.pi * x / (L - 1)),
    'gaussian0.4':
    lambda x, L: np.exp(-0.5 * ((x - (L - 1) / 2) / (0.4 * (L - 1) / 2))**2),
    'kaiser2':
    lambda x, L: i0(np.pi * 2 * np.sqrt(1 - (2 * x /
                                             (L - 1) - 1)**2)) / i0(np.pi * 2),
    'kaiser3':
    lambda x, L: i0(np.pi * 3 * np.sqrt(1 - (2 * x /
                                             (L - 1) - 1)**2)) / i0(np.pi * 3),
    'hamming':
    lambda x, L: .54 - .46 * np.cos(2 * np.pi * x / (L - 1)),
    'hanning':
    lambda x, L: .5 - .5 * np.cos(2 * np.pi * x / (L - 1)),
    'parzen':
    lambda x, L: 1 - np.abs(L / 2. - x) / (L / 2.),
    'none':
    lambda x, L: 1,
}


def gen_window(L, window='hamming'):