/
table.py
70 lines (51 loc) · 2.24 KB
/
table.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
# BurnMan - a lower mantle toolkit
# Copyright (C) 2012, 2013, Heister, T., Unterborn, C., Rose, I. and Cottaar, S.
# Released under GPL v2 or later.
""" Generates a text table with mineral properties. Run 'python table.py latex' to write a tex version of the table to mytable.tex """
import os, sys, numpy as np, matplotlib.pyplot as plt
#hack to allow scripts to be placed in subdirectories next to burnman:
if not os.path.exists('burnman') and os.path.exists('../burnman'):
sys.path.insert(1,os.path.abspath('..'))
import burnman
import inspect
from burnman import minerals
from burnman import tools
if __name__ == "__main__":
names = set()
phases = []
libs = dir(minerals)
for l in libs:
mineralgroup = getattr(minerals, l)
if mineralgroup.__class__.__name__ == "module":
for m in dir(mineralgroup):
mineral = getattr(mineralgroup, m)
#print mineral
if inspect.isclass(mineral) and mineral!=burnman.Mineral and issubclass(mineral, burnman.Mineral):
#print mineral.__module__ + mineral.__name__
name = mineral.__module__.replace("minlib_","").replace("burnman.","minerals.") + "." + mineral.__name__
if not name in names:
names.add(name)
try:
x=mineral()
phases.append(x)
except:
print "Could not create '%s'" % name
params = ['V_0','K_0','Kprime_0','G_0','Gprime_0','molar_mass','n','Debye_0','grueneisen_0','q_0','eta_s_0']
def create_list(mineral):
row = [ p.to_string() ]
for param in params:
row.append(str(p.params[param] if param in p.params else ""))
return row
table = [ ['Name'] + params ]
tablel = []
for p in phases:
#print p.to_string()
p.set_method('bm3')
p.set_state(1e9,300)
row = create_list(p)
table.append(row)
tablel.append(row)
if (len(sys.argv)==1):
tools.pretty_print_table(table, False)
elif sys.argv[1]=="tab":
tools.pretty_print_table(table, True)