-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc_funcs.py
122 lines (106 loc) · 3.23 KB
/
misc_funcs.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
from scipy.integrate import cumulative_trapezoid
import numpy as np
import matplotlib.pyplot as plt
import os
def delnu_per_fiss(times, counts, fissions, efficiency):
"""
Calculates the number of delayed neutrons per fission
for a given dataset
"""
norm_cnts = list()
for cnt in counts:
norm_cnts.append(cnt / (fissions * efficiency))
#int_cnt = cumulative_trapezoid(norm_cnts,
# x=times)
#tot_cnt = int_cnt[-1] - int_cnt[0]
tot_cnt = np.trapz(norm_cnts, x=times)
dnpf = tot_cnt# / (fissions * efficiency)
print(f'Approximate n/f: {dnpf}\n')
print('-'*40)
return dnpf
def delnu_per_fiss_norm(times, norm_counts):
"""
Calculates the number of delayed neutrons per fission
for a given dataset without eff or fiss
"""
int_cnt = cumulative_trapezoid(norm_counts,
x=times)
tot_cnt = int_cnt[-1] - int_cnt[0]
dnpf = tot_cnt
print(f'Approximate2 n/f: {dnpf}\n')
print('-'*40)
return dnpf
def multplt(x,
y,
label='unlabeled',
alpha=1,
errors=None):
"""
Makes multiplotting on a single figure easier
"""
linestyle_tuple = [
('dotted', (0, (1, 1))),
('loosely dashed', (0, (5, 10))),
('dashed', (0, (5, 5))),
('loosely dashdotted', (0, (3, 10, 1, 10))),
('dashdotted', (0, (3, 5, 1, 5))),
('dashdotdotted', (0, (3, 5, 1, 5, 1, 5))),
('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10)))]
#linestyle=linestyle_tuple[np.random.randint(0, len(linestyle_tuple))][-1]
global miscmultpltid
try:
miscmultpltid
except NameError:
miscmultpltid = 0
miscmultpltid += 1
if miscmultpltid == len(linestyle_tuple):
miscmultpltid = 0
linestyle=linestyle_tuple[miscmultpltid][-1]
plt.plot(x, y, label=label, alpha=alpha, linestyle=linestyle)
if type(errors) != type(None):
if type(errors) == type(list()):
errors = np.array(errors)
while len(np.shape(errors)) > 1:
errors = errors[0]
if type(y) == type(list()):
y = np.array(y)
while len(np.shape(y)) > 1:
y = y[0]
#plt.errorbar(x, y, yerr=errors, elinewidth=1,
#alpha=alpha, linestyle=linestyle, label=label)
plt.fill_between(x, y+errors, y-errors, alpha=alpha/2)
else:
#
pass
plt.legend()
return
def dir_handle(path):
"""
Checks if the directory exists, and creates it if it doesn't
"""
if not os.path.isdir(path):
val = os.mkdir(f'{path}')
return
def movie_gen(current_path, num_files):
"""
Generate a .gif
Parameters
----------
current_path : str
Current path where files are located
num_files : int
Number of plots
Returns
-------
None
"""
filenames = list()
for i in range(num_files):
name = f'{i}.png'
filenames.append(current_path + name)
import imageio
images = []
for filename in filenames:
images.append(imageio.v2.imread(filename))
imageio.mimsave(f'{current_path}movie.gif', images)
return