Example #1
0
def load_MALM_synthetic(ZZ=-13.75, shape=(30, 30), field=False):

    # ------------------------------  Model parametes
    ZZ = ZZ  # depth of the synthetic anomaly
    x1, x2, y1, y2, z1, z2 = -5, 5, -5, 5, ZZ - 2.5 / 2, ZZ + 2.5 / 2
    Rsoil = 1000
    maxdepth = 20

    # ------------------------------- Load data
    filename = 'MSoilR' + str(Rsoil) + 'AnoR1Z' + str(ZZ) + 'L5h2.5'
    MainPath = 'E:/Padova/Simulation/MALM_SensitivityAnalysis/Sens3d/' + filename + '/Data/'
    #MainPath='E:/Padova/Simulation/MALM_SensitivityAnalysis/Sens3d/' + filename + '/Data/'
    os.chdir(MainPath)
    if field == True:
        xp, yp, zp, U = np.loadtxt(filename + '_uz0_grid.dat', unpack=True)
    else:
        x, y, z, gz = np.loadtxt('3d_SENS_FAT.txt', unpack=True)
        # ------------------------------- remove B return electrode effects
        B = [-104.16666666666667, -104.16666666666667, 0]
        U = dEXP.cor_field_B(x, y, z, gz, B, rho=100)
        # U_cor = U
        xp, yp, U = gridder.interp(x, y, U, shape)
        # xp,yp,gz_cor= gridder.interp(x,y,gz_cor,shape)

    return xp, yp, z, U, maxdepth, shape
Example #2
0
def scalearray(fname, ranges=None, shape=None):
    #image = scipy.misc.fromimage(PIL.Image.open(fname), flatten=True)
    # Invert the color scale and normalize
    values = (fname.max() - fname)/np.abs(fname).max()
    if ranges is not None:
        vmin, vmax = ranges
        values *= vmax - vmin
        values += vmin
    if shape is not None and tuple(shape) != values.shape:
        ny, nx = values.shape
        X, Y = np.meshgrid(range(nx), range(ny))
        values = gridder.interp(X.ravel(), Y.ravel(), values.ravel(),
                                shape)[2].reshape(shape)
    return values
 def animate(t):
     ax.clear()
     date = start + datetime.timedelta(days=t)
     ax.set_title(date)
     a, b, th = gridder.interp(positions[:, 1],
                               positions[:, 0],
                               strain[:, 0, t],
                               shape,
                               algorithm='cubic',
                               extrapolate=False)
     cs = ax.contourf(xp.reshape(shape),
                      yp.reshape(shape),
                      th.reshape(shape),
                      200,
                      cmap='jet',
                      vmin=minstrain,
                      vmax=maxstrain)
     grid = ax.triplot(vertices[:, 1],
                       vertices[:, 0],
                       simplices,
                       linewidth=0.5)
     ax.axis('equal')
from __future__ import division, print_function
from fatiando import mesher, gridder, utils
from fatiando.datasets import fetch_hawaii_gravity
from fatiando.gravmag import transform
import matplotlib.pyplot as plt
import numpy as np

# Fetch Hawaii data
data = fetch_hawaii_gravity()

# When the data is projected using UTM zone 4, it is no longer regular gridded.
# We must regrid it.
area = (1.483e6, 3.079e6, -60e3, 1.326e6)
shape = (77, 67)
x, y, gravity = gridder.interp(data['x'], data['y'],
                               data['topo-free'],
                               shape, area=area)

# Lets compute the Power Density Spectra (2d arrays)
kx, ky, pds = transform.power_density_spectra(x, y, gravity, shape)

# And then compute the radial average of the PDS
k_radial, pds_radial = transform.radial_average_spectrum(kx, ky, pds)

# Plot Hawaii gravity and radially averaged power spectrum
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4))
cm = ax1.contourf(y.reshape(shape),
                  x.reshape(shape),
                  gravity.reshape(shape), 100)
ax1.contour(y.reshape(shape),
            x.reshape(shape),
Example #5
0
    'MSoilR1AnoR1Z-13.75W15H2.5L5S0Noise0',
    'MSoilR10AnoR1Z-13.75W15H2.5L5S0Noise0',
    'MSoilR100AnoR1Z-13.75W15H2.5L5S0Noise0',
    'MSoilR1000AnoR1Z-13.75W15H2.5L5S0Noise0'
]

x_axis = 'y'

for fi in filenames:
    print(fi)
    x_raw, y_raw, z_raw, U_raw, maxdepth, shape_raw, p1, p2, SimName, ano_prop = MALM.load_MALM_sens3d(
        filename='./loadmalm/' + fi + '.pkl')

    # pEXP.plot_field(x_raw, y_raw,)
    shape = (200, 200)
    xp, yp, U = gridder.interp(x_raw, y_raw, U_raw, shape)

    parameters = para.set_par(shape=shape, max_elevation=abs(maxdepth))
    interp = True
    scaled = parameters[0]
    SI = parameters[1]
    zp, qorder, nlay = parameters[2:5]
    minAlt_ridge, maxAlt_ridge = parameters[5:7]

    #%%
    # ridges analysis parameters
    nlay = 25
    max_elevation = 30
    minAlt_ridge = max_elevation * 0.05
    maxAlt_ridge = max_elevation * 0.65
shape = (100, 100)

# First, we need to know the real data at the grid points
grdx, grdy = gridder.regular(area, shape)
grdz = data(grdx, grdy)
mpl.figure()
mpl.subplot(2, 2, 1)
mpl.axis('scaled')
mpl.title("True grid data")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)

# Use the default interpolation (cubic)
grdx, grdy, grdz = gridder.interp(x, y, z, shape)
mpl.subplot(2, 2, 2)
mpl.axis('scaled')
mpl.title("Interpolated using cubic minimum-curvature")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)

# Use the nearest neighbors interpolation
grdx, grdy, grdz = gridder.interp(x, y, z, shape, algorithm='nn')
mpl.subplot(2, 2, 3)
mpl.axis('scaled')
mpl.title("Interpolated using nearest neighbors")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
Example #7
0
shape = (100, 100)

# First, we need to know the real data at the grid points
grdx, grdy = gridder.regular(area, shape)
grdz = data(grdx, grdy)
mpl.figure()
mpl.subplot(2, 2, 1)
mpl.axis("scaled")
mpl.title("True grid data")
mpl.plot(x, y, ".k", label="Data points")
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc="lower right", numpoints=1)

# Use the default interpolation (cubic)
grdx, grdy, grdz = gridder.interp(x, y, z, shape)
mpl.subplot(2, 2, 2)
mpl.axis("scaled")
mpl.title("Interpolated using cubic minimum-curvature")
mpl.plot(x, y, ".k", label="Data points")
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc="lower right", numpoints=1)

# Use the nearest neighbors interpolation
grdx, grdy, grdz = gridder.interp(x, y, z, shape, algorithm="nearest")
mpl.subplot(2, 2, 3)
mpl.axis("scaled")
mpl.title("Interpolated using nearest neighbors")
mpl.plot(x, y, ".k", label="Data points")
mpl.contourf(grdx, grdy, grdz, shape, 50)
Example #8
0
#if os.path.exists(pathData) == False:
#   os.mkdir(pathData)

# ------------------------------- Load data
# import exemples.fwd_mag_sphere as magfwd
# xp, yp, zp, gz, shape, p1, p2, coord= magfwd.load_mag_synthetic()

shape = (50, 50)
x, y, z, gz = np.loadtxt('3d_SENS_FAT.txt', unpack=True)

# remove B return electrode effects
B = [-104.16666666666667, -104.16666666666667, 0]
gz_cor = dEXP.cor_field_B(x, y, z, gz, B, rho=100)

gz_cor = gz
xp, yp, gz = gridder.interp(x, y, gz, shape)
xp, yp, gz_cor = gridder.interp(x, y, gz_cor, shape)
zp = 0

# # ------------------------------- Export for CWT analysis

# # Extract a profile between points 1 and 2
p1, p2 = [min(xp), 0], [max(xp), 0]
# p1, p2 = [0, min(xp)], [0, max(xp)]
xx, yy, distance, profile = gridder.profile(xp, yp, gz, p1, p2, 1000)
# xx, yy, distance, profile_cor = gridder.profile(xp, yp, gz_cor, p1, p2, 1000)

# ------------------------------- Export for CWT analysis

## Extract a profile between points 1 and 2
#p1, p2 = [0.1, 0.1], [12000, 0.1]
Example #9
0
# Generate synthetic data measured at random points
area = (0, 1, 0, 1)
x, y = gridder.scatter(area, n=500, seed=0)
data = x * (1 - x) * np.cos(4 * np.pi * x) * np.sin(4 * np.pi * y ** 2) ** 2

# Say we want to interpolate the data onto a regular grid with a given shape
shape = (100, 200)

# The gridder.interp function takes care of selecting the containing area of
# the data and generating the regular grid for us.
# Let's interpolate using the different options offered by gridddata and plot
# them all.

plt.figure(figsize=(10, 8))

xp, yp, nearest = gridder.interp(x, y, data, shape, algorithm="nearest")
plt.subplot(2, 2, 1)
plt.title("Nearest-neighbors")
plt.contourf(yp.reshape(shape), xp.reshape(shape), nearest.reshape(shape), 30, cmap="RdBu_r")

xp, yp, linear = gridder.interp(x, y, data, shape, algorithm="linear")
plt.subplot(2, 2, 2)
plt.title("Linear")
plt.contourf(yp.reshape(shape), xp.reshape(shape), linear.reshape(shape), 30, cmap="RdBu_r")

xp, yp, cubic = gridder.interp(x, y, data, shape, algorithm="cubic")
plt.subplot(2, 2, 3)
plt.title("Cubic")
plt.contourf(yp.reshape(shape), xp.reshape(shape), cubic.reshape(shape), 30, cmap="RdBu_r")

# Notice that the cubic and linear interpolation leave empty the points that
def analyse(file_name):
    #phi lam space
    data, start, stop = load_set(file_name)
    splines = make_spline_set(data, start)
    initial = np.zeros((len(splines), 2))
    for i in range(initial.shape[0]):
        initial[i, 0] = splines[i][0](0)
        initial[i, 1] = splines[i][1](0)

    triangulation = Delaunay(initial)
    connections = []
    for simplex in triangulation.simplices:
        connections.append(list(sorted([simplex[0], simplex[1]])))
        connections.append(list(sorted([simplex[1], simplex[2]])))
        connections.append(list(sorted([simplex[0], simplex[2]])))

    connections = np.unique(np.array(connections), axis=0)

    positions = []
    for i in range(connections.shape[0]):
        phi1 = splines[connections[i, 0]][0](0)
        lam1 = splines[connections[i, 0]][1](0)
        positions.append([phi1, lam1])

    initial_dist = []
    for i in range(connections.shape[0]):
        initial_dist.append(splines[connections[i, 0]][2](0))
    initial_dist = np.array(initial_dist)

    rng = (stop - start).days
    strain = np.zeros((connections.shape[0], 1, rng))

    for t in range(0, rng):
        for i in range(connections.shape[0]):
            phi1 = splines[connections[i, 0]][0](t)
            lam1 = splines[connections[i, 0]][1](t)
            strain[i, 0,
                   t] = splines[connections[i, 0]][2](t) - initial_dist[i]

    positions = np.array(positions)
    shape = (500, 500)

    xp, yp, cubic = gridder.interp(positions[:, 1],
                                   positions[:, 0],
                                   strain[:, 0, -1],
                                   shape,
                                   algorithm='cubic',
                                   extrapolate=False)

    pics = []
    fig, ax = plt.subplots()
    vertices = triangulation.points
    simplices = triangulation.simplices
    minstrain = np.amin(strain)
    maxstrain = np.amax(strain)
    cs = 0

    def animate(t):
        ax.clear()
        date = start + datetime.timedelta(days=t)
        ax.set_title(date)
        a, b, th = gridder.interp(positions[:, 1],
                                  positions[:, 0],
                                  strain[:, 0, t],
                                  shape,
                                  algorithm='cubic',
                                  extrapolate=False)
        cs = ax.contourf(xp.reshape(shape),
                         yp.reshape(shape),
                         th.reshape(shape),
                         200,
                         cmap='jet',
                         vmin=minstrain,
                         vmax=maxstrain)
        grid = ax.triplot(vertices[:, 1],
                          vertices[:, 0],
                          simplices,
                          linewidth=0.5)
        ax.axis('equal')

    ani = animation.FuncAnimation(fig,
                                  animate,
                                  frames=range(0, rng, 7),
                                  interval=80,
                                  save_count=500,
                                  blit=False)
    ani.save("move.mp4")
    plt.show()
from fatiando import mesher, gridder, utils
from fatiando.datasets import fetch_hawaii_gravity
from fatiando.gravmag import transform
import matplotlib.pyplot as plt
import numpy as np

# Fetch Hawaii data
data = fetch_hawaii_gravity()

# When the data is projected using UTM zone 4, it is no longer regular gridded.
# We must regrid it.
area = (1.483e6, 3.079e6, -60e3, 1.326e6)
shape = (77, 67)
x, y, gravity = gridder.interp(data['x'],
                               data['y'],
                               data['topo-free'],
                               shape,
                               area=area)

# Lets compute the Power Density Spectra (2d arrays)
kx, ky, pds = transform.power_density_spectra(x, y, gravity, shape)

# And then compute the radial average of the PDS
k_radial, pds_radial = transform.radial_average_spectrum(kx, ky, pds)

# Plot Hawaii gravity and radially averaged power spectrum
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4))
cm = ax1.contourf(y.reshape(shape), x.reshape(shape), gravity.reshape(shape),
                  100)
ax1.contour(y.reshape(shape),
            x.reshape(shape),
Example #12
0
    x1, x2, z1, z2 = [
        max(xp) / 2 - model_prop['HWD'][1] / 2,
        max(xp) / 2 + model_prop['HWD'][1] / 2,
        model_prop['HWD'][2] + model_prop['HWD'][0] / 2,
        model_prop['HWD'][2] - model_prop['HWD'][0] / 2
    ]
    xxzz = [x1, x2, z1, z2]
    CT = model_prop['SoilR'] / model_prop['AnoR']

    fix_peak_nb = 4
    smooth = False
    interp = True

    #%%
    shape = (200, 200)
    _, _, uA = gridder.interp(xp, yp, uA, shape)
    xp, yp, uT = gridder.interp(xp, yp, uT, shape)

    #%%
    # remove B return electrode effects using :mod:`uEXP.cor_field_B` using a resistivity of 1 Ohm.m

    U_cor = uEXP.cor_field_B(xyzs[:-3, 0],
                             xyzs[:-3, 1],
                             xyzs[:-3, 2],
                             uT_elecs,
                             Bpos,
                             rho=model_prop['SoilR'])

    #%%
    # Compare the voltage seen by the surface electrode using 2d plot over a line
    p1_elecs = [min(xyzs[:-3, 0]), (max(xyzs[:-3, 0]) + min(xyzs[:-3, 0])) / 2]
Example #13
0
shape = (100, 100)

# First, we need to know the real data at the grid points
grdx, grdy = gridder.regular(area, shape)
grdz = data(grdx, grdy)
mpl.figure()
mpl.subplot(2, 2, 1)
mpl.axis('scaled')
mpl.title("True grid data")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)

# Use the default interpolation (cubic)
grdx, grdy, grdz = gridder.interp(x, y, z, shape)
mpl.subplot(2, 2, 2)
mpl.axis('scaled')
mpl.title("Interpolated using cubic minimum-curvature")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)

# Use the nearest neighbors interpolation
grdx, grdy, grdz = gridder.interp(x, y, z, shape, algorithm='nn')
mpl.subplot(2, 2, 3)
mpl.axis('scaled')
mpl.title("Interpolated using nearest neighbors")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
Example #14
0
# Generate synthetic data measured at random points
area = (0, 1, 0, 1)
x, y = gridder.scatter(area, n=500, seed=0)
data = x * (1 - x) * np.cos(4 * np.pi * x) * np.sin(4 * np.pi * y**2)**2

# Say we want to interpolate the data onto a regular grid with a given shape
shape = (100, 200)

# The gridder.interp function takes care of selecting the containing area of
# the data and generating the regular grid for us.
# Let's interpolate using the different options offered by gridddata and plot
# them all.

plt.figure(figsize=(10, 8))

xp, yp, nearest = gridder.interp(x, y, data, shape, algorithm='nearest')
plt.subplot(2, 2, 1)
plt.title('Nearest-neighbors')
plt.contourf(yp.reshape(shape),
             xp.reshape(shape),
             nearest.reshape(shape),
             30,
             cmap='RdBu_r')

xp, yp, linear = gridder.interp(x, y, data, shape, algorithm='linear')
plt.subplot(2, 2, 2)
plt.title('Linear')
plt.contourf(yp.reshape(shape),
             xp.reshape(shape),
             linear.reshape(shape),
             30,
Example #15
0
# U = dEXP.smooth2d(xp, yp, U, sigma=5)

#%% ------------------------------- Plot the data
# U = np.copy(Us)

# _, p1, p2, _ = MALM.definep1p2(path=Main,radius=300)
# xx, yy, distance, profile = pEXP.plot_line(xp, yp, U ,p1,p2, interp=True)
# xx, yy, distance, profile = pEXP.plot_line(xp, yp, U ,p1,p2, interp=False, smooth=True)
# xx, yy, distance, profile = pEXP.plot_line(xp, yp, U ,p1,p2, interp=False, smooth=False)

# xx, yy, distance, profile = pEXP.plot_line(xp, yp, U_f ,p1,p2, interp=interp)

#%%
shape = (100, 100)
xp_int, yp_int, U_int = gridder.interp(xp, yp, U, shape, extrapolate=False)

plt.figure()
plt.scatter(xp_int, yp_int, c=U_int, label='U_int')
plt.grid()
plt.legend()
p12x = [p1[0], p2[0]]
p12y = [p1[1], p2[1]]
plt.plot(p12x, p12y, c='red')
p12v = plt.scatter(p12x, p12y, c='red')
txt = ['p1', 'p2']
for i in range(len(p12x)):
    plt.annotate(txt[i], (p12x[i], p12y[i]), c='red')

plt.xlabel('x (m)')
plt.ylabel('y (m)')