-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_average_map.py
More file actions
132 lines (108 loc) · 4.8 KB
/
make_average_map.py
File metadata and controls
132 lines (108 loc) · 4.8 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
This script will make average and standard deviation maps,
based on all of the predictions for various neural network runs
found in the root_folder.
It will save the maps in the root_folder. It will also save a CSV with the
average and standard deviations of the predictions.
"""
import os
import pandas as pd
import numpy as np
from make_map import make_map
# Set the target folder here
root_folder = 'run_A/'
# If using spyder or an IDE which presists variables, you can run this script
# many times on various root folders, and all results will be aggregated
# The following check facilitates this, by not deleting the all_predictions
# dataframe. It must be deleted manually to reset.
try:
len(all_predictions)
except:
all_predictions = pd.DataFrame()
for path, dirs, files in os.walk(root_folder):
# print(path)
# print(dirs)
# print(files)
for file in files:
if file == '3D_data_with_predictions.csv':
full_path = path + '/' + file
print(full_path)
current_file = pd.read_csv(full_path, index_col = 0)
if len(all_predictions) == 0:
all_predictions = current_file
else:
all_predictions = all_predictions.merge(current_file,
how = 'left',
on = ['X', 'Y'])
del current_file
def convert_velocity_to_serp(velocity):
return 0.119474*(3314 - ((velocity/1000) + 4.9587)/0.0039)
above_predictions = all_predictions.filter(like = 'Above')
above_predictions.columns = ['Above_Velocity' for _ in above_predictions.columns]
below_predictions = all_predictions.filter(like = 'Below')
below_predictions.columns = ['Below_Velocity' for _ in below_predictions.columns]
for column in set(below_predictions.columns):
serp_predictions = below_predictions[column].apply(convert_velocity_to_serp)
aggr_predictions = all_predictions[['X', 'Y']].copy()
aggr_predictions['Above Velocity - Average'] = above_predictions.mean(axis=1)
aggr_predictions['Above Velocity - Stdev'] = above_predictions.std(axis=1)
aggr_predictions['Below Velocity - Average'] = below_predictions.mean(axis=1)
aggr_predictions['Below Velocity - Stdev'] = below_predictions.std(axis=1)
aggr_predictions['Serp Precent - Average'] = serp_predictions.mean(axis=1)
aggr_predictions['Serp Precent - Stdev'] = serp_predictions.std(axis=1)
aggr_predictions.to_csv(root_folder + "Master_predictions_averaged.csv")
#%%
make_map(np.array(aggr_predictions['X']),
np.array(aggr_predictions['Y']),
np.array(aggr_predictions['Below Velocity - Average']),
point_spacing=25,
cmap='gist_heat',
title='Mantle Velocity m/s - Averaged',
scale_min=5000,
scale_max=8500,
save_location=root_folder + 'Mantle Velocity - Average Map.png')
make_map(np.array(aggr_predictions['X']),
np.array(aggr_predictions['Y']),
np.array(aggr_predictions['Below Velocity - Stdev']),
point_spacing=25,
cmap='gist_heat',
title='Mantle Velocity m/s - Standard Deviation',
scale_min=None,
scale_max=None,
save_location=root_folder + 'Mantle Velocity - Standard Deviation Map.png')
make_map(np.array(aggr_predictions['X']),
np.array(aggr_predictions['Y']),
np.array(aggr_predictions['Serp Precent - Average']),
point_spacing=25,
cmap='viridis',
title='Percent Serpentinite - Averaged',
scale_min=0,
scale_max=100,
save_location=root_folder + 'Percent Serpentinite - Average Map.png')
make_map(np.array(aggr_predictions['X']),
np.array(aggr_predictions['Y']),
np.array(aggr_predictions['Serp Precent - Stdev']),
point_spacing=25,
cmap='viridis',
title='Percent Serpentinite - Standard Deviation',
scale_min=None,
scale_max=None,
save_location=root_folder + 'Percent Serpentinite - Standard Deviation Map.png')
make_map(np.array(aggr_predictions['X']),
np.array(aggr_predictions['Y']),
np.array(aggr_predictions['Above Velocity - Average']),
point_spacing=25,
cmap='gnuplot2',
title='Basement Velocity m/s - Averaged',
scale_min=5000,
scale_max=8500,
save_location=root_folder + 'Basement Velocity - Average Map.png')
make_map(np.array(aggr_predictions['X']),
np.array(aggr_predictions['Y']),
np.array(aggr_predictions['Above Velocity - Stdev']),
point_spacing=25,
cmap='gnuplot2',
title='Basement Velocity m/s - Standard Deviation',
scale_min=None,
scale_max=None,
save_location=root_folder + 'Basement Velocity - Standard Deviation Map.png')