VolFe 0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
VolFe/import_files.py ADDED
@@ -0,0 +1,10 @@
1
+ # import_data.py
2
+
3
+ import pandas as pd
4
+
5
+ # loads species.csv, models.csv, and user setup file
6
+ def import_files(filename):
7
+ species = pd.read_csv("species.csv", index_col = [0]) # attributes of the different species used in the system
8
+ models = pd.read_csv("models.csv", index_col = [0]) # model options
9
+ setup = pd.read_csv(filename) # csv for initial conditions of the system - typically inputs.csv
10
+ return species, models, setup
VolFe/isotopes.py ADDED
@@ -0,0 +1,181 @@
1
+ # isotopes.py
2
+
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ import VolFe.melt_gas as mg
7
+ import VolFe.calculations as c
8
+
9
+ ######################
10
+ ### delta notation ###
11
+ ######################
12
+
13
+ def delta_standards(standard,isotope,element):
14
+ if element == "S":
15
+ if standard == "VCDT":
16
+ if isotope == 34:
17
+ reference = 1/22.6436 # 34S/32S Ding et al. (2001)
18
+ elif element == "C":
19
+ if standard == "VPBD":
20
+ if isotope == 13:
21
+ reference = 0.01123720 # 13C/12C International Atomic Energy Agency (1995)
22
+ elif element == "H":
23
+ if standard == "VSMOW":
24
+ if isotope == 2:
25
+ reference = 155.76/1.e6 # 2H/1H Hagemann et al. (1970)
26
+ return reference
27
+
28
+ def ratio2delta(standard,isotope,ratio,element):
29
+ reference = delta_standard(standard,isotope,element)
30
+ d = ((ratio - reference)/reference)*1000.
31
+ return d
32
+
33
+ def delta2ratio(standard,isotope,d):
34
+ reference = delta_standard(standard,isotope,element)
35
+ ratio = ((d/1000.)*reference) + reference
36
+ return ratio
37
+
38
+ # newton raphson solver
39
+ def newton_raphson(x0,constants,e1,step,eqs,deriv,maxiter=1000):
40
+
41
+ def dx(x,eqs):
42
+ f_ = eqs(x,constants)
43
+ result =(abs(0-f_))
44
+ return result
45
+
46
+ def nr(x0,eqs,deriv):
47
+ f_ = eqs(x0,constants)
48
+ df_ = deriv
49
+ x0 = x0 - step*(f_/df_)
50
+ return x0
51
+
52
+ # create results table
53
+ results = pd.DataFrame([["guessx","diff","step"]])
54
+ results.to_csv('results_nr_isotopes.csv', index=False, header=False)
55
+ diff = dx(x0,eqs)
56
+ results1 = pd.DataFrame([[x0,diff,step]])
57
+ results = results.append(results1, ignore_index=True)
58
+ results.to_csv('results_nr_isotopes.csv', index=False, header=False)
59
+
60
+ delta1 = dx(x0,eqs)
61
+ results = pd.DataFrame([["guessx","diff","step"]])
62
+ results.to_csv('results_nr_isotopes.csv', index=False, header=False)
63
+ results1 = pd.DataFrame([[x0,delta1,step]])
64
+ results = results.append(results1, ignore_index=True)
65
+ results.to_csv('results_nr_isotopes.csv', index=False, header=False)
66
+
67
+ while delta1 > e1:
68
+ guessx = x0
69
+ f_ = eqs(x0,constants)
70
+ df_ = deriv(x0,constants)
71
+ x0 = x0 - step*(f_/df_)
72
+ #while x0 < 0.:
73
+ # step = step/10.
74
+ # x0 = x0 - step*(f_/df_)
75
+ delta1 = dx(x0,eqs)
76
+ results1 = pd.DataFrame([[x0,delta1,step]])
77
+ results = results.append(results1, ignore_index=True)
78
+ results.to_csv('results_nr_isotopes.csv', index=False, header=False)
79
+ return x0
80
+
81
+ # two isotopes, two species
82
+ def i2s2(element,PT,R_i,melt_wf):
83
+ if element == "S":
84
+ knowns = i2s2_S_melt(PT,R_i,melt_wf)
85
+ a, x, L = knowns # a = fractionation factor A-B, x = mole fraction of S in B, L = mole fraction of light isotope total
86
+ A = a - 1.
87
+ B = (1. - a)*(L + x) - 1.
88
+ C = a*x*L
89
+ l_b = (-B - ((B**2) - (4.*A*C))**0.5)/(2.*A)
90
+ h_b = x - l_b
91
+ R_b = h_b/l_b
92
+ R_a = a*R_b
93
+ return R_a, R_b
94
+
95
+ def i2s2_S_melt(PT,R_i,melt_wf):
96
+ a = (1./mg.alpha_SO2_SO4(PT))*mg.alpha_H2S_S(PT)*mg.alpha_gas("S","SO2","H2S",PT) # SO4-S2-
97
+ x = 1.-melt_wf["S6ST"] # mole fraction of S as S2- in the melt
98
+ R_i_ = 1./R_i["S"] # 32S/34S
99
+ L = R_i_/(R_i_ + 1.) # mole fraction of 32S
100
+ return a, x, L
101
+
102
+ def i2s6_S_alphas(PT): # all alphas against S2- in the melt
103
+ a_b = mg.alpha_H2S_S(PT) # H2S-S
104
+ a_c = (1./mg.alpha_SO2_SO4(PT))*mg.alpha_H2S_S(PT)*mg.alpha_gas("S","SO2","H2S",PT) # SO4-S
105
+ a_d = mg.alpha_H2S_S(PT)*mg.alpha_gas("S","S2","H2S",PT) # S2-S
106
+ a_e = mg.alpha_H2S_S(PT)*mg.alpha_gas("S","SO2","H2S",PT) # SO2-S
107
+ a_f = mg.alpha_H2S_S(PT)*mg.alpha_gas("S","OCS","H2S",PT) # OCS-S
108
+ return a_b, a_c, a_d, a_e, a_f
109
+
110
+ def i2s6(element,PT,R,melt_wf,gas_mf,species,nr_step,nr_tol,guessx): # species distribution is mole fraction of S in each species
111
+
112
+ if element == "S":
113
+ a_b, a_c, a_d, a_e, a_f = i2s6_S_alphas(PT)
114
+ species_distribution = c.mf_S_species(melt_wf,gas_mf,species)
115
+ T_a = species_distribution["S2-"]
116
+ T_b = species_distribution["H2S"]
117
+ T_c = species_distribution["SO42-"]
118
+ T_d = species_distribution["S2"]
119
+ T_e = species_distribution["SO2"]
120
+ T_f = species_distribution["OCS"]
121
+ R_i = R["S"]
122
+
123
+ constants = a_b, a_c, a_d, a_e, a_f, T_a, T_b, T_c, T_d, T_e, T_f, R_i
124
+
125
+ def isotope_distribution(l_a, constants):
126
+ a_b, a_c, a_d, a_e, a_f, T_a, T_b, T_c, T_d, T_e, T_f, R_i = constants
127
+ R_a = (T_a - l_a)/l_a # 34S/32S
128
+ R_b = a_b*R_a
129
+ R_c = a_c*R_a
130
+ R_d = a_d*R_a
131
+ R_e = a_e*R_a
132
+ R_f = a_f*R_a
133
+ return R_a, R_b, R_c, R_d, R_e, R_f
134
+
135
+ def av_m_g(element,l_a,constants):
136
+
137
+ a_b, a_c, a_d, a_e, a_f, T_a, T_b, T_c, T_d, T_e, T_f, R_i = constants
138
+ R_a, R_b, R_c, R_d, R_e, R_f = isotope_distribution(l_a, constants)
139
+
140
+ # heavy/total isotope ratio
141
+ R_a_ = R_a/(R_a + 1.)
142
+ R_b_ = R_b/(R_b + 1.)
143
+ R_c_ = R_c/(R_c + 1.)
144
+ R_d_ = R_d/(R_d + 1.)
145
+ R_e_ = R_e/(R_e + 1.)
146
+ R_f_ = R_f/(R_f + 1.)
147
+
148
+ if element == "S":
149
+ h_m = R_a_*T_a + R_c_*T_c # 34S melt (S2- + SO42-)
150
+ l_m = (1. - R_a_)*T_a + (1. - R_c_)*T_c
151
+ h_g = R_b_*T_b + R_d_*T_d + R_e_*T_e + R_f_*T_f # 34S gas (H2S + S2 + SO2 + OCS)
152
+ l_g = (1. - R_b_)*T_b + (1. - R_d_)*T_d + (1. - R_e_)*T_e + (1. - R_f_)*T_f # 34S gas (H2S + S2 + SO2 + OCS)
153
+
154
+ R_m = h_m/l_m
155
+ R_g = h_g/l_g
156
+ return R_m, R_g
157
+
158
+ def f(l_a, constants):
159
+ a_b, a_c, a_d, a_e, a_f, T_a, T_b, T_c, T_d, T_e, T_f, R_i = constants
160
+ R_a = (T_a/l_a) - 1.
161
+ l_b = T_b/(1.+a_b*R_a)
162
+ l_c = T_c/(1.+a_c*R_a)
163
+ l_d = T_d/(1.+a_d*R_a)
164
+ l_e = T_e/(1.+a_e*R_a)
165
+ l_f = T_f/(1.+a_f*R_a)
166
+ total = l_a + l_b + l_c + l_d + l_e + l_f
167
+ R_i_ = 1./R_i
168
+ l_t = (R_i_/(R_i_ + 1.))
169
+ return l_t - total
170
+
171
+ def df(l_a, constants):
172
+ a_b, a_c, a_d, a_e, a_f, T_a, T_b, T_c, T_d, T_e, T_f, R_i = constants
173
+ R_i_ = 1./R_i
174
+ l_t = (R_i_/(R_i_ + 1.))
175
+ result = -T_a*T_b*a_b/(l_a**2*(a_b*(T_a/l_a - 1.0) + 1.0)**2) - T_a*T_c*a_c/(l_a**2*(a_c*(T_a/l_a - 1.0) + 1.0)**2) - T_a*T_d*a_d/(l_a**2*(a_d*(T_a/l_a - 1.0) + 1.0)**2) - T_a*T_f*a_f/(l_a**2*(a_f*(T_a/l_a - 1.0) + 1.0)**2) - 1.
176
+ return result
177
+
178
+ l_a = newton_raphson(guessx,constants,nr_tol,nr_step,f,df)
179
+ result1 = isotope_distribution(l_a, constants)
180
+ result2 = av_m_g(element,l_a,constants)
181
+ return result1, result2