Repository navigation
Expand file tree
/
Copy pathplot_hv.py
More file actions
105 lines (95 loc) · 3.26 KB
/
Copy pathplot_hv.py
File metadata and controls
105 lines (95 loc) · 3.26 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
'''
File: plot_hv.py
Project: MINICHEM
File Created: Tuesday, 7th January 2020 8:49:51 am
Author: John Arul & Parth (arul@igcar.gov.in, parthpdpu@gmail.com)
-----
Last Modified: Thursday, 9th January 2020 8:24:52 am
Modified By: John Arul & Parth Patel (arul@igcar.gov.in, parthpdpu@gmail.com)
-----
Copyright: IGCAR - 2020
'''
import numpy as np
import pythermoread
import holoviews as hv
import matplotlib.pyplot as plt
import networkx as nx
from holoviews import opts, renderer, render
from holoviews import dim
from bokeh.plotting import show
import pandas as pd
from itertools import chain
# import from other modules
# from functions import *
import re
# thermo_dict, stoichiometric_dict = pythermoread.thermoread()
# grt_dict = {}
# temperature = 900
# dict_of_all_sp_grt = pythermoread.calculate_grt(grt_dict, temperature,
# thermo_dict)
# adding lanthanides and actinides oxide and elemental thermochemical database
# h_rt_dict, s_r_dict, temp_range = make_sr_hrt_dict()
# st_dict = make_stoichiometric_coeff()
# stoichiometric_dict, dict_of_all_sp_grt = data_base(temperature,
# dict_of_all_sp_grt, stoichiometric_dict)
# for i in st_dict:
# stoichiometric_dict[i] = st_dict[i]
# input1 = ['He', 'Kr', 'Xe', 'O', 'H', 'I', 'Br', 'Na', 'Cs', 'Rb', 'Ba',
# 'Sr', 'Mo', 'Zr', 'U', 'Sb']
# include_el = ['I', 'Cs'] # ['U', 'Mo', 'Xe', 'Zr']
# include_sp = []
def plot_hv(input1, stoichiometric_dict, include_el, opfilename, Min=0,
Max=1e9):
"""
Plotting module
input1: list of input elements
include_el: list of element for which sankey chart is drawn
Min: min mole number species to be included in chart
Max: max mole number species to be included in the chart
opfilename: opfilename with extension (allowed formats:
['html', 'json', 'auto', 'png', 'widgets', 'scrubber', 'auto', None])
returns:
saves sankey chart
"""
f = open('released_sp.txt', 'r')
data = f.readlines()
sp_dict = {}
for line in data:
cols = line.split()
sp_dict[cols[0]] = float(cols[1])
e = []
sp = []
val = []
hv.extension('bokeh')
for i in include_el:
for j in sp_dict:
s1 = set()
for j1 in stoichiometric_dict[j]:
s1.add(j1[0])
if i.upper() in s1:
if i == j:
if sp_dict[j] > Min and sp_dict[j] < Max:
e.append(i)
sp.append(j + '*')
val.append(sp_dict[j])
else:
if sp_dict[j] > Min and sp_dict[j] < Max:
e.append(i)
sp.append(j)
val.append(sp_dict[j])
data = {'elements': e, 'species': sp, 'values': val}
print(data)
df = pd.DataFrame(data)
print(df)
sankey = hv.Sankey(df)
# , show_values=False
sankey.opts(label_position='right', edge_color='species',
node_color='elements',
labelled=['elements', 'species'], xlabel='part',
show_values=False)
hv.save(sankey, opfilename, backend='bokeh')
# show(hv.render(sankey))
# hv.extension('matplotlib')
# hv.save(sankey, 'curve1.png', fmt='svg')
# plt.show(hv.render(sankey))
# plot_hv(input1, sp_dict, include_el)