-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.py
59 lines (51 loc) · 1.63 KB
/
tools.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
import numpy as np
MAX_COST = 28271.0
MAX_WASTE = 380835.65
def diff_last(arr):
"""Takes the difference of the last column only, inplace."""
subtot = np.array(arr[arr.dtype.names[1]])
for k in arr.dtype.names[2:-1]:
subtot += arr[k]
arr[arr.dtype.names[-1]] -= subtot
# USD per tonne
COSTS = {
"Wet Storage": 457871.820334581,
"Dry Storage": 245664.9606599954,
"Interim Storage": 200*1e3,
"Repository": 650000.0,
#"Total Used Fuel": 245664.9606599954,
}
def cost_val(arr):
dt = np.dtype(arr.dtype.descr[:-1])
brr = np.empty(len(arr), dtype=dt)
brr['year'] = arr['year']
for k in arr.dtype.names[1:-1]:
brr[k] = arr[k] * COSTS[k] / 1e6
return brr
def load_kind(filename, kind):
data = np.recfromcsv(filename, delimiter=',', filling_values=np.nan,
case_sensitive=True, deletechars='', replace_space=' ')
if kind == "waste":
data = data[list(data.dtype.names[:-1])]
#diff_last(data)
elif kind == "cost":
pass
else:
raise ValueError("kind must be cost or waste")
return data
def label_kind(val, kind):
if kind == "waste":
label = "{0:,}\ntonnes".format(int(val))
elif kind == "cost":
label = "${0:,}\nmillion".format(int(val))
else:
raise ValueError("kind must be cost or waste")
return label
def outter_reproccessed(parent):
kids = {"name": "", "children": []}
for i in range(len(parent)-1, -1, -1):
if parent[i]['name'].startswith("Reprocessed"):
continue
kids['children'].append(parent[i])
del parent[i]
parent.append(kids)