Skip to content

Commit 3fbf217

Browse files
authored
Add sample airborne magnetic data from Rio (fatiando#24)
Use a subsection from the survey to limit file size. Original data are made freely available by the Geological Survey of Brazil (CPRM) through their [GEOSGB portal](http://geosgb.cprm.gov.br/). Adds pandas as a dependency.
1 parent 6b467c6 commit 3fbf217

13 files changed

+125
-5
lines changed

.codacy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ exclude_paths:
55
- '**/__init__.py'
66
- '**/tests/**'
77
- 'examples/**'
8+
- 'data/examples/**'

data/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ These files are used as sample data in Harmonica:
1515
from the EIGEN-6C4 gravity field model. Both grids were generated by the
1616
[ICGEM Calculation Service](http://icgem.gfz-potsdam.de). The data are stored in a
1717
netCDF file and then `xz` compressed using Python's `lzma` library.
18+
* `rio-magnetic.csv.xz`: Total-field magnetic anomaly data from the northwestern part of
19+
an airborne survey of Rio de Janeiro, Brazil, conducted in 1978. Columns are
20+
longitude, latitude, total field anomaly (nanoTesla), observation height above the
21+
WGS84 ellipsoid (meters), type of flight line (LINE or TIE), and flight line number.
22+
The anomaly is calculated with respect to the IGRF field at the center of the survey
23+
area at 500 m altitude for the year 1978.3. This dataset was cropped from the original
24+
survey, made available by the Geological Survey of Brazil (CPRM) through their [GEOSGB
25+
portal](http://geosgb.cprm.gov.br/). See the original data for more processing
26+
information.

data/examples/rio_magnetic.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Total Field Magnetic Anomaly from Rio de Janeiro
3+
================================================
4+
5+
A subsection from an airborne survey of the state of Rio de Janeiro, Brazil, conducted
6+
in 1978. The data are stored in a :class:`pandas.DataFrame` with columns: longitude,
7+
latitude, total field anomaly (nanoTesla), observation height above the WGS84 ellipsoid
8+
(meters), type of flight line (LINE or TIE), and flight line number. See the
9+
documentation for :func:`harmonica.datasets.fetch_rio_magnetic` for more information.
10+
"""
11+
import matplotlib.pyplot as plt
12+
import cartopy.crs as ccrs
13+
import verde as vd
14+
import harmonica as hm
15+
16+
# Fetch the data in a pandas.DataFrame
17+
data = hm.datasets.fetch_rio_magnetic()
18+
print(data)
19+
20+
# Plot the observations in a Mercator map using Cartopy
21+
fig = plt.figure(figsize=(10, 6))
22+
ax = plt.axes(projection=ccrs.Mercator())
23+
ax.set_title("Magnetic data from Rio de Janeiro", pad=25)
24+
maxabs = vd.maxabs(data.total_field_anomaly_nt)
25+
tmp = ax.scatter(
26+
data.longitude,
27+
data.latitude,
28+
c=data.total_field_anomaly_nt,
29+
s=0.8,
30+
cmap="seismic",
31+
vmin=-maxabs,
32+
vmax=maxabs,
33+
transform=ccrs.PlateCarree(),
34+
)
35+
plt.colorbar(
36+
tmp,
37+
ax=ax,
38+
label="total field magnetic anomaly [nT]",
39+
orientation="horizontal",
40+
aspect=50,
41+
shrink=0.7,
42+
pad=0.06,
43+
)
44+
ax.set_extent(vd.get_region((data.longitude, data.latitude)))
45+
ax.gridlines(draw_labels=True)
46+
plt.tight_layout()
47+
plt.show()

data/rio-magnetic.csv.xz

746 KB
Binary file not shown.

doc/api/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Datasets
4747

4848
datasets.fetch_gravity_earth
4949
datasets.fetch_topography_earth
50+
datasets.fetch_rio_magnetic
5051

5152
Utilities
5253
---------

doc/install.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ Dependencies
2121

2222
* `numpy <http://www.numpy.org/>`__
2323
* `scipy <https://docs.scipy.org/doc/scipy/reference/>`__
24-
* `pooch <http://www.fatiando.org/pooch/>`__
25-
* `attrs <https://www.attrs.org/>`__
24+
* `pandas <http://pandas.pydata.org/>`__
2625
* `xarray <https://xarray.pydata.org/>`__
26+
* `attrs <https://www.attrs.org/>`__
27+
* `pooch <http://www.fatiando.org/pooch/>`__
28+
* `verde <http://www.fatiando.org/verde/>`__
2729

2830
Most of the examples in the :ref:`gallery` also use:
2931

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ dependencies:
77
- pip
88
- numpy
99
- scipy
10+
- pandas
1011
- pooch
1112
- verde
1213
- attrs

harmonica/datasets/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# pylint: disable=missing-docstring
2-
from .sample_data import fetch_gravity_earth, fetch_topography_earth
2+
from .sample_data import fetch_gravity_earth, fetch_topography_earth, fetch_rio_magnetic

harmonica/datasets/registry.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
etopo1-0.5deg.nc.xz 9f21f7c946e649389dce28631de94fa05217750e9ebc77df4311458c33f0682b
22
gravity-earth-0.5deg.nc.xz 02c62a251225e2e76722a80d87c488160fbdcae2c1a8bbc2386c32e68ea8f43a
3+
rio-magnetic.csv.xz 134542c1a0c4b89040a4b7d0e52ff55b97e4a3fb7cbda7004a739166897a5eeb

harmonica/datasets/sample_data.py

+36
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import shutil
88

99
import xarray as xr
10+
import pandas as pd
1011
import pooch
1112

1213
from ..version import full_version
@@ -72,6 +73,41 @@ def fetch_topography_earth():
7273
return data
7374

7475

76+
def fetch_rio_magnetic():
77+
"""
78+
Fetch total-field magnetic anomaly data from Rio de Janeiro, Brazil.
79+
80+
These data are a subsection of an airborne survey of the state of Rio de Janeiro,
81+
Brazil, conducted in 1978. The data are made available by the Geological Survey of
82+
Brazil (CPRM) through their `GEOSGB portal <http://geosgb.cprm.gov.br/>`__.
83+
84+
The columns of the data table are longitude, latitude, total-field magnetic anomaly
85+
(nanoTesla), observation height above the WGS84 ellipsoid (in meters), flight line
86+
type (LINE or TIE), and flight line number for each data point.
87+
88+
The anomaly is calculated with respect to the IGRF field parameters listed on the
89+
table below. See the original data for more processing information.
90+
91+
+----------+-----------+----------------+-------------+-------------+
92+
| IGRF for year 1978.3 at 500 m height |
93+
+----------+-----------+----------------+-------------+-------------+
94+
| Latitude | Longitude | Intensity (nT) | Declination | Inclination |
95+
+==========+===========+================+=============+=============+
96+
| -22º15' | -42º15' | 23834 | -19º19' | -27º33' |
97+
+----------+-----------+----------------+-------------+-------------+
98+
99+
If the file isn't already in your data directory, it will be downloaded
100+
automatically.
101+
102+
Returns
103+
-------
104+
data : :class:`pandas.DataFrame`
105+
The magnetic anomaly data.
106+
107+
"""
108+
return pd.read_csv(POOCH.fetch("rio-magnetic.csv.xz"), compression="xz")
109+
110+
75111
def _load_xz_compressed_grid(fname, **kwargs):
76112
"""
77113
Load a netCDF grid that has been xz compressed. Keyword arguments are passed to

harmonica/tests/test_sample_data.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"""
44
import numpy.testing as npt
55

6-
from ..datasets.sample_data import fetch_gravity_earth, fetch_topography_earth
6+
from ..datasets.sample_data import (
7+
fetch_gravity_earth,
8+
fetch_topography_earth,
9+
fetch_rio_magnetic,
10+
)
711

812

913
def test_gravity_earth():
@@ -22,3 +26,20 @@ def test_topography_earth():
2226
assert grid.topography.shape == (361, 721)
2327
npt.assert_allclose(grid.topography.max(), 5622)
2428
npt.assert_allclose(grid.topography.min(), -8397)
29+
30+
31+
def test_rio_magnetic():
32+
"Sanity checks for the loaded dataset"
33+
data = fetch_rio_magnetic()
34+
assert data.shape == (81796, 6)
35+
npt.assert_allclose(data.longitude.min(), -43.199966)
36+
npt.assert_allclose(data.longitude.max(), -41.950012)
37+
npt.assert_allclose(data.latitude.min(), -22.569992)
38+
npt.assert_allclose(data.latitude.max(), -22.050003)
39+
npt.assert_allclose(data.total_field_anomaly_nt.min(), -636.180000)
40+
npt.assert_allclose(data.total_field_anomaly_nt.max(), 875.120000)
41+
npt.assert_allclose(data.altitude_m.min(), 62.180000)
42+
npt.assert_allclose(data.altitude_m.max(), 300.000000)
43+
npt.assert_allclose(data.line_number.min(), 1680)
44+
npt.assert_allclose(data.line_number.max(), 9600)
45+
assert set(data.line_type.unique()) == {"TIE", "LINE"}

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
numpy
22
scipy
3+
pandas
34
pooch
45
attrs
56
xarray

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"harmonica.datasets": ["registry.txt"],
4141
"harmonica.tests": ["data/*", "baseline/*"],
4242
}
43-
INSTALL_REQUIRES = ["numpy", "scipy", "pooch", "attrs", "xarray", "verde"]
43+
INSTALL_REQUIRES = ["numpy", "scipy", "pandas", "pooch", "attrs", "xarray", "verde"]
4444
PYTHON_REQUIRES = ">=3.5"
4545

4646
if __name__ == "__main__":

0 commit comments

Comments
 (0)