[cig-commits] [commit] inversion, master, validate_MT_params: restructure benchmarks (687fce2)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Fri Dec 12 18:29:02 PST 2014


Repository : https://github.com/geodynamics/burnman

On branches: inversion,master,validate_MT_params
Link       : https://github.com/geodynamics/burnman/compare/80c2a295c42dfdb38f83f6c1334bf7d8f97a8463...409647ff05dfad6a686198cac1481bd46b5e2e62

>---------------------------------------------------------------

commit 687fce222618db1a10b021831e4f442a8b2d0b40
Author: Timo Heister <timo.heister at gmail.com>
Date:   Fri Dec 12 16:05:16 2014 -0800

    restructure benchmarks


>---------------------------------------------------------------

687fce222618db1a10b021831e4f442a8b2d0b40
 burnman/molar_mass.py                              |  47 ---------------------
 {tests => misc/benchmarks}/benchmark.py            |  34 +++++++--------
 .../benchmarks/configurational_entropy.png         | Bin
 {tests => misc/benchmarks}/debye.py                |   7 ++-
 dicats.png => misc/benchmarks/dicats.png           | Bin
 .../benchmarks/solidsolution_benchmarks.py         |   3 ++
 test.sh                                            |  10 ++++-
 7 files changed, 31 insertions(+), 70 deletions(-)

diff --git a/burnman/molar_mass.py b/burnman/molar_mass.py
deleted file mode 100644
index 1f6473a..0000000
--- a/burnman/molar_mass.py
+++ /dev/null
@@ -1,47 +0,0 @@
-# BurnMan - a lower mantle toolkit
-# Copyright (C) 2012, 2013, Myhill, R., Heister, T., Unterborn, C., Rose, I. and Cottaar, S.
-# Released under GPL v2 or later.
-
-# This is a short standalone program which calculates the molar mass of a chemical formula specified as a command line argument.
-
-import sys
-import re
-
-if len(sys.argv) != 2:
-    print 'Usage:', sys.argv[0], '<formula>'
-    exit()
-
-formula=sys.argv[1]
-
-
-filename="data/input_masses/atomic_masses.dat"
-file = open(filename, "r")
-el_name = []
-el_mass = []
-
-i=0
-for line in file:
-    data="%".join(line.split("%")[:1]).split()
-    if data != []:
-        el_name.append(data[0])
-        el_mass.append(float(data[1]))
-file.close()
-
-# Loop over elements
-n=0.
-molar_mass=0.
-for element in re.findall('[A-Z][^A-Z]*', formula):
-    list=filter(None, re.split(r'(\d+)', element))
-    # Look up number of atoms of element
-    if len(list) == 1:
-        nel=1.
-    else: 
-        nel=float(list[1])
-    # Increment size of compound
-    n += nel
-
-    # Find atomic mass of element
-    molar_mass += nel * el_mass[el_name.index(list[0])]
-
-print 'number of atoms per formula unit:', n
-print 'molar mass of formula unit:', molar_mass, 'kg'
diff --git a/tests/benchmark.py b/misc/benchmarks/benchmark.py
similarity index 95%
rename from tests/benchmark.py
rename to misc/benchmarks/benchmark.py
index f4cdf20..967c0ce 100644
--- a/tests/benchmark.py
+++ b/misc/benchmarks/benchmark.py
@@ -2,10 +2,10 @@
 # Copyright (C) 2012, 2013, Heister, T., Unterborn, C., Rose, I. and Cottaar, S.
 # Released under GPL v2 or later.
 
-import os, sys, numpy as np, matplotlib.pyplot as plt
-if not os.path.exists('burnman') and os.path.exists('../burnman'):
-    sys.path.insert(1,os.path.abspath('..')) 
-sys.path.insert(1,os.path.abspath('.')) 
+import os.path, sys
+sys.path.insert(1,os.path.abspath('../..')) 
+import numpy as np, matplotlib.pyplot as plt
+
 import burnman
 
 import burnman.eos.birch_murnaghan as bm
@@ -49,7 +49,7 @@ def check_birch_murnaghan():
 
     #compare with figure 1
     plt.plot(pressure/1.e9, bulk_modulus/1.e9, pressure/1.e9, shear_modulus/1.e9)
-    fig1 = mpimg.imread('../burnman/data/input_figures/slb_fig1.png')
+    fig1 = mpimg.imread('../../burnman/data/input_figures/slb_fig1.png')
     plt.imshow(fig1, extent=[0,140,0,800], aspect='auto')
     plt.plot(pressure/1.e9, bulk_modulus/1.e9, 'g+', pressure/1.e9, shear_modulus/1.e9, 'g+')
     plt.ylim(0,800)
@@ -168,7 +168,7 @@ def check_slb_fig3():
         q_mgd[i] = perovskite.params['q_0']
 
     #compare with figure 7
-    fig1 = mpimg.imread('../burnman/data/input_figures/slb_fig3.png')
+    fig1 = mpimg.imread('../../burnman/data/input_figures/slb_fig3.png')
     plt.imshow(fig1, extent=[0.6, 1.0,0.35,2.0], aspect='auto')
     plt.plot(volume, grueneisen_slb, 'g+', volume, grueneisen_mgd, 'b+')
     plt.plot(volume, q_slb, 'g+', volume, q_mgd, 'b+')
@@ -199,7 +199,7 @@ def check_slb_fig7_txt():
                     'eta_s_0' : 2.364}
     forsterite.set_method('slb3')
 
-    data = np.loadtxt("../burnman/data/input_minphys/slb_fig7.txt", skiprows=2)
+    data = np.loadtxt("../../burnman/data/input_minphys/slb_fig7.txt", skiprows=2)
  
     temperature = np.array(data[:,2])
     pressure = np.array(data[:,0])
@@ -321,7 +321,7 @@ def check_slb_fig7():
  
 
     #compare with figure 7
-    fig1 = mpimg.imread('../burnman/data/input_figures/slb_fig7_vol.png')
+    fig1 = mpimg.imread('../../burnman/data/input_figures/slb_fig7_vol.png')
     plt.imshow(fig1, extent=[0,2200,0.99,1.08], aspect='auto')
     plt.plot(temperature, volume, 'g+')
     plt.ylim(0.99,1.08)
@@ -331,7 +331,7 @@ def check_slb_fig7():
     plt.title("Comparing with Figure 7 of Stixrude and Lithgow-Bertelloni (2005)")
     plt.show()
 
-    fig1 = mpimg.imread('../burnman/data/input_figures/slb_fig7_Cp.png')
+    fig1 = mpimg.imread('../../burnman/data/input_figures/slb_fig7_Cp.png')
     plt.imshow(fig1, extent=[0,2200,0.,70.], aspect='auto')
     plt.plot(temperature, heat_capacity, 'g+')
     plt.ylim(0,70)
@@ -342,7 +342,7 @@ def check_slb_fig7():
     plt.show()
 
 
-    fig1 = mpimg.imread('../burnman/data/input_figures/slb_fig7_K.png')
+    fig1 = mpimg.imread('../../burnman/data/input_figures/slb_fig7_K.png')
     plt.imshow(fig1, extent=[0,2200,0.6,1.02], aspect='auto')
     plt.plot(temperature, bulk_modulus, 'g+')
     plt.ylim(0.6,1.02)
@@ -352,7 +352,7 @@ def check_slb_fig7():
     plt.title("Comparing with Figure 7 of Stixrude and Lithgow-Bertelloni (2005)")
     plt.show()
 
-    fig1 = mpimg.imread('../burnman/data/input_figures/slb_fig7_G.png')
+    fig1 = mpimg.imread('../../burnman/data/input_figures/slb_fig7_G.png')
     plt.imshow(fig1, extent=[0,2200,0.6,1.02], aspect='auto')
     plt.plot(temperature, shear_modulus, 'g+')
     plt.ylim(0.6,1.02)
@@ -413,7 +413,7 @@ def check_averaging():
       hsl_bulk_modulus[i]  = hashin_shtrikman_lower.average_bulk_moduli( [volumes[i], 1.0-volumes[i]], [K1,K2], [G1,G2] )
       hsl_shear_modulus[i] = hashin_shtrikman_lower.average_shear_moduli( [volumes[i], 1.0-volumes[i]], [K1,K2], [G1,G2] )
  
-    fig = mpimg.imread('../burnman/data/input_figures/watt_1976_a1.png')
+    fig = mpimg.imread('../../burnman/data/input_figures/watt_1976_a1.png')
     plt.imshow(fig, extent=[0,1.0,0.25,1.0], aspect='auto')
     plt.plot(volumes, v_bulk_modulus/K2, 'g-')
     plt.plot(volumes, r_bulk_modulus/K2, 'g-')
@@ -427,7 +427,7 @@ def check_averaging():
     plt.title("Comparing with Figure 1 of Watt et al 1976")
     plt.show()
 
-    fig = mpimg.imread('../burnman/data/input_figures/watt_1976_a2.png')
+    fig = mpimg.imread('../../burnman/data/input_figures/watt_1976_a2.png')
     plt.imshow(fig, extent=[0,1.0,0.0,1.0], aspect='auto')
     plt.plot(volumes, v_shear_modulus/G2, 'g-')
     plt.plot(volumes, r_shear_modulus/G2, 'g-')
@@ -452,7 +452,7 @@ def check_averaging():
       hsu_bulk_modulus_vals[i] = hashin_shtrikman_upper.average_bulk_moduli( [porosity[i], 1.0-porosity[i]], [0.0, K], [0.0, G])
     for i in range(len(volumes)):
       hsu_bulk_modulus[i] = hashin_shtrikman_upper.average_bulk_moduli( [volumes[i], 1.0-volumes[i]], [0.0, K], [0.0, G])
-    fig = mpimg.imread('../burnman/data/input_figures/berryman_fig4.png')
+    fig = mpimg.imread('../../burnman/data/input_figures/berryman_fig4.png')
     plt.imshow(fig, extent=[0,1.0,0.0,50.0], aspect='auto')
     plt.plot(volumes, hsu_bulk_modulus, 'g-')
     plt.scatter(porosity, hsu_bulk_modulus_vals, c='r')
@@ -496,7 +496,7 @@ def check_averaging_2():
       hsl_bulk_modulus[i]  = hashin_shtrikman_lower.average_bulk_moduli( [1.0-volumes[i], volumes[i]], [K1,K2], [G1,G2] )
       hsl_shear_modulus[i] = hashin_shtrikman_lower.average_shear_moduli( [1.0-volumes[i], volumes[i]], [K1,K2], [G1,G2] )
  
-    fig = mpimg.imread('../burnman/data/input_figures/Hashin_Shtrikman_1963_fig1_K.png')
+    fig = mpimg.imread('../../burnman/data/input_figures/Hashin_Shtrikman_1963_fig1_K.png')
     plt.imshow(fig, extent=[0,1.0,1.1,K2+0.3], aspect='auto')
     plt.plot(volumes, hsu_bulk_modulus, 'g-')
     plt.plot(volumes, hsl_bulk_modulus, 'g-')
@@ -507,7 +507,7 @@ def check_averaging_2():
     plt.title("Comparing with Figure 1 of Hashin and Shtrikman (1963)")
     plt.show()
 
-    fig = mpimg.imread('../burnman/data/input_figures/Hashin_Shtrikman_1963_fig2_G.png')
+    fig = mpimg.imread('../../burnman/data/input_figures/Hashin_Shtrikman_1963_fig2_G.png')
     plt.imshow(fig, extent=[0,1.0,0.3,G2], aspect='auto')
     plt.plot(volumes, hsu_shear_modulus, 'g-')
     plt.plot(volumes, hsl_shear_modulus, 'g-')
@@ -573,7 +573,7 @@ def check_averaging_3():
       hs_av_bulk_modulus[i]  = 0.5*hsl_bulk_modulus[i] + 0.5*hsu_bulk_modulus[i]
       hs_av_shear_modulus[i] = 0.5*hsl_shear_modulus[i] + 0.5*hsu_shear_modulus[i]
 
-    fig = mpimg.imread('../burnman/data/input_figures/Avseth_et_al_2010_fig3_K.png')
+    fig = mpimg.imread('../../burnman/data/input_figures/Avseth_et_al_2010_fig3_K.png')
     plt.imshow(fig, extent=[0,1.0,0.,40.0], aspect='auto')
     plt.plot(volumes, v_bulk_modulus, 'g-')
     plt.plot(volumes, r_bulk_modulus, 'g-')
diff --git a/configurational_entropy.png b/misc/benchmarks/configurational_entropy.png
similarity index 100%
rename from configurational_entropy.png
rename to misc/benchmarks/configurational_entropy.png
diff --git a/tests/debye.py b/misc/benchmarks/debye.py
similarity index 87%
rename from tests/debye.py
rename to misc/benchmarks/debye.py
index 8b322a0..b5f02fd 100644
--- a/tests/debye.py
+++ b/misc/benchmarks/debye.py
@@ -1,7 +1,6 @@
-import os, sys, numpy as np, matplotlib.pyplot as plt
-if not os.path.exists('burnman') and os.path.exists('../burnman'):
-    sys.path.insert(1,os.path.abspath('..')) 
-sys.path.insert(1,os.path.abspath('.')) 
+import os.path, sys
+sys.path.insert(1,os.path.abspath('../..'))
+import numpy as np, matplotlib.pyplot as plt
 import burnman
 
 import scipy.integrate
diff --git a/dicats.png b/misc/benchmarks/dicats.png
similarity index 100%
rename from dicats.png
rename to misc/benchmarks/dicats.png
diff --git a/solidsolution_benchmarks.py b/misc/benchmarks/solidsolution_benchmarks.py
similarity index 99%
rename from solidsolution_benchmarks.py
rename to misc/benchmarks/solidsolution_benchmarks.py
index b1a16e1..5779447 100644
--- a/solidsolution_benchmarks.py
+++ b/misc/benchmarks/solidsolution_benchmarks.py
@@ -1,4 +1,7 @@
 # Benchmarks for the solid solution class
+import os.path, sys
+sys.path.insert(1,os.path.abspath('../..'))
+
 import burnman
 from burnman import minerals
 from burnman.processchemistry import *
diff --git a/test.sh b/test.sh
index 0ad275d..96f4e60 100755
--- a/test.sh
+++ b/test.sh
@@ -52,13 +52,19 @@ done
 
 cd tests
 python tests.py || exit 1
-testit "benchmark.py"
-testit "debye.py"
 cd ..
 
+
 cd misc
 echo "gen_doc..."
 python gen_doc.py >/dev/null || exit 1
+
+cd benchmarks
+for test in `ls *.py`
+do
+    testit $test
+done
+cd ..
 cd ..
 
 



More information about the CIG-COMMITS mailing list