示例#1
0
文件: tools.py 项目: sessink/NIW
def compute_spectra_cfs(raw, array):
    raw['dtime'] = ('time',
                    np.array((raw.time - raw.time.isel(time=0)).values * 1e-9,
                             dtype=float))
    raw = raw.swap_dims({'time': 'dtime'})
    return dsp.spectrogram(raw[array],
                           dim='dtime',
                           fs=86400 / dsp.get_sampling_step(raw, dim='dtime'),
                           nperseg=128)
示例#2
0
文件: tools.py 项目: sessink/NIW
def bandpass_velocity(raw, low_f, high_f):
    import xrscipy.signal as dsp

    # TODO: fix naming of variables

    # convert datetime to seconds since t=0
    raw['dtime'] = ('time',
                    np.array((raw.time - raw.time.isel(time=0)).values * 1e-9,
                             dtype=float))
    # raw['dtime'] = ('time', np.array( (raw.time - raw.time.isel(time=0)).values, dtype=float))

    # make dtime a dimension
    raw = raw.swap_dims({'time': 'dtime'})

    # filtering proceduce
    # determine sampling timestep and Nyquist frequency
    T = (dsp.get_sampling_step(raw, dim='dtime'))
    # T = 5000
    fs = 1 / T
    ny = 0.5 * fs

    # limits for bandpass
    # low_f = gsw.f(lat_mean)*low # in 1/s
    # high_f = gsw.f(lat_mean)*high # in 1/s
    eps = 0  # how to fill nans
    # # pick an order?
    # print(low_f/ny)
    # print(high_f/ny)
    ulow = dsp.bandpass(raw.u.fillna(eps),
                        low_f / ny,
                        high_f / ny,
                        dim='dtime',
                        in_nyq=True,
                        order=4)
    vlow = dsp.bandpass(raw.v.fillna(eps),
                        low_f / ny,
                        high_f / ny,
                        dim='dtime',
                        in_nyq=True,
                        order=4)
    # ulow = dsp.bandpass(raw.u.fillna(eps), low_f, high_f, dim='dtime', in_nyq=False, order=4)
    # vlow = dsp.bandpass(raw.v.fillna(eps), low_f, high_f, dim='dtime', in_nyq=False, order=4)

    # swap dims back
    ulow = ulow.swap_dims({'dtime': 'time'})
    vlow = vlow.swap_dims({'dtime': 'time'})
    raw = raw.swap_dims({'dtime': 'time'})

    # remove time and space means?
    ulow = ulow  #- ulow.mean(dim='z') - ulow.mean(dim='time')
    vlow = vlow  #- vlow.mean(dim='z') - ulow.mean(dim='time')

    mask = ~np.isnan(raw.u) & ~np.isnan(raw.v)
    raw['uNI'] = ulow.where(mask)
    raw['vNI'] = vlow.where(mask)

    return raw
示例#3
0
文件: tools.py 项目: sessink/NIW
def bandstop_variable(raw, array, low_f, high_f):
    import xrscipy.signal as dsp

    # TODO: fix naming of variables

    # convert datetime to seconds since t=0
    raw['dtime'] = ('time',
                    np.array((raw.time - raw.time.isel(time=0)).values * 1e-9,
                             dtype=float))
    # raw['dtime'] = ('time', np.array( (raw.time - raw.time.isel(time=0)).values, dtype=float))

    # make dtime a dimension
    raw = raw.swap_dims({'time': 'dtime'})

    # filtering proceduce
    # determine sampling timestep and Nyquist frequency
    T = (dsp.get_sampling_step(raw, dim='dtime'))
    fs = 1 / T
    ny = 0.5 * fs

    # limits for bandpass
    eps = 0  # how to fill nans
    # # pick an order?
    # print(low_f/ny)
    # print(high_f/ny)
    ulow = dsp.bandstop(raw[array].fillna(eps),
                        low_f / ny,
                        high_f / ny,
                        dim='dtime',
                        in_nyq=True,
                        order=4)

    # swap dims back
    ulow = ulow.swap_dims({'dtime': 'time'})
    raw = raw.swap_dims({'dtime': 'time'})

    # remove time and space means?
    ulow = ulow  #- ulow.mean(dim='z') - ulow.mean(dim='time')

    mask = ~np.isnan(raw[array])
    varname = array + 'NI'
    raw[varname] = ulow.where(mask)

    return raw