def _get_min_val(spaceshift, *params):
    r"""Calculate minimum resolved amplitude or maximum r."""

    # Get parameters from tuples
    spacing, shift = spaceshift
    n, fI, fC, r, r_def, error, reim, cvar, verb, plot, log = params

    # Get filter for these parameters
    dlf = _calculate_filter(n, spacing, shift, fI, r_def, reim, 'filt')

    # Calculate rhs-response with this filter
    k = dlf.base/r[:, None]

    # Loop over transforms
    for i, f in enumerate(fC):
        # Calculate lhs and rhs; rhs depends on ftype
        lhs = f.lhs(k)
        if f.name == 'j2':
            rhs0 = np.dot(lhs[0], getattr(dlf, 'j0'))/r
            rhs1 = np.dot(lhs[1], getattr(dlf, 'j1'))/r**2
            rhs = rhs0 + rhs1
        else:
            rhs = np.dot(lhs, getattr(dlf, f.name))/r

        # Get relative error
        rel_error = np.abs((rhs - f.rhs)/f.rhs)

        # Get indices where relative error is bigger than error
        imin0 = np.where(rel_error > error)[0]

        # Find first occurrence of failure
        if np.all(rhs == 0) or np.all(np.isnan(rhs)):
            # if all rhs are zeros or nans, the filter is useless
            imin0 = 0

        elif imin0.size == 0:
            # if imin0.size == 0:  # empty array, all rel_error < error.
            imin0 = rhs.size-1  # set to last r
            if verb > 0 and log['warn-r'] == 0:
                print('* WARNING :: all data have error < ' + str(error) +
                      '; choose larger r or set error-level higher.')
                log['warn-r'] = 1  # Only do this once

        else:
            # Kind of a dirty hack: Permit to jump up to four bad values,
            # resulting for instance from high rel_error from zero crossings
            # of the transform pair. Should be made an input argument or
            # generally improved.
            if imin0.size > 4:
                imin0 = np.max([0, imin0[4]-5])
            else:  # just take the first one (no jumping allowed; normal case)
                imin0 = np.max([0, imin0[0]-1])
            # Note that both version yield the same result if the failure is
            # consistent.

        # Depending on cvar, store minimum amplitude or 1/maxr
        if cvar == 'amp':
            min_val0 = np.abs(rhs[imin0])
        else:
            min_val0 = 1/r[imin0]

        # Check if this inversion is better than previous ones
        if i == 0:  # First run, store these values
            imin = dc(imin0)
            min_val = dc(min_val0)
        else:  # Replace imin, min_val if this one is better
            if min_val0 > min_val:
                min_val = dc(min_val0)
                imin = dc(imin0)

        # QC plot
        if plot > 2:
            _plot_inversion(f, rhs, r, k, imin0, spacing, shift, cvar)

    # If verbose, print progress
    if verb > 1:
        log = _print_count(log)

    # If there is no point with rel_error < error (imin=0) it returns np.inf.
    return np.where(imin == 0, np.inf, min_val)
def _get_min_val ( spaceshift , * params ) : spacing , shift = spaceshift n , fI , fC , r , r_def , error , reim , cvar , verb , plot , log = params dlf = _calculate_filter ( n , spacing , shift , fI , r_def , reim , 'filt' ) k = dlf . base / r [ : , None ] for i , f in enumerate ( fC ) : lhs = f . lhs ( k ) if f . name == 'j2' : rhs0 = np . dot ( lhs [ 0 ] , getattr ( dlf , 'j0' ) ) / r rhs1 = np . dot ( lhs [ 1 ] , getattr ( dlf , 'j1' ) ) / r ** 2 rhs = rhs0 + rhs1 else : rhs = np . dot ( lhs , getattr ( dlf , f . name ) ) / r rel_error = np . abs ( ( rhs - f . rhs ) / f . rhs ) imin0 = np . where ( rel_error > error ) [ 0 ] if np . all ( rhs == 0 ) or np . all ( np . isnan ( rhs ) ) : imin0 = 0 elif imin0 . size == 0 : imin0 = rhs . size - 1 if verb > 0 and log [ 'warn-r' ] == 0 : print ( '* WARNING :: all data have error < ' + str ( error ) + '; choose larger r or set error-level higher.' ) log [ 'warn-r' ] = 1 else : if imin0 . size > 4 : imin0 = np . max ( [ 0 , imin0 [ 4 ] - 5 ] ) else : imin0 = np . max ( [ 0 , imin0 [ 0 ] - 1 ] ) if cvar == 'amp' : min_val0 = np . abs ( rhs [ imin0 ] ) else : min_val0 = 1 / r [ imin0 ] if i == 0 : imin = dc ( imin0 ) min_val = dc ( min_val0 ) else : if min_val0 > min_val : min_val = dc ( min_val0 ) imin = dc ( imin0 ) if plot > 2 : _plot_inversion ( f , rhs , r , k , imin0 , spacing , shift , cvar ) if verb > 1 : log = _print_count ( log ) return np . where ( imin == 0 , np . inf , min_val )
r"""Calculate minimum resolved amplitude or maximum r.