r"""Kong 61 pt Hankel filter, as published in [Kong07]_.

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

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

    """

    dlf = DigitalFilter('Kong 61', 'kong_61_2007')

    dlf.base = np.array([
            2.3517745856009100e-02, 2.6649097336355482e-02,
            3.0197383422318501e-02, 3.4218118311666032e-02,
            3.8774207831722009e-02, 4.3936933623407420e-02,
            4.9787068367863938e-02, 5.6416139503777350e-02,
            6.3927861206707570e-02, 7.2439757034251456e-02,
            8.2084998623898800e-02, 9.3014489210663506e-02,
            1.0539922456186430e-01, 1.1943296826671961e-01,
            1.3533528323661270e-01, 1.5335496684492850e-01,
            1.7377394345044520e-01, 1.9691167520419400e-01,
            2.2313016014842979e-01, 2.5283959580474641e-01,
            2.8650479686019009e-01, 3.2465246735834979e-01,
            3.6787944117144239e-01, 4.1686201967850839e-01,
            4.7236655274101469e-01, 5.3526142851899028e-01,
            6.0653065971263342e-01, 6.8728927879097224e-01,
            7.7880078307140488e-01, 8.8249690258459546e-01,
            1.0000000000000000e+00, 1.1331484530668261e+00,
            1.2840254166877421e+00, 1.4549914146182010e+00,
            1.6487212707001280e+00, 1.8682459574322221e+00,
            2.1170000166126748e+00, 2.3988752939670981e+00,
            2.7182818284590451e+00, 3.0802168489180310e+00,
            3.4903429574618419e+00, 3.9550767229205772e+00,
            4.4816890703380636e+00, 5.0784190371800806e+00,
            5.7546026760057307e+00, 6.5208191203301116e+00,
            7.3890560989306504e+00, 8.3728974881272649e+00,
            9.4877358363585262e+00, 1.0751013186076360e+01,
            1.2182493960703470e+01, 1.3804574186067100e+01,
            1.5642631884188170e+01, 1.7725424121461639e+01,
            2.0085536923187671e+01, 2.2759895093526730e+01,
            2.5790339917193059e+01, 2.9224283781234941e+01,
            3.3115451958692312e+01, 3.7524723159601002e+01,
            4.2521082000062783e+01])

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

    dlf.j0 = np.array([
            1.4463210615326699e+02, -1.1066222143752420e+03,
            3.7030010025325978e+03, -6.8968188464424520e+03,
            7.1663544112656937e+03, -2.4507884783377681e+03,
            -4.0166567754046082e+03, 6.8623845298546094e+03,
            -5.0013321011775661e+03, 2.1291291365196648e+03,
            -1.3845222435542289e+03, 2.1661554291595580e+03,
            -2.2260393789657141e+03, 8.0317156013986391e+02,
            1.0142221718890841e+03, -1.9350455051432630e+03,
            1.6601169447226580e+03, -7.5159684285420133e+02,
            -9.0315984178183285e+01, 5.0705574889546148e+02,
            -5.1207646422722519e+02, 2.9722959494490038e+02,
            -5.0248319908072993e+01, -1.2290725861955920e+02,
            1.9695244755899429e+02, -1.9175679966946601e+02,
            1.4211755630338590e+02, -7.7463216543224149e+01,
            1.7638009334931201e+01, 2.8855056499202671e+01,
            -5.9225643887809561e+01, 7.5987941373668960e+01,
            -8.1687962781233580e+01, 8.0599209238447102e+01,
            -7.4895905328771619e+01, 6.7516291538794434e+01,
            -5.9325033647358048e+01, 5.1617042242841528e+01,
            -4.4664967446820263e+01, 3.8366152052928278e+01,
            -3.3308787868993100e+01, 2.8278671651033459e+01,
            -2.4505863388620480e+01, 2.0469632532079750e+01,
            -1.7074034940700429e+01, 1.4206119215530070e+01,
            -1.0904435643084650e+01, 8.7518389425802283e+00,
            -6.7721665239085622e+00, 4.5096884588095891e+00,
            -3.2704247166629590e+00, 2.6827195063720430e+00,
            -1.8406031821386459e+00, 9.1586697140412443e-01,
            -3.2436011485890798e-01, 8.0675176189581893e-02,
            -1.2881307195759690e-02, 7.0489137468452920e-04,
            2.3846917590855061e-04, -6.9102205995825531e-05,
            6.7792635718095777e-06])

    dlf.j1 = np.array([
            4.6440396425864918e+01, -4.5034239857914162e+02,
            1.7723440076223640e+03, -3.7559735516994660e+03,
            4.4736494009764137e+03, -2.2476603569606068e+03,
            -1.5219842155931799e+03, 3.4904608559273802e+03,
            -2.4814243247472318e+03, 5.7328164634108396e+02,
            5.3132044837659631e-01, 6.8895205008006235e+02,
            -1.2012013872160269e+03, 7.9679138423597340e+02,
            4.9874460187939818e+01, -5.6367338332457007e+02,
            4.7971936503711203e+02, -5.8979702298044558e+01,
            -3.1935800954986922e+02, 4.5762551999442371e+02,
            -3.7239927283248380e+02, 1.8255852885279569e+02,
            -2.3504740340815669e-01, -1.1588151583545380e+02,
            1.5740956677133170e+02, -1.4334746114883359e+02,
            9.9857411013284818e+01, -4.8246322019171487e+01,
            2.0371404343057380e+00, 3.3003938094974323e+01,
            -5.5476151884197712e+01, 6.7354852323852583e+01,
            -7.0735403363284121e+01, 6.8872932663164747e+01,
            -6.3272750944993042e+01, 5.6501568721817442e+01,
            -4.8706577819918110e+01, 4.1737211284663481e+01,
            -3.4776621242200903e+01, 2.9161717578906430e+01,
            -2.3886749056000909e+01, 1.9554007583544220e+01,
            -1.5966397353366460e+01, 1.2429310210239199e+01,
            -1.0139180791868180e+01, 7.4716493393871861e+00,
            -5.5509479014742613e+00, 4.3380799768234208e+00,
            -2.5911516181746550e+00, 1.6300524630626780e+00,
            -1.4041567266387460e+00, 7.5225141726873213e-01,
            4.6808777208492733e-02, -3.6630197849601159e-01,
            2.8948389902792782e-01, -1.3705521898064801e-01,
            4.6292091649913013e-02, -1.1721281347435180e-02,
            2.2002397354029149e-03, -2.8146036357227600e-04,
            1.8788896009128770e-05])

    return dlf
769588
def cb_filter(fastq, bc1, bc2, bc3, cores, nedit):
    ''' 
    '''

    with open_gzipsafe(bc1) as bc1_fh:
        bc1 = set(cb.strip() for cb in bc1_fh)
    if bc2:
        with open_gzipsafe(bc2) as bc2_fh:
            bc2 = set(cb.strip() for cb in bc2_fh)
    if bc3:
        with open_gzipsafe(bc3) as bc3_fh:
            bc3 = set(cb.strip() for cb in bc3_fh)

    annotations = detect_fastq_annotations(fastq)
    re_string = construct_transformed_regex(annotations)

    if nedit == 0:
        filter_cb = partial(exact_barcode_filter, bc1=bc1, bc2=bc2, bc3=bc3,
                            re_string=re_string)
    else:
        bc1hash = MutationHash(bc1, nedit)
        bc2hash = None
        bc3hash = None
        if bc2:
            bc2hash = MutationHash(bc2, nedit)
        if bc3:
            bc3hash = MutationHash(bc3, nedit)
        filter_cb = partial(correcting_barcode_filter, bc1hash=bc1hash,
                            bc2hash=bc2hash, bc3hash=bc3hash, re_string=re_string)
    p = multiprocessing.Pool(cores)

    chunks = tz.partition_all(10000, read_fastq(fastq))
    bigchunks = tz.partition_all(cores, chunks)
    for bigchunk in bigchunks:
        for chunk in p.map(filter_cb, list(bigchunk)):
            for read in chunk:
                sys.stdout.write(read)
293781
def _get_filter_modifier(self, field):
        """"""
        tokens = field.split(FIELD_SEPARATOR)
        if len(tokens) == 1:
            return field, ""
        if tokens[-1] in self.FILTER_OPERATORS.keys():
            return u'.'.join(tokens[:-1]), tokens[-1]
        return u'.'.join(tokens), ""
827322
def spa_distance(psd, mass1, mass2, lower_frequency_cutoff, snr=8):
    
    kend = int(spa_tmplt_end(mass1=mass1, mass2=mass2) / psd.delta_f)
    norm1 = spa_tmplt_norm(psd, len(psd), psd.delta_f, lower_frequency_cutoff)
    norm2 = (spa_amplitude_factor(mass1=mass1, mass2=mass2)) ** 2.0

    if kend >= len(psd):
        kend = len(psd) - 1
    return sqrt(norm1[kend] * norm2) / snr
884310
def _twofilter_smoothing_ON(self, t, ti, info, phi, lwinfo, return_ess,
                               modif_forward, modif_info):
        
        if modif_info is not None:
            lwinfo += modif_info
        Winfo = rs.exp_and_normalise(lwinfo)
        I = rs.multinomial(Winfo)
        if modif_forward is not None:
            lw = self.wgt[t].lw + modif_forward
            W = rs.exp_and_normalise(lw)
        else:
            W = self.wgt[t].W
        J = rs.multinomial(W)
        log_omega = self.model.logpt(t + 1, self.X[t][J], info.hist.X[ti][I])
        if modif_forward is not None:
            log_omega -= modif_forward[J]
        if modif_info is not None:
            log_omega -= modif_info[I]
        Om = rs.exp_and_normalise(log_omega)
        est = np.average(phi(self.X[t][J], info.hist.X[ti][I]), axis=0,
                         weights=Om)
        if return_ess:
            return (est, 1. / np.sum(Om**2))
        else:
            return est
1225145
protected void doFilterImpl(ServletRequest pRequest, ServletResponse pResponse, FilterChain pChain) throws IOException, ServletException {
        // TODO: Max size configuration, to avoid DOS attacks? OutOfMemory

        // Size parameters
        int width = ServletUtil.getIntParameter(pRequest, sizeWidthParam, -1);
        int height = ServletUtil.getIntParameter(pRequest, sizeHeightParam, -1);
        if (width > 0 || height > 0) {
            pRequest.setAttribute(ImageServletResponse.ATTRIB_SIZE, new Dimension(width, height));
        }

        // Size uniform/percent
        boolean uniform = ServletUtil.getBooleanParameter(pRequest, sizeUniformParam, true);
        if (!uniform) {
            pRequest.setAttribute(ImageServletResponse.ATTRIB_SIZE_UNIFORM, Boolean.FALSE);
        }
        boolean percent = ServletUtil.getBooleanParameter(pRequest, sizePercentParam, false);
        if (percent) {
            pRequest.setAttribute(ImageServletResponse.ATTRIB_SIZE_PERCENT, Boolean.TRUE);
        }

        // Area of interest parameters
        int x = ServletUtil.getIntParameter(pRequest, regionLeftParam, -1); // Default is center
        int y = ServletUtil.getIntParameter(pRequest, regionTopParam, -1);  // Default is center
        width = ServletUtil.getIntParameter(pRequest, regionWidthParam, -1);
        height = ServletUtil.getIntParameter(pRequest, regionHeightParam, -1);
        if (width > 0 || height > 0) {
            pRequest.setAttribute(ImageServletResponse.ATTRIB_AOI, new Rectangle(x, y, width, height));
        }

        // AOI uniform/percent
        uniform = ServletUtil.getBooleanParameter(pRequest, regionUniformParam, false);
        if (uniform) {
            pRequest.setAttribute(ImageServletResponse.ATTRIB_SIZE_UNIFORM, Boolean.TRUE);
        }
        percent = ServletUtil.getBooleanParameter(pRequest, regionPercentParam, false);
        if (percent) {
            pRequest.setAttribute(ImageServletResponse.ATTRIB_SIZE_PERCENT, Boolean.TRUE);
        }

        super.doFilterImpl(pRequest, pResponse, pChain);
    }
517870
def median_fltr(dem, fsize=7, origmask=False):
    
    print("Applying median filter with size %s" % fsize)
    from scipy.ndimage.filters import median_filter
    dem_filt_med = median_filter(dem.filled(np.nan), fsize)
    #Now mask all nans
    out = np.ma.fix_invalid(dem_filt_med, copy=False, fill_value=dem.fill_value)
    if origmask:
        out = np.ma.array(out, mask=dem.mask, fill_value=dem.fill_value)
    out.set_fill_value(dem.fill_value)
    return out
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
381929
def _get_struct_convolutionfilter(self):
        """"""
        obj = _make_object("ConvolutionFilter")
        obj.MatrixX = unpack_ui8(self._src)
        obj.MatrixY = unpack_ui8(self._src)
        obj.Divisor = unpack_float(self._src)
        obj.Bias = unpack_float(self._src)

        _quant = obj.MatrixX * obj.MatrixY
        obj.Matrix = [unpack_float(self._src) for _ in range(_quant)]

        obj.DefaultColor = self._get_struct_rgba()
        bc = BitConsumer(self._src)
        obj.Reserved = bc.u_get(6)
        obj.Clamp = bc.u_get(1)
        obj.PreserveAlpha = bc.u_get(1)
        return obj
1083477
public static int cudnnGetConvolution2dForwardOutputDim(
        cudnnConvolutionDescriptor convDesc, 
        cudnnTensorDescriptor inputTensorDesc, 
        cudnnFilterDescriptor filterDesc, 
        int[] n, 
        int[] c, 
        int[] h, 
        int[] w)
    {
        return checkResult(cudnnGetConvolution2dForwardOutputDimNative(convDesc, inputTensorDesc, filterDesc, n, c, h, w));
    }
90735
def new_for_fk10_fig9(cls, shlib_path):
        
        inst = (cls(shlib_path)
            .set_thermal_background(2.1e7, 3e9)
            .set_bfield(48)
            .set_edist_powerlaw(0.016, 4.0, 3.7, 5e9/3)
            .set_freqs(100, 0.5, 50)
            .set_hybrid_parameters(12, 12)
            .set_ignore_q_terms(False)
            .set_obs_angle(50 * np.pi / 180)
            .set_padist_gaussian_loss_cone(0.5 * np.pi, 0.4)
            .set_trapezoidal_integration(15))

        # haven't yet figure out how to deal with this part:
        inst.in_vals[0] = 1.33e18
        inst.in_vals[1] = 6e8
        return inst
413888
def maskedFilter(arr, mask, ksize=30, fill_mask=True,
                 fn='median'):
    '''
    
    '''

    if fill_mask:
        mask1 = mask
        out = arr
    else:
        mask1 = ~mask
        out = np.full_like(arr, fill_value=np.nan)
    mask2 = ~mask

    if fn == 'mean':
        _calcMean(arr, mask1, mask2, out, ksize // 2)
    else:
        buff = np.empty(shape=(ksize * ksize), dtype=arr.dtype)
        _calcMedian(arr, mask1, mask2, out, ksize // 2, buff)
    return out
53613
def fdfilter(data, *filt, **kwargs):
    
    # parse keyword args
    inplace = kwargs.pop('inplace', False)
    analog = kwargs.pop('analog', False)
    fs = kwargs.pop('sample_rate', None)
    if kwargs:
        raise TypeError("filter() got an unexpected keyword argument '%s'"
                        % list(kwargs.keys())[0])

    # parse filter
    if fs is None:
        fs = 2 * (data.shape[-1] * data.df).to('Hz').value
    form, filt = parse_filter(filt, analog=analog, sample_rate=fs)
    lti = signal.lti(*filt)

    # generate frequency response
    freqs = data.frequencies.value.copy()
    fresp = numpy.nan_to_num(abs(lti.freqresp(w=freqs)[1]))

    # apply to array
    if inplace:
        data *= fresp
        return data
    new = data * fresp
    return new
288693
def undo_filter_paeth(filter_unit, scanline, previous, result):
    """"""

    # Also used for ci.
    ai = -filter_unit
    for i in range(len(result)):
        x = scanline[i]
        if ai < 0:
            a = c = 0
        else:
            a = result[ai]
            c = previous[ai]
        b = previous[i]
        p = a + b - c
        pa = abs(p - a)
        pb = abs(p - b)
        pc = abs(p - c)
        if pa <= pb and pa <= pc:
            pr = a
        elif pb <= pc:
            pr = b
        else:
            pr = c
        result[i] = (x + pr) & 0xff
        ai += 1
827209
def _already_cutoff_filtered(in_file, filter_type):
    
    filter_file = "%s-filter%s.vcf.gz" % (utils.splitext_plus(in_file)[0], filter_type)
    return utils.file_exists(filter_file)
932696
def fastFilter(arr, ksize=30, every=None, resize=True, fn='median',
                  interpolation=cv2.INTER_LANCZOS4,
                  smoothksize=0,
                  borderMode=cv2.BORDER_REFLECT):
    '''
    
    '''
    if every is None:
        every = max(ksize//3, 1)
    else:
        assert ksize >= 3*every
    s0,s1 = arr.shape[:2]
    
    ss0 = s0//every
    every = s0//ss0
    ss1 = s1//every
    
    out = np.full((ss0+1,ss1+1), np.nan)
    
    c = {'median':_calcMedian,
         'nanmedian':_calcNanMedian,
         'nanmean':_calcNanMean,
         'mean':_calcMean,
         }[fn]
    ss0,ss1 = c(arr, out, ksize, every)
    out = out[:ss0,:ss1]
    
    if smoothksize:
        out = gaussian_filter(out, smoothksize)
        
    
    if not resize:
        return out
    return cv2.resize(out, arr.shape[:2][::-1],
               interpolation=interpolation)
260134
def _calculate_filter(n, spacing, shift, fI, r_def, reim, name):
    """

    # Base :: For this n/spacing/shift
    base = np.exp(spacing*(np.arange(n)-n//2) + shift)

    # r :: Start/end is defined by base AND r_def[0]/r_def[1]
    #      Overdetermined system if r_def[2] > 1
    r = np.logspace(np.log10(1/np.max(base)) - r_def[0],
                    np.log10(1/np.min(base)) + r_def[1], r_def[2]*n)

    # k :: Get required k-values (matrix of shape (r.size, base.size))
    k = base/r[:, None]

    # Create filter instance
    dlf = DigitalFilter(name.split('.')[0])
    dlf.base = base
    dlf.factor = np.around(np.average(base[1:]/base[:-1]), 15)

    # Loop over transforms
    for f in fI:
        # Calculate lhs and rhs for inversion
        lhs = reim(f.lhs(k))
        rhs = reim(f.rhs(r)*r)

        # Calculate filter values: Solve lhs*J=rhs using linalg.qr.
        # If factoring fails (qr) or if matrix is singular or square (solve) it
        # will raise a LinAlgError. Error is ignored and zeros are returned
        # instead.
        try:
            qq, rr = np.linalg.qr(lhs)
            J = np.linalg.solve(rr, rhs.dot(qq))
        except np.linalg.LinAlgError:
            J = np.zeros((base.size,))

        setattr(dlf, f.name, J)

    return dlf