def complex_arr(arr1, arr2):
    nb1 = np.size(arr1)
    nb2 = np.size(arr2)

    if nb1 == nb2:
        out_arr = np.zeros(nb1, complex)
        out_arr.real = arr1
        out_arr.imag = arr2

    if nb1 != nb2 and nb1 == 1:
        out_arr = np.zeros(nb2, complex)
        i = np.arange(1, nb2 + 1) / np.arange(1, nb2 + 1)
        out_arr.real = i * arr1
        out_arr.imag = arr2

    if nb1 != nb2 and nb2 == 1:
        out_arr = np.zeros(nb1, complex)
        i = np.arange(1, nb1 + 1) / np.arange(1, nb1 + 1)
        out_arr.real = arr1
        out_arr.imag = i * arr2

    if nb1 == 1 and nb2 == 1:
        out_arr = np.eros(nb1, complex)
        out_arr.real = arr1
        out_arr.imag = arr2

    return np.array(out_arr)
Exemple #2
0
def complex_arr(arr1,arr2):
    nb1 = np.size(arr1)
    nb2 = np.size(arr2)

    if nb1 == nb2:
        out_arr = np.zeros(nb1,complex)
        out_arr.real=arr1
        out_arr.imag=arr2

    if nb1!=nb2 and nb1==1:
        out_arr = np.zeros(nb2,complex)
        i = np.arange(1,nb2+1)/np.arange(1,nb2+1)
        out_arr.real=i*arr1
        out_arr.imag=arr2

    if nb1!=nb2 and nb2==1:
        out_arr = np.zeros(nb1,complex)
        i = np.arange(1,nb1+1)/np.arange(1,nb1+1)
        out_arr.real=arr1
        out_arr.imag=i*arr2

    if nb1==1 and nb2==1:
        out_arr = np.eros(nb1,complex)
        out_arr.real=arr1
        out_arr.imag=arr2

    return np.array(out_arr)
Exemple #3
0
def WW2000(mcval, mags, binsize):
    """Wiemer and Wyss (2000) method for determining a and b values."""
    mags = mags[~np.isnan(mags)]
    mags = np.around(mags, 1)
    mc_vec = np.arange(mcval - 1.5, mcval + 1.5 + binsize / 2., binsize)
    max_mag = max(mags)
    corr = binsize / 2.
    bvalue = np.zeros(len(mc_vec))
    std_dev = np.zeros(len(mc_vec))
    avalue = np.zeros(len(mc_vec))
    rval = np.eros(len(mc_vec))

    for idx in range(len(mc_vec)):
        mval = mags[mags >= mc_vec[idx] - 0.001]
        mag_bins_edges = np.arange(mc_vec[idx] - binsize / 2.,
                                   max_mag + binsize, binsize)
        mag_bins_centers = np.arange(mc_vec[idx], max_mag + binsize / 2.,
                                     binsize)

        cdf = np.zeros(len(mag_bins_centers))

        for jdx in range(len(cdf)):
            cdf[jdx] = np.count_nonzero(
                ~np.isnan(mags[mags >= mag_bins_centers[jdx] - 0.001]))

        bvalue[idx] = np.log10(np.exp(1)) / (np.average(mval) -
                                             (mc_vec[idx] - corr))
        std_dev[idx] = bvalue[idx] / sqrt(cdf[0])

        avalue[idx] = np.log10(len(mval)) + bvalue[idx] * mc_vec[idx]
        log_l = avalue[idx] - bvalue[idx] * mag_bins_centers
        lval = 10.**log_l

        bval, _ = np.histogram(mval, mag_bins_edges)
        sval = abs(np.diff(lval))
        rval[idx] = (sum(abs(bval[:-1] - sval)) / len(mval)) * 100

    ind = np.where(rval <= 10)[0]

    if len(ind) != 0:
        idx = ind[0]
    else:
        idx = list(rval).index(min(rval))

    mcval = mc_vec[idx]
    bvalue = bvalue[idx]
    avalue = avalue[idx]
    std_dev = std_dev[idx]
    mag_bins = np.arange(o, max_mag + binsize / 2., binsize)
    lval = 10.**(avalue - bvalue * mag_bins)

    return mcval, bvalue, avalue, lval, mag_bins, std_dev