Exemplo n.º 1
0
        h)

    for i in range(nb_nr):
        for j in range(nb_ni):
            # for each specific sphere
            n0 = nr[i] + ni[j] * 1j
            a0 = a[h]

            # calculate B vector
            B = ms.coeff_b(l, k, n0, a0)

            Es = np.sum(scatter * B, axis=2)

            Et = Es + Ef

            Eprop = ms.propagate_2D(simRes, simFov, Et, -z_max)

            # save real and imaginary part of the field
            im_data[:, :, 0, i, j] = np.real(Eprop)
            im_data[:, :, 1, i, j] = np.imag(Eprop)

            # save label
            sphere_data[:, i, j, h] = [nr[i], ni[j], a[h]]

            #save B vector
            B_data_real[:np.size(B), i, j, h] = np.real(B)
            B_data_imag[:np.size(B), i, j, h] = np.imag(B)

            # print progress
            cnt += 1
            sys.stdout.write('\r' + str(cnt / (nb_a * nb_ni * nb_nr) * 100) +
ps = [0, 0, 0]
simRes, simFov = ms.pad(res, fov, padding)

#%%
# calculate the horizontal simulation
Et_h, B0, Emask0, rVecs = traditional_mie.getTotalField(
    k, k, n0, res, a, ps, pp, padding, fov, numSample, NA_in, NA_out, option)
# calculate the vertical simulation
Et_v, B1, Emask1, rVecs_v = traditional_mie.getTotalField(
    k, k, n0, res, a, ps, pp, padding, fov, numSample, NA_in, NA_out,
    'Vertical')

# propagate the horizontal simulation
# the field can be propagated along the k direction for d distance
d = 1
Et_0_p = ms.propagate_2D(simRes, simFov, Et_h, d)

# we can add noise to the simulation
noise_amp = 200
noise_mask = np.random.randint(-noise_amp, noise_amp,
                               size=np.shape(Et_h)) / 1000000 + 1
Et_plus_noise = Et_h * noise_mask

#%%
# plot images
plt.figure()

plt.subplot(2, 2, 1)
plt.imshow(np.real(Et_h))
plt.title('Horizontal Real')
plt.axis('off')