DiadFit 0.0.84__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.
Files changed (35) hide show
  1. DiadFit/CO2_EOS.py +2 -2
  2. DiadFit/CO2_H2O_EOS.py +173 -90
  3. DiadFit/CO2_in_bubble_error.py +217 -115
  4. DiadFit/Highrho_polyfit_dataUCB_1117_1400.pkl +0 -0
  5. DiadFit/Highrho_polyfit_dataUCB_1117_1447.pkl +0 -0
  6. DiadFit/Highrho_polyfit_dataUCB_1220_1400.pkl +0 -0
  7. DiadFit/Highrho_polyfit_dataUCB_1220_1447.pkl +0 -0
  8. DiadFit/Highrho_polyfit_dataUCB_1220_1567.pkl +0 -0
  9. DiadFit/Highrho_polyfit_data_CMASS_24C.pkl +0 -0
  10. DiadFit/Lowrho_polyfit_dataUCB_1117_1400.pkl +0 -0
  11. DiadFit/Lowrho_polyfit_dataUCB_1117_1447.pkl +0 -0
  12. DiadFit/Lowrho_polyfit_dataUCB_1220_1400.pkl +0 -0
  13. DiadFit/Lowrho_polyfit_dataUCB_1220_1447.pkl +0 -0
  14. DiadFit/Lowrho_polyfit_dataUCB_1220_1567.pkl +0 -0
  15. DiadFit/Lowrho_polyfit_data_CMASS_24C.pkl +0 -0
  16. DiadFit/Mediumrho_polyfit_dataUCB_1117_1400.pkl +0 -0
  17. DiadFit/Mediumrho_polyfit_dataUCB_1117_1447.pkl +0 -0
  18. DiadFit/Mediumrho_polyfit_dataUCB_1220_1400.pkl +0 -0
  19. DiadFit/Mediumrho_polyfit_dataUCB_1220_1447.pkl +0 -0
  20. DiadFit/Mediumrho_polyfit_dataUCB_1220_1567.pkl +0 -0
  21. DiadFit/_version.py +1 -1
  22. DiadFit/densimeter_fitting.py +7 -1
  23. DiadFit/densimeters.py +182 -40
  24. DiadFit/density_depth_crustal_profiles.py +37 -5
  25. DiadFit/diads.py +85 -48
  26. DiadFit/error_propagation.py +141 -229
  27. DiadFit/importing_data_files.py +81 -15
  28. DiadFit/lookup_table.csv +64001 -0
  29. DiadFit/lookup_table_noneg.csv +63707 -0
  30. DiadFit/ne_lines.py +58 -29
  31. {DiadFit-0.0.84.dist-info → DiadFit-0.0.88.dist-info}/METADATA +1 -1
  32. DiadFit-0.0.88.dist-info/RECORD +50 -0
  33. {DiadFit-0.0.84.dist-info → DiadFit-0.0.88.dist-info}/WHEEL +1 -1
  34. DiadFit-0.0.84.dist-info/RECORD +0 -40
  35. {DiadFit-0.0.84.dist-info → DiadFit-0.0.88.dist-info}/top_level.txt +0 -0
@@ -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.empty(len_loop)
140
- Std_density_liq=np.empty(len_loop)
141
- Mean_density_gas=np.empty(len_loop)
142
- Mean_density_liq=np.empty(len_loop)
143
- Std_density_gas_IQR=np.empty(len_loop)
144
- Std_density_Liq_IQR=np.empty(len_loop)
145
- Sample=np.empty(len_loop, dtype=np.dtype('U100') )
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
- if type(error_T_h_C) is pd.Series:
151
- error_T_h_C=error_T_h_C.iloc[i]
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=make_error_dist_microthermometry_1sam(T_h_C=T_h_C_i,
170
- sample_i=i, error_T_h_C=error_T_h_C, N_dup=N_dup,
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': 0})
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': 0}, index=[0])
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
- if error_type_T_K=='Abs':
316
- error_T_K=error_T_K
317
- if error_type_T_K =='Perc':
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
- if error_type_XH2O=='Abs':
348
- error_XH2O=error_XH2O
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
- # This is the simplicest scenario, just makes a distribution of pressures
371
-
372
- if error_type_crust_dens=='Abs':
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,12 +354,13 @@ 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
  """
455
361
  This function performs Monte Carlo simulations of uncertainty in CO2 density, input temperature,
456
- and crustal density.
362
+ crustal density and XH2O. If XH2O is specified as not None, it will use Duan and Zhang 2006 EOS
363
+
457
364
  It uses the function 'calculate_temperature_density_MC' to make the simulated variables,
458
365
  and then uses this to calculate a resulting
459
366
  pressure using the equation of state of choice
@@ -498,7 +405,7 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
498
405
 
499
406
 
500
407
 
501
- X_H2O: pd.Series, integer, float
408
+ XH2O: Default Nan, else pd.Series, integer, float
502
409
  mol proportion of H2O in the fluid phase
503
410
  error_XH2O: float
504
411
  Error in XH2O
@@ -547,7 +454,9 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
547
454
 
548
455
 
549
456
 
550
-
457
+ neg_values: bool (default True)
458
+ if True, negative values of input parameters allowed, if False, makes neg values zero.
459
+
551
460
  Returns
552
461
  ----------------
553
462
 
@@ -564,12 +473,19 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
564
473
 
565
474
 
566
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
+
567
481
  if XH2O is not None:
568
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')
569
483
  print('Please note, the DZ2006 EOS is about 5-40X slower to run than the SP94 and SW94 EOS')
484
+
570
485
  if isinstance(T_K, float) or isinstance(T_K, int) :
571
486
  if pd.isna(T_K):
572
487
  raise TypeError("Your Input Temperature is NaN - We cant do EOS calculatoins")
488
+
573
489
  elif isinstance(T_K, pd.Series):
574
490
  if T_K.isna().any():
575
491
  raise TypeError("At least one of your Input Temperature is NaN - We cant do EOS calculatoins")
@@ -577,33 +493,30 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
577
493
  if isinstance(crust_dens_kgm3, str):
578
494
  raise TypeError('Do not enter a string for crustal density, put it as a model instead')
579
495
 
580
- # Set up empty things to fill up.
581
496
 
582
497
  if type(CO2_dens_gcm3) is pd.Series:
583
498
  len_loop=len(CO2_dens_gcm3)
584
499
  else:
585
500
  len_loop=1
586
501
 
587
-
588
-
589
-
502
+ # Setting up empty arrays filled with zeros
590
503
 
591
- SingleCalc_D_km = np.empty(len_loop, dtype=float)
592
- SingleCalc_Press_kbar = np.empty(len_loop, dtype=float)
504
+ SingleCalc_D_km = np.zeros(len_loop, dtype=float)
505
+ SingleCalc_Press_kbar = np.zeros(len_loop, dtype=float)
593
506
 
594
- mean_Press_kbar = np.empty(len_loop, dtype=float)
595
- med_Press_kbar = np.empty(len_loop, dtype=float)
596
- std_Press_kbar = np.empty(len_loop, dtype=float)
597
- std_Press_kbar_IQR=np.empty(len_loop, dtype=float)
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)
598
511
 
599
- mean_D_km = np.empty(len_loop, dtype=float)
600
- med_D_km = np.empty(len_loop, dtype=float)
601
- std_D_km = np.empty(len_loop, dtype=float)
602
- std_D_km_IQR=np.empty(len_loop, dtype=float)
603
- CO2_density_input=np.empty(len_loop, dtype=float)
604
- error_crust_dens_loop=np.empty(len_loop, dtype=float)
605
- error_crust_dens2_loop=np.empty(len_loop, dtype=float)
606
- Sample=np.empty(len_loop, dtype=np.dtype('U100') )
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') )
607
520
 
608
521
  All_outputs=pd.DataFrame([])
609
522
 
@@ -618,82 +531,79 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
618
531
 
619
532
 
620
533
  #This loops through each fluid inclusion entered density
621
- for i in range(0, len_loop):
622
- if i % 20 == 0:
623
- print('working on sample number '+str(i))
534
+
624
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.
625
540
  SingleCalc_D_km[i]=df_ind['Depth (km)'].iloc[i]
626
541
  SingleCalc_Press_kbar[i]=df_ind['Pressure (kbar)'].iloc[i]
627
-
628
-
629
- # If user has entered a pandas series for error, takes right one for each loop
630
- if type(error_T_K) is pd.Series:
631
- error_T_K=error_T_K.iloc[i]
632
- else:
633
- error_T_K=error_T_K
634
-
635
- if type(T_K) is pd.Series:
636
- T_K_i=T_K.iloc[i]
637
- else:
638
- T_K_i=T_K
639
-
640
-
641
- if type(CO2_dens_gcm3) is pd.Series:
642
- CO2_dens_gcm3_i=CO2_dens_gcm3.iloc[i]
643
- else:
644
- CO2_dens_gcm3_i=CO2_dens_gcm3
645
-
646
-
647
- if type(error_CO2_dens) is pd.Series:
648
- error_CO2_dens=error_CO2_dens.iloc[i]
649
- else:
650
- error_CO2_dens=error_CO2_dens
651
-
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.
652
553
  if XH2O is not None:
653
- if type(error_XH2O) is pd.Series:
654
- error_XH2O=error_XH2O.iloc[i]
655
- else:
656
- error_XH2O=error_XH2O
657
-
658
- if type(error_crust_dens) is pd.Series:
659
- error_crust_dens=error_crust_dens.iloc[i]
660
- else:
661
- error_crust_dens=error_crust_dens
662
-
554
+ error_XH2O_i=get_value(error_XH2O, i)
555
+ XH2O_i=get_value(XH2O, i)
663
556
 
664
557
 
665
558
 
666
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.
667
563
  if XH2O is None:
668
- df_synthetic=calculate_temperature_density_MC(sample_i=i, N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3,
669
- T_K=T_K, error_T_K=error_T_K, error_type_T_K=error_type_T_K, error_dist_T_K=error_dist_T_K,
670
- error_CO2_dens=error_CO2_dens, error_type_CO2_dens=error_type_CO2_dens, error_dist_CO2_dens=error_dist_CO2_dens,
671
- crust_dens_kgm3=crust_dens_kgm3, error_crust_dens=error_crust_dens, error_type_crust_dens= error_type_crust_dens, error_dist_crust_dens=error_dist_crust_dens,
672
- model=model)
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)
673
582
 
674
583
  if XH2O is not None:
675
- df_synthetic=calculate_temperature_density_MC(sample_i=i, N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3,
676
- T_K=T_K, error_T_K=error_T_K, error_type_T_K=error_type_T_K, error_dist_T_K=error_dist_T_K,
677
- error_CO2_dens=error_CO2_dens, error_type_CO2_dens=error_type_CO2_dens, error_dist_CO2_dens=error_dist_CO2_dens,
678
- crust_dens_kgm3=crust_dens_kgm3, error_crust_dens=error_crust_dens, error_type_crust_dens= error_type_crust_dens, error_dist_crust_dens=error_dist_crust_dens,
679
- model=model, XH2O=XH2O, error_XH2O=error_XH2O, error_type_XH2O=error_type_XH2O, error_dist_XH2O=error_dist_XH2O)
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)
680
590
 
681
591
 
682
592
  # Convert to densities for MC
683
593
 
684
- if model is None:
685
- MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
686
- CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
687
- crust_dens_kgm3=df_synthetic['crust_dens_with_noise'],
688
- XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
689
- d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,model=model,
690
- EOS=EOS, )
691
- else:
692
- MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
693
- CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
694
- XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
695
- d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,
696
- model=model, EOS=EOS)
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)
697
607
 
698
608
 
699
609
 
@@ -749,7 +659,6 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
749
659
  'CO2_dens_gcm3': CO2_density_input,
750
660
  'SingleFI_D_km': SingleCalc_D_km,
751
661
  'SingleFI_P_kbar': SingleCalc_Press_kbar,
752
-
753
662
  'Mean_MC_P_kbar': mean_Press_kbar,
754
663
  'Med_MC_P_kbar': med_Press_kbar,
755
664
  'std_dev_MC_P_kbar': std_Press_kbar,
@@ -821,7 +730,7 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
821
730
 
822
731
  # ax4 is XH2O
823
732
  if error_dist_XH2O=='normal' and error_type_XH2O == 'Abs':
824
- ax4.set_title('Input Distribution XH2O: Normally-distributed, 1σ =' +str(error_XH2O) + 'kg/m$^{3}$')
733
+ ax4.set_title('Input Distribution XH2O: Normally-distributed, 1σ =' +str(error_XH2O) + 'molar prop')
825
734
  if error_dist_XH2O=='normal' and error_type_XH2O == 'Perc':
826
735
  ax4.set_title('Input distribution XH2O: Normally-distributed, 1σ =' +str(error_XH2O) + '%')
827
736
  if XH2O is not None and df_1_step['error_XH2O'][0]!=0:
@@ -846,7 +755,7 @@ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=
846
755
  ax1.set_xlabel('T (K)')
847
756
  ax2.set_xlabel('CO$_2$ Density (g/cm$^{3}$)')
848
757
  ax3.set_xlabel('Crustal Density (kg/m$^{3}$)')
849
- ax4.set_xlabel('X$_{H_{2}O}$ (molar)')
758
+ ax4.set_xlabel('X$_{H_{2}O}$ (molar prop)')
850
759
 
851
760
 
852
761
  fig.tight_layout()
@@ -915,6 +824,8 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
915
824
 
916
825
 
917
826
  # First step is to get pressure
827
+
828
+
918
829
  if XH2O is None:
919
830
  Pressure=calculate_P_for_rho_T(T_K=T_K,
920
831
  CO2_dens_gcm3=CO2_dens_gcm3,
@@ -948,8 +859,7 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
948
859
  'MC_T_K': T_K,
949
860
  'MC_CO2_dens_gcm3': CO2_dens_gcm3})
950
861
 
951
- #df.replace([np.inf, -np.inf], np.nan, inplace=True)
952
-
862
+
953
863
 
954
864
  # Make as a dict to allow index=0 if depth is float, else not.
955
865
  data_dict = {
@@ -966,8 +876,10 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
966
876
 
967
877
 
968
878
  # If XH2O, need different outputs.
879
+
969
880
  else:
970
881
 
882
+
971
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 )
972
884
 
973
885