PetThermoTools 0.2.33__py3-none-any.whl → 0.2.35__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.
PetThermoTools/Barom.py CHANGED
@@ -11,50 +11,94 @@ from PetThermoTools.Plotting import *
11
11
  from PetThermoTools.Liq import *
12
12
  from PetThermoTools.MELTS import *
13
13
  from PetThermoTools.Path import *
14
- # try:
15
- # from PetThermoTools.Holland import *
16
- # except:
17
- # pass
18
14
  import multiprocessing
19
15
  from multiprocessing import Queue
20
16
  from multiprocessing import Process
21
17
  import time
22
- import sys
23
- from tqdm.notebook import tqdm, trange
24
18
  from scipy import interpolate
25
19
  from shapely.geometry import MultiPoint, Point, Polygon
26
20
 
27
- from functools import partial
28
- import concurrent.futures
21
+ import numpy as np
22
+ import pandas as pd
23
+ import multiprocessing
24
+ import time
29
25
 
26
+ def path_4_saturation_multi(q, index, *, Model = None, P_bar = None, comp = None, T_maxdrop_C = None, dt_C = None, T_initial_C = None, fO2_buffer = None,
27
+ fO2_offset = 0.0, H2O_Sat = None, phases = None):
28
+ results = {}
29
+ idx = []
30
+
31
+ if "MELTS" in Model:
32
+ from meltsdynamic import MELTSdynamic
30
33
 
31
- def run_melts_single(Pin, Model, comp, T_maxdrop_C, dt_C, T_initial_C,
32
- fO2_buffer, fO2_offset, H2O_Sat, phases):
33
- try:
34
- return path_MELTS(
35
- Model=Model,
36
- comp=comp,
37
- T_maxdrop_C=T_maxdrop_C,
38
- dt_C=dt_C,
39
- T_initial_C=T_initial_C,
40
- P_bar=Pin,
41
- find_liquidus=True,
42
- fO2_buffer=fO2_buffer,
43
- fO2_offset=fO2_offset,
44
- fluid_sat=H2O_Sat,
45
- Suppress=['rutile', 'tridymite'],
46
- phases=phases
47
- )
48
- except Exception as e:
49
- print(f"Failed at {Pin} bar: {e}")
50
- return None
51
-
52
- def mineral_cosaturation(Model="MELTSv1.0.2", cores=int(np.floor(multiprocessing.cpu_count()/2)), bulk=None,
34
+ if Model is None or Model == "MELTSv1.0.2":
35
+ melts = MELTSdynamic(1)
36
+ elif Model == "pMELTS":
37
+ melts = MELTSdynamic(2)
38
+ elif Model == "MELTSv1.1.0":
39
+ melts = MELTSdynamic(3)
40
+ elif Model == "MELTSv1.2.0":
41
+ melts = MELTSdynamic(4)
42
+ else:
43
+ from juliacall import Main as jl, convert as jlconvert
44
+
45
+ jl.seval("using MAGEMinCalc")
46
+
47
+ comp_julia = jl.seval("Dict")(comp)
48
+
49
+ for i in index:
50
+ # try:
51
+ if "MELTS" in Model:
52
+ Results, tr = path_MELTS(P_bar = P_bar[i],
53
+ Model=Model,
54
+ comp=comp,
55
+ T_maxdrop_C=T_maxdrop_C,
56
+ dt_C=dt_C,
57
+ T_initial_C=T_initial_C,
58
+ find_liquidus=True,
59
+ fO2_buffer=fO2_buffer,
60
+ fO2_offset=fO2_offset,
61
+ fluid_sat=H2O_Sat,
62
+ Suppress=['rutile', 'tridymite'],
63
+ phases=phases,
64
+ trail = True,
65
+ melts = melts
66
+ )
67
+ else:
68
+ if fO2_offset is None:
69
+ fO2_offset = 0.0
70
+
71
+ Results_df = jl.MAGEMinCalc.path(
72
+ comp=comp_julia, dt_C=dt_C,
73
+ P_bar=P_bar[i], T_min_C = T_maxdrop_C,
74
+ Model=Model, fo2_buffer=fO2_buffer,
75
+ fo2_offset=fO2_offset, find_liquidus=True,
76
+ frac_xtal = False
77
+ )
78
+
79
+ Results = dict(Results_df)
80
+
81
+ tr = True
82
+
83
+ idx.append(i)
84
+
85
+
86
+ results[f"index = {i}"] = Results
87
+
88
+ if tr is False:
89
+ break
90
+ # except:
91
+ # idx.append(i)
92
+
93
+ q.put([idx, results])
94
+ return
95
+
96
+ def mineral_cosaturation(Model="MELTSv1.0.2", cores=int(np.floor(multiprocessing.cpu_count())), bulk=None,
53
97
  phases=['quartz1', 'alkali-feldspar1', 'plagioclase1'],
54
98
  P_bar=np.linspace(250, 5000, 32), Fe3Fet_init=None, H2O_init=None,
55
99
  CO2_init=None, H2O_Sat=False, T_initial_C=None, dt_C=2,
56
100
  T_maxdrop_C=50, T_cut_C=20, find_range=True,
57
- find_min=True, fO2_buffer=None, fO2_offset=0.0, timeout = 30):
101
+ find_min=True, fO2_buffer=None, fO2_offset=0.0, timeout = 90, multiprocesses = True):
58
102
 
59
103
  comp = bulk.copy()
60
104
  if H2O_Sat:
@@ -63,33 +107,100 @@ def mineral_cosaturation(Model="MELTSv1.0.2", cores=int(np.floor(multiprocessing
63
107
  comp = comp_fix(Model=Model, comp=comp, Fe3Fet_Liq=Fe3Fet_init,
64
108
  H2O_Liq=H2O_init, CO2_Liq=CO2_init)
65
109
 
66
- run_partial = partial(run_melts_single,
67
- Model=Model, comp=comp, T_maxdrop_C=T_maxdrop_C,
68
- dt_C=dt_C, T_initial_C=T_initial_C,
69
- fO2_buffer=fO2_buffer, fO2_offset=fO2_offset,
70
- H2O_Sat=H2O_Sat, phases=phases)
110
+ combined_results = {}
111
+ if multiprocesses:
112
+ index_in = np.arange(len(P_bar))
113
+ index_out = np.array([], dtype=int)
71
114
 
72
- results = {}
73
- with concurrent.futures.ProcessPoolExecutor(max_workers=cores) as executor:
74
- futures = {executor.submit(run_partial, p): i for i, p in enumerate(P_bar)}
115
+ while len(index_out) < len(index_in):
116
+ index = np.setdiff1d(index_in, index_out)
117
+ groups = np.array_split(index, cores)
118
+ non_empty_groups = [g for g in groups if g.size > 0]
119
+ groups = non_empty_groups
75
120
 
76
- done, not_done = concurrent.futures.wait(
77
- futures.keys(), timeout=timeout, return_when=concurrent.futures.ALL_COMPLETED
78
- )
121
+ processes = []
122
+ for i in range(len(groups)):
123
+ q = Queue()
124
+ p = Process(target = path_4_saturation_multi, args = (q, groups[i]),
125
+ kwargs = {'Model': Model, 'comp': comp,
126
+ 'T_initial_C': T_initial_C, 'T_maxdrop_C': T_maxdrop_C,
127
+ 'dt_C': dt_C, 'P_bar': P_bar, 'phases': phases,
128
+ 'fO2_buffer': fO2_buffer, 'fO2_offset': fO2_offset})
129
+
130
+ processes.append((p, q, groups[i]))
131
+ p.start()
132
+
133
+ for p, q, group in processes:
134
+ try:
135
+ res = q.get(timeout=timeout)
136
+ except:
137
+ res = []
138
+ idx_chunks = np.array([group[0]], dtype = int)
139
+ p.join(timeout = 2)
140
+ p.terminate()
79
141
 
80
- for future in done:
81
- i = futures[future]
82
- try:
83
- results[f"P = {P_bar[i]:.2f} bars"] = future.result()
84
- except Exception as e:
85
- print(f"Failure at {P_bar[i]} bar: {e}")
86
- results[f"P = {P_bar[i]:.2f} bars"] = {}
142
+ if len(res) > 0.0:
143
+ idx_chunks, results = res
144
+ combined_results.update(results)
87
145
 
88
- for future in not_done:
89
- i = futures[future]
90
- print(f"Timeout at {P_bar[i]} bar. Either the calculation was slow (increase timeout) or it failed.")
91
- results[f"P = {P_bar[i]:.2f} bars"] = {}
92
- future.cancel() # Cancel if still running
146
+ index_out = np.hstack((index_out, idx_chunks))
147
+ else:
148
+ if "MELTS" in Model:
149
+ from meltsdynamic import MELTSdynamic
150
+
151
+ if Model is None or Model == "MELTSv1.0.2":
152
+ melts = MELTSdynamic(1)
153
+ elif Model == "pMELTS":
154
+ melts = MELTSdynamic(2)
155
+ elif Model == "MELTSv1.1.0":
156
+ melts = MELTSdynamic(3)
157
+ elif Model == "MELTSv1.2.0":
158
+ melts = MELTSdynamic(4)
159
+ else:
160
+ from juliacall import Main as jl, convert as jlconvert
161
+
162
+ jl.seval("using MAGEMinCalc")
163
+
164
+ comp_julia = jl.seval("Dict")(comp)
165
+
166
+ if "MELTS" in Model:
167
+ for i in range(len(P_bar)):
168
+ results = {}
169
+ Results = path_MELTS(P_bar = P_bar[i],
170
+ Model=Model,
171
+ comp=comp,
172
+ T_maxdrop_C=T_maxdrop_C,
173
+ dt_C=dt_C,
174
+ T_initial_C=T_initial_C,
175
+ find_liquidus=True,
176
+ fO2_buffer=fO2_buffer,
177
+ fO2_offset=fO2_offset,
178
+ fluid_sat=H2O_Sat,
179
+ Suppress=['rutile', 'tridymite'],
180
+ phases=phases,
181
+ melts = melts
182
+ )
183
+ results[f"index = {i}"] = Results
184
+ combined_results.update(results)
185
+ else:
186
+ if fO2_offset is None:
187
+ fO2_offset = 0.0
188
+
189
+ for i in range(len(P_bar)):
190
+ results = {}
191
+ Results_df = jl.MAGEMinCalc.path(
192
+ comp=comp_julia, dt_C=dt_C,
193
+ P_bar=P_bar[i], T_min_C = T_maxdrop_C,
194
+ Model=Model, fo2_buffer=fO2_buffer,
195
+ fo2_offset=fO2_offset, find_liquidus=True,
196
+ frac_xtal = False
197
+ )
198
+
199
+ Results = dict(Results_df)
200
+ results[f"index = {i}"] = Results
201
+ combined_results.update(results)
202
+
203
+ results = combined_results
93
204
 
94
205
  Results = stich(Res=results, multi=True, Model=Model)
95
206
 
@@ -110,7 +221,7 @@ def mineral_cosaturation(Model="MELTSv1.0.2", cores=int(np.floor(multiprocessing
110
221
  arr2[:, 0] = np.abs(arr[:,1] - arr[:,2])
111
222
  arr2[:, 1] = np.abs(arr[:,1] - arr[:,3])
112
223
  arr2[:, 2] = np.abs(arr[:,2] - arr[:,3])
113
- arr2[:,3] = np.max(arr2[:,0:2], axis = 1)
224
+ arr2[:, 3] = np.max(arr2[:,0:2], axis = 1)
114
225
 
115
226
  r_arr = np.hstack((arr,arr2))
116
227
 
@@ -131,7 +242,7 @@ def mineral_cosaturation(Model="MELTSv1.0.2", cores=int(np.floor(multiprocessing
131
242
 
132
243
  arr[:,3] = np.abs(arr[:,1] - arr[:,2])
133
244
 
134
- out = pd.DataFrame(data = r_arr, columns = columns)
245
+ out = pd.DataFrame(data = arr, columns = columns)
135
246
  out = out.sort_values('P_bar').reset_index(drop=True)
136
247
 
137
248
  if find_min:
@@ -286,6 +397,8 @@ def find_mineral_cosaturation(cores = None, Model = None, bulk = None, phases =
286
397
  Results: Dict
287
398
  Dictionary containing information regarding the saturation temperature of each phase and the residuals between the different phases
288
399
  '''
400
+ print('This function will be removed following the update to v0.3.0. Please switch to using the mineral_cosaturation() function')
401
+
289
402
  try:
290
403
  from meltsdynamic import MELTSdynamic
291
404
  except:
PetThermoTools/MELTS.py CHANGED
@@ -808,7 +808,7 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
808
808
  P_bar = None, P_path_bar = None, P_start_bar = None, P_end_bar = None, dp_bar = None,
809
809
  isenthalpic = None, isentropic = None, isochoric = None, find_liquidus = None,
810
810
  fO2_buffer = None, fO2_offset = None, fluid_sat = None, Crystallinity_limit = None,
811
- Suppress = ['rutile', 'tridymite'], Suppress_except=False, phases=None):
811
+ Suppress = ['rutile', 'tridymite'], Suppress_except=False, phases=None, trail = None, melts = None):
812
812
  '''
813
813
  Perform a single calculation in MELTS. WARNING! Running this function directly from the command land/jupyter notebook will initiate the MELTS C library in the main python process. Once this has been initiated the MELTS C library cannot be re-loaded and failures during the calculation will likely cause a terminal error to occur.
814
814
 
@@ -884,6 +884,8 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
884
884
 
885
885
  '''
886
886
  Results = {}
887
+ if trail is not None:
888
+ trail = False
887
889
 
888
890
  if comp is None:
889
891
  raise Exception("No composition specified")
@@ -898,16 +900,17 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
898
900
  if T_path_C is None and T_start_C is None and find_liquidus is None:
899
901
  raise Exception("Starting temperature must be specified or the liquidus must be found")
900
902
 
901
- from meltsdynamic import MELTSdynamic
903
+ if melts is None:
904
+ from meltsdynamic import MELTSdynamic
902
905
 
903
- if Model is None or Model == "MELTSv1.0.2":
904
- melts = MELTSdynamic(1)
905
- elif Model == "pMELTS":
906
- melts = MELTSdynamic(2)
907
- elif Model == "MELTSv1.1.0":
908
- melts = MELTSdynamic(3)
909
- elif Model == "MELTSv1.2.0":
910
- melts = MELTSdynamic(4)
906
+ if Model is None or Model == "MELTSv1.0.2":
907
+ melts = MELTSdynamic(1)
908
+ elif Model == "pMELTS":
909
+ melts = MELTSdynamic(2)
910
+ elif Model == "MELTSv1.1.0":
911
+ melts = MELTSdynamic(3)
912
+ elif Model == "MELTSv1.2.0":
913
+ melts = MELTSdynamic(4)
911
914
 
912
915
  bulk = [comp['SiO2_Liq'], comp['TiO2_Liq'], comp['Al2O3_Liq'], comp['Fe3Fet_Liq']*((159.59/2)/71.844)*comp['FeOt_Liq'], comp['Cr2O3_Liq'], (1- comp['Fe3Fet_Liq'])*comp['FeOt_Liq'], comp['MnO_Liq'], comp['MgO_Liq'], 0.0, 0.0, comp['CaO_Liq'], comp['Na2O_Liq'], comp['K2O_Liq'], comp['P2O5_Liq'], comp['H2O_Liq'], comp['CO2_Liq'], 0.0, 0.0, 0.0]
913
916
  bulk = list(100*np.array(bulk)/np.sum(bulk))
@@ -952,12 +955,18 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
952
955
  else:
953
956
  Liq_Results = findLiq_MELTS(P_bar = P_path_bar, comp = bulk, melts = melts, fO2_buffer = fO2_buffer, fO2_offset = fO2_offset, T_C_init = T_initial_C)
954
957
  except:
955
- return Results
958
+ if trail is not None:
959
+ return Results, trail
960
+ else:
961
+ return Results
956
962
  elif P_start_bar is not None:
957
963
  try:
958
964
  Liq_Results = findLiq_MELTS(P_bar = P_start_bar, comp = bulk, melts = melts, fO2_buffer = fO2_buffer, fO2_offset = fO2_offset, T_C_init = T_initial_C)
959
965
  except:
960
- return Results
966
+ if trail is not None:
967
+ return Results, trail
968
+ else:
969
+ return Results
961
970
 
962
971
  print(Liq_Results)
963
972
  T_start_C = Liq_Results['T_Liq'] + 0.1
@@ -1039,6 +1048,10 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
1039
1048
  Results['liquid1_prop'] = pd.DataFrame(data = np.zeros((length, 4)), columns = ['h', 'mass', 'v', 'rho'])
1040
1049
 
1041
1050
  for i in range(length):
1051
+ if i == 1:
1052
+ if trail is not None:
1053
+ trail = True
1054
+
1042
1055
  if type(T) == np.ndarray:
1043
1056
  melts.engine.temperature = T[i]
1044
1057
  if type(P) == np.ndarray:
@@ -1087,7 +1100,11 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
1087
1100
  else:
1088
1101
  melts.engine.calcEquilibriumState(1,0)
1089
1102
  except:
1090
- return Results
1103
+ trail = False
1104
+ # if trail is not None:
1105
+ # return Results, trail
1106
+ # else:
1107
+ # return Results
1091
1108
  break
1092
1109
 
1093
1110
  if isenthalpic is not None:
@@ -1097,7 +1114,11 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
1097
1114
  else:
1098
1115
  melts.engine.calcEquilibriumState(2,0)
1099
1116
  except:
1100
- # return Results
1117
+ trail = False
1118
+ # if trail is not None:
1119
+ # return Results, trail
1120
+ # else:
1121
+ # return Results
1101
1122
  break
1102
1123
 
1103
1124
  if isentropic is not None:
@@ -1107,6 +1128,7 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
1107
1128
  else:
1108
1129
  melts.engine.calcEquilibriumState(3,0)
1109
1130
  except:
1131
+ trail = False
1110
1132
  # return Results
1111
1133
  break
1112
1134
 
@@ -1114,6 +1136,7 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
1114
1136
  try:
1115
1137
  melts.engine.calcEquilibriumState(4,0)
1116
1138
  except:
1139
+ trail = False
1117
1140
  # return Results
1118
1141
  break
1119
1142
 
@@ -1133,7 +1156,8 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
1133
1156
  try:
1134
1157
  PhaseList = ['liquid1'] + melts.engine.solidNames
1135
1158
  except:
1136
- return Results
1159
+ trail = False
1160
+ # return Results
1137
1161
  break
1138
1162
 
1139
1163
  for phase in PhaseList:
@@ -1171,7 +1195,11 @@ def path_MELTS(Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
1171
1195
 
1172
1196
  melts = melts.addNodeAfter()
1173
1197
 
1174
- return Results
1198
+
1199
+ if trail is not None:
1200
+ return Results, trail
1201
+ else:
1202
+ return Results
1175
1203
 
1176
1204
  def findSatPressure_MELTS_multi(Model = None, comp = None, fO2_buffer = None, fO2_offset = None, P_bar = None, T_fixed_C = None):
1177
1205
  out = pd.DataFrame(columns = ['Sample_ID_Liq', 'SiO2_Liq', 'TiO2_Liq', 'Al2O3_Liq', 'Cr2O3_Liq', 'FeOt_Liq', 'MnO_Liq', 'MgO_Liq', 'CaO_Liq', 'Na2O_Liq', 'K2O_Liq', 'P2O5_Liq', 'H2O_Liq', 'CO2_Liq', 'Fe3Fet_Liq', 'P_bar', 'T_Liq'])
PetThermoTools/Path.py CHANGED
@@ -122,6 +122,7 @@ def multi_path(cores = None, Model = None, bulk = None, comp = None, Frac_solid
122
122
  except:
123
123
  Warning('alphaMELTS for Python files are not on the python path. \n Please add these files to the path running \n import sys \n sys.path.append(r"insert_your_path_to_melts_here") \n You are looking for the location of the meltsdynamic.py file')
124
124
 
125
+ timeout_main = timeout
125
126
 
126
127
  if Frac_solid is False:
127
128
  Frac_solid = None
@@ -302,157 +303,143 @@ def multi_path(cores = None, Model = None, bulk = None, comp = None, Frac_solid
302
303
  elif type(fO2_offset) == float or type(fO2_offset) == int:
303
304
  fO2_offset = np.zeros(int(L)) + fO2_offset
304
305
 
305
- for j in tqdm(range(len(Group))):
306
- ps = []
306
+ index_in = np.arange(int(L))
307
+ combined_results = {}
308
+ index_out = np.array([], dtype=int)
307
309
 
308
- if Print_suppress is None:
309
- print("Running " + Model + " calculations " + str(int(cores*j)) + " to " + str(int(cores*j) + Group[j] - 1) + " ...", end = "", flush = True)
310
- s = time.time()
310
+ while len(index_out) < len(index_in):
311
+ index = np.setdiff1d(index_in, index_out)
312
+ groups = np.array_split(index, cores)
313
+ non_empty_groups = [g for g in groups if g.size > 0]
314
+ groups = non_empty_groups
311
315
 
312
- for i in range(int(cores*j), int(cores*j + Group[j])):
313
- if type(comp) == dict:
314
- p = Process(target = path, args = (q, i),
316
+ if len(groups[0])< 15:
317
+ timeout = len(groups[0])*timeout_main
318
+ else:
319
+ timeout = 15*timeout_main
320
+
321
+ processes = []
322
+ Start = time.time()
323
+ for i in range(len(groups)):
324
+ q = Queue()
325
+ p = Process(target = path_multi, args = (q, groups[i]),
315
326
  kwargs = {'Model': Model, 'comp': comp, 'Frac_solid': Frac_solid, 'Frac_fluid': Frac_fluid,
316
- 'T_C': T_C[i], 'T_path_C': T_path_C[i], 'T_start_C': T_start_C[i], 'T_end_C': T_end_C[i], 'dt_C': dt_C[i],
317
- 'P_bar': P_bar[i], 'P_path_bar': P_path_bar[i], 'P_start_bar': P_start_bar[i], 'P_end_bar': P_end_bar[i], 'dp_bar': dp_bar[i],
318
- 'isenthalpic': isenthalpic, 'isentropic': isentropic, 'isochoric': isochoric, 'find_liquidus': find_liquidus,
319
- 'fO2_buffer': fO2_buffer, 'fO2_offset': fO2_offset[i], 'fluid_sat': fluid_sat, 'Crystallinity_limit': Crystallinity_limit,
320
- 'Suppress': Suppress, 'Suppress_except': Suppress_except})
321
- else:
322
- p = Process(target = path, args = (q, i),
323
- kwargs = {'Model': Model, 'comp': comp.loc[i].to_dict(), 'Frac_solid': Frac_solid, 'Frac_fluid': Frac_fluid,
324
- 'T_C': T_C[i], 'T_path_C': T_path_C[i], 'T_start_C': T_start_C[i], 'T_end_C': T_end_C[i], 'dt_C': dt_C[i],
325
- 'P_bar': P_bar[i], 'P_path_bar': P_path_bar[i], 'P_start_bar': P_start_bar[i], 'P_end_bar': P_end_bar[i], 'dp_bar': dp_bar[i],
327
+ 'T_C': T_C, 'T_path_C': T_path_C, 'T_start_C': T_start_C, 'T_end_C': T_end_C, 'dt_C': dt_C,
328
+ 'P_bar': P_bar, 'P_path_bar': P_path_bar, 'P_start_bar': P_start_bar, 'P_end_bar': P_end_bar, 'dp_bar': dp_bar,
326
329
  'isenthalpic': isenthalpic, 'isentropic': isentropic, 'isochoric': isochoric, 'find_liquidus': find_liquidus,
327
- 'fO2_buffer': fO2_buffer, 'fO2_offset': fO2_offset[i], 'fluid_sat': fluid_sat, 'Crystallinity_limit': Crystallinity_limit,
330
+ 'fO2_buffer': fO2_buffer, 'fO2_offset': fO2_offset, 'fluid_sat': fluid_sat, 'Crystallinity_limit': Crystallinity_limit,
328
331
  'Suppress': Suppress, 'Suppress_except': Suppress_except})
329
-
330
- ps.append(p)
332
+
333
+ processes.append((p, q, groups[i]))
331
334
  p.start()
332
335
 
333
- if timeout is None:
334
- TIMEOUT = 240
335
- else:
336
- TIMEOUT = timeout
337
-
338
- start = time.time()
339
- first = True
340
- for p in ps:
341
- if time.time() - start < TIMEOUT - 10:
342
- try:
343
- ret = q.get(timeout = TIMEOUT - (time.time()-start) + 10)
344
- except:
345
- ret = []
346
- else:
347
- if first == True:
348
- print('Timeout Reached - this likely indicates the calculation failed. \n You can try increasing the timeout limit using the "timeout" kwarg.')
349
- first = False
350
- try:
351
- ret = q.get(timeout = 10)
352
- except:
353
- ret = []
354
-
355
- qs.append(ret)
356
-
357
- TIMEOUT = 5
358
- start = time.time()
359
- for p in ps:
360
- if p.is_alive():
361
- while time.time() - start <= TIMEOUT:
362
- if not p.is_alive():
363
- p.join()
364
- p.terminate()
365
- break
366
- time.sleep(.1)
336
+ for p, q, group in processes:
337
+ try:
338
+ if time.time() - Start < timeout + 5:
339
+ res = q.get(timeout=timeout)
367
340
  else:
368
- p.terminate()
369
- p.join(5)
370
- else:
371
- p.join()
372
- p.terminate()
341
+ res = q.get(timeout=10)
342
+ except:
343
+ res = []
344
+ idx_chunks = np.array([group[0]], dtype = int)
373
345
 
374
- if Print_suppress is None:
375
- print(" Complete (time taken = " + str(round(time.time() - s,2)) + " seconds)", end = "\n", flush = True)
376
-
377
-
378
- Results = {}
379
- Out = {}
380
- for i in range(len(qs)):
381
- if len(qs[i]) > 0:
382
- Res, index = qs[i]
383
- # if label is None:
384
- Results['index = ' + str(index)] = Res
385
- # elif label == "P" or label == "pressure" or label == "P_bar":
386
- # Out[str(round(Res['Conditions']['pressure'].loc[0]))] = Res
387
- # elif label == "water" or label == "H2O" or label == "H2O_Liq":
388
- # if H2O_Liq is not None:
389
- # Out[str(round(H2O_Liq[index], 2))] = Res
390
- # else:
391
- # Out[str(round(bulk.loc[index, "H2O_Liq"], 2))] = Res
392
- # elif label == "carbon" or label == "CO2":
393
- # Out[str(round(Res['liquid1']['CO2'].loc[0], 2))] = Res
394
- # elif label == "oxygen fugacity" or label == "fO2":
395
- # Out[str(round(fO2_offset[index], 2))] = Res
396
- # elif label == "Fe redox" or label == "Fe3Fet" or label == "Fe3Fet_Liq":
397
- # Out[str[round(Res['liquid1']['FeO'].loc[0]/(Res['liquid1']['FeO'].loc[0] + (71.844/(159.69/2))*Res['liquid1']['Fe2O3'].loc[0]),2)]] = Res
398
- # elif label in list(comp.keys()):
399
- # Results[str(comp[label].loc[index])] = Res
400
-
401
- # if label == "P" or label == "pressure" or label == "P_bar":
402
- # # A = Out.copy()
403
- # # B = [float(x) for x in A]
404
- # O = sorted(Out)
405
- # for o in O:
406
- # # if o % 1 == 0:
407
- # # o = int(o)
408
- # Results['P = ' + o + ' bars'] = Out[o]
409
-
410
- # if label == "water" or label == "H2O" or label == "H2O_Liq":
411
- # # A = Out.copy()
412
- # # B = [float(x) for x in A]
413
- # O = sorted(Out)
414
- # for o in O:
415
- # # if o % 1 == 0:
416
- # # o = int(o)
417
- # Results['H2O_i = ' + o + ' wt%'] = Out[o]
418
-
419
- # # if label == "carbon" or label == "CO2":
420
- # # # A = Out.copy()
421
- # # # B = [float(x) for x in A]
422
- # # O = sorted(B)
423
- # # for o in O:
424
- # # # if o % 1 == 0:
425
- # # # o = int(o)
426
- # # Results['CO2 = ' + str(o) + ' wt%'] = Out[str[o]]
427
-
428
- # if label == "oxygen fugacity" or label == "fO2":
429
- # # A = Out.copy()
430
- # # B = [float(x) for x in A]
431
- # O = sorted(B)
432
- # for o in O:
433
- # # if o % 1 == 0:
434
- # # o = int(o)
435
-
436
- # # if o > 0.0:
437
- # # Results[fO2_buffer + ' +' + str(o)] = out[str(o)]
438
- # # else:
439
- # Results[fO2_buffer + ' ' + str(o)] = Out[str[o]]
440
-
441
- # if label == "Fe redox" or label == "Fe3Fet_Liq" or label == 'Fe3Fet':
442
- # # A = Out.copy()
443
- # # B = [float(x) for x in A]
444
- # O = sorted(B)
445
- # for o in O:
446
- # # if o % 1 == 0:
447
- # # o = int(o)
448
- # Results['Fe3/Fet = ' + str(o)] = Out[str[o]]
449
-
450
- # if print_label is not None:
451
- # print(Results.keys())
346
+ p.join(timeout = 2)
347
+ p.terminate()
452
348
 
349
+ if len(res) > 0.0:
350
+ idx_chunks, results = res
351
+ combined_results.update(results)
352
+
353
+ index_out = np.hstack((index_out, idx_chunks))
354
+
355
+ print(f"Completed {100*len(index_out)/len(index_in)} %")
356
+
357
+ results = combined_results
358
+
359
+ Results = stich(Res=results, multi=True, Model=Model, Frac_fluid = Frac_fluid, Frac_solid = Frac_solid)
360
+
361
+ # for j in tqdm(range(len(Group))):
362
+ # ps = []
363
+
364
+ # if Print_suppress is None:
365
+ # print("Running " + Model + " calculations " + str(int(cores*j)) + " to " + str(int(cores*j) + Group[j] - 1) + " ...", end = "", flush = True)
366
+ # s = time.time()
367
+
368
+ # for i in range(int(cores*j), int(cores*j + Group[j])):
369
+ # if type(comp) == dict:
370
+ # p = Process(target = path, args = (q, i),
371
+ # kwargs = {'Model': Model, 'comp': comp, 'Frac_solid': Frac_solid, 'Frac_fluid': Frac_fluid,
372
+ # 'T_C': T_C[i], 'T_path_C': T_path_C[i], 'T_start_C': T_start_C[i], 'T_end_C': T_end_C[i], 'dt_C': dt_C[i],
373
+ # 'P_bar': P_bar[i], 'P_path_bar': P_path_bar[i], 'P_start_bar': P_start_bar[i], 'P_end_bar': P_end_bar[i], 'dp_bar': dp_bar[i],
374
+ # 'isenthalpic': isenthalpic, 'isentropic': isentropic, 'isochoric': isochoric, 'find_liquidus': find_liquidus,
375
+ # 'fO2_buffer': fO2_buffer, 'fO2_offset': fO2_offset[i], 'fluid_sat': fluid_sat, 'Crystallinity_limit': Crystallinity_limit,
376
+ # 'Suppress': Suppress, 'Suppress_except': Suppress_except})
377
+ # else:
378
+ # p = Process(target = path, args = (q, i),
379
+ # kwargs = {'Model': Model, 'comp': comp.loc[i].to_dict(), 'Frac_solid': Frac_solid, 'Frac_fluid': Frac_fluid,
380
+ # 'T_C': T_C[i], 'T_path_C': T_path_C[i], 'T_start_C': T_start_C[i], 'T_end_C': T_end_C[i], 'dt_C': dt_C[i],
381
+ # 'P_bar': P_bar[i], 'P_path_bar': P_path_bar[i], 'P_start_bar': P_start_bar[i], 'P_end_bar': P_end_bar[i], 'dp_bar': dp_bar[i],
382
+ # 'isenthalpic': isenthalpic, 'isentropic': isentropic, 'isochoric': isochoric, 'find_liquidus': find_liquidus,
383
+ # 'fO2_buffer': fO2_buffer, 'fO2_offset': fO2_offset[i], 'fluid_sat': fluid_sat, 'Crystallinity_limit': Crystallinity_limit,
384
+ # 'Suppress': Suppress, 'Suppress_except': Suppress_except})
385
+
386
+ # ps.append(p)
387
+ # p.start()
388
+
389
+ # if timeout is None:
390
+ # TIMEOUT = 240
391
+ # else:
392
+ # TIMEOUT = timeout
393
+
394
+ # start = time.time()
395
+ # first = True
396
+ # for p in ps:
397
+ # if time.time() - start < TIMEOUT - 10:
398
+ # try:
399
+ # ret = q.get(timeout = TIMEOUT - (time.time()-start) + 10)
400
+ # except:
401
+ # ret = []
402
+ # else:
403
+ # if first == True:
404
+ # print('Timeout Reached - this likely indicates the calculation failed. \n You can try increasing the timeout limit using the "timeout" kwarg.')
405
+ # first = False
406
+ # try:
407
+ # ret = q.get(timeout = 10)
408
+ # except:
409
+ # ret = []
410
+
411
+ # qs.append(ret)
412
+
413
+ # TIMEOUT = 5
414
+ # start = time.time()
415
+ # for p in ps:
416
+ # if p.is_alive():
417
+ # while time.time() - start <= TIMEOUT:
418
+ # if not p.is_alive():
419
+ # p.join()
420
+ # p.terminate()
421
+ # break
422
+ # time.sleep(.1)
423
+ # else:
424
+ # p.terminate()
425
+ # p.join(5)
426
+ # else:
427
+ # p.join()
428
+ # p.terminate()
429
+
430
+ # if Print_suppress is None:
431
+ # print(" Complete (time taken = " + str(round(time.time() - s,2)) + " seconds)", end = "\n", flush = True)
432
+
433
+
434
+ # Results = {}
435
+ # Out = {}
436
+ # for i in range(len(qs)):
437
+ # if len(qs[i]) > 0:
438
+ # Res, index = qs[i]
439
+ # Results['index = ' + str(index)] = Res
453
440
 
454
441
  #if "MELTS" in Model:
455
- Results = stich(Results, multi = True, Model = Model, Frac_fluid = Frac_fluid, Frac_solid = Frac_solid)
442
+ # Results = stich(Results, multi = True, Model = Model, Frac_fluid = Frac_fluid, Frac_solid = Frac_solid)
456
443
 
457
444
  for r in Results:
458
445
  i = int(r.split('=')[1].strip())
@@ -502,6 +489,99 @@ def label_results(Result,label):
502
489
 
503
490
  return new_out
504
491
 
492
+ def path_multi(q, index, *, Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
493
+ T_C = None, T_path_C = None, T_start_C = None, T_end_C = None, dt_C = None,
494
+ P_bar = None, P_path_bar = None, P_start_bar = None, P_end_bar = None, dp_bar = None,
495
+ isenthalpic = None, isentropic = None, isochoric = None, find_liquidus = None,
496
+ fO2_buffer = None, fO2_offset = None, fluid_sat = None, Crystallinity_limit = None,
497
+ Suppress = None, Suppress_except = None, trail = True):
498
+ results = {}
499
+ idx = []
500
+
501
+ if len(index) > 15:
502
+ index = index[:15]
503
+
504
+ if "MELTS" in Model:
505
+ from meltsdynamic import MELTSdynamic
506
+
507
+ if Model is None or Model == "MELTSv1.0.2":
508
+ melts = MELTSdynamic(1)
509
+ elif Model == "pMELTS":
510
+ melts = MELTSdynamic(2)
511
+ elif Model == "MELTSv1.1.0":
512
+ melts = MELTSdynamic(3)
513
+ elif Model == "MELTSv1.2.0":
514
+ melts = MELTSdynamic(4)
515
+ else:
516
+ from juliacall import Main as jl, convert as jlconvert
517
+
518
+ jl.seval("using MAGEMinCalc")
519
+
520
+
521
+ for i in index:
522
+ try:
523
+ if "MELTS" in Model:
524
+ if type(comp) == dict:
525
+ Results, tr = path_MELTS(Model = Model, comp = comp, Frac_solid = Frac_solid, Frac_fluid = Frac_fluid,
526
+ T_initial_C = 1400, T_C = T_C[i], T_path_C = T_path_C[i], T_start_C = T_start_C[i],
527
+ T_end_C = T_end_C[i], dt_C = dt_C[i], P_bar = P_bar[i], P_path_bar = P_path_bar[i],
528
+ P_start_bar = P_start_bar[i], P_end_bar = P_end_bar[i], dp_bar = dp_bar[i],
529
+ isenthalpic = isenthalpic, isentropic = isentropic, isochoric = isochoric,
530
+ find_liquidus = find_liquidus, fO2_buffer = fO2_buffer, fO2_offset = fO2_offset[i],
531
+ fluid_sat = fluid_sat, Crystallinity_limit = Crystallinity_limit, Suppress = Suppress,
532
+ Suppress_except=Suppress_except, trail = trail, melts = melts)
533
+ else:
534
+ Results, tr = path_MELTS(Model = Model, comp = comp.loc[i].to_dict(), Frac_solid = Frac_solid, Frac_fluid = Frac_fluid,
535
+ T_initial_C = 1400, T_C = T_C[i], T_path_C = T_path_C[i], T_start_C = T_start_C[i],
536
+ T_end_C = T_end_C[i], dt_C = dt_C[i], P_bar = P_bar[i], P_path_bar = P_path_bar[i],
537
+ P_start_bar = P_start_bar[i], P_end_bar = P_end_bar[i], dp_bar = dp_bar[i],
538
+ isenthalpic = isenthalpic, isentropic = isentropic, isochoric = isochoric,
539
+ find_liquidus = find_liquidus, fO2_buffer = fO2_buffer, fO2_offset = fO2_offset[i],
540
+ fluid_sat = fluid_sat, Crystallinity_limit = Crystallinity_limit, Suppress = Suppress,
541
+ Suppress_except=Suppress_except, trail = trail, melts = melts)
542
+ else:
543
+ if fO2_offset[i] is None:
544
+ fO2_offset[i] = 0.0
545
+
546
+ if Frac_solid is None:
547
+ Frac_solid = False
548
+
549
+ if type(comp) == dict:
550
+ comp_julia = jl.seval("Dict")(comp)
551
+ else:
552
+ comp_new = comp.loc[i].to_dict()
553
+ comp_julia = jl.seval("Dict")(comp_new)
554
+
555
+ # Results_df = jl.MAGEMinCalc.path(Model = Model, comp=comp_julia, T_start_C = T_start_C[i], T_end_C = T_end_C[i], dt_C=dt_C,
556
+ # T_C = T_C[i], T_path_C = T_path_C[i], P_start_bar = P_start_bar[i], P_end_bar = P_end_bar[i],
557
+ # dp_bar = dp_bar[i], P_bar = P_bar[i], P_path_bar = P_path_bar[i], frac_xtal = Frac_solid,
558
+ # fo2_buffer = fO2_buffer, fo2_offset = fO2_offset[i], find_liquidus = find_liquidus)
559
+
560
+ Results_df = jl.MAGEMinCalc.path(
561
+ comp=comp_julia, T_start_C=T_start_C[i], T_end_C=T_end_C[i], dt_C=dt_C[i],
562
+ T_C=T_C[i], P_start_bar=P_start_bar[i], P_end_bar=P_end_bar[i], dp_bar=dp_bar[i],
563
+ P_bar=P_bar[i], T_path_C=T_path_C[i], P_path_bar=P_path_bar[i], frac_xtal=Frac_solid,
564
+ Model=Model, fo2_buffer=fO2_buffer, fo2_offset=fO2_offset[i], find_liquidus=find_liquidus
565
+ )
566
+
567
+ Results = dict(Results_df)
568
+
569
+ tr = True
570
+
571
+ idx.append(i)
572
+
573
+
574
+ results[f"index = {i}"] = Results
575
+
576
+ if tr is False:
577
+ break
578
+ except:
579
+ idx.append(i)
580
+ break
581
+
582
+ q.put([idx, results])
583
+ return
584
+
505
585
 
506
586
  def path(q, index, *, Model = None, comp = None, Frac_solid = None, Frac_fluid = None,
507
587
  T_C = None, T_path_C = None, T_start_C = None, T_end_C = None, dt_C = None,
@@ -5,4 +5,4 @@
5
5
  # 1) we don't load dependencies by storing it in __init__.py
6
6
  # 2) we can import it in setup.py for the same reason
7
7
  # 3) we can import it into your module
8
- __version__ = '0.2.33'
8
+ __version__ = '0.2.35'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PetThermoTools
3
- Version: 0.2.33
3
+ Version: 0.2.35
4
4
  Summary: PetThermoTools
5
5
  Home-page: https://github.com/gleesonm1/PetThermoTools
6
6
  Author: Matthew Gleeson
@@ -1,20 +1,20 @@
1
- PetThermoTools/Barom.py,sha256=zfRgGnqInXP1B5oG_k5ZMJH3cylHcQXWiBRz7YlQjkw,36119
1
+ PetThermoTools/Barom.py,sha256=CXjwCb7KpQG8x7IhewCLTfqoJ02s4Ott3NwDcGQMWtQ,40221
2
2
  PetThermoTools/Compositions.py,sha256=65NzfduzWdfHJ8VmHBN1Cv7fMz7kF3QbDVLei-e4v00,1483
3
3
  PetThermoTools/GenFuncs.py,sha256=u2GWqH--Wmqd0WXHxfulEAatQb6uswjl1s9SyyoHSa8,16412
4
4
  PetThermoTools/Holland.py,sha256=udBFeVUyTBpSfLIhx7Hy6o0I8ApNCDvwU_gZa0diY5w,7251
5
5
  PetThermoTools/Installation.py,sha256=UfVOW1NZFdzMWPyID5u7t0KwvpJA0AqYohzidXIAwYs,6098
6
6
  PetThermoTools/Liq.py,sha256=2kdU8r00Y20khwvPvCvLr6P7y2HEOvCH2cwrF_qw5u8,35541
7
- PetThermoTools/MELTS.py,sha256=hqc5vSDwvnCyBwD7wbEOwemUNpDQGpsWdOOoVjNnMvE,72810
7
+ PetThermoTools/MELTS.py,sha256=CjUOJSUEoq4yXEojl77HgCj7aewhFDeSGt4ZGk3L3vs,73688
8
8
  PetThermoTools/Melting.py,sha256=h1-KchPFw5tI2xoOyNJUfVy_TJqTtcYiHtGuInIwzio,11017
9
- PetThermoTools/Path.py,sha256=FI_JkpCDXUVWsaKxA_PKOyKvXSzsQEBiLonGNiamcIM,33424
9
+ PetThermoTools/Path.py,sha256=u2PNtgnqsXbiWvpj-shSjzxiC5kLus9aIzsq_YLjRfY,38220
10
10
  PetThermoTools/Path_wrappers.py,sha256=_0pBs_cK2hICxAHkYxKXICUnUEBSiUg07-qhgBeuTdc,26555
11
11
  PetThermoTools/PhaseDiagrams.py,sha256=8S_BcqggBzfUbiCPcsJRWFBenGL4tcCevte3-ATQjQI,30884
12
12
  PetThermoTools/Plotting.py,sha256=IMYYusZy6REQATG9NI3dGlGs6h3vQ48aJHkZnHmSDDY,28924
13
13
  PetThermoTools/Saturation.py,sha256=XXY6fKVouQM3RLgQgXur4xSq7_uGp7bCw_k7NNlWYi8,14095
14
14
  PetThermoTools/__init__.py,sha256=PbiwQj_mNNEwuIZOLETmtMMshiXa50wjCA6mfvpOpOs,2393
15
- PetThermoTools/_version.py,sha256=i2Na-DPnshyTFid0Y6FmelIcA0OHEcYVuQdFt_mKzeI,296
16
- PetThermoTools-0.2.33.dist-info/LICENSE.txt,sha256=-mkx4iEw8Pk1RZUvncBhGLW87Uur5JB7FBQtOmX-VP0,1752
17
- PetThermoTools-0.2.33.dist-info/METADATA,sha256=MM-RsleOmZq3PfygLozR2VrdewAuBMezGJLwnGc9Km8,796
18
- PetThermoTools-0.2.33.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
19
- PetThermoTools-0.2.33.dist-info/top_level.txt,sha256=IqK8iYBR3YJozzMOTRZ8x8mU2k6x8ycoMBxZTm-I06U,15
20
- PetThermoTools-0.2.33.dist-info/RECORD,,
15
+ PetThermoTools/_version.py,sha256=Yz_zSUyefR3Q96ONxPsaaqcFw6TTx12jT1iGtXcC84o,296
16
+ PetThermoTools-0.2.35.dist-info/LICENSE.txt,sha256=-mkx4iEw8Pk1RZUvncBhGLW87Uur5JB7FBQtOmX-VP0,1752
17
+ PetThermoTools-0.2.35.dist-info/METADATA,sha256=UyTbMSzbIvHSV0GGsJRDvkqlp1P7jAU27wNbIK8MyR4,796
18
+ PetThermoTools-0.2.35.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
19
+ PetThermoTools-0.2.35.dist-info/top_level.txt,sha256=IqK8iYBR3YJozzMOTRZ8x8mU2k6x8ycoMBxZTm-I06U,15
20
+ PetThermoTools-0.2.35.dist-info/RECORD,,