Example #1
0
    freq_points = side//2
    freqs = np.arange( 0,freq_points )

    powers = scipy_ndimage_mean(image_fft, np.round(rad), index=freqs)


    autoexp, autoc, autopcov = fract.autoseeded_weighted_power_law_fit(freqs[2:-cutoff], powers[2:-cutoff], sigmas=powers[2:-cutoff])

    tailexp, tailc, tailpcov = fract.autoseeded_weighted_power_law_fit(freqs[-cutoff:], powers[-cutoff:], sigmas=powers[-cutoff:])

    detect_H = fract.freq_exp_to_H(autoexp)
    print("expected H", gen_H)
    print("    detect_H",detect_H)
    det_H_s[i] = detect_H


    plt.figure()
    plt.scatter(freqs,powers, marker=".", color="deepskyblue")
    plt.plot(freqs, fract.power_law(freqs, autoexp, autoc), color="red")
    plt.plot(freqs, fract.power_law(freqs, tailexp, tailc), color="green")
    # plt.plot(freqs, (10**c)*freqs**expected_freq_exp, color="red")
    plt.xscale("log")
    plt.yscale("log")
    plt.title("detect_H = %g, gen_H = %g, tail exp = %g" % (detect_H, gen_H, tailexp) )
    plt.show()


plt.figure()
plt.plot(gen_H_s, gen_H_s)
plt.scatter(gen_H_s, det_H_s)
plt.show()
Example #2
0
plt.figure()
plt.imshow(npy_points)
plt.show()

## fourier
fourier_H, freq_exp, f_c, freqs, powers = fract.fourier_H(np.copy(npy_points),
                                                          fill_with_mean=True,
                                                          images=True,
                                                          corr=True)
print("fourier_H", fourier_H)

plt.figure()
plt.scatter(freqs, powers)
plt.plot(freqs,
         fract.power_law(freqs, freq_exp, f_c),
         color="red",
         label="fourier")
plt.xscale("log")
plt.yscale("log")
plt.legend()
plt.show()

#### dfa
dfa_H, dfa_c, scales3, flucts3 = fract.dfa_H(npy_points,
                                             messages=False,
                                             min_nonzero=0.99)
print("dfa_H", dfa_H)

### first branch
dfa_H2, c2, pcov = fract.autoseeded_weighted_power_law_fit(
Example #3
0
M, N = z2d.shape

if s_max == "auto":
    s_max = min(N, M) // 4
else:
    pass  # (keep the passed s_max)

scales_flucts = np.zeros((s_max - s_min, 2))

# remove nan values (from linear regression on too few data points)
scales_flucts = scales_flucts[~np.isnan(scales_flucts).any(axis=1)]

# return scales_flucts[:,0], scales_flucts[:,1]

scales, flucts = scales_flucts[:, 0], scales_flucts[:, 1]

dfa_H, dfa_c, pcov = fract.autoseeded_weighted_power_law_fit(scales,
                                                             flucts,
                                                             sigmas=scales)

plt.figure()
plt.scatter(scales, flucts)
plt.plot(scales,
         fract.power_law(scales, dfa_H, dfa_c),
         color="springgreen",
         label="dfa")

plt.xscale("log")
plt.yscale("log")
plt.legend()
plt.show()
Example #4
0
            ######### else: zero boxes
    nbox_s[i] = n_boxes * area
    scales[i] = s

num = 1
b_exp, b_c, b_k, pcov = fract.autoseeded_weighted_power_law_fit(
    scales[num:], nbox_s[num:])

# det_H = 2 - (-b_exp +1 )
det_H = 3 + b_exp - s_dim
fract_dim = 3 - det_H

print("fractal dimension:", fract_dim)
print("detected H:", det_H)
plt.scatter(scales, nbox_s)
plt.plot(scales, fract.power_law(scales, b_exp, b_c, b_k), color="red")
plt.xscale("log")
plt.yscale("log")
plt.title("Box counting: H = " + str(det_H))
plt.show()

# def to_data(name, inner_func, *args, **kwargs):
#     npy_points = np.load("/home/gaboloth/D/fisica/tesi/dati/npysquare/all/"+name+"-2d.npy")
#     return inner_func(npy_points, *args, **kwargs)

# def higuchi_H_discard(*args, **kwargs):
#     try:
#         det_H, _b_c, _scales, _areas = higuchi_H(*args, **kwargs)
#         print(det_H)
#         return det_H
#     except Exception as ex:
Example #5
0
# windowing?
image_fft = abs( np.fft.fftshift(np.fft.fft2(z2d*hann))   ) **2
# image_fft = abs( np.fft.fftshift(np.fft.fft2(z2d))   ) **2

corr2d = scipy.signal.fftconvolve(z2d, z2d[::-1,::-1], mode="full")

# plt.figure()
# plt.imshow(z2d, interpolation="None")
# plt.show()
plt.figure()
plt.imshow(corr2d, interpolation="None")
plt.show()

r_points = np.arange(1,max_r)

autocorrs = scipy.ndimage.mean(image_fft, np.round(rad), index=r_points)

exp, c, pcov = fract.autoseeded_weighted_power_law_fit(r_points, autocorrs, sigmas=autocorrs)
plt.scatter(r_points, autocorrs)
plt.plot(r_points, fract.power_law(r_points, exp, c), color="orange")
plt.xscale("log")
plt.yscale("log")
plt.show()

det_H =  -exp/2 -1
print("gen_H", H)
print("det_H", det_H)



Example #6
0
    scales[i] = k**2

h_exp, h_c, pcov = fract.autoseeded_weighted_power_law_fit(scales[30:],
                                                           areas[30:],
                                                           sigmas=areas[30:])

det_H = 2 - (-h_exp + 1)

# return det_H, h_exp, h_c, scales, areas

# det_H, h_exp, h_c, scales, areas = higuchi_H(z2d)

print("fractal dimension:", -h_exp + 1)
plt.scatter(scales, areas)
plt.plot(scales, fract.power_law(scales, h_exp, h_c), color="red")
plt.xscale("log")
plt.yscale("log")
plt.title("Higuchi: H = " + str(det_H))
plt.show()

# def to_data(name, inner_func, *args, **kwargs):
#     npy_points = np.load("/home/gaboloth/D/fisica/tesi/dati/npysquare/all/"+name+"-2d.npy")
#     return inner_func(npy_points, *args, **kwargs)

# def higuchi_H_discard(*args, **kwargs):
#     try:
#         det_H, _h_c, _scales, _areas = higuchi_H(*args, **kwargs)
#         print(det_H)
#         return det_H
#     except Exception as ex:
Example #7
0
## fourier
fourier_H, freq_exp, f_c, freqs, powers = fract.fourier_H(np.copy(npy_points),
                                                          fill_with_mean=True,
                                                          images=True,
                                                          corr=True)
print("fourier_H", fourier_H)

freq_exp_2, fc2, pcov = fract.autoseeded_weighted_power_law_fit(
    freqs[2:20], powers[2:20], sigmas=powers[2:20])
fourier_H2 = fract.freq_exp_to_H(freq_exp_2)

plt.figure()
plt.scatter(freqs, powers)
plt.plot(freqs,
         fract.power_law(freqs, freq_exp, f_c),
         color="red",
         label="fourier: H =" + str(fourier_H))
plt.plot(freqs,
         fract.power_law(freqs, freq_exp_2, fc2),
         color="springgreen",
         label="fourier: H =" + str(fourier_H2))
plt.xscale("log")
plt.yscale("log")
plt.legend()
plt.show()

#### dfa
dfa_H, dfa_c, scales3, flucts3 = fract.dfa_H(npy_points,
                                             messages=False,
                                             min_nonzero=0.99)
Example #8
0
    np.min(scales_out)

    print("dma_1", dma_1)

    # ### branches
    # scale_f1 = 17
    scale_f2 = 25

    # dfa_H2, c2, pcov = fract.autoseeded_weighted_power_law_fit(scales_out[:scale_f1], flucts_out[:scale_f1], flucts_out[:scale_f1])
    dfa_H2, c2, pcov = fract.autoseeded_weighted_power_law_fit(
        scales_out[scale_f2:], flucts_out[scale_f2:], flucts_out[scale_f2:])
    # print("dfa_H2", dfa_H2)

    plt.figure()
    plt.scatter(scales_out, flucts_out)
    plt.plot(scales_out,
             fract.power_law(scales_out, dma_1, dma_c),
             color="springgreen",
             label="dma: H =" + str(dma_1))
    plt.plot(scales_out,
             fract.power_law(scales_out, dfa_H2, c2),
             color="red",
             label="dfa: H = " + str(dfa_H2))

    # plt.plot(scales_out, fract.power_law(scales_out, fourier_H, c2/0.8), color="purple", label="fourier: H = "+str(fourier_H))

    plt.xscale("log")
    plt.yscale("log")
    plt.legend()
    plt.show()