Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to create a tesseroid layer #316

Merged
merged 51 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ebcd3e3
Add pandas and ensaio in the environment file
aguspesce May 30, 2022
f8470e9
Create tesseroid layer example
aguspesce May 30, 2022
20228ed
Merge branch 'main' into tesseroid_layers
aguspesce May 30, 2022
ebd120a
Update how to create the surface and reference arrays in the example
aguspesce Jun 9, 2022
e69d5e6
Add tesseroid_layer in the init file
aguspesce Jun 9, 2022
da5fd2b
Merge branch 'tesseroid_layers' of github.com:aguspesce/harmonica int…
aguspesce Jun 9, 2022
d3d9668
Start to write the tesseroid layer function
aguspesce Jun 10, 2022
b22b6fe
Add docstring and more properties
aguspesce Jun 10, 2022
b688647
Calculate the gravity in the example
aguspesce Jun 24, 2022
bce870c
Import warning
aguspesce Jun 24, 2022
1379904
Improve docstring in some functions on tesseroid_layer
aguspesce Jun 24, 2022
ea800df
Fix the name of the _check_regular_grid function
aguspesce Jun 24, 2022
586b520
Create a property called boundaries.
aguspesce Jun 24, 2022
a15f24e
Start function to calcuate the gravity for a tesseroid layer
aguspesce Jul 5, 2022
7f5053f
Fix docstring and change some variable names
aguspesce Jul 7, 2022
e2ba40b
Some changes to tesseroid layer example
santisoler Jul 7, 2022
737fefc
Make check and format
aguspesce Aug 25, 2022
7521959
Add test to check if a layer of prisms is property constructed
aguspesce Aug 25, 2022
6f220a4
Merge branch 'main' of github.com:fatiando/harmonica into tesseroid_l…
aguspesce Sep 8, 2022
a5585fc
Add test to check properties and surface reference
aguspesce Sep 8, 2022
1508436
Add test to check the tesseroid layer with a not regular grid
aguspesce Sep 8, 2022
0b2a15a
Add a test to check attributes and _to_tesseroids method
aguspesce Sep 10, 2022
26f34c6
Add method to obtain the tesseroid by index
aguspesce Sep 12, 2022
86dfb48
Add test to check tesseroid by index
aguspesce Sep 12, 2022
3b59f14
Add test to check nans mask
aguspesce Sep 13, 2022
dd01485
Fix return in nonans_mask method
aguspesce Sep 13, 2022
ff84516
Add test to check the property in the nonans_mask
aguspesce Sep 13, 2022
15406f9
Add test to check if gravity method works
aguspesce Sep 13, 2022
647822d
Add test to check if gravity method works when surface has nans
aguspesce Sep 13, 2022
05de3b1
Add test to check if gravity method works when density has nans
aguspesce Sep 13, 2022
96933fb
Check format
aguspesce Sep 13, 2022
b885836
Merge branch 'main' into tesseroid_layers
aguspesce Sep 13, 2022
bad6ae4
Improve test for invalid surface and reference
santisoler Sep 22, 2022
9a2aba7
Fix failing test
santisoler Sep 22, 2022
fe6864d
Add a function to check the tesseroid overlap
aguspesce Sep 23, 2022
2073874
Add a test to check the overlap function
aguspesce Sep 23, 2022
f015fd6
Fit typo on harmonica/forward/tesseroid_layer.py
aguspesce Sep 23, 2022
5ada8fe
Fix the number of point in linspace in the overlap function
aguspesce Sep 23, 2022
c14a880
Change when the overlap check runs
aguspesce Sep 23, 2022
35043da
Merge branch 'tesseroid_layers' of github.com:aguspesce/harmonica int…
aguspesce Sep 23, 2022
7f4444a
Change the error message in the overlap check
aguspesce Sep 23, 2022
edb0b9e
Fix the test function to check tesseroid overlap
aguspesce Sep 23, 2022
80061c4
Add a plot to the example
aguspesce Sep 27, 2022
fef62db
Run make format
aguspesce Sep 27, 2022
82ce294
Merge branch 'main' into tesseroid_layers
aguspesce Sep 27, 2022
b3a087c
Replace height for radius in docstring
santisoler Sep 28, 2022
771257d
Minor function and parameters renaming
santisoler Sep 28, 2022
58c3507
Fix errors and move error message to its own variable
santisoler Sep 28, 2022
48f581f
Fix sign of density contrast of the ocean
santisoler Sep 28, 2022
5002c6d
Improve the map of the example
santisoler Sep 28, 2022
a10495f
Add missing attrs to the tesseroid layer
santisoler Sep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions examples/forward/tesseroid_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) 2018 The Harmonica Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
#
# This code is part of the Fatiando a Terra project (https://www.fatiando.org)
#
"""
Layer of tesseroids
===================
"""
import boule as bl
import ensaio
import numpy as np
import pygmt
import verde as vd
import xarray as xr

import harmonica as hm

fname = ensaio.fetch_earth_topography(version=1)
topo = xr.load_dataarray(fname)

region = (-78, -53, -57, -20)
topo = topo.sel(latitude=slice(*region[2:]), longitude=slice(*region[:2]))

ellipsoid = bl.WGS84

longitude, latitude = np.meshgrid(topo.longitude, topo.latitude)
reference = ellipsoid.geocentric_radius(latitude)
surface = topo + reference
density = xr.where(topo > 0, 2670.0, 2670.0 - 1040.0)

tesseroids = hm.tesseroid_layer(
coordinates=(topo.longitude, topo.latitude),
surface=surface,
reference=reference,
properties={"density": density},
)

# Create a regular grid of computation points located at 10km above reference
grid_longitude, grid_latitude = vd.grid_coordinates(region=region, spacing=0.5)
grid_radius = ellipsoid.geocentric_radius(grid_latitude) + 10e3
grid_coords = (grid_longitude, grid_latitude, grid_radius)

# Compute gravity field of tesseroids on a regular grid of observation points
gravity = tesseroids.tesseroid_layer.gravity(grid_coords, field="g_z")

grid = pygmt.xyz2grd(
x=grid_longitude.flatten(),
y=grid_latitude.flatten(),
z=gravity.flatten(),
region=region,
spacing=(0.5, 0.5),
)

# Plot gravity field
fig = pygmt.Figure()
fig.grdimage(
grid,
projection="M15c",
cmap="viridis",
nan_transparent=True,
)
fig.basemap(frame=True)
fig.colorbar(frame='af+l"Gravity [mGal]"', position="JCR")
fig.coast(shorelines="0.5p,black", borders=["1/0.5p,black"])
fig.show()
1 change: 1 addition & 0 deletions harmonica/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .forward.prism import prism_gravity
from .forward.prism_layer import DatasetAccessorPrismLayer, prism_layer
from .forward.tesseroid import tesseroid_gravity
from .forward.tesseroid_layer import DatasetAccessorTesseroidLayer, tesseroid_layer
from .gravity_corrections import bouguer_correction
from .io import load_icgem_gdf
from .isostasy import isostasy_airy, isostatic_moho_airy
Expand Down
Loading