-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrench_resolver.py
78 lines (62 loc) · 2.87 KB
/
trench_resolver.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
73
74
75
76
77
78
import os
import os.path
import pygplates
import subduction_convergence_for_absolute_plate_motion as scap
import sys
class TrenchResolver(object):
"""
Class to resolved topologies and extract resolved trenches.
"""
def __init__(
self,
data_dir,
original_rotation_filenames, # Relative to the 'data/' directory.
topology_features,
data_model):
"""
Load the topology features and load original rotation model.
"""
self.data_dir = data_dir
self.topology_features = topology_features
# Load all the original rotation feature collections.
rotation_features = []
for rotation_filename in original_rotation_filenames:
# Read the current rotation file.
rotation_feature_collection = pygplates.FeatureCollection(
os.path.join(self.data_dir, rotation_filename))
rotation_features.extend(rotation_feature_collection)
# Load all the rotations into a rotation model.
self.rotation_model = pygplates.RotationModel(rotation_features)
# The trench migration filename (relative to the 'data/' directory) to contain resolved trenches
# generated by 'generate_resolved_trenches()' at a particular reconstruction time.
self.trench_migration_filename = os.path.join(
data_model, 'optimisation', 'temp_resolved_trenches.gpml')
def __del__(self):
# Remove temporary trench migration file.
try:
file_to_remove = os.path.join(self.data_dir, self.trench_migration_filename)
if os.path.exists(file_to_remove):
os.remove(file_to_remove)
except AttributeError:
# 'self.trench_migration_filename' might not exist if exception raised inside '__init__()'.
pass
def get_trench_migration_filename(self):
"""
Return the filename (relative to the 'data/' directory) of the file containing trenches resolved
at the reconstruction time specified in most recent call to 'generate_resolved_trenches()'.
"""
return self.trench_migration_filename
def generate_resolved_trenches(
self,
ref_rotation_start_age):
"""
Generate the resolved trench features at the specified time and save them to the trench migration file.
"""
# Resolve trench features
resolved_trench_features = scap.resolve_subduction_zones(
self.rotation_model,
self.topology_features,
ref_rotation_start_age)
# Write resolved trenches to the trench migration file.
pygplates.FeatureCollection(resolved_trench_features).write(
os.path.join(self.data_dir, self.trench_migration_filename))