DiadFit 0.0.85__py3-none-any.whl → 0.0.88__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.
- DiadFit/CO2_EOS.py +2 -2
- DiadFit/CO2_H2O_EOS.py +8 -8
- DiadFit/CO2_in_bubble_error.py +190 -112
- DiadFit/Highrho_polyfit_dataUCB_1117_1400.pkl +0 -0
- DiadFit/Highrho_polyfit_dataUCB_1117_1447.pkl +0 -0
- DiadFit/Highrho_polyfit_dataUCB_1220_1400.pkl +0 -0
- DiadFit/Highrho_polyfit_dataUCB_1220_1447.pkl +0 -0
- DiadFit/Highrho_polyfit_dataUCB_1220_1567.pkl +0 -0
- DiadFit/Highrho_polyfit_data_CMASS_24C.pkl +0 -0
- DiadFit/Lowrho_polyfit_dataUCB_1117_1400.pkl +0 -0
- DiadFit/Lowrho_polyfit_dataUCB_1117_1447.pkl +0 -0
- DiadFit/Lowrho_polyfit_dataUCB_1220_1400.pkl +0 -0
- DiadFit/Lowrho_polyfit_dataUCB_1220_1447.pkl +0 -0
- DiadFit/Lowrho_polyfit_dataUCB_1220_1567.pkl +0 -0
- DiadFit/Lowrho_polyfit_data_CMASS_24C.pkl +0 -0
- DiadFit/Mediumrho_polyfit_dataUCB_1117_1400.pkl +0 -0
- DiadFit/Mediumrho_polyfit_dataUCB_1117_1447.pkl +0 -0
- DiadFit/Mediumrho_polyfit_dataUCB_1220_1400.pkl +0 -0
- DiadFit/Mediumrho_polyfit_dataUCB_1220_1447.pkl +0 -0
- DiadFit/Mediumrho_polyfit_dataUCB_1220_1567.pkl +0 -0
- DiadFit/_version.py +1 -1
- DiadFit/densimeter_fitting.py +7 -1
- DiadFit/densimeters.py +182 -40
- DiadFit/density_depth_crustal_profiles.py +37 -5
- DiadFit/diads.py +26 -13
- DiadFit/error_propagation.py +137 -226
- DiadFit/importing_data_files.py +81 -15
- DiadFit/ne_lines.py +51 -23
- {DiadFit-0.0.85.dist-info → DiadFit-0.0.88.dist-info}/METADATA +1 -1
- DiadFit-0.0.88.dist-info/RECORD +50 -0
- DiadFit-0.0.85.dist-info/RECORD +0 -42
- {DiadFit-0.0.85.dist-info → DiadFit-0.0.88.dist-info}/WHEEL +0 -0
- {DiadFit-0.0.85.dist-info → DiadFit-0.0.88.dist-info}/top_level.txt +0 -0
DiadFit/error_propagation.py
CHANGED
@@ -3,68 +3,15 @@ import numpy as np
|
|
3
3
|
import pandas as pd
|
4
4
|
import matplotlib.pyplot as plt
|
5
5
|
import DiadFit as pf
|
6
|
-
|
6
|
+
from tqdm import tqdm
|
7
7
|
from DiadFit.density_depth_crustal_profiles import *
|
8
8
|
from DiadFit.CO2_EOS import *
|
9
|
+
# This gets us the functions for Monte Carloing
|
10
|
+
from DiadFit.CO2_in_bubble_error import *
|
9
11
|
|
10
12
|
## Microthermometry error propagation
|
11
|
-
# propagate_microthermometry_uncertainty_1sam goes to 'make_error_dist_microthermometry_1sam'
|
12
|
-
|
13
|
-
def make_error_dist_microthermometry_1sam(*, T_h_C, sample_i=0, error_T_h_C=0.3, N_dup=1000,
|
14
|
-
error_dist_T_h_C='uniform', error_type_T_h_C='Abs', len_loop=1):
|
15
|
-
|
16
|
-
"""
|
17
|
-
|
18
|
-
This function generates a dataset of temperature measurements for a given sample.
|
19
|
-
It adds random noise to the temperature measurement based on the specified distribution and error type.
|
20
|
-
|
21
|
-
Parameters
|
22
|
-
----------
|
23
|
-
T_h_C : numeric or list of numeric values
|
24
|
-
The measured temperature(s) of the sample(s) in degrees Celsius.
|
25
|
-
sample_i : int, optional
|
26
|
-
The index of the sample for which the error distribution will be generated. Default value is 0.
|
27
|
-
error_T_h_C : numeric, optional
|
28
|
-
The amount of error to add to the temperature measurement. Default value is 0.3.
|
29
|
-
N_dup : int, optional
|
30
|
-
The number of duplicated samples to generate with random noise. Default value is 1000.
|
31
|
-
error_dist_T_h_C : str, optional
|
32
|
-
The distribution of the random noise to be added to the temperature measurement. Can be either 'normal' or 'uniform'. Default value is 'uniform'.
|
33
|
-
error_type_T_h_C : str, optional
|
34
|
-
The type of error to add to the temperature measurement. Can be either 'Abs' or 'Perc'. Default value is 'Abs'.
|
35
|
-
len_loop : int, optional
|
36
|
-
The number of samples for which the error distribution will be generated. Default value is 1.
|
37
13
|
|
38
|
-
Returns
|
39
|
-
-------
|
40
|
-
numpy.ndarray
|
41
|
-
An array of temperature measurements with random noise added to them based on the specified error
|
42
|
-
distribution and error type. The size of the array is (N_dup, len(T_h_C)).
|
43
14
|
|
44
|
-
"""
|
45
|
-
|
46
|
-
if len_loop==1:
|
47
|
-
df_c=pd.DataFrame(data={'T_h_C': T_h_C}, index=[0])
|
48
|
-
else:
|
49
|
-
df_c=pd.DataFrame(data={'T_h_C': T_h_C})
|
50
|
-
|
51
|
-
|
52
|
-
# Temperature error distribution
|
53
|
-
if error_type_T_h_C=='Abs':
|
54
|
-
error_T_h_C=error_T_h_C
|
55
|
-
if error_type_T_h_C =='Perc':
|
56
|
-
error_T_h_C=df_c['T_h_C'].iloc[sample_i]*error_T_h_C/100
|
57
|
-
if error_dist_T_h_C=='normal':
|
58
|
-
Noise_to_add_T_h_C = np.random.normal(0, error_T_h_C, N_dup)
|
59
|
-
if error_dist_T_h_C=='uniform':
|
60
|
-
Noise_to_add_T_h_C = np.random.uniform(- error_T_h_C, +
|
61
|
-
error_T_h_C, N_dup)
|
62
|
-
|
63
|
-
T_h_C_with_noise=Noise_to_add_T_h_C+df_c['T_h_C'].iloc[0]
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
return T_h_C_with_noise
|
68
15
|
|
69
16
|
|
70
17
|
def propagate_microthermometry_uncertainty(T_h_C, Sample_ID=None, error_T_h_C=0.3, N_dup=1000,
|
@@ -136,26 +83,20 @@ def propagate_microthermometry_uncertainty(T_h_C, Sample_ID=None, error_T_h_C=0
|
|
136
83
|
|
137
84
|
|
138
85
|
All_outputs=pd.DataFrame([])
|
139
|
-
Std_density_gas=np.
|
140
|
-
Std_density_liq=np.
|
141
|
-
Mean_density_gas=np.
|
142
|
-
Mean_density_liq=np.
|
143
|
-
Std_density_gas_IQR=np.
|
144
|
-
Std_density_Liq_IQR=np.
|
145
|
-
Sample=np.
|
86
|
+
Std_density_gas=np.zeros(len_loop)
|
87
|
+
Std_density_liq=np.zeros(len_loop)
|
88
|
+
Mean_density_gas=np.zeros(len_loop)
|
89
|
+
Mean_density_liq=np.zeros(len_loop)
|
90
|
+
Std_density_gas_IQR=np.zeros(len_loop)
|
91
|
+
Std_density_Liq_IQR=np.zeros(len_loop)
|
92
|
+
Sample=np.zeros(len_loop, dtype=np.dtype('U100') )
|
146
93
|
|
147
94
|
for i in range(0, len_loop):
|
148
95
|
|
149
96
|
# If user has entered a pandas series for error, takes right one for each loop
|
150
|
-
|
151
|
-
|
152
|
-
else:
|
153
|
-
error_T_h_C=error_T_h_C
|
97
|
+
error_T_h_C_i=get_value(error_T_h_C, i)
|
98
|
+
T_h_C_i=get_value(T_h_C, i)
|
154
99
|
|
155
|
-
if type(T_h_C) is pd.Series:
|
156
|
-
T_h_C_i=T_h_C.iloc[i]
|
157
|
-
else:
|
158
|
-
T_h_C_i=T_h_C
|
159
100
|
|
160
101
|
# Check of
|
161
102
|
if Sample_ID is None:
|
@@ -166,9 +107,8 @@ def propagate_microthermometry_uncertainty(T_h_C, Sample_ID=None, error_T_h_C=0
|
|
166
107
|
else:
|
167
108
|
Sample[i]=Sample_ID.iloc[i]
|
168
109
|
|
169
|
-
Temp_MC=
|
170
|
-
|
171
|
-
error_dist_T_h_C=error_dist_T_h_C, error_type_T_h_C=error_type_T_h_C, len_loop=1)
|
110
|
+
Temp_MC= add_noise_to_variable(T_h_C, error_T_h_C,
|
111
|
+
error_type_T_h_C, error_dist_T_h_C, N_dup, True, neg_threshold=0.0000000001)
|
172
112
|
|
173
113
|
Sample2=Sample[i]
|
174
114
|
MC_T=calculate_CO2_density_homog_T(T_h_C=Temp_MC, Sample_ID=Sample2, EOS=EOS, homog_to=homog_to, set_to_critical=set_to_critical)
|
@@ -217,7 +157,7 @@ CO2_dens_gcm3=None, error_CO2_dens=0, error_type_CO2_dens='Abs', error_dist_CO2_
|
|
217
157
|
T_K=None, error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
|
218
158
|
crust_dens_kgm3=None, error_crust_dens=0, error_type_crust_dens='Abs', error_dist_crust_dens='normal', XH2O=None,
|
219
159
|
error_XH2O=None, error_type_XH2O='Abs', error_dist_XH2O='normal',
|
220
|
-
model=None):
|
160
|
+
model=None, neg_values=True):
|
221
161
|
|
222
162
|
"""
|
223
163
|
This function generates the range of T_K, CO2 densities, XH2O and crustal densities for 1 sample
|
@@ -290,12 +230,12 @@ error_XH2O=None, error_type_XH2O='Abs', error_dist_XH2O='normal',
|
|
290
230
|
if isinstance(T_K, pd.Series) or isinstance(CO2_dens_gcm3, pd.Series) or isinstance(T_K, np.ndarray) or isinstance(CO2_dens_gcm3, np.ndarray):
|
291
231
|
df_c=pd.DataFrame(data={'T_K': T_K,
|
292
232
|
'CO2_dens_gcm3': CO2_dens_gcm3,
|
293
|
-
'XH2O':
|
233
|
+
'XH2O': None})
|
294
234
|
else:
|
295
235
|
#print('here')
|
296
236
|
df_c=pd.DataFrame(data={'T_K': T_K,
|
297
237
|
'CO2_dens_gcm3': CO2_dens_gcm3,
|
298
|
-
'XH2O':
|
238
|
+
'XH2O': None}, index=[0])
|
299
239
|
# IF have XH2O add here
|
300
240
|
else:
|
301
241
|
if isinstance(T_K, pd.Series) or isinstance(CO2_dens_gcm3, pd.Series) or isinstance(T_K, np.ndarray) or isinstance(CO2_dens_gcm3, np.ndarray) or isinstance(XH2O, np.ndarray):
|
@@ -312,77 +252,32 @@ error_XH2O=None, error_type_XH2O='Abs', error_dist_XH2O='normal',
|
|
312
252
|
|
313
253
|
|
314
254
|
# Temperature error distribution
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
error_T_K=df_c['T_K'].iloc[sample_i]*error_T_K/100
|
319
|
-
if error_dist_T_K=='normal':
|
320
|
-
Noise_to_add_T_K = np.random.normal(0, error_T_K, N_dup)
|
321
|
-
if error_dist_T_K=='uniform':
|
322
|
-
Noise_to_add_T_K = np.random.uniform(- error_T_K, +
|
323
|
-
error_T_K, N_dup)
|
324
|
-
|
325
|
-
|
326
|
-
T_K_with_noise=Noise_to_add_T_K+df_c['T_K'].iloc[sample_i]
|
327
|
-
T_K_with_noise[T_K_with_noise < 0.0001] = 0.0001
|
328
|
-
|
329
|
-
|
255
|
+
T_K_with_noise=add_noise_to_variable(T_K, error_T_K,
|
256
|
+
error_type_T_K, error_dist_T_K, N_dup, neg_values, neg_threshold=0.0000000001)
|
257
|
+
|
330
258
|
# CO2 error distribution
|
259
|
+
CO2_dens_with_noise=add_noise_to_variable(CO2_dens_gcm3, error_CO2_dens,
|
260
|
+
error_type_CO2_dens, error_dist_CO2_dens, N_dup, neg_values, neg_threshold=0.0000000001)
|
261
|
+
|
331
262
|
|
332
|
-
if error_type_CO2_dens=='Abs':
|
333
|
-
error_CO2_dens=error_CO2_dens
|
334
|
-
if error_type_CO2_dens =='Perc':
|
335
|
-
error_CO2_dens=df_c['CO2_dens_gcm3'].iloc[sample_i]*error_CO2_dens/100
|
336
|
-
if error_dist_CO2_dens=='normal':
|
337
|
-
Noise_to_add_CO2_dens = np.random.normal(0, error_CO2_dens, N_dup)
|
338
|
-
if error_dist_CO2_dens=='uniform':
|
339
|
-
Noise_to_add_CO2_dens = np.random.uniform(- error_CO2_dens, +
|
340
|
-
error_CO2_dens, N_dup)
|
341
|
-
|
342
|
-
CO2_dens_with_noise=Noise_to_add_CO2_dens+df_c['CO2_dens_gcm3'].iloc[sample_i]
|
343
|
-
CO2_dens_with_noise[CO2_dens_with_noise < 0.0001] = 0.0001
|
344
263
|
|
345
264
|
# XH2O error distribution (if relevant)
|
346
265
|
if XH2O is not None:
|
347
|
-
|
348
|
-
|
349
|
-
if error_type_XH2O =='Perc':
|
350
|
-
error_XH2O=df_c['XH2O'].iloc[sample_i]*error_XH2O/100
|
351
|
-
if error_dist_XH2O=='normal':
|
352
|
-
Noise_to_add_XH2O = np.random.normal(0, error_XH2O, N_dup)
|
353
|
-
if error_dist_XH2O=='uniform':
|
354
|
-
Noise_to_add_XH2O = np.random.uniform(- error_XH2O, +
|
355
|
-
error_XH2O, N_dup)
|
356
|
-
|
357
|
-
XH2O_with_noise=Noise_to_add_XH2O+df_c['XH2O'].iloc[sample_i]
|
266
|
+
XH2O_with_noise=add_noise_to_variable(XH2O, error_XH2O,
|
267
|
+
error_type_XH2O, error_dist_XH2O, N_dup, True, neg_threshold=0.0000000000)
|
358
268
|
XH2O_with_noise[XH2O_with_noise < 0.000000] = 0.00000
|
359
269
|
XH2O_with_noise[XH2O_with_noise > 1] = 1
|
360
|
-
|
361
270
|
|
362
|
-
|
363
|
-
|
271
|
+
|
272
|
+
|
364
273
|
|
365
|
-
|
366
274
|
# Crustal density noise
|
367
275
|
# First need to work out what crustal density is
|
368
276
|
|
369
277
|
if type(crust_dens_kgm3) is float or type(crust_dens_kgm3) is int:
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
error_crust_dens=error_crust_dens
|
374
|
-
if error_type_crust_dens =='Perc':
|
375
|
-
error_crust_dens=crust_dens_kgm3*error_crust_dens/100
|
376
|
-
if error_dist_crust_dens=='normal':
|
377
|
-
Noise_to_add_crust_dens = np.random.normal(0, error_crust_dens, N_dup)
|
378
|
-
if error_dist_crust_dens=='uniform':
|
379
|
-
Noise_to_add_crust_dens = np.random.uniform(- error_crust_dens, +
|
380
|
-
error_crust_dens, N_dup)
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
crust_dens_with_noise=Noise_to_add_crust_dens+crust_dens_kgm3
|
385
|
-
crust_dens_with_noise[crust_dens_with_noise < 0.0001] = 0.0001
|
278
|
+
crust_dens_with_noise=add_noise_to_variable(crust_dens_kgm3, error_crust_dens_kgm3,
|
279
|
+
error_type_crust_dens, error_dist_crust_dens, N_dup, neg_values, neg_threshold=0.0000000001)
|
280
|
+
|
386
281
|
|
387
282
|
elif model is not None:
|
388
283
|
crust_dens_with_noise=None
|
@@ -416,12 +311,6 @@ error_XH2O=None, error_type_XH2O='Abs', error_dist_XH2O='normal',
|
|
416
311
|
df_out['XH2O_with_noise']=XH2O_with_noise
|
417
312
|
df_out['error_type_XH2O']=error_type_XH2O
|
418
313
|
df_out['error_dist_XH2O']=error_dist_XH2O
|
419
|
-
else:
|
420
|
-
df_out['error_XH2O']=0
|
421
|
-
df_out['XH2O_with_noise']=0
|
422
|
-
|
423
|
-
|
424
|
-
|
425
314
|
|
426
315
|
|
427
316
|
|
@@ -438,6 +327,23 @@ error_CO2_dens=0, error_type_CO2_dens='Abs', error_dist_CO2_dens='normal',
|
|
438
327
|
|
439
328
|
print('Please use the new function propagate_FI_uncertainty instead as this allows you use different EOS')
|
440
329
|
|
330
|
+
# Check for panda Series
|
331
|
+
|
332
|
+
def convert_inputs_to_series(T_K, error_T_K, CO2_dens_gcm3, error_CO2_dens_gcm3, XH2O, error_XH2O):
|
333
|
+
# Create a list of all inputs
|
334
|
+
inputs = [T_K, error_T_K, CO2_dens_gcm3, error_CO2_dens_gcm3, XH2O, error_XH2O]
|
335
|
+
|
336
|
+
# Convert any numpy arrays in the inputs to pandas Series
|
337
|
+
converted_inputs = [pd.Series(item) if isinstance(item, np.ndarray) else item for item in inputs]
|
338
|
+
|
339
|
+
# Unpack the converted inputs back to their respective variables
|
340
|
+
T_K, error_T_K, CO2_dens_gcm3, error_CO2_dens_gcm3, XH2O, error_XH2O = converted_inputs
|
341
|
+
|
342
|
+
# Continue with the function using the possibly converted inputs...
|
343
|
+
# For demonstration, just return the converted inputs
|
344
|
+
return T_K, error_T_K, CO2_dens_gcm3, error_CO2_dens_gcm3, XH2O, error_XH2O
|
345
|
+
|
346
|
+
|
441
347
|
|
442
348
|
|
443
349
|
def propagate_FI_uncertainty(sample_ID, CO2_dens_gcm3, T_K, N_dup=1000, EOS='SW96',
|
@@ -448,7 +354,7 @@ error_CO2_dens=0, error_type_CO2_dens='Abs', error_dist_CO2_dens='normal',
|
|
448
354
|
model=None, d1=None, d2=None, rho1=None, rho2=None, rho3=None,
|
449
355
|
error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
|
450
356
|
XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=True,
|
451
|
-
|
357
|
+
neg_values=True
|
452
358
|
):
|
453
359
|
|
454
360
|
"""
|
@@ -499,7 +405,7 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
|
|
499
405
|
|
500
406
|
|
501
407
|
|
502
|
-
|
408
|
+
XH2O: Default Nan, else pd.Series, integer, float
|
503
409
|
mol proportion of H2O in the fluid phase
|
504
410
|
error_XH2O: float
|
505
411
|
Error in XH2O
|
@@ -548,7 +454,9 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
|
|
548
454
|
|
549
455
|
|
550
456
|
|
551
|
-
|
457
|
+
neg_values: bool (default True)
|
458
|
+
if True, negative values of input parameters allowed, if False, makes neg values zero.
|
459
|
+
|
552
460
|
Returns
|
553
461
|
----------------
|
554
462
|
|
@@ -565,12 +473,19 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
|
|
565
473
|
|
566
474
|
|
567
475
|
"""
|
476
|
+
# Check for non pandas series as inputs
|
477
|
+
T_K, error_T_K, CO2_dens_gcm3, error_CO2_dens, XH2O, error_XH2O = convert_inputs_to_series(
|
478
|
+
T_K, error_T_K, CO2_dens_gcm3, error_CO2_dens, XH2O, error_XH2O)
|
479
|
+
|
480
|
+
|
568
481
|
if XH2O is not None:
|
569
482
|
print('You have entered a value for XH2O, so we are now using the EOS of Duan and Zhang 2006. If you dont want this, specify XH2O=None')
|
570
483
|
print('Please note, the DZ2006 EOS is about 5-40X slower to run than the SP94 and SW94 EOS')
|
484
|
+
|
571
485
|
if isinstance(T_K, float) or isinstance(T_K, int) :
|
572
486
|
if pd.isna(T_K):
|
573
487
|
raise TypeError("Your Input Temperature is NaN - We cant do EOS calculatoins")
|
488
|
+
|
574
489
|
elif isinstance(T_K, pd.Series):
|
575
490
|
if T_K.isna().any():
|
576
491
|
raise TypeError("At least one of your Input Temperature is NaN - We cant do EOS calculatoins")
|
@@ -578,33 +493,30 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
|
|
578
493
|
if isinstance(crust_dens_kgm3, str):
|
579
494
|
raise TypeError('Do not enter a string for crustal density, put it as a model instead')
|
580
495
|
|
581
|
-
# Set up empty things to fill up.
|
582
496
|
|
583
497
|
if type(CO2_dens_gcm3) is pd.Series:
|
584
498
|
len_loop=len(CO2_dens_gcm3)
|
585
499
|
else:
|
586
500
|
len_loop=1
|
587
501
|
|
588
|
-
|
589
|
-
|
590
|
-
|
502
|
+
# Setting up empty arrays filled with zeros
|
591
503
|
|
592
|
-
SingleCalc_D_km = np.
|
593
|
-
SingleCalc_Press_kbar = np.
|
504
|
+
SingleCalc_D_km = np.zeros(len_loop, dtype=float)
|
505
|
+
SingleCalc_Press_kbar = np.zeros(len_loop, dtype=float)
|
594
506
|
|
595
|
-
mean_Press_kbar = np.
|
596
|
-
med_Press_kbar = np.
|
597
|
-
std_Press_kbar = np.
|
598
|
-
std_Press_kbar_IQR=np.
|
507
|
+
mean_Press_kbar = np.zeros(len_loop, dtype=float)
|
508
|
+
med_Press_kbar = np.zeros(len_loop, dtype=float)
|
509
|
+
std_Press_kbar = np.zeros(len_loop, dtype=float)
|
510
|
+
std_Press_kbar_IQR=np.zeros(len_loop, dtype=float)
|
599
511
|
|
600
|
-
mean_D_km = np.
|
601
|
-
med_D_km = np.
|
602
|
-
std_D_km = np.
|
603
|
-
std_D_km_IQR=np.
|
604
|
-
CO2_density_input=np.
|
605
|
-
error_crust_dens_loop=np.
|
606
|
-
error_crust_dens2_loop=np.
|
607
|
-
Sample=np.
|
512
|
+
mean_D_km = np.zeros(len_loop, dtype=float)
|
513
|
+
med_D_km = np.zeros(len_loop, dtype=float)
|
514
|
+
std_D_km = np.zeros(len_loop, dtype=float)
|
515
|
+
std_D_km_IQR=np.zeros(len_loop, dtype=float)
|
516
|
+
CO2_density_input=np.zeros(len_loop, dtype=float)
|
517
|
+
error_crust_dens_loop=np.zeros(len_loop, dtype=float)
|
518
|
+
error_crust_dens2_loop=np.zeros(len_loop, dtype=float)
|
519
|
+
Sample=np.zeros(len_loop, dtype=np.dtype('U100') )
|
608
520
|
|
609
521
|
All_outputs=pd.DataFrame([])
|
610
522
|
|
@@ -619,82 +531,79 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
|
|
619
531
|
|
620
532
|
|
621
533
|
#This loops through each fluid inclusion entered density
|
622
|
-
|
623
|
-
if i % 20 == 0:
|
624
|
-
print('working on sample number '+str(i))
|
534
|
+
|
625
535
|
|
536
|
+
for i in tqdm(range(0, len_loop), desc="Processing"):
|
537
|
+
|
538
|
+
|
539
|
+
# This fills in the columns for the single calculation, e.g. no Monte-Carloing from above.
|
626
540
|
SingleCalc_D_km[i]=df_ind['Depth (km)'].iloc[i]
|
627
541
|
SingleCalc_Press_kbar[i]=df_ind['Pressure (kbar)'].iloc[i]
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
T_K_i=T_K
|
640
|
-
|
641
|
-
|
642
|
-
if type(CO2_dens_gcm3) is pd.Series:
|
643
|
-
CO2_dens_gcm3_i=CO2_dens_gcm3.iloc[i]
|
644
|
-
else:
|
645
|
-
CO2_dens_gcm3_i=CO2_dens_gcm3
|
646
|
-
|
647
|
-
|
648
|
-
if type(error_CO2_dens) is pd.Series:
|
649
|
-
error_CO2_dens=error_CO2_dens.iloc[i]
|
650
|
-
else:
|
651
|
-
error_CO2_dens=error_CO2_dens
|
652
|
-
|
542
|
+
|
543
|
+
# Now lets get the value, using the function in the CO2_in_bubble_error.py file
|
544
|
+
error_T_K_i=get_value(error_T_K, i)
|
545
|
+
T_K_i=get_value(T_K, i)
|
546
|
+
|
547
|
+
CO2_dens_gcm3_i=get_value(CO2_dens_gcm3, i)
|
548
|
+
error_CO2_dens_i=get_value(error_CO2_dens, i)
|
549
|
+
|
550
|
+
crust_dens_kgm3_i=get_value(crust_dens_kgm3, i)
|
551
|
+
error_crust_dens_i=get_value(error_crust_dens, i)
|
552
|
+
# Now, if XH2O was entered, and isnt None, do the same. Else keeps as None.
|
653
553
|
if XH2O is not None:
|
654
|
-
|
655
|
-
|
656
|
-
else:
|
657
|
-
error_XH2O=error_XH2O
|
658
|
-
|
659
|
-
if type(error_crust_dens) is pd.Series:
|
660
|
-
error_crust_dens=error_crust_dens.iloc[i]
|
661
|
-
else:
|
662
|
-
error_crust_dens=error_crust_dens
|
663
|
-
|
554
|
+
error_XH2O_i=get_value(error_XH2O, i)
|
555
|
+
XH2O_i=get_value(XH2O, i)
|
664
556
|
|
665
557
|
|
666
558
|
|
667
559
|
# This is the function doing the work to actually make the simulations for each variable.
|
560
|
+
# For each input variable, it makes a distribution.
|
561
|
+
|
562
|
+
# If XH2O is None, it doesnt return the column XH2O_with_noise, which helps ID this later.
|
668
563
|
if XH2O is None:
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
564
|
+
|
565
|
+
df_synthetic=calculate_temperature_density_MC(N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3_i,
|
566
|
+
T_K=T_K_i, error_T_K=error_T_K_i, error_type_T_K=error_type_T_K, error_dist_T_K=error_dist_T_K,
|
567
|
+
error_CO2_dens=error_CO2_dens_i, error_type_CO2_dens=error_type_CO2_dens, error_dist_CO2_dens=error_dist_CO2_dens,
|
568
|
+
crust_dens_kgm3=crust_dens_kgm3_i, error_crust_dens=error_crust_dens_i, error_type_crust_dens= error_type_crust_dens, error_dist_crust_dens=error_dist_crust_dens,
|
569
|
+
model=model, neg_values=neg_values)
|
570
|
+
|
571
|
+
if model is None:
|
572
|
+
MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
|
573
|
+
CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
|
574
|
+
crust_dens_kgm3=df_synthetic['crust_dens_with_noise'],
|
575
|
+
d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,model=model,
|
576
|
+
EOS=EOS )
|
577
|
+
else:
|
578
|
+
MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
|
579
|
+
CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
|
580
|
+
d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,
|
581
|
+
model=model, EOS=EOS)
|
674
582
|
|
675
583
|
if XH2O is not None:
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
584
|
+
|
585
|
+
df_synthetic=calculate_temperature_density_MC(N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3_i,
|
586
|
+
T_K=T_K_i, error_T_K=error_T_K_i, error_type_T_K=error_type_T_K, error_dist_T_K=error_dist_T_K,
|
587
|
+
error_CO2_dens=error_CO2_dens_i, error_type_CO2_dens=error_type_CO2_dens, error_dist_CO2_dens=error_dist_CO2_dens,
|
588
|
+
crust_dens_kgm3=crust_dens_kgm3_i, error_crust_dens=error_crust_dens_i, error_type_crust_dens= error_type_crust_dens, error_dist_crust_dens=error_dist_crust_dens,
|
589
|
+
model=model, XH2O=XH2O_i, error_XH2O=error_XH2O_i, error_type_XH2O=error_type_XH2O, error_dist_XH2O=error_dist_XH2O, neg_values=neg_values)
|
681
590
|
|
682
591
|
|
683
592
|
# Convert to densities for MC
|
684
593
|
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
594
|
+
if model is None:
|
595
|
+
MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
|
596
|
+
CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
|
597
|
+
crust_dens_kgm3=df_synthetic['crust_dens_with_noise'],
|
598
|
+
XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
|
599
|
+
d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,model=model,
|
600
|
+
EOS=EOS )
|
601
|
+
else:
|
602
|
+
MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
|
603
|
+
CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
|
604
|
+
XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
|
605
|
+
d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,
|
606
|
+
model=model, EOS=EOS)
|
698
607
|
|
699
608
|
|
700
609
|
|
@@ -750,7 +659,6 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
|
|
750
659
|
'CO2_dens_gcm3': CO2_density_input,
|
751
660
|
'SingleFI_D_km': SingleCalc_D_km,
|
752
661
|
'SingleFI_P_kbar': SingleCalc_Press_kbar,
|
753
|
-
|
754
662
|
'Mean_MC_P_kbar': mean_Press_kbar,
|
755
663
|
'Med_MC_P_kbar': med_Press_kbar,
|
756
664
|
'std_dev_MC_P_kbar': std_Press_kbar,
|
@@ -916,6 +824,8 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
|
|
916
824
|
|
917
825
|
|
918
826
|
# First step is to get pressure
|
827
|
+
|
828
|
+
|
919
829
|
if XH2O is None:
|
920
830
|
Pressure=calculate_P_for_rho_T(T_K=T_K,
|
921
831
|
CO2_dens_gcm3=CO2_dens_gcm3,
|
@@ -949,8 +859,7 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
|
|
949
859
|
'MC_T_K': T_K,
|
950
860
|
'MC_CO2_dens_gcm3': CO2_dens_gcm3})
|
951
861
|
|
952
|
-
|
953
|
-
|
862
|
+
|
954
863
|
|
955
864
|
# Make as a dict to allow index=0 if depth is float, else not.
|
956
865
|
data_dict = {
|
@@ -967,8 +876,10 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
|
|
967
876
|
|
968
877
|
|
969
878
|
# If XH2O, need different outputs.
|
879
|
+
|
970
880
|
else:
|
971
881
|
|
882
|
+
|
972
883
|
P_kbar_calc=pf.calculate_entrapment_P_XH2O(XH2O=XH2O, CO2_dens_gcm3=CO2_dens_gcm3, T_K=T_K, T_K_ambient=T_K_ambient, fast_calcs=True, Hloss=Hloss )
|
973
884
|
|
974
885
|
|