[cig-commits] [commit] master: fix package/module python weirdness (a94c81f)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Dec 10 21:39:09 PST 2014
Repository : https://github.com/geodynamics/burnman
On branch : master
Link : https://github.com/geodynamics/burnman/compare/ab0efb9b1ff17b6d893db6c4d457836c768cdd59...f76fd51b3334a16aae97d4dd7ab1f0204e1d2eb0
>---------------------------------------------------------------
commit a94c81f5d0edb615103893705101b961d753bc8e
Author: Timo Heister <timo.heister at gmail.com>
Date: Thu Dec 11 00:21:04 2014 -0500
fix package/module python weirdness
We no longer import constants in __init__ so that it works without
installing.
>---------------------------------------------------------------
a94c81f5d0edb615103893705101b961d753bc8e
burnman/__init__.py | 1 -
burnman/constants.py | 8 ++++----
burnman/debye.py | 13 ++++++-------
burnman/geotherm.py | 18 ++++++++----------
burnman/mie_grueneisen_debye.py | 6 +++---
burnman/partitioning.py | 7 +++----
burnman/seismic.py | 18 +++++++++---------
burnman/tools.py | 4 ++--
8 files changed, 35 insertions(+), 40 deletions(-)
diff --git a/burnman/__init__.py b/burnman/__init__.py
index 7bd3517..0866126 100644
--- a/burnman/__init__.py
+++ b/burnman/__init__.py
@@ -72,4 +72,3 @@ import geotherm
#miscellaneous
import tools
from partitioning import calculate_partition_coefficient,calculate_phase_percents
-import constants
diff --git a/burnman/constants.py b/burnman/constants.py
index 97af1ac..d4f8079 100644
--- a/burnman/constants.py
+++ b/burnman/constants.py
@@ -1,5 +1,5 @@
-import scipy.constants as constants
+import scipy.constants
-R = gas_constant = constants.gas_constant
-N_A = Avogadro = constants.Avogadro
-k = Boltzmann = constants.Boltzmann
+gas_constant = scipy.constants.gas_constant # also known as R
+Avogadro = scipy.constants.Avogadro # also known as N_A
+Boltzmann = scipy.constants.Boltzmann # also k_B
diff --git a/burnman/debye.py b/burnman/debye.py
index 8f0d6e4..1a337d1 100644
--- a/burnman/debye.py
+++ b/burnman/debye.py
@@ -5,7 +5,8 @@
import numpy as np
import scipy.integrate as integrate
from numpy.polynomial.chebyshev import Chebyshev
-from burnman.constants import gas_constant
+
+import constants
"""
Functions for the Debye model. Note that this is not Mie-Grueneisen-Debye,
@@ -13,8 +14,6 @@ just Debye, so is pretty limited. Combine this with Mie-Grueneisen and
Birch-Murnaghan to get a full EOS
"""
-R = gas_constant
-
def debye_fn(x):
@@ -83,7 +82,7 @@ def thermal_energy(T, debye_T, n):
"""
if T == 0:
return 0
- E_th = 3.*n*R*T * debye_fn_cheb(debye_T/T)
+ E_th = 3.*n*constants.gas_constant*T * debye_fn_cheb(debye_T/T)
return E_th
def heat_capacity_v(T,debye_T,n):
@@ -93,7 +92,7 @@ def heat_capacity_v(T,debye_T,n):
if T ==0:
return 0
x = debye_T/T
- C_v = 3.0*n*R* ( 4.0*debye_fn_cheb(x) - 3.0*x/(np.exp(x)-1.0) )
+ C_v = 3.0*n*constants.gas_constant* ( 4.0*debye_fn_cheb(x) - 3.0*x/(np.exp(x)-1.0) )
return C_v
@@ -106,13 +105,13 @@ if __name__ == "__main__":
def old_thermal(T, debye_T, n):
if T == 0:
return 0
- return 3.*n*R*T * debye_fn(debye_T/T)
+ return 3.*n*constants.R*T * debye_fn(debye_T/T)
def old_heat(T, debye_T, n):
if T ==0:
return 0
deb = integrate.quad( lambda x : pow(x,4.)*np.exp(x)/pow((np.exp(x)-1.),2.), 0.0, debye_T/T)
- return 9.*n*R*deb[0]/pow(debye_T/T,3.)
+ return 9.*n*constants.gas_constant*deb[0]/pow(debye_T/T,3.)
temperatures = np.linspace(100,5000, 10000)
Debye_T = 1000.
diff --git a/burnman/geotherm.py b/burnman/geotherm.py
index e057701..5faf0f7 100644
--- a/burnman/geotherm.py
+++ b/burnman/geotherm.py
@@ -5,10 +5,8 @@
import numpy as np
import matplotlib.pyplot as pyplot
import scipy.integrate as integrate
-
-import burnman.tools
-import burnman.seismic
-
+import tools
+import seismic
def brown_shankland(pressure):
"""
@@ -26,8 +24,8 @@ def brown_shankland(pressure):
"""
temperature = np.empty_like(pressure)
for i in range(len(pressure)):
- depth = burnman.seismic.prem_model.depth(pressure[i])
- temperature[i] = burnman.tools.lookup_and_interpolate(table_brown_depth, table_brown_temperature, depth)
+ depth = seismic.prem_model.depth(pressure[i])
+ temperature[i] = tools.lookup_and_interpolate(table_brown_depth, table_brown_temperature, depth)
return temperature
@@ -47,8 +45,8 @@ def anderson(pressure):
"""
temperature = np.empty_like(pressure)
for i in range(len(pressure)):
- depth = burnman.seismic.prem_model.depth(pressure[i])
- temperature[i] = burnman.tools.lookup_and_interpolate(table_anderson_depth, table_anderson_temperature, depth)
+ depth = seismic.prem_model.depth(pressure[i])
+ temperature[i] = tools.lookup_and_interpolate(table_anderson_depth, table_anderson_temperature, depth)
return temperature
def adiabatic(pressures, T0, rock):
@@ -133,11 +131,11 @@ def dTdP(temperature, pressure, rock):
return temperature*top/bottom
-table_brown = burnman.tools.read_table("input_geotherm/brown_81.txt")
+table_brown = tools.read_table("input_geotherm/brown_81.txt")
table_brown_depth = np.array(table_brown)[:,0]
table_brown_temperature = np.array(table_brown)[:,1]
-table_anderson = burnman.tools.read_table("input_geotherm/anderson_82.txt")
+table_anderson = tools.read_table("input_geotherm/anderson_82.txt")
table_anderson_depth = np.array(table_anderson)[:,0]
table_anderson_temperature = np.array(table_anderson)[:,1]
diff --git a/burnman/mie_grueneisen_debye.py b/burnman/mie_grueneisen_debye.py
index 9b3a1e5..4f0b0fe 100644
--- a/burnman/mie_grueneisen_debye.py
+++ b/burnman/mie_grueneisen_debye.py
@@ -8,7 +8,7 @@ import scipy.optimize as opt
import burnman.equation_of_state as eos
import burnman.birch_murnaghan as bm
import burnman.debye as debye
-
+import constants
class MGDBase(eos.EquationOfState):
"""
@@ -121,7 +121,7 @@ class MGDBase(eos.EquationOfState):
gr = self.__grueneisen_parameter(params['V_0']/V, params)
Debye_T = self.__debye_temperature(params['V_0']/V, params)
G_th= 3./5. * ( self.__thermal_bulk_modulus(T,V,params) - \
- 6*debye.R*T*params['n']/V * gr * debye.debye_fn(Debye_T/T) ) # EQ B10
+ 6*constants.gas_constant*T*params['n']/V * gr * debye.debye_fn(Debye_T/T) ) # EQ B10
return G_th
#compute the Debye temperature in K. Takes the
@@ -152,7 +152,7 @@ class MGDBase(eos.EquationOfState):
def __thermal_bulk_modulus(self, T,V,params):
gr = self.__grueneisen_parameter(params['V_0']/V, params)
Debye_T = self.__debye_temperature(params['V_0']/V, params)
- K_th = 3.*params['n']*debye.R*T/V * gr * \
+ K_th = 3.*params['n']*constants.gas_constant*T/V * gr * \
((1. - params['q_0'] - 3.*gr)*debye.debye_fn(Debye_T/T)+3.*gr*(Debye_T/T)/(np.exp(Debye_T/T) - 1.)) # EQ B5
return K_th
diff --git a/burnman/partitioning.py b/burnman/partitioning.py
index a99d7c3..1c5ac8f 100644
--- a/burnman/partitioning.py
+++ b/burnman/partitioning.py
@@ -3,7 +3,7 @@
# Released under GPL v2 or later.
import numpy as np
-from burnman.constants import gas_constant, N_A
+import constants
# TODO: add up weight percent and check <100 and tell them how much
@@ -12,11 +12,10 @@ lower_mantle_mass = 4.043e24*.75 # in kg
-
# convert weight percentage (amount, 1.00 = 100%) of a given element to molar mass
def weight_pct_to_mol(element, amount):
- return amount * lower_mantle_mass / molar_mass[element] * N_A
+ return amount * lower_mantle_mass / molar_mass[element] * constants.Avogadro
def calculate_phase_percents(inp):
@@ -58,7 +57,7 @@ def calculate_partition_coefficient(pressure, temperature, components, initial_d
delV = 2.e-7 #in m^3/mol, average taken from Nakajima et al 2012, JGR
- rs = ((25.e9-pressure)*(delV)/(gas_constant*temperature))+np.log(Kd_0) #eq 5 Nakajima et al 2012, JGR. Solved for ln(K(P,T,X))
+ rs = ((25.e9-pressure)*(delV)/(constants.gas_constant*temperature))+np.log(Kd_0) #eq 5 Nakajima et al 2012, JGR. Solved for ln(K(P,T,X))
K = np.exp(rs) #The exchange coefficent at P and T. K(P,T,X) in eq 5 Nakajima et al 2012
diff --git a/burnman/seismic.py b/burnman/seismic.py
index 227628e..e64a6b5 100644
--- a/burnman/seismic.py
+++ b/burnman/seismic.py
@@ -5,7 +5,7 @@
import numpy as np
import matplotlib.pyplot as plt
-import burnman.tools
+import tools
class Seismic1DModel:
"""
@@ -245,7 +245,7 @@ class PREM(SeismicRadiusTable):
"""
def __init__(self):
SeismicRadiusTable.__init__(self)
- table = burnman.tools.read_table("input_seismic/prem_table.txt") # radius, pressure, density, v_p, v_s
+ table = tools.read_table("input_seismic/prem_table.txt") # radius, pressure, density, v_p, v_s
table = np.array(table)
self.table_radius = table[:,0]
self.table_pressure = table[:,1]
@@ -254,7 +254,7 @@ class PREM(SeismicRadiusTable):
self.table_vs = table[:,4]
# read in gravity data
- table = burnman.tools.read_table("input_seismic/grav_for_PREM.txt") # radius, g
+ table = tools.read_table("input_seismic/grav_for_PREM.txt") # radius, g
table = np.array(table)
self.table_radiusgravity = table[:,0]
self.table_gravity = table[:,1]
@@ -273,12 +273,12 @@ class Slow(SeismicRadiusTable):
def __init__(self):
SeismicRadiusTable.__init__(self)
- table = burnman.tools.read_table("input_seismic/prem_lowermantle.txt")#data is: radius pressure density V_p V_s Q_K Q_G
+ table = tools.read_table("input_seismic/prem_lowermantle.txt")#data is: radius pressure density V_p V_s Q_K Q_G
table = np.array(table)
table[:,0] = table[:,0]
- table2 = burnman.tools.read_table("input_seismic/swave_slow.txt")
+ table2 = tools.read_table("input_seismic/swave_slow.txt")
table2 = np.array(table2)
- table3 = burnman.tools.read_table("input_seismic/pwave_slow.txt")
+ table3 = tools.read_table("input_seismic/pwave_slow.txt")
table3 = np.array(table3)
min_radius = self.earth_radius-max(table2[:,0])
@@ -305,12 +305,12 @@ class Fast(SeismicRadiusTable):
def __init__(self):
SeismicRadiusTable.__init__(self)
- table = burnman.tools.read_table("input_seismic/prem_lowermantle.txt")#data is: radius pressure density V_p V_s Q_K Q_G
+ table = tools.read_table("input_seismic/prem_lowermantle.txt")#data is: radius pressure density V_p V_s Q_K Q_G
table = np.array(table)
table[:,0] = table[:,0]
- table2 = burnman.tools.read_table("input_seismic/swave_fast.txt")
+ table2 = tools.read_table("input_seismic/swave_fast.txt")
table2 = np.array(table2)
- table3 = burnman.tools.read_table("input_seismic/pwave_fast.txt")
+ table3 = tools.read_table("input_seismic/pwave_fast.txt")
table3 = np.array(table3)
min_radius = self.earth_radius-max(table2[:,0])
diff --git a/burnman/tools.py b/burnman/tools.py
index ebf46b8..5239292 100644
--- a/burnman/tools.py
+++ b/burnman/tools.py
@@ -7,7 +7,7 @@ import bisect
import os
import pkgutil
import numpy as np
-from burnman.constants import N_A
+import constants
def pretty_print_table(table,use_tabs=False):
"""
@@ -91,5 +91,5 @@ def molar_volume_from_unit_cell_volume(unit_cell_v, z):
NOT number of atoms per formula unit), and calculates
the molar volume, as expected by the equations of state.
"""
- return unit_cell_v*N_A/1e30/z
+ return unit_cell_v*constants.Avogadro/1e30/z
More information about the CIG-COMMITS
mailing list