|
| 1 | +# Importing GemPy |
| 2 | +import gempy as gp |
| 3 | +from gempy_plugins.assets.geophysics import MagneticsPreprocessing |
| 4 | + |
| 5 | +# Importing auxiliary libraries |
| 6 | +import numpy as np |
| 7 | +import pytest |
| 8 | + |
| 9 | + |
| 10 | +def test_magnetics_api(interpolator_magnetics): |
| 11 | + # TODO add the check |
| 12 | + |
| 13 | + geo_model = gp.create_model('test_center_grid_slicing') |
| 14 | + geo_model.set_default_surfaces() |
| 15 | + geo_model.add_surface_points(X=-1, Y=0, Z=0, surface='surface1') |
| 16 | + geo_model.add_surface_points(X=1, Y=0, Z=0, surface='surface1') |
| 17 | + geo_model.add_orientations(X=0, Y=0, Z=0, surface='surface1', pole_vector=(0, 0, 1)) |
| 18 | + geo_model._surfaces.add_surfaces_values([0.037289, 0.0297], ['susceptibility']) |
| 19 | + |
| 20 | + # needed constants |
| 21 | + mu_0 = 4.0 * np.pi * 10e-7 # magnetic permeability in free space [N/A^2] |
| 22 | + cm = mu_0 / (4.0 * np.pi) # constant for SI unit |
| 23 | + incl = 77.0653 # NOAA |
| 24 | + decl = 6.8116 |
| 25 | + B_ext = 52819.8506939139e-9 # T |
| 26 | + |
| 27 | + geo_model.set_regular_grid(extent=[-5, 5, -5, 5, -5, 5], resolution=[5, 5, 5]) |
| 28 | + geo_model.set_centered_grid(np.array([[0, 0, 0]]), resolution=[10, 10, 15], radius=5000) |
| 29 | + geo_model.set_aesara_function(interpolator_magnetics) |
| 30 | + geo_model._interpolator.set_aesara_shared_magnetics(V='auto', pos_magnetics=1, |
| 31 | + incl= incl, decl=decl, B_ext=B_ext) |
| 32 | + |
| 33 | + gp.compute_model(geo_model) |
| 34 | + print(geo_model._interpolator.aesara_graph.lg0.get_value()) |
| 35 | + print(geo_model.solutions.fw_magnetics) |
| 36 | + np.testing.assert_almost_equal(geo_model.solutions.fw_magnetics, |
| 37 | + np.array([473.7836]), decimal=4) |
| 38 | + |
| 39 | + |
| 40 | +@pytest.fixture(scope="module") |
| 41 | +def test_magnetics_no_regular_grid(interpolator_magnetics): |
| 42 | + # TODO add the check |
| 43 | + |
| 44 | + geo_model = gp.create_model('test_center_grid_slicing') |
| 45 | + geo_model.set_default_surfaces() |
| 46 | + geo_model.add_surface_points(X=-1, Y=0, Z=0, surface='surface1') |
| 47 | + geo_model.add_surface_points(X=1, Y=0, Z=0, surface='surface1') |
| 48 | + geo_model.add_orientations(X=0, Y=0, Z=0, surface='surface1', pole_vector=(0, 0, 1)) |
| 49 | + geo_model._surfaces.add_surfaces_values([0.037289, 0.0297], ['susceptibility']) |
| 50 | + |
| 51 | + # needed constants |
| 52 | + mu_0 = 4.0 * np.pi * 10e-7 # magnetic permeability in free space [N/A^2] |
| 53 | + cm = mu_0 / (4.0 * np.pi) # constant for SI unit |
| 54 | + incl = 77.0653 # NOAA |
| 55 | + decl = 6.8116 |
| 56 | + B_ext = 52819.8506939139e-9 # T |
| 57 | + |
| 58 | + geo_model.set_centered_grid(np.array([0, 0, 0]), resolution=[10, 10, 15], radius=5000) |
| 59 | + |
| 60 | + Vmodel = MagneticsPreprocessing(geo_model._grid.centered_grid).set_Vs_kernel() |
| 61 | + # gp.set_interpolator(geo_model, output=['magnetics']) |
| 62 | + geo_model.set_aesara_function(interpolator_magnetics) |
| 63 | + geo_model._interpolator.set_aesara_shared_magnetics(V= Vmodel, pos_magnetics=1, |
| 64 | + incl= incl, decl=decl, B_ext=B_ext) |
| 65 | + |
| 66 | + # geo_model.interpolator.aesara_graph.V.set_value(Vmodel) |
| 67 | + # geo_model.interpolator.aesara_graph.incl.set_value(incl) |
| 68 | + # geo_model.interpolator.aesara_graph.decl.set_value(decl) |
| 69 | + # geo_model.interpolator.aesara_graph.B_ext.set_value(B_ext) |
| 70 | + |
| 71 | + gp.compute_model(geo_model) |
| 72 | + np.testing.assert_almost_equal(geo_model.solutions.fw_magnetics, |
| 73 | + np.array([473.7836]), decimal=4) |
| 74 | + |
| 75 | + return geo_model |
| 76 | + |
| 77 | + |
| 78 | +def test_center_grid_slicing(test_magnetics_no_regular_grid): |
| 79 | + geo_model = test_magnetics_no_regular_grid |
| 80 | + |
| 81 | + geo_model.set_centered_grid(np.array([[0, 0, 0], |
| 82 | + [1, 1, 1]]), resolution=[10, 10, 15], radius=5000) |
| 83 | + |
| 84 | + gp.compute_model(geo_model) |
| 85 | + print(geo_model._interpolator.aesara_graph.lg0.get_value()) |
0 commit comments