r"""Key 81 pt CosSin filter, as published in [Key09]_.

    Taken from file ``FilterModules.f90`` provided with 1DCSEM_.

    License: `Apache License, Version 2.0,
    <http://www.apache.org/licenses/LICENSE-2.0>`_.
966763
def key_81_CosSin_2009():
    

    """

    dlf = DigitalFilter('Key 81 CosSin (2009)', 'key_81_CosSin_2009')

    dlf.base = np.array([
        3.354626279025119e-04, 4.097349789797864e-04,  5.004514334406104e-04,
        6.112527611295723e-04, 7.465858083766792e-04,  9.118819655545162e-04,
        1.113775147844802e-03, 1.360368037547893e-03,  1.661557273173934e-03,
        2.029430636295734e-03, 2.478752176666358e-03,  3.027554745375813e-03,
        3.697863716482929e-03, 4.516580942612666e-03,  5.516564420760772e-03,
        6.737946999085467e-03, 8.229747049020023e-03,  1.005183574463358e-02,
        1.227733990306844e-02, 1.499557682047770e-02,  1.831563888873418e-02,
        2.237077185616559e-02, 2.732372244729256e-02,  3.337326996032607e-02,
        4.076220397836620e-02, 4.978706836786394e-02,  6.081006262521795e-02,
        7.427357821433388e-02, 9.071795328941247e-02,  1.108031583623339e-01,
        1.353352832366127e-01, 1.652988882215865e-01,  2.018965179946554e-01,
        2.465969639416064e-01, 3.011942119122020e-01,  3.678794411714423e-01,
        4.493289641172216e-01, 5.488116360940264e-01,  6.703200460356393e-01,
        8.187307530779818e-01, 1e0,  1.221402758160170e+00,
        1.491824697641270e+00, 1.822118800390509e+00,  2.225540928492468e+00,
        2.718281828459046e+00, 3.320116922736548e+00,  4.055199966844675e+00,
        4.953032424395115e+00, 6.049647464412947e+00,  7.389056098930650e+00,
        9.025013499434122e+00, 1.102317638064160e+01,  1.346373803500169e+01,
        1.644464677109706e+01, 2.008553692318767e+01,  2.453253019710935e+01,
        2.996410004739703e+01, 3.659823444367799e+01,  4.470118449330084e+01,
        5.459815003314424e+01, 6.668633104092515e+01,  8.145086866496814e+01,
        9.948431564193386e+01, 1.215104175187350e+02,  1.484131591025766e+02,
        1.812722418751512e+02, 2.214064162041872e+02,  2.704264074261528e+02,
        3.302995599096489e+02, 4.034287934927351e+02,  4.927490410932563e+02,
        6.018450378720822e+02, 7.350951892419732e+02,  8.978472916504184e+02,
        1.096633158428459e+03, 1.339430764394418e+03,  1.635984429995927e+03,
        1.998195895104119e+03, 2.440601977624501e+03,  2.980957987041728e+03])

    dlf.factor = np.array([1.2214027581601701])

    dlf.cos = np.array([
        1.746412733678043e-02, -7.658725022064888e-02, 1.761673907472465e-01,
        -2.840940679113589e-01,  3.680388960144733e-01, -4.115498161707958e-01,
        4.181209762362728e-01, -3.967204599348831e-01, 3.608829691008270e-01,
        -3.171870084102961e-01,  2.744932842186247e-01, -2.324673650676961e-01,
        1.971144816936984e-01, -1.634915360178986e-01, 1.381406405905393e-01,
        -1.125728533897677e-01,  9.619580319372194e-02, -7.640431432353632e-02,
        6.748891657821673e-02, -5.097864570224415e-02, 4.853609305288441e-02,
        -3.293272689265632e-02,  3.677175984620380e-02, -1.969323595300588e-02,
        3.053726798991684e-02, -9.301135480582538e-03, 2.895215492109734e-02,
        -1.875526095801418e-04,  3.181452657662026e-02, 9.025726238227111e-03,
        3.955376604096631e-02,  1.966766645672513e-02, 5.318782805621459e-02,
        3.300575875620110e-02,  7.409212944640006e-02, 4.972863917303501e-02,
        1.029344264288086e-01,  6.776855697600163e-02, 1.357865756912759e-01,
        7.511614666518443e-02,  1.522218287240260e-01, 3.034571997381229e-02,
        8.802563675323094e-02, -1.689255322598353e-01, -1.756581788680092e-01,
        -6.123863775740898e-01, -5.098359641153184e-01, -6.736869803920745e-01,
        4.599561125225532e-01,  8.907010262082216e-01, 1.039153770711999e+00,
        -2.178135931072732e+00,  8.040971159674268e-01, 5.659848584656202e-01,
        -9.349050336534268e-01,  8.006099486213468e-01, -5.944960111930493e-01,
        4.369614304892440e-01, -3.292566347310282e-01, 2.547426420681868e-01,
        -2.010899026277397e-01,  1.609467208423519e-01, -1.299975550484158e-01,
        1.056082501090365e-01, -8.608337452556068e-02, 7.027252107999236e-02,
        -5.735742622053085e-02,  4.673270108060494e-02, -3.793635725863799e-02,
        3.060786160620013e-02, -2.446220554726340e-02, 1.927399223200865e-02,
        -1.486843016804444e-02,  1.111747692371507e-02, -7.939442960305236e-03,
        5.298852472637883e-03, -3.200104589830043e-03, 1.665382777953919e-03,
        -6.913074254614758e-04,  1.999065225130592e-04,
        -2.955159288961187e-05])

    dlf.sin = np.array([
        7.478326513505658e-07, -2.572850425065560e-06, 5.225955618519281e-06,
        -7.352539610140040e-06,  8.768819961093828e-06, -8.560004370841340e-06,
        8.101932279460349e-06, -5.983552716117552e-06, 5.036792825138655e-06,
        -1.584355068233649e-06,  1.426050228179462e-06, 3.972863429067356e-06,
        -1.903788077376088e-06,  1.144652944379527e-05, -4.327773998196030e-06,
        2.297298998355334e-05, -4.391227697686659e-06, 4.291202395830839e-05,
        1.760279032167125e-06,  8.017887907026914e-05, 2.364651853689879e-05,
        1.535031685829202e-04,  8.375427119939347e-05, 3.030115685600468e-04,
        2.339455351760637e-04,  6.157392107422657e-04, 5.921808556382737e-04,
        1.281873037121434e-03,  1.424276189020714e-03, 2.718506171172064e-03,
        3.324504626808429e-03,  5.839859904586436e-03, 7.608663600764702e-03,
        1.263571470998938e-02,  1.714199295539484e-02, 2.735013970005427e-02,
        3.794840483226463e-02,  5.858519896601026e-02, 8.166914231915734e-02,
        1.215508018998907e-01,  1.658946642767184e-01, 2.324389477118542e-01,
        2.938956625118840e-01,  3.572525844816433e-01, 3.479235360502319e-01,
        2.294314115090992e-01, -1.250412450354792e-01, -6.340986743027450e-01,
        -9.703404081656508e-01, -2.734109755210948e-01, 1.321852608494946e+00,
        6.762199721133603e-01, -2.093257651144232e+00, 1.707842350925794e+00,
        -8.844618831465598e-01,  3.720792781726873e-01, -1.481509947473694e-01,
        6.124339615448667e-02, -2.726194382687923e-02, 1.307668436907975e-02,
        -6.682101544475918e-03,  3.599101395415812e-03, -2.030735143712865e-03,
        1.197624324158372e-03, -7.382202519234128e-04, 4.756906961407787e-04,
        -3.199977708080284e-04,  2.238628518300115e-04, -1.618377502708346e-04,
        1.199233854156409e-04, -9.025345928219504e-05, 6.830860296946832e-05,
        -5.143409372298764e-05,  3.804574823200909e-05, -2.720604959632104e-05,
        1.839913059679674e-05, -1.140157702141663e-05, 6.172802138985788e-06,
        -2.706562852604888e-06,  8.403636781016683e-07,
        -1.356300450956746e-07])

    return dlf
1228793
def _sigmaclip_noaxis(self, data, masked=True, return_bounds=False,
                          copy=True):
        

        filtered_data = data.ravel()

        # remove masked values and convert to ndarray
        if isinstance(filtered_data, np.ma.MaskedArray):
            filtered_data = filtered_data.data[~filtered_data.mask]

        # remove invalid values
        good_mask = np.isfinite(filtered_data)
        if np.any(~good_mask):
            filtered_data = filtered_data[good_mask]
            warnings.warn('Input data contains invalid values (NaNs or '
                          'infs), which were automatically clipped.',
                          AstropyUserWarning)

        nchanged = 1
        iteration = 0
        while nchanged != 0 and (iteration < self.maxiters):
            iteration += 1
            size = filtered_data.size
            self._compute_bounds(filtered_data, axis=None)
            filtered_data = filtered_data[(filtered_data >= self._min_value) &
                                          (filtered_data <= self._max_value)]
            nchanged = size - filtered_data.size

        self._niterations = iteration

        if masked:
            # return a masked array and optional bounds
            filtered_data = np.ma.masked_invalid(data, copy=copy)

            # update the mask in place, ignoring RuntimeWarnings for
            # comparisons with NaN data values
            with np.errstate(invalid='ignore'):
                filtered_data.mask |= np.logical_or(data < self._min_value,
                                                    data > self._max_value)

        if return_bounds:
            return filtered_data, self._min_value, self._max_value
        else:
            return filtered_data
267653
def spa_tmplt(**kwds):
    
    # Pull out the input arguments
    f_lower = kwds['f_lower']
    delta_f = kwds['delta_f']
    distance = kwds['distance']
    mass1 = kwds['mass1']
    mass2 = kwds['mass2']
    s1z = kwds['spin1z']
    s2z = kwds['spin2z']
    phase_order = int(kwds['phase_order'])
    #amplitude_order = int(kwds['amplitude_order'])
    spin_order = int(kwds['spin_order'])

    if 'out' in kwds:
        out = kwds['out']
    else:
        out = None

    amp_factor = spa_amplitude_factor(mass1=mass1, mass2=mass2) / distance

    lal_pars = lal.CreateDict()
    if phase_order != -1:
        lalsimulation.SimInspiralWaveformParamsInsertPNPhaseOrder(
            lal_pars, phase_order)

    if spin_order != -1:
        lalsimulation.SimInspiralWaveformParamsInsertPNSpinOrder(
            lal_pars, spin_order)

    #Calculate the PN terms
    phasing = lalsimulation.SimInspiralTaylorF2AlignedPhasing(
                                    float(mass1), float(mass2),
                                    float(s1z), float(s2z),
                                    lal_pars)

    pfaN = phasing.v[0]
    pfa2 = phasing.v[2] / pfaN
    pfa3 = phasing.v[3] / pfaN
    pfa4 = phasing.v[4] / pfaN
    pfa5 = phasing.v[5] / pfaN
    pfa6 = (phasing.v[6] - phasing.vlogv[6] * log(4)) / pfaN
    pfa7 = phasing.v[7] / pfaN

    pfl5 = phasing.vlogv[5] / pfaN
    pfl6 = phasing.vlogv[6] / pfaN

    piM = lal.PI * (mass1 + mass2) * lal.MTSUN_SI

    kmin = int(f_lower / float(delta_f))

    vISCO = 1. / sqrt(6.)
    fISCO = vISCO * vISCO * vISCO / piM
    kmax = int(fISCO / delta_f)
    f_max = ceilpow2(fISCO)
    n = int(f_max / delta_f) + 1

    if not out:
        htilde = FrequencySeries(zeros(n, dtype=numpy.complex64), delta_f=delta_f, copy=False)
    else:
        if type(out) is not Array:
            raise TypeError("Output must be an instance of Array")
        if len(out) < kmax:
            kmax = len(out)
        if out.dtype != complex64:
            raise TypeError("Output array is the wrong dtype")
        htilde = FrequencySeries(out, delta_f=delta_f, copy=False)

    spa_tmplt_engine(htilde[kmin:kmax], kmin, phase_order, delta_f, piM, pfaN,
                     pfa2, pfa3, pfa4, pfa5, pfl5,
                     pfa6, pfl6, pfa7, amp_factor)
    return htilde
815624
def get_filter(self, name=constants.STRING_FILTER):
        
        try:
            filter_key = c_uamqp.symbol_value(name)
            return self._address.filter_set[filter_key].value
        except (TypeError, KeyError):
            return None
343995
def nan_acf(noise):
    
    corr = np.zeros(noise.shape)
    ix,jx = noise.shape
    for i in range(ix):
        si_min = slice(i, None, None)
        si_max = slice(None, ix-i, None)
        for j in range(jx):
            sj_min = slice(j, None, None)
            sj_max = slice(None, jx-j, None)
            if np.all(np.isnan(noise[si_min, sj_min])) or np.all(np.isnan(noise[si_max, sj_max])):
                corr[i, j] = np.nan
            else:
                corr[i, j] = np.nansum(noise[si_min, sj_min] * noise[si_max, sj_max])
    # return the normalised acf
    return corr / np.nanmax(corr)
981676
function setCurrentFilter(filter) {
    var token = cache.get('token');
    var dfrd = Q.defer();
    var id;
    if (!token) {
      dfrd.reject(MODULE_ERRORS.undefinedToken);
    } else {
      id = typeof filter === 'string' ? filter : filter.id;
      request(format(URLs.setCurrentFilter, PROTOCOL, conf.host, id,
        token), function(err, res, body) {
        if (err) {
          dfrd.reject(err);
        } else {
          _extractEmptyResponse(body, dfrd);
          dfrd.resolve(true);
        }
      });
    }
    return dfrd.promise;
  }
52270
def dct_spectrum(spec):
    
    ncep = spec.shape[0]
    dctm = np.zeros((ncep, ncep))
    for i in range(ncep):
        dctm[i, :] = np.cos(i * np.arange(1, 2 * ncep, 2) / (2 * ncep) * np.pi) * np.sqrt(2 / ncep)
    dctm *= 0.230258509299405
    cep = np.dot(dctm, (10 * np.log10(spec + np.spacing(1))))
    return cep
1216949
def filter_for_ringspan(clearnacs, spanlimit):
    ""
    delta = clearnacs.MAXIMUM_RING_RADIUS - clearnacs.MINIMUM_RING_RADIUS
    f = delta < spanlimit
    ringspan = clearnacs[f].copy()
    return ringspan
1166514
def pre_filter(self):
        
        if self._name in self.PRE_FILTER_FIELDS:
            return '"{}={},value={}"'.format(
                   self._rt_cmp, self.PRE_FILTER_FIELDS[self._name], int(self._value))
        return ''
42045
def filter(self, table, keypairs, filter_string):
        """"""
        query = filter_string.lower()
        return [keypair for keypair in keypairs
                if query in keypair.name.lower()]
836242
def sepconv_relu_sepconv(inputs,
                         filter_size,
                         output_size,
                         first_kernel_size=(1, 1),
                         second_kernel_size=(1, 1),
                         padding="LEFT",
                         nonpadding_mask=None,
                         dropout=0.0,
                         name=None):
  """"""
  with tf.variable_scope(name, "sepconv_relu_sepconv", [inputs]):
    inputs = maybe_zero_out_padding(inputs, first_kernel_size, nonpadding_mask)
    if inputs.get_shape().ndims == 3:
      is_3d = True
      inputs = tf.expand_dims(inputs, 2)
    else:
      is_3d = False
    h = separable_conv(
        inputs,
        filter_size,
        first_kernel_size,
        activation=tf.nn.relu,
        padding=padding,
        name="conv1")
    if dropout != 0.0:
      h = tf.nn.dropout(h, 1.0 - dropout)
    h = maybe_zero_out_padding(h, second_kernel_size, nonpadding_mask)
    ret = separable_conv(
        h, output_size, second_kernel_size, padding=padding, name="conv2")
    if is_3d:
      ret = tf.squeeze(ret, 2)
    return ret
1162734
def ccmodmd_xstep(k):
    

    YU0 = mp_D_Y0 - mp_D_U0[k]
    YU1 = mp_D_Y1[k] + mp_S[k] - mp_D_U1[k]
    b = sl.rfftn(YU0, None, mp_cri.axisN) + \
      np.conj(mp_Zf[k]) * sl.rfftn(YU1, None, mp_cri.axisN)
    Xf = sl.solvedbi_sm(mp_Zf[k], 1.0, b, axis=mp_cri.axisM)
    mp_D_X[k] = sl.irfftn(Xf, mp_cri.Nv, mp_cri.axisN)
    mp_DX[k] = sl.irfftn(sl.inner(Xf, mp_Zf[k]), mp_cri.Nv, mp_cri.axisN)
973720
def correlation(s, o):
    
    # s,o = filter_nan(s,o)
    if s.size == 0:
        corr = np.NaN
    else:
        corr = np.corrcoef(o, s)[0, 1]
    return corr
864005
def _sigmainf(N, h, m, dW, Km0, Pm0):
    """"""
    M = m*(m-1)//2
    Im = broadcast_to(np.eye(m), (N, m, m))
    IM = broadcast_to(np.eye(M), (N, M, M))
    Ims0 = np.eye(m**2)
    factor1 = broadcast_to((2.0/h)*np.dot(Km0, Ims0 - Pm0), (N, M, m**2))
    factor2 = _kp2(Im, _dot(dW, _t(dW)))
    factor3 = broadcast_to(np.dot(Ims0 - Pm0, Km0.T), (N, m**2, M))
    return 2*IM + _dot(_dot(factor1, factor2), factor3)
1005206
def get_pks_for_filter(self, key, filter_type, value):
        
        start, end, __ = self.get_boundaries(filter_type, value)  # we have nothing to exclude
        return self.connection.zrangebyscore(key, start, end)
870973
def get_waveform_filter_precondition(approximant, length, delta_f):
    
    if approximant in _filter_preconditions:
        return _filter_preconditions[approximant](length, delta_f)
    else:
        return None
1366201
def _twofilter_smoothing_ON2(self, t, ti, info, phi, lwinfo):
        
        sp, sw = 0., 0.
        upb = lwinfo.max() + self.wgt[t].lw.max()
        if hasattr(self.model, 'upper_bound_trans'):
            upb += self.model.upper_bound_trans(t + 1)
        # Loop over n, to avoid having in memory a NxN matrix
        for n in range(self.N):
            omegan = np.exp(lwinfo + self.wgt[t].lw[n] - upb
                            + self.model.logpt(t + 1, self.X[t][n],
                                               info.hist.X[ti]))
            sp += np.sum(omegan * phi(self.X[t][n], info.hist.X[ti]))
            sw += np.sum(omegan)
        return sp / sw