This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
/
seafloor.py
72 lines (63 loc) · 2.48 KB
/
seafloor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
Load the seafloor age, spreading rate, and spreading symmetry grids by
Müller et al. (2008).
"""
import xarray as xr
from pooch import Decompress
from .registry import REGISTRY
def fetch_seafloor_age(*, resolution="6min", load=True, **kwargs):
"""
Fetch the age of the oceanic lithosphere global grid
Grids produced by [Muller2008]_.
Includes the age uncertainty grid as well. Both are available in 2 and
6 arc-minute resolutions. The units for the ages are millions of years. The
grids span longitudes from 0 E to 360 E and latitudes from 90 N to -90
N and are grid-line registered.
If the files aren't already in your data directory, they will be downloaded
automatically.
Parameters
----------
resolution : str
Which resolution grid to load. Must be ``"6min"`` or ``"2min"``.
load : bool
Whether to load the data into an :class:`xarray.Dataset` or just return
the path to the downloaded data. If False, will return a list with the
paths to the age and age uncertainty grids, respectively.
kwargs
Keyword arguments will be forwarded to the :func:`xarray.open_dataset`
function that loads the grid into memory.
Returns
-------
grid : :class:`xarray.Dataset` or str
The loaded grid or the file path to the downloaded data.
"""
resolutions = ["6min", "2min"]
if resolution not in resolutions:
raise ValueError(
"Invalid seafloor age grid resolution '{}'. Must be one of {}.".format(
resolution, resolutions
)
)
fname_age = REGISTRY.fetch(
"age.3.{}.nc.bz2".format(resolution[0]), processor=Decompress()
)
fname_error = REGISTRY.fetch(
"ageerror.3.{}.nc.bz2".format(resolution[0]), processor=Decompress()
)
if not load:
return [fname_age, fname_error]
grid = xr.merge(
[
xr.open_dataset(fname_age, **kwargs).rename(z="age") / 100,
xr.open_dataset(fname_error, **kwargs).rename(z="uncertainty") / 100,
]
)
# Add more metadata and fix some names
grid = grid.rename(x="longitude", y="latitude")
grid.attrs["title"] = "Age of oceanic lithosphere"
grid.attrs["doi"] = "10.1029/2007GC001743"
grid.age.attrs["long_name"] = "Age of oceanic lithosphere"
grid.age.attrs["units"] = "million_years"
grid.uncertainty.attrs["long_name"] = "Age uncertainty"
grid.uncertainty.attrs["units"] = "million_years"
return grid