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 plate model manager #114

Merged
merged 41 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
68d3eac
initial work of cache
michaelchin Jul 4, 2023
4ee09e9
fetch file with etag
michaelchin Jul 5, 2023
b962396
use multithread download large zip file
michaelchin Jul 6, 2023
14b4512
try aiohttp
michaelchin Jul 6, 2023
c0a17e0
add two new unittest files
michaelchin Jul 6, 2023
507edc9
pytest ingore unittest folder
michaelchin Jul 6, 2023
47bf33b
download multiple files with requests
michaelchin Jul 9, 2023
a025a29
rename files
michaelchin Jul 10, 2023
3bdd9bb
allow user to provide singal path for multiple files
michaelchin Jul 10, 2023
fe0e732
get rotation model
michaelchin Jul 17, 2023
41214ad
test plot function with the new PlateModel class
michaelchin Jul 23, 2023
e8a12ab
download all layers concurrently
michaelchin Jul 25, 2023
eea1a30
code to download agegrids
michaelchin Jul 25, 2023
0032cef
refine plate_model.py
michaelchin Jul 26, 2023
1eee4cb
minor updates
michaelchin Aug 20, 2023
89e5177
check in gplately/plate_model.py to keep the file safe
michaelchin Aug 20, 2023
188678d
Merge branch 'master' into mchin/etag
michaelchin Aug 20, 2023
5621a2c
workaround for the '/usr/lib/libarchive.13.dylib' (no such file) erro…
michaelchin Aug 20, 2023
5719106
try to workaround libarchive again
michaelchin Aug 20, 2023
35fd1a9
try to workaround libarchive error once more
michaelchin Aug 20, 2023
50ea572
another attemp to fix the test workflow
michaelchin Aug 21, 2023
f36497b
attemp to fix the test workflow
michaelchin Aug 21, 2023
de89993
no conda command on windows. don't need
michaelchin Aug 21, 2023
30b91c0
remove unused files
michaelchin Aug 25, 2023
4c37f51
use micromamba to replace miniconda. setup-miniconda@v2 uses old liba…
michaelchin Aug 25, 2023
cc0f638
Merge branch 'master' into mchin/etag
michaelchin Aug 25, 2023
fde9182
Merge branch 'mchin/etag' of https://github.com/GPlates/gplately into…
michaelchin Aug 25, 2023
bf1e4e9
remove unused file and update test scripts
michaelchin Aug 25, 2023
73e175f
Merge branch 'master' into mchin/etag
michaelchin Sep 11, 2023
a6135d2
deal with test cases
michaelchin Sep 11, 2023
60cfa59
move new testcases into a new folder
michaelchin Sep 11, 2023
69ca5bb
add raster test case
michaelchin Sep 11, 2023
495097e
ignore test-with-plate-model-manager folder
michaelchin Sep 11, 2023
8c8dbc4
specify test path
michaelchin Sep 11, 2023
dcf81db
add more testcase
michaelchin Sep 12, 2023
c18d168
use pmm to get raster
michaelchin Sep 14, 2023
ab33fd3
skip slow testcase test_reverse_reconstruct
michaelchin Sep 23, 2023
e6a4592
Merge branch 'master' into mchin/etag
michaelchin Oct 1, 2023
4b8a0f0
install plate_model_manager if not already
michaelchin Oct 5, 2023
1e5af5e
Merge branch 'master' into mchin/etag
michaelchin Oct 8, 2023
dacda28
enable anchor plate id
michaelchin Oct 8, 2023
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
9 changes: 9 additions & 0 deletions gplately/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,12 @@
"_ContinentCollision": False,
"_ReconstructByTopologies": False,
}

try:
import plate_model_manager
except ImportError:
print("The plate_model_manager is not installed, installing it now!")
import subprocess
import sys

subprocess.call([sys.executable, "-m", "pip", "install", "plate-model-manager"])
180 changes: 99 additions & 81 deletions gplately/pygplates.py

Large diffs are not rendered by default.

1,514 changes: 873 additions & 641 deletions gplately/reconstruction.py

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions models.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"Muller2019": {
"BigTime": 250,
"SmallTime": 0,
"Rotations": "https://www.earthbyte.org/webdav/ftp/gplately/Muller2019/Rotations.zip",
"Layers": {
"Coastlines": "https://www.earthbyte.org/webdav/ftp/gplately/Muller2019/Coastlines.zip",
"StaticPolygons": "https://www.earthbyte.org/webdav/ftp/gplately/Muller2019/StaticPolygons.zip",
"ContinentalPolygons": "https://www.earthbyte.org/webdav/ftp/gplately/Muller2019/ContinentalPolygons.zip",
"Topologies": "https://www.earthbyte.org/webdav/ftp/gplately/Muller2019/Topologies.zip",
"COBs": "https://www.earthbyte.org/webdav/ftp/gplately/Muller2019/COBs.zip"
},
"TimeDepRasters": {
"AgeGrids": "https://www.earthbyte.org/webdav/ftp/Data_Collections/Muller_etal_2019_Tectonics/Muller_etal_2019_Agegrids/Muller_etal_2019_Tectonics_v2.0_netCDF/Muller_etal_2019_Tectonics_v2.0_AgeGrid-{}.nc"
}
}
}
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
addopts = --ignore=unittest --ignore=test-with-plate-model-manager
testpaths = test
1 change: 1 addition & 0 deletions test-with-plate-model-manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
muller2019
184 changes: 184 additions & 0 deletions test-with-plate-model-manager/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import gzip
import os
import shutil

import numpy as np
import pygplates
import pytest
import gplately
from plate_model_manager import (
PlateModelManager,
PresentDayRasterManager,
network_requests,
)


## ==========================

# We will test GPlately functionalities on the Müller et al. (2019) plate reconstruction
# model at 0 and 100 Ma.
reconstruction_times = [0, 100]
gridding_times = [249.0, 250.0]
pt_lon = np.array([-155.4696, 164.3])
pt_lat = np.array([19.8202, 53.5])
test_geometry_n_points = 1000
test_geometry_origins = ((20, -10), (175, -40)) # (lon, lat)
test_geometry_radii = (100, 500, 1000, 2000) # km
test_geometry_azimuths = (45, -100) # degrees


@pytest.fixture(scope="module")
def muller_2019_model():
pm_manger = PlateModelManager()
return pm_manger.get_model("Muller2019")


@pytest.fixture(scope="module")
def merdith_2021_model():
pm_manger = PlateModelManager()
return pm_manger.get_model("Merdith2021")


@pytest.fixture(scope="module")
def gplately_muller_static_geometries(muller_2019_model):
coastlines = pygplates.FeatureCollection()
for file in muller_2019_model.get_layer("Coastlines"):
coastlines.add(pygplates.FeatureCollection(file))
continental_polygons = pygplates.FeatureCollection()
for file in muller_2019_model.get_layer("ContinentalPolygons"):
continental_polygons.add(pygplates.FeatureCollection(file))
COBs = pygplates.FeatureCollection()
for file in muller_2019_model.get_layer("COBs"):
COBs.add(pygplates.FeatureCollection(file))
return coastlines, continental_polygons, COBs


@pytest.fixture(scope="module")
def gplately_merdith_static_geometries(merdith_2021_model):
coastlines = pygplates.FeatureCollection()
for file in merdith_2021_model.get_layer("Coastlines"):
coastlines.add(pygplates.FeatureCollection(file))
continental_polygons = pygplates.FeatureCollection()
for file in merdith_2021_model.get_layer("ContinentalPolygons"):
continental_polygons.add(pygplates.FeatureCollection(file))

return coastlines, continental_polygons


@pytest.fixture(scope="module")
def gplately_muller_reconstruction_files(muller_2019_model):
rotation_model = pygplates.RotationModel(muller_2019_model.get_rotation_model())
topology_features = pygplates.FeatureCollection()
for file in muller_2019_model.get_layer("Topologies"):
topology_features.add(pygplates.FeatureCollection(file))
static_polygons = pygplates.FeatureCollection()
for file in muller_2019_model.get_layer("StaticPolygons"):
static_polygons.add(pygplates.FeatureCollection(file))
return rotation_model, topology_features, static_polygons


@pytest.fixture(scope="module")
def gplately_merdith_reconstruction_files(merdith_2021_model):
rotation_model = pygplates.RotationModel(merdith_2021_model.get_rotation_model())
topology_features = pygplates.FeatureCollection()
for file in merdith_2021_model.get_layer("Topologies"):
topology_features.add(pygplates.FeatureCollection(file))
static_polygons = pygplates.FeatureCollection()
for file in merdith_2021_model.get_layer("StaticPolygons"):
static_polygons.add(pygplates.FeatureCollection(file))
return rotation_model, topology_features, static_polygons


@pytest.fixture(scope="module")
def gplately_plate_reconstruction_object(muller_2019_model):
return gplately.PlateReconstruction(
rotation_model=muller_2019_model.get_rotation_model(),
topology_features=muller_2019_model.get_layer("Topologies"),
static_polygons=muller_2019_model.get_layer("StaticPolygons"),
)


@pytest.fixture(scope="module")
def gplately_merdith_reconstruction(gplately_merdith_reconstruction_files):
return gplately.PlateReconstruction(*gplately_merdith_reconstruction_files)


@pytest.fixture(scope="module")
def gplately_plot_topologies_object(
gplately_plate_reconstruction_object,
gplately_muller_static_geometries,
):
gplot = gplately.PlotTopologies(
gplately_plate_reconstruction_object,
*gplately_muller_static_geometries,
)
gplot.time = 0
return gplot


@pytest.fixture(scope="module")
def gplately_points_object(gplately_plate_reconstruction_object):
model = gplately_plate_reconstruction_object
time = 0 # Ma, will change to 100 Ma in test 2.

# For example: Longitude and latitude of the Hawaiian-Emperor Seamount chain seed points
pt_lon = np.array([-155.4696, 164.3])
pt_lat = np.array([19.8202, 53.5])

# Call the Points object: pass the PlateReconstruction object, and the latitudes and longitudes of the seed points.
gpts = gplately.Points(model, pt_lon, pt_lat)
return gpts


@pytest.fixture(scope="module")
def gplately_raster_object(
muller_2019_model,
gplately_plate_reconstruction_object,
):
model = gplately_plate_reconstruction_object
time = 0
agegrid_path = muller_2019_model.get_raster("AgeGrids", time)

graster = gplately.Raster(
data=agegrid_path,
plate_reconstruction=model,
extent=[-180, 180, -90, 90],
)

return graster


@pytest.fixture(scope="module")
def gplately_merdith_raster(
gplately_merdith_reconstruction,
):
raster_manager = PresentDayRasterManager()
etopo = gplately.Raster(data=raster_manager.get_raster("ETOPO1_grd"))
etopo = etopo.data.astype("float")
downsampled = etopo[::15, ::15]
raster = gplately.Raster(
plate_reconstruction=gplately_merdith_reconstruction,
data=downsampled,
origin="lower",
)
return raster


@pytest.fixture(scope="module")
def gplately_seafloorgrid_object(
gplately_plate_reconstruction_object, gplately_plot_topologies_object
):
model = gplately_plate_reconstruction_object
gplot = gplately_plot_topologies_object

seafloorgrid = gplately.SeafloorGrid(
model,
gplot,
max_time=250,
min_time=249,
ridge_time_step=1.0,
save_directory="test-seafloor-grid",
file_collection="Muller2019",
grid_spacing=0.25,
)
return seafloorgrid
40 changes: 40 additions & 0 deletions test-with-plate-model-manager/test_0_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest

## ==========================

def test_numpy_import():
import numpy
return

def test_scipy_import():
import scipy
print("\t\t You have scipy version {}".format(scipy.__version__))


def test_cartopy_import():
import cartopy


def test_pygplates_import():
import pygplates


def test_pooch_import():
import pooch


def test_gplately_modules():
import gplately
from gplately import plot
from gplately import download
from gplately import tools
from gplately import grids


def test_jupyter_available():
from subprocess import check_output
try:
result = str(check_output(['which', 'jupyter']))[2:-3]
except:
print("Jupyter not installed")
print("Jupyter is needed to run the example documentation")
Loading