-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASW___plot_settings.py
132 lines (114 loc) · 5 KB
/
ASW___plot_settings.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
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
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import *
import matplotlib as mpl
from matplotlib.colors import *
from ASW___CLASSES import *
########### FUNCTION to get input info and tags for plotting ##########
def get_plot_info(input):
sample_plot_details = plot_details(
sample = input["sample"] ,
action = input["action"] ,
analysis = input["analysis"] ,
work_directory = input["work_directory"] ,
results_directory = input["results_directory"] ,
)
# get exceptions
try:
for file in input["exceptions"].split(","):
sample_plot_details.exceptions.append(int(file))
except (KeyError):
pass
# set plot title
for s in sample_plot_details.sample.split("_"):
if s == sample_plot_details.sample.split("_")[-1]:
sample_plot_details.plot_title = "10% "+"CO$_2$ ""/" " D$_2$O " + "(" + s.split("K")[0] + " K): "
else:
sample_plot_details.plot_title = sample_plot_details.plot_title + "%s " %(s)
for a in sample_plot_details.analysis.split("_"):
sample_plot_details.plot_title = sample_plot_details.plot_title + "%s " %(a)
sample_plot_details.plot_title = sample_plot_details.plot_title + "during "+ sample_plot_details.action
print(sample_plot_details.plot_title)
# Get files and labels:
file_start, file_end, thickness, tweak_factor, temperatures, temp_err_neg, temp_err_pos, times, time_err_neg, time_err_pos = np.loadtxt("results_%s_%s_%s.txt" %(sample_plot_details.sample, sample_plot_details.action, sample_plot_details.analysis), unpack=1)
try:
if len(file_start) > 1:
pass
sample_gudrun_results = gudrun_results(
file_start = file_start ,
file_end = file_end ,
thickness = thickness ,
tweak_factor = tweak_factor ,
temperatures = temperatures ,
temp_err_neg = temp_err_neg,
temp_err_pos = temp_err_pos ,
times = times ,
time_err_neg = time_err_neg ,
time_err_pos = time_err_pos ,
)
except(TypeError):
sample_gudrun_results = gudrun_results(
file_start = [file_start] ,
file_end = [file_end] ,
thickness = [thickness] ,
tweak_factor = [tweak_factor] ,
temperatures = [temperatures] ,
temp_err_neg = [temp_err_neg] ,
temp_err_pos = [temp_err_pos] ,
times = [times] ,
time_err_neg = [time_err_neg] ,
time_err_pos = [time_err_pos] ,
)
return sample_plot_details, sample_gudrun_results
########### FUNCTION to set the colour scheme ##########
def define_color_scheme(sample_plot_details, sample_gudrun_results):
# Set colors, labels & ranges, depending on action to be plotted
if "deposition" in sample_plot_details.action:
# label
sample_plot_details.color_bar_label = "Deposition Time (h)"
# plot ranges
sample_plot_details.color_range = [0., 16.]
tick_number = 9
# color_values
sample_plot_details.color_values = sample_gudrun_results.times
# colormap
sample_plot_details.color_map = plt.cm.gnuplot
elif "heating" in sample_plot_details.action:
# label
sample_plot_details.color_bar_label = "Annealing Temperature (K)"
# plot ranges
sample_plot_details.color_range = [10., 190.]
tick_number = 10
# color_values
sample_plot_details.color_values = sample_gudrun_results.temperatures
# colormap
cdict_heating = {
'red': ((0., 0, 0) , (0.35, 0, 0) , (0.66, 0.7, 0.7) , (0.89, 0.8, 0.8) , (1, 0.5, 0.5) ),
'green': ((0., 0, 0) , (0.125, 0, 0) , (0.375, 0.7, 0.7) , (0.64, 0.8, 0.8) , (0.91, 0, 0) , (1, 0, 0) ),
'blue': ((0., 0.5, 0.5) , (0.11, 0.2, 0.2) , (0.34, 0.8, 0.8) , (0.65, 0, 0) , (1, 0, 0) )
}
sample_plot_details.color_map = LinearSegmentedColormap('heating', cdict_heating)
# Set color cycles and scale
# (exception handling required for cases with only one data point)
try:
sample_plot_details.color_scale = [sample_plot_details.color_map(i) for i in (sample_plot_details.color_values)/sample_plot_details.color_range[-1]]
except (TypeError):
sample_plot_details.color_scale = "k"
# Set range for colors
sample_plot_details.color_norm = mpl.colors.Normalize(
vmin=sample_plot_details.color_range[0] ,
vmax=sample_plot_details.color_range[-1]
)
# Set range and granularity of colorbar
sample_plot_details.color_bounds = np.linspace(
sample_plot_details.color_range[0] ,
sample_plot_details.color_range[-1] ,
500
)
# Set ticks for colorbar
sample_plot_details.color_plot_ticks = np.linspace(
sample_plot_details.color_range[0] ,
sample_plot_details.color_range[-1] ,
tick_number
)
return sample_plot_details