def test_crust(): """ Regression test that checks whether the mean crustal depths and velocity is still the same as at time of creation, also generates vtk files :return: """ # Generate Grid rad = 6351.0 fib_grid = FibonacciGrid() radii = np.array(np.linspace(rad, rad, 1)) resolution = np.ones_like(radii) * 500 fib_grid.set_global_sphere(radii, resolution) grid_data = GridData(*fib_grid.get_coordinates()) grid_data.add_one_d() crust = Crust() crust_dep = crust.interpolate(grid_data.df['c'], grid_data.df['l'], param='crust_dep', smooth_fac=crust.crust_dep_smooth_fac) crust_vs = crust.interpolate(grid_data.df['c'], grid_data.df['l'], param='crust_vs', smooth_fac=crust.crust_dep_smooth_fac) #Test if mean crustal depth and velocity remain the same mean_crust_dep_test = np.array([18.9934922621]) mean_crust_vs_test = np.array([3.42334914127]) mean_crust_dep = np.mean(crust_dep) mean_crust_vs = np.mean(crust_vs) np.testing.assert_almost_equal(mean_crust_dep, mean_crust_dep_test, decimal=DECIMAL_CLOSE) np.testing.assert_almost_equal(mean_crust_vs, mean_crust_vs_test, decimal=DECIMAL_CLOSE) # Write vtk's x, y, z = grid_data.get_coordinates().T elements = triangulate(x, y, z) coords = np.array((x, y, z)).T write_vtk(os.path.join(VTK_DIR, 'crust_dep.vtk'), coords, elements, crust_dep, 'crust_dep') write_vtk(os.path.join(VTK_DIR, 'crust_vs.vtk'), coords, elements, crust_vs, 'crust_vs')
def test_rotation(): # Generate visualisation grid fib_grid = FibonacciGrid() # Set global background grid radii = np.linspace(6271.0, 6271.0, 1) resolution = np.ones_like(radii) * 300 fib_grid.set_global_sphere(radii, resolution) grid_data = GridData(*fib_grid.get_coordinates()) grid_data.add_one_d() grid_data.set_component('vsv', np.zeros(len(grid_data))) mod = s3d.Ses3d(os.path.join(os.path.join(TEST_DATA_DIR, 'test_region')), components=['vsv']) mod.eval_point_cloud_griddata(grid_data) mod = s3d.Ses3d(os.path.join(os.path.join(TEST_DATA_DIR, 'test_region')), components=['vsv']) mod.eval_point_cloud_griddata(grid_data, interp_method='radial_basis_func') mod.eval_point_cloud_griddata(grid_data, interp_method='griddata_linear') mod.eval_point_cloud_griddata(grid_data) grid_data.del_one_d()
def evaluate_csem(x, y, z, regions=None, regions_2=None): """ Evaluate the CSEM on Cartesian grid points x, y, z, provided as input. Return a GridData object. :param x: np array of x-coordinates in kilometers :param y: np array of y-coordinates in kilometers :param z: np array of y-coordinates in kilometers :param regions: specifies the region where the point(x,y,z) falls into in the one dimensional Earth model. :param regions_2: secondary region used for averaging over discontinuities :return: a grid_data object with the required information contained on it. """ csemlib_directory, _ = os.path.split(os.path.split(__file__)[0]) model_dir = os.path.join(csemlib_directory, 'data', 'refinements') grid_data = GridData(x, y, z) # Base Model. -------------------------------------------------------------- # Add 1D background model to a mesh with or without explicit # discontinuities. if (regions is not None) and (regions_2 is not None): grid_data.add_one_d_continuous(region_min_eps=regions, region_plus_eps=regions_2) elif regions is not None: grid_data.add_one_d_discontinuous(regions) else: grid_data.add_one_d() # Add S20RTS s20 = S20rts() s20.eval_point_cloud_griddata(grid_data) # Regional refinements and crustal model. ---------------------------------- # Models without crust that must be added before adding the crust. # Add South Atlantic ses3d = Ses3d(os.path.join(model_dir, 'south_atlantic_2013'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # # Add Australia ses3d = Ses3d(os.path.join(model_dir, 'australia_2010'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Overwrite crustal values. cst = Crust() cst.eval_point_cloud_grid_data(grid_data) # Add 3D models with crustal component. # Add Japan ses3d = Ses3d(os.path.join(model_dir, 'japan_2016'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add Europe ses3d = Ses3d(os.path.join(model_dir, 'europe_2013'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add Marmara ses3d = Ses3d(os.path.join(model_dir, 'marmara_2017'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add South-East Asia ses3d = Ses3d(os.path.join(model_dir, 'south_east_asia_2017'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add Iberia 2015 ses3d = Ses3d(os.path.join(model_dir, 'iberia_2015'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add Iberia 2017 ses3d = Ses3d(os.path.join(model_dir, 'iberia_2017'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add North Atlantic 2013 ses3d = Ses3d(os.path.join(model_dir, 'north_atlantic_2013'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add North America 2017 ses3d = Ses3d(os.path.join(model_dir, 'north_america_2017'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add Japan 2017 ses3d = Ses3d(os.path.join(model_dir, 'japan_2017'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add Eastern Mediterranean 2019 ses3d = Ses3d(os.path.join(model_dir, 'eastern_mediterranean_2019'), grid_data.components) ses3d.eval_point_cloud_griddata(grid_data) # Add Michael Afanasiev's global update global1 = Specfem(interp_method="trilinear_interpolation") global1.eval_point_cloud_griddata(grid_data) # Add Neda Masouminia's Iran model salvus_v1 = Salvus_v1(os.path.join(model_dir, 'iran_2019')) salvus_v1.eval_point_cloud_griddata(grid_data) return grid_data