Skip to content

Commit

Permalink
Merge pull request #1 from fatiando/master
Browse files Browse the repository at this point in the history
bring recent changes from fatiando/harmonica master
  • Loading branch information
birocoles authored Oct 23, 2019
2 parents 5e33a79 + 43ba585 commit 116c3aa
Show file tree
Hide file tree
Showing 28 changed files with 1,469 additions and 156 deletions.
6 changes: 6 additions & 0 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ jobs:
- bash: echo "##vso[task.prependpath]$CONDA/bin"
displayName: Add conda to PATH

# On Hosted macOS, the agent user doesn't have ownership of Miniconda's installation
# directory We need to take ownership if we want to update conda or install packages
# globally
- bash: sudo chown -R $USER $CONDA
displayName: Take ownership of conda installation

# Get the Fatiando CI scripts
- bash: git clone --branch=1.1.1 --depth=1 https:/fatiando/continuous-integration.git
displayName: Fetch the Fatiando CI scripts
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,attribute-defined-outside-init,similarities,bad-continuation,import-error,assignment-from-no-return
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,attribute-defined-outside-init,similarities,bad-continuation,import-error,assignment-from-no-return,unsubscriptable-object

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ read it carefully.
## How Can I Talk to You?

Discussion often happens in the issues and pull requests.
In addition, there is a [Gitter chat room](https://gitter.im/fatiando/fatiando) for the
In addition, there is a [Slack chat room](http://contact.fatiando.org) for the
Fatiando a Terra project where you can ask questions.


Expand Down
9 changes: 3 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

`Documentation <http://www.fatiando.org/harmonica>`__ |
`Documentation (dev version) <http://www.fatiando.org/harmonica/dev>`__ |
`Contact <https://gitter.im/fatiando/fatiando>`__ |
`Contact <http://contact.fatiando.org>`__ |
Part of the `Fatiando a Terra <https://www.fatiando.org>`__ project

.. image:: http://img.shields.io/pypi/v/harmonica.svg?style=flat-square
Expand All @@ -30,9 +30,6 @@ Part of the `Fatiando a Terra <https://www.fatiando.org>`__ project
.. image:: https://img.shields.io/pypi/pyversions/harmonica.svg?style=flat-square
:alt: Compatible Python versions.
:target: https://pypi.python.org/pypi/harmonica
.. image:: https://img.shields.io/gitter/room/fatiando/fatiando.svg?style=flat-square
:alt: Chat room on Gitter
:target: https://gitter.im/fatiando/fatiando


.. placeholder-for-doc-index
Expand All @@ -47,7 +44,7 @@ We welcome any feedback and ideas!
Let us know by submitting
`issues on Github <https:/fatiando/harmonica/issues>`__
or send us a message on our
`Gitter chatroom <https://gitter.im/fatiando/fatiando>`__.
`Slack chatroom <http://contact.fatiando.org>`__.


About
Expand Down Expand Up @@ -91,7 +88,7 @@ Contacting Us
Feel free to `open an issue
<https:/fatiando/harmonica/issues/new>`__ or comment
on any open issue or pull request.
* We have `chat room on Gitter <https://gitter.im/fatiando/fatiando>`__
* We have `chat room on Slack <http://contact.fatiando.org>`__
where you can ask questions and leave comments.


Expand Down
11 changes: 11 additions & 0 deletions data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ These files are used as sample data in Harmonica:
survey, made available by the Geological Survey of Brazil (CPRM) through their [GEOSGB
portal](http://geosgb.cprm.gov.br/). See the original data for more processing
information.
* `south-africa-gravity.ast.xz`:
Land gravity survey performed in January 1986 within the boundaries of the Republic of
South Africa. Columns are longitude, latitude, elevation (above sea level) and gravity
(mGal). The observed gravity values are referenced to the International Gravity
Standardization Net 1971 (IGSN 71). The data was made available by the [National
Centers for Environmental Information (NCEI)](https://www.ngdc.noaa.gov/) (formerly
NGDC) and are in the [public
domain](https://www.ngdc.noaa.gov/ngdcinfo/privacy.html#copyright-notice). Original
data files can be found at:
https://www.ngdc.noaa.gov/mgg/gravity/1999/data/regional/africa/ The data are stored
in a netCDF file and then `xz` compressed.
41 changes: 41 additions & 0 deletions data/examples/south_africa_gravity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Land Gravity Data from South Africa
===================================
Land gravity survey performed in January 1986 within the boundaries of the Republic of
South Africa. The data was made available by the `National Centers for Environmental
Information (NCEI) <https://www.ngdc.noaa.gov/>`__ (formerly NGDC) and are in the
`public domain <https://www.ngdc.noaa.gov/ngdcinfo/privacy.html#copyright-notice>`__.
The entire dataset is stored in a :class:`pandas.DataFrame` with columns: longitude,
latitude, elevation (above sea level) and gravity(mGal). See the documentation for
:func:`harmonica.datasets.fetch_south_africa_gravity` for more information.
"""
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import verde as vd
import harmonica as hm

# Fetch the data in a pandas.DataFrame
data = hm.datasets.fetch_south_africa_gravity()
print(data)

# Plot the observations in a Mercator map using Cartopy
fig = plt.figure(figsize=(6.5, 5))
ax = plt.axes(projection=ccrs.Mercator())
ax.set_title("Observed gravity data from South Africa", pad=25)
tmp = ax.scatter(
data.longitude,
data.latitude,
c=data.gravity,
s=0.8,
cmap="viridis",
transform=ccrs.PlateCarree(),
)
plt.colorbar(
tmp, ax=ax, label="observed gravity [mGal]", aspect=50, pad=0.1, shrink=0.92
)
ax.set_extent(vd.get_region((data.longitude, data.latitude)))
ax.gridlines(draw_labels=True)
ax.coastlines()
plt.tight_layout()
plt.show()
Binary file added data/south-africa-gravity.ast.xz
Binary file not shown.
10 changes: 10 additions & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ Gravity Corrections
normal_gravity
bouguer_correction

Equivalent Layers
--------------------------

.. autosummary::
:toctree: generated/

EQLHarmonic

Forward modelling
-----------------

.. autosummary::
:toctree: generated/

point_mass_gravity
prism_gravity
tesseroid_gravity

Isostasy
Expand Down Expand Up @@ -76,6 +85,7 @@ Datasets
datasets.fetch_geoid_earth
datasets.fetch_topography_earth
datasets.fetch_rio_magnetic
datasets.fetch_south_africa_gravity

Utilities
---------
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
('<i class="fa fa-external-link-square fa-fw"></i> Fatiando a Terra', 'https://www.fatiando.org'),
('<i class="fa fa-users fa-fw"></i> Contributing', 'https:/fatiando/harmonica/blob/master/CONTRIBUTING.md'),
('<i class="fa fa-gavel fa-fw"></i> Code of Conduct', 'https:/fatiando/harmonica/blob/master/CODE_OF_CONDUCT.md'),
('<i class="fa fa-comment fa-fw"></i> Contact', 'https://gitter.im/fatiando/fatiando'),
('<i class="fa fa-comment fa-fw"></i> Contact', 'http://contact.fatiando.org'),
('<i class="fa fa-github fa-fw"></i> Source Code', 'https:/fatiando/harmonica'),
],
# Custom variables to enable "Improve this page"" and "Download notebook"
Expand Down
5 changes: 5 additions & 0 deletions doc/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ References
.. [AmanteEakins2009] Amante, C. and B.W. Eakins, 2009. ETOPO1 1 Arc-Minute Global Relief Model: Procedures, Data Sources and Analysis. NOAA Technical Memorandum NESDIS NGDC-24. National Geophysical Data Center, NOAA. doi:`10.7289/V5C8276M <https://doi.org/10.7289/V5C8276M>`__
.. [BarthelmesKohler2016] Barthelmes, F. and Kohler, W. (2016), International Centre for Global Earth Models (ICGEM), in: Drewes, H., Kuglitsch, F., Adam, J. et al., The Geodesists Handbook 2016, Journal of Geodesy (2016), 90(10), pp 907-1205, doi:`10.1007/s00190-016-0948-z <https://doi.org/10.1007/s00190-016-0948-z>`__
.. [Blakely1995] Blakely, R. (1995). Potential Theory in Gravity and Magnetic Applications. Cambridge: Cambridge University Press. doi:`10.1017/CBO9780511549816 <https://doi.org/10.1017/CBO9780511549816>`__
.. [Cooper2000] Cooper, G.R.J. (2000), Gridding gravity data using an equivalent layer, Computers & Geosciences, Computers & Geosciences, doi:`10.1016/S0098-3004(99)00089-8 <https://doi.org/10.1016/S0098-3004(99)00089-8>`__
.. [Dampney1969] Dampney, C. N. G. (1969). The equivalent source technique. Geophysics, 34(1), 39–53. doi:`10.1190/1.1439996 <https://doi.org/10.1190/1.1439996>`__
.. [Forste_etal2014] Förste, Christoph; Bruinsma, Sean.L.; Abrikosov, Oleg; Lemoine, Jean-Michel; Marty, Jean Charles; Flechtner, Frank; Balmino, G.; Barthelmes, F.; Biancale, R. (2014): EIGEN-6C4 The latest combined global gravity field model including GOCE data up to degree and order 2190 of GFZ Potsdam and GRGS Toulouse. GFZ Data Services. doi:`10.5880/icgem.2015.1 <http://doi.org/10.5880/icgem.2015.1>`__
.. [Fukushima2019] Fukushima, T. (2019). Fast computation of prismatic gravitational field. doi:`10.13140/RG.2.2.30598.93766 <https://doi.org/10.13140/RG.2.2.30598.93766>`__
.. [Grombein2013] Grombein, T., Seitz, K., Heck, B. (2013), Optimized formulas for the gravitational field of a tesseroid, Journal of Geodesy. doi:`10.1007/s00190-013-0636-1 <https://doi.org/10.1007/s00190-013-0636-1>`__
.. [Hofmann-WellenhofMoritz2006] Hofmann-Wellenhof, B., & Moritz, H. (2006). Physical Geodesy (2nd, corr. ed. 2006 edition ed.). Wien ; New York: Springer.
.. [LiGotze2001] Li, X. and H. J. Gotze, 2001, Tutorial: Ellipsoid, geoid, gravity, geodesy, and geophysics, Geophysics, 66(6), p. 1660-1668, doi:`10.1190/1.1487109 <https://doi.org/10.1190/1.1487109>`__
.. [Nagy2000] Nagy, D., Papp, G. & Benedek, J.(2000). The gravitational potential and its derivatives for the prism. Journal of Geodesy 74: 552. doi:`10.1007/s001900000116 <https://doi.org/10.1007/s001900000116>`__
.. [Nagy2002] Nagy, D., Papp, G. & Benedek, J.(2000). Corrections to "The gravitational potential and its derivatives for the prism". Journal of Geodesy (2002) 76: 475. doi:`10.1007/s00190-002-0264-7 <https://doi.org/10.1007/s00190-002-0264-7>`__
.. [TurcotteSchubert2014] Turcotte, D. L., & Schubert, G. (2014). Geodynamics (3 edition). Cambridge, United Kingdom: Cambridge University Press.
.. [Vermeille2002] Vermeille, H., 2002. Direct transformation from geocentric coordinates to geodetic coordinates. Journal of Geodesy. 76. 451-454. doi:`10.1007/s00190-002-0273-6 <https://doi.org/10.1007/s00190-002-0273-6>`__
.. [Moritz2000] Moritz, H. (2000). Geodetic Reference System 1980. Journal of Geodesy, 74(1), 128–133. doi:`10.1007/s001900050278 <https://doi.org/10.1007/s001900050278>`__
2 changes: 2 additions & 0 deletions examples/eql/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Equivalent Layers
-----------------
97 changes: 97 additions & 0 deletions examples/eql/harmonic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""
Gridding and upward continuation
================================
Most potential field surveys gather data along scattered and uneven flight lines or
ground measurements. For a great number of applications we may need to interpolate these
data points onto a regular grid at a constant altitude. Upward-continuation is also a
routine task for smoothing, noise attenuation, source separation, etc.
Both tasks can be done simultaneously through an *equivalent layer* [Dampney1969]_. We
will use :class:`harmonica.EQLHarmonic` to estimate the coefficients of a set of point
sources (the equivalent layer) that fit the observed data. The fitted layer can then be
used to predict data values wherever we want, like on a grid at a certain altitude. The
sources for :class:`~harmonica.EQLHarmonic` in particular are placed one beneath each
data point at a constant relative depth from the elevation of the data point following
[Cooper2000]_.
The advantage of using an equivalent layer is that it takes into account the 3D nature
of the observations, not just their horizontal positions. It also allows data
uncertainty to be taken into account and noise to be suppressed though the least-squares
fitting process. The main disadvantage is the increased computational load (both in
terms of time and memory).
"""
import matplotlib.pyplot as plt
import numpy as np
import pyproj
import verde as vd
import harmonica as hm


# Fetch the sample total-field magnetic anomaly data from Rio de Janeiro
data = hm.datasets.fetch_rio_magnetic()

# Slice a smaller portion of the survey data to speed-up calculations for this example
region = [-42.35, -42.10, -22.35, -22.15]
inside = vd.inside((data.longitude, data.latitude), region)
data = data[inside]
print("Number of data points:", data.shape[0])

# Since this is a small area, we'll project our data and use Cartesian coordinates
projection = pyproj.Proj(proj="merc", lat_ts=data.latitude.mean())
easting, northing = projection(data.longitude.values, data.latitude.values)
coordinates = (easting, northing, data.altitude_m)

# Create the equivalent layer. We'll use the default point source configuration at a
# constant relative depth beneath each observation point. The damping parameter helps
# smooth the predicted data and ensure stability.
eql = hm.EQLHarmonic(relative_depth=1000, damping=10)

# Fit the layer coefficients to the observed magnetic anomaly.
eql.fit(coordinates, data.total_field_anomaly_nt)

# Evaluate the data fit by calculating an R² score against the observed data.
# This is a measure of how well layer the fits the data NOT how good the interpolation
# will be.
print("R² score:", eql.score(coordinates, data.total_field_anomaly_nt))

# Interpolate data on a regular grid with 400 m spacing. The interpolation requires an
# extra coordinate (upward height). By passing in 500 m, we're effectively
# upward-continuing the data (mean flight height is 200 m).
grid = eql.grid(spacing=400, data_names=["magnetic_anomaly"], extra_coords=500)

# The grid is a xarray.Dataset with values, coordinates, and metadata
print("\nGenerated grid:\n", grid)

# Plot original magnetic anomaly and the gridded and upward-continued version
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(12, 6), sharey=True)

# Get the maximum absolute value between the original and gridded data so we can use the
# same color scale for both plots and have 0 centered at the white color.
maxabs = vd.maxabs(data.total_field_anomaly_nt, grid.magnetic_anomaly.values)

ax1.set_title("Observed magnetic anomaly data")
tmp = ax1.scatter(
easting,
northing,
c=data.total_field_anomaly_nt,
s=20,
vmin=-maxabs,
vmax=maxabs,
cmap="seismic",
)
plt.colorbar(tmp, ax=ax1, label="nT", pad=0.05, aspect=40, orientation="horizontal")

ax2.set_title("Gridded and upward-continued")
tmp = grid.magnetic_anomaly.plot.pcolormesh(
ax=ax2,
add_colorbar=False,
add_labels=False,
vmin=-maxabs,
vmax=maxabs,
cmap="seismic",
)
plt.colorbar(tmp, ax=ax2, label="nT", pad=0.05, aspect=40, orientation="horizontal")

plt.tight_layout(pad=0)
plt.show()
Loading

0 comments on commit 116c3aa

Please sign in to comment.