DiadFit 0.0.81__py3-none-any.whl → 0.0.84__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.
@@ -171,7 +171,7 @@ def propagate_microthermometry_uncertainty(T_h_C, Sample_ID=None, error_T_h_C=0
171
171
  error_dist_T_h_C=error_dist_T_h_C, error_type_T_h_C=error_type_T_h_C, len_loop=1)
172
172
 
173
173
  Sample2=Sample[i]
174
- MC_T=calculate_CO2_density_homog_T(T_h_C=Temp_MC, Sample_ID=Sample2, EOS=EOS, homog_to=homog_to)
174
+ 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)
175
175
 
176
176
  # Replace critical with NaN
177
177
 
@@ -215,11 +215,12 @@ def propagate_microthermometry_uncertainty(T_h_C, Sample_ID=None, error_T_h_C=0
215
215
  def calculate_temperature_density_MC(sample_i=0, N_dup=1000,
216
216
  CO2_dens_gcm3=None, error_CO2_dens=0, error_type_CO2_dens='Abs', error_dist_CO2_dens='normal',
217
217
  T_K=None, error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
218
- crust_dens_kgm3=None, error_crust_dens=0, error_type_crust_dens='Abs', error_dist_crust_dens='normal',
218
+ crust_dens_kgm3=None, error_crust_dens=0, error_type_crust_dens='Abs', error_dist_crust_dens='normal', XH2O=None,
219
+ error_XH2O=None, error_type_XH2O='Abs', error_dist_XH2O='normal',
219
220
  model=None):
220
221
 
221
222
  """
222
- This function generates the range of T_K, CO2 densities and crustal densities for 1 sample
223
+ This function generates the range of T_K, CO2 densities, XH2O and crustal densities for 1 sample
223
224
  for performing Monte Carlo simulations
224
225
  using the function propagate_FI_uncertainty (e.g. this function makes the range of
225
226
  input parameters for each sample, but doesnt do the EOS calculations).
@@ -284,23 +285,32 @@ crust_dens_kgm3=None, error_crust_dens=0, error_type_crust_dens='Abs', error_dis
284
285
 
285
286
  """
286
287
 
287
- # print('entered T_K')
288
- # print(T_K)
289
- # print('entered CO2')
290
- # print(CO2_dens_gcm3)
291
288
  # If any of them are panda series or numpy nd array, you dont need an index
292
- 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):
293
- df_c=pd.DataFrame(data={'T_K': T_K,
294
- 'CO2_dens_gcm3': CO2_dens_gcm3})
295
-
296
- # you do need an index here
289
+ if XH2O is None:
290
+ 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
+ df_c=pd.DataFrame(data={'T_K': T_K,
292
+ 'CO2_dens_gcm3': CO2_dens_gcm3,
293
+ 'XH2O': 0})
294
+ else:
295
+ #print('here')
296
+ df_c=pd.DataFrame(data={'T_K': T_K,
297
+ 'CO2_dens_gcm3': CO2_dens_gcm3,
298
+ 'XH2O': 0}, index=[0])
299
+ # IF have XH2O add here
297
300
  else:
298
- #print('here')
299
- df_c=pd.DataFrame(data={'T_K': T_K,
300
- 'CO2_dens_gcm3': CO2_dens_gcm3}, index=[0])
301
+ 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):
302
+ df_c=pd.DataFrame(data={'T_K': T_K,
303
+ 'CO2_dens_gcm3': CO2_dens_gcm3,
304
+ 'XH2O': XH2O})
305
+ else:
306
+ df_c=pd.DataFrame(data={'T_K': T_K,
307
+ 'CO2_dens_gcm3': CO2_dens_gcm3,
308
+ 'XH2O': XH2O}, index=[0])
301
309
 
310
+
311
+ # you do need an index here
302
312
 
303
-
313
+
304
314
  # Temperature error distribution
305
315
  if error_type_T_K=='Abs':
306
316
  error_T_K=error_T_K
@@ -331,6 +341,27 @@ crust_dens_kgm3=None, error_crust_dens=0, error_type_crust_dens='Abs', error_dis
331
341
 
332
342
  CO2_dens_with_noise=Noise_to_add_CO2_dens+df_c['CO2_dens_gcm3'].iloc[sample_i]
333
343
  CO2_dens_with_noise[CO2_dens_with_noise < 0.0001] = 0.0001
344
+
345
+ # XH2O error distribution (if relevant)
346
+ 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]
358
+ XH2O_with_noise[XH2O_with_noise < 0.000000] = 0.00000
359
+ XH2O_with_noise[XH2O_with_noise > 1] = 1
360
+
361
+
362
+
363
+
364
+
334
365
 
335
366
  # Crustal density noise
336
367
  # First need to work out what crustal density is
@@ -380,6 +411,16 @@ crust_dens_kgm3=None, error_crust_dens=0, error_type_crust_dens='Abs', error_dis
380
411
  'error_type_crust_dens': error_type_crust_dens,
381
412
  'error_dist_crust_dens': error_dist_crust_dens,
382
413
  })
414
+ if XH2O is not None:
415
+ df_out['error_XH2O']=error_XH2O
416
+ df_out['XH2O_with_noise']=XH2O_with_noise
417
+ df_out['error_type_XH2O']=error_type_XH2O
418
+ 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
+
383
424
 
384
425
 
385
426
 
@@ -399,13 +440,16 @@ error_CO2_dens=0, error_type_CO2_dens='Abs', error_dist_CO2_dens='normal',
399
440
 
400
441
 
401
442
 
402
- def propagate_FI_uncertainty(sample_ID, CO2_dens_gcm3, T_K, N_dup=1000, EOS='SW96',
443
+ def propagate_FI_uncertainty(sample_ID, CO2_dens_gcm3, T_K, N_dup=1000, EOS='SW96',
403
444
  plot_figure=False, fig_i=0,
404
445
  error_CO2_dens=0, error_type_CO2_dens='Abs', error_dist_CO2_dens='normal',
405
- crust_dens_kgm3=None, model=None, d1=None, d2=None, rho1=None, rho2=None, rho3=None,
406
- error_crust_dens=0, error_type_crust_dens='Abs', error_dist_crust_dens='uniform',
446
+ crust_dens_kgm3=None,
447
+ error_crust_dens=0, error_type_crust_dens='Abs', error_dist_crust_dens='uniform',
448
+ model=None, d1=None, d2=None, rho1=None, rho2=None, rho3=None,
407
449
  error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
408
- ):
450
+ XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=True,
451
+
452
+ ):
409
453
 
410
454
  """
411
455
  This function performs Monte Carlo simulations of uncertainty in CO2 density, input temperature,
@@ -451,6 +495,19 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
451
495
  error_dist_T_K: str
452
496
  Distribution of temperature error. Can be 'normal' or 'uniform'.
453
497
 
498
+
499
+
500
+
501
+ X_H2O: pd.Series, integer, float
502
+ mol proportion of H2O in the fluid phase
503
+ error_XH2O: float
504
+ Error in XH2O
505
+ error_type_XH2O: str
506
+ Type of XH2O error. Can be 'Abs' or 'Perc'.
507
+ error_dist_XH2O: str
508
+ Distribution of XH2O error. Can be 'normal' or 'uniform'.
509
+
510
+
454
511
  For converting pressure to depth in the crust, choose either
455
512
 
456
513
  A fixed crustal density
@@ -507,6 +564,9 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
507
564
 
508
565
 
509
566
  """
567
+ if XH2O is not None:
568
+ 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
+ print('Please note, the DZ2006 EOS is about 5-40X slower to run than the SP94 and SW94 EOS')
510
570
  if isinstance(T_K, float) or isinstance(T_K, int) :
511
571
  if pd.isna(T_K):
512
572
  raise TypeError("Your Input Temperature is NaN - We cant do EOS calculatoins")
@@ -523,6 +583,8 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
523
583
  len_loop=len(CO2_dens_gcm3)
524
584
  else:
525
585
  len_loop=1
586
+
587
+
526
588
 
527
589
 
528
590
 
@@ -551,7 +613,7 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
551
613
  CO2_dens_gcm3=CO2_dens_gcm3,
552
614
  crust_dens_kgm3=crust_dens_kgm3, output='kbar',
553
615
  g=9.81, model=model,
554
- d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3, EOS=EOS)
616
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3, EOS=EOS, XH2O=XH2O, Hloss=Hloss)
555
617
 
556
618
 
557
619
 
@@ -586,19 +648,36 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
586
648
  error_CO2_dens=error_CO2_dens.iloc[i]
587
649
  else:
588
650
  error_CO2_dens=error_CO2_dens
651
+
652
+ 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
589
657
 
590
658
  if type(error_crust_dens) is pd.Series:
591
659
  error_crust_dens=error_crust_dens.iloc[i]
592
660
  else:
593
661
  error_crust_dens=error_crust_dens
662
+
663
+
594
664
 
595
665
 
596
666
  # This is the function doing the work to actually make the simulations for each variable.
597
- df_synthetic=calculate_temperature_density_MC(sample_i=i, N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3,
667
+ if XH2O is None:
668
+ df_synthetic=calculate_temperature_density_MC(sample_i=i, N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3,
598
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,
599
670
  error_CO2_dens=error_CO2_dens, error_type_CO2_dens=error_type_CO2_dens, error_dist_CO2_dens=error_dist_CO2_dens,
600
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,
601
672
  model=model)
673
+
674
+ 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)
680
+
602
681
 
603
682
  # Convert to densities for MC
604
683
 
@@ -606,11 +685,13 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
606
685
  MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
607
686
  CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
608
687
  crust_dens_kgm3=df_synthetic['crust_dens_with_noise'],
688
+ XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
609
689
  d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,model=model,
610
- EOS=EOS)
690
+ EOS=EOS, )
611
691
  else:
612
692
  MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
613
693
  CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
694
+ XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
614
695
  d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,
615
696
  model=model, EOS=EOS)
616
697
 
@@ -663,7 +744,7 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
663
744
 
664
745
 
665
746
 
666
-
747
+
667
748
  df_step=pd.DataFrame(data={'Filename': Sample,
668
749
  'CO2_dens_gcm3': CO2_density_input,
669
750
  'SingleFI_D_km': SingleCalc_D_km,
@@ -686,80 +767,88 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
686
767
  'crust_dens_kgm3':crust_dens_kgm3,
687
768
  'EOS': EOS
688
769
  })
770
+ if XH2O is not None:
771
+ df_step['error_XH2O']=error_XH2O
772
+ df_step['error_type_XH2O']=error_type_XH2O
773
+ df_step['error_dist_XH2O']=error_dist_XH2O
774
+
775
+
689
776
 
690
777
 
691
778
 
692
779
 
693
780
  if plot_figure is True:
694
781
  df_1_sample=All_outputs.loc[All_outputs['Filename']==All_outputs['Filename'].iloc[fig_i]]
695
- fig, ((ax1, ax4), (ax2, ax5), (ax3, ax6)) = plt.subplots(3, 2, figsize=(12,8))
782
+
783
+ df_1_step=df_step.loc[df_step['Filename']==All_outputs['Filename'].iloc[fig_i]]
784
+ fig, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(3, 2, figsize=(12,8))
785
+
786
+
696
787
  fig.suptitle('Simulations for sample = ' + str(All_outputs['Filename'].iloc[fig_i]), fontsize=20)
697
- ax4.set_title('Calculated distribution of depths')
698
- ax5.set_title('Calculated distribution of pressures (MPa)')
699
- ax6.set_title('Calculated distribution of pressures (kbar)')
700
-
701
-
702
- ax1.hist(df_1_sample['MC_T_K'], color='red', ec='k')
703
- ax2.hist(df_1_sample['MC_CO2_dens_gcm3'], facecolor='white', ec='k')
704
- ax2.xaxis.set_major_formatter(plt.FormatStrFormatter('%.3f'))
705
- if model is None:
706
- ax3.hist(df_1_sample['input_crust_dens_kgm3'], color='salmon', ec='k')
707
- ax4.hist(df_1_sample['Depth (km)'], color='cornflowerblue', ec='k')
708
- ax5.hist(df_1_sample['Pressure (MPa)'], color='cyan', ec='k')
709
- ax6.hist(df_1_sample['Pressure (kbar)'], color='cyan', ec='k')
710
-
711
- ax4.set_xlabel('Depth (km)')
712
- ax5.set_xlabel('Pressure (MPa)')
713
- ax6.set_xlabel('Pressure (kbar)')
714
788
 
715
789
 
790
+ # Ax1 is temperature
716
791
  if error_dist_T_K=='normal' and error_type_T_K == 'Abs':
717
792
  ax1.set_title('Input distribution Temp: Normally-distributed, 1σ =' +str(error_T_K) + ' K')
718
793
  if error_dist_T_K=='normal' and error_type_T_K == 'Perc':
719
794
  ax1.set_title('Input distribution Temp: Normally-distributed, 1σ =' +str(error_T_K) + '%')
720
-
721
-
722
-
795
+ if df_1_step['error_T_K'][0]!=0:
796
+ ax1.hist(df_1_sample['MC_T_K'], color='red', ec='k')
797
+ else:
798
+ ax1.plot([0, 0], [0, N_dup], '-r')
799
+
800
+ # ax2 is CO2 density
723
801
  if error_dist_CO2_dens=='normal' and error_type_CO2_dens == 'Abs':
724
802
  ax2.set_title('Input distribution CO$_2$ density: Normally-distributed, 1σ =' +str(error_CO2_dens) + ' g/cm$^{3}$')
725
803
  if error_dist_CO2_dens=='normal' and error_type_CO2_dens == 'Perc':
726
804
  ax2.set_title('Input distribution CO$_2$ density: Normally-distributed, 1σ =' +str(error_CO2_dens) + '%')
727
-
728
-
805
+ if df_1_step['error_CO2_dens_gcm3'][0]!=0:
806
+ ax2.hist(df_1_sample['MC_CO2_dens_gcm3'], facecolor='white', ec='k')
807
+ else:
808
+ ax2.plot([0, 0], [0, N_dup], '-r')
809
+ ax2.xaxis.set_major_formatter(plt.FormatStrFormatter('%.3f'))
810
+
811
+ # ax3 is the crustal density error
729
812
  if error_dist_crust_dens=='normal' and error_type_crust_dens == 'Abs':
730
813
  ax3.set_title('Input Distribution Crustal density: Normally-distributed, 1σ =' +str(error_crust_dens) + 'kg/m$^{3}$')
731
814
  if error_dist_crust_dens=='normal' and error_type_crust_dens == 'Perc':
732
815
  ax3.set_title('Input distribution crustal density: Normally-distributed, 1σ =' +str(error_crust_dens) + '%')
733
-
734
- if error_dist_T_K=='uniform' and error_type_T_K == 'Abs':
735
- ax1.set_title('Input Distribution Temp=+-' +str(error_T_K))
736
- if error_dist_T_K=='uniform' and error_type_T_K == 'Perc':
737
- ax1.set_title('Input distribution Temp=+-' +str(error_T_K) + '%')
738
-
739
-
740
-
741
-
742
-
743
- if error_dist_CO2_dens=='uniform' and error_type_CO2_dens == 'Abs':
744
- ax2.set_title('Input Distribution CO$_2$ density: uniformly-distributed, +-' +str(error_CO2_dens))
745
- if error_dist_CO2_dens=='uniform' and error_type_CO2_dens == 'Perc':
746
- ax2.set_title('Input distribution CO$_2$ density=+-' +str(error_CO2_dens) + '%')
747
-
748
-
749
- if error_dist_crust_dens=='uniform' and error_type_crust_dens == 'Abs':
750
- ax3.set_title('Input distribution crustal density: uniformly-distributed, +- ' +str(error_crust_dens))
751
- if error_dist_crust_dens=='uniform' and error_type_crust_dens == 'Perc':
752
- ax3.set_title('Input distribution crustal density: uniformly-distributed, +- ' +str(error_crust_dens) + '%')
753
-
754
-
755
-
756
- ax1.set_xlabel('Temperature simulation (K)')
757
- ax2.set_xlabel('CO$_2$ density simulation (g/cm$^{3}$)')
758
- ax3.set_xlabel('Crustal density simulation (g/cm$^{3}$)')
816
+ if model is None and df_1_step['error_crust_dens_kgm3'][0]!=0:
817
+ ax3.hist(df_1_sample['input_crust_dens_kgm3'], facecolor='white', ec='k')
818
+ else:
819
+ ax3.plot([0, 0], [0, N_dup], '-r')
820
+ ax3.ticklabel_format(useOffset=False)
821
+
822
+ # ax4 is XH2O
823
+ 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}$')
825
+ if error_dist_XH2O=='normal' and error_type_XH2O == 'Perc':
826
+ ax4.set_title('Input distribution XH2O: Normally-distributed, 1σ =' +str(error_XH2O) + '%')
827
+ if XH2O is not None and df_1_step['error_XH2O'][0]!=0:
828
+ ax4.hist(df_1_sample['MC_XH2O'], facecolor='white', ec='k')
829
+ else:
830
+ ax4.plot([0, 0], [0, N_dup], '-r')
831
+ ax4.ticklabel_format(useOffset=False)
832
+
833
+
834
+ # ax5 is pressure output of simulation
835
+ ax5.hist(df_1_sample['Pressure (kbar)'], color='cyan', ec='k')
836
+ ax5.set_xlabel('Pressure (kbar)')
837
+
838
+ # ax6
839
+ ax6.hist(df_1_sample['Depth (km)'], color='cornflowerblue', ec='k')
840
+ ax6.set_xlabel('Depth (km)')
841
+
759
842
  ax1.set_ylabel('# of synthetic samples')
760
- ax2.set_ylabel('# of synthetic samples')
761
843
  ax3.set_ylabel('# of synthetic samples')
762
-
844
+ ax5.set_ylabel('# of synthetic samples')
845
+
846
+ ax1.set_xlabel('T (K)')
847
+ ax2.set_xlabel('CO$_2$ Density (g/cm$^{3}$)')
848
+ ax3.set_xlabel('Crustal Density (kg/m$^{3}$)')
849
+ ax4.set_xlabel('X$_{H_{2}O}$ (molar)')
850
+
851
+
763
852
  fig.tight_layout()
764
853
 
765
854
  #return df_step, All_outputs, fig
@@ -771,8 +860,8 @@ error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
771
860
  def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
772
861
  CO2_dens_gcm3=None,
773
862
  crust_dens_kgm3=None, output='kbar',
774
- g=9.81, model=None,
775
- d1=None, d2=None, rho1=None, rho2=None, rho3=None, ):
863
+ g=9.81, model=None, XH2O=None, Hloss=True,
864
+ d1=None, d2=None, rho1=None, rho2=None, rho3=None,T_K_ambient=37+273.15 ):
776
865
 
777
866
  """ This function calculates pressure and depth based on input CO2 densities,
778
867
  temperatures, and crustal density information from the user
@@ -826,42 +915,98 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
826
915
 
827
916
 
828
917
  # First step is to get pressure
829
- Pressure=calculate_P_for_rho_T(T_K=T_K,
830
- CO2_dens_gcm3=CO2_dens_gcm3,
831
- EOS=EOS)
832
-
833
- # Second step is to get crustal depths
834
-
835
- Depth_km=convert_pressure_to_depth(P_kbar=Pressure['P_kbar'],
836
- crust_dens_kgm3=crust_dens_kgm3, g=9.81, model=model,
837
- d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3)
838
-
839
-
840
-
841
- if type(Depth_km) is float:
842
- # Crustal density, using P=rho g H
843
- df=pd.DataFrame(data={'Pressure (kbar)': Pressure['P_kbar'],
844
- 'Pressure (MPa)': Pressure['P_MPa'],
845
- 'Depth (km)': Depth_km,
846
- 'input_crust_dens_kgm3': crust_dens_kgm3,
847
- 'model': model,
848
- 'MC_T_K': T_K,
849
- 'MC_CO2_dens_gcm3': CO2_dens_gcm3}, index=[0])
918
+ if XH2O is None:
919
+ Pressure=calculate_P_for_rho_T(T_K=T_K,
920
+ CO2_dens_gcm3=CO2_dens_gcm3,
921
+ EOS=EOS)
922
+
923
+ # Second step is to get crustal depths
924
+
925
+ Depth_km=convert_pressure_to_depth(P_kbar=Pressure['P_kbar'],
926
+ crust_dens_kgm3=crust_dens_kgm3, g=9.81, model=model,
927
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3)
928
+
929
+
930
+ if type(Depth_km) is float:
931
+ # Crustal density, using P=rho g H
932
+ df=pd.DataFrame(data={'Pressure (kbar)': Pressure['P_kbar'],
933
+ 'Pressure (MPa)': Pressure['P_MPa'],
934
+ 'Depth (km)': Depth_km,
935
+ 'input_crust_dens_kgm3': crust_dens_kgm3,
936
+ 'model': model,
937
+ 'MC_T_K': T_K,
938
+ 'MC_CO2_dens_gcm3': CO2_dens_gcm3}, index=[0])
939
+
940
+ else:
941
+
942
+
943
+ df=pd.DataFrame(data={'Pressure (kbar)': Pressure['P_kbar'],
944
+ 'Pressure (MPa)': Pressure['P_MPa'],
945
+ 'Depth (km)': Depth_km,
946
+ 'input_crust_dens_kgm3': crust_dens_kgm3,
947
+ 'model': model,
948
+ 'MC_T_K': T_K,
949
+ 'MC_CO2_dens_gcm3': CO2_dens_gcm3})
950
+
951
+ #df.replace([np.inf, -np.inf], np.nan, inplace=True)
952
+
953
+
954
+ # Make as a dict to allow index=0 if depth is float, else not.
955
+ data_dict = {
956
+ 'Pressure (kbar)': [Pressure['P_kbar']],
957
+ 'Pressure (MPa)': [Pressure['P_MPa']],
958
+ 'Depth (km)': [Depth_km] if isinstance(Depth_km, float) else Depth_km,
959
+ 'input_crust_dens_kgm3': [crust_dens_kgm3],
960
+ 'model': [model],
961
+ 'MC_T_K': [T_K],
962
+ 'MC_CO2_dens_gcm3': [CO2_dens_gcm3]
963
+ }
964
+
850
965
 
966
+
967
+
968
+ # If XH2O, need different outputs.
851
969
  else:
970
+
971
+ 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
+
973
+
974
+ Depth_km=convert_pressure_to_depth(P_kbar_calc,
975
+ crust_dens_kgm3=crust_dens_kgm3, g=9.81, model=model,
976
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3)
977
+
978
+ if type(Depth_km) is float:
979
+ # Crustal density, using P=rho g H
980
+ df=pd.DataFrame(data={'Pressure (kbar)': P_kbar_calc,
981
+ 'Pressure (MPa)': 100*P_kbar_calc,
982
+ 'Depth (km)': Depth_km,
983
+ 'input_crust_dens_kgm3': crust_dens_kgm3,
984
+ 'model': model,
985
+ 'MC_T_K': T_K,
986
+ 'MC_CO2_dens_gcm3': CO2_dens_gcm3,
987
+ 'MC_XH2O': XH2O}, index=[0])
988
+
989
+ else:
990
+
991
+
992
+ df=pd.DataFrame(data={'Pressure (kbar)': P_kbar_calc,
993
+ 'Pressure (MPa)': 100*P_kbar_calc,
994
+ 'Depth (km)': Depth_km,
995
+ 'input_crust_dens_kgm3': crust_dens_kgm3,
996
+ 'model': model,
997
+ 'MC_T_K': T_K,
998
+ 'MC_CO2_dens_gcm3': CO2_dens_gcm3,
999
+ 'MC_XH2O': XH2O})
1000
+
1001
+
1002
+
1003
+ df.replace([np.inf, -np.inf], np.nan, inplace=True)
1004
+
1005
+ return df
852
1006
 
853
1007
 
854
- df=pd.DataFrame(data={'Pressure (kbar)': Pressure['P_kbar'],
855
- 'Pressure (MPa)': Pressure['P_MPa'],
856
- 'Depth (km)': Depth_km,
857
- 'input_crust_dens_kgm3': crust_dens_kgm3,
858
- 'model': model,
859
- 'MC_T_K': T_K,
860
- 'MC_CO2_dens_gcm3': CO2_dens_gcm3})
861
1008
 
862
- df.replace([np.inf, -np.inf], np.nan, inplace=True)
863
1009
 
864
- return df
865
1010
 
866
1011
 
867
1012
 
@@ -1193,7 +1193,7 @@ def stitch_loop_individual_fits(*, fit_individually=True,
1193
1193
 
1194
1194
 
1195
1195
  ## Save settings files
1196
- def save_settings(meta_path, spectra_path, filetype, prefix, prefix_str, file_ext, TruPower):
1196
+ def save_settings(meta_path, spectra_path, spectra_filetype, prefix, prefix_str, spectra_file_ext, meta_file_ext, TruPower):
1197
1197
  """ This function saves settings so you can load them across multiple notebooks without repition
1198
1198
 
1199
1199
  Parameters
@@ -1202,14 +1202,18 @@ def save_settings(meta_path, spectra_path, filetype, prefix, prefix_str, file_ex
1202
1202
  Path where your metadata is stored
1203
1203
  spectra_path: str
1204
1204
  path where your spectra is stored
1205
- filetype: str
1205
+
1206
+ spectra_filetype: str
1207
+ Style of data.
1206
1208
  Choose from 'Witec_ASCII', 'headless_txt', 'headless_csv', 'head_csv', 'Witec_ASCII', 'HORIBA_txt', 'Renishaw_txt'
1209
+
1210
+ spectra_file_ext, meta_file_ext: str
1211
+ Extension of spectra file and metadatafile. e.g. '.txt', '.csv'
1212
+
1207
1213
  prefix: bool
1208
1214
  If True, removes 01, 02, from filename (WITEC problem)
1209
1215
  Also need to state prefix_str: prefix separating string (in this case, 01 Ne would be ' '
1210
1216
 
1211
- file_ext: str
1212
- Extension of file. e.g. txt
1213
1217
 
1214
1218
  TruPower: bool
1215
1219
  If WITEC instrument and you have TruPower, set as True
@@ -1223,12 +1227,12 @@ def save_settings(meta_path, spectra_path, filetype, prefix, prefix_str, file_ex
1223
1227
  filetype_opts = ['Witec_ASCII', 'headless_txt', 'headless_csv', 'head_csv', 'Witec_ASCII', 'HORIBA_txt', 'Renishaw_txt']
1224
1228
 
1225
1229
 
1226
- if filetype in filetype_opts:
1230
+ if spectra_filetype in filetype_opts:
1227
1231
  # Proceed with your logic here
1228
- print(f"Filetype {filetype} is valid.")
1232
+ print(f"Good job! Filetype {spectra_filetype} is valid.")
1229
1233
  # You can add more logic here if needed
1230
1234
  else:
1231
- raise TypeError(f"Invalid filetype: {filetype}. Supported filetypes are {filetype_opts}")
1235
+ raise TypeError(f"Invalid spectra_filetype: {filetype}. Supported filetypes are {filetype_opts}")
1232
1236
 
1233
1237
  # Get the current folder
1234
1238
  folder = os.getcwd()
@@ -1237,10 +1241,11 @@ def save_settings(meta_path, spectra_path, filetype, prefix, prefix_str, file_ex
1237
1241
  settings = {
1238
1242
  'meta_path': meta_path,
1239
1243
  'spectra_path': spectra_path,
1240
- 'filetype': filetype,
1244
+ 'spectra_filetype': spectra_filetype,
1241
1245
  'prefix': prefix,
1242
1246
  'prefix_str': repr(prefix_str),
1243
- 'file_ext': file_ext,
1247
+ 'spectra_file_ext': spectra_file_ext,
1248
+ 'meta_file_ext': meta_file_ext,
1244
1249
  'TruPower': TruPower,
1245
1250
  }
1246
1251
 
@@ -1253,6 +1258,7 @@ def save_settings(meta_path, spectra_path, filetype, prefix, prefix_str, file_ex
1253
1258
  file.write(f"{key}={value}\n")
1254
1259
 
1255
1260
  def get_settings():
1261
+ """ This function reads the settings file saved in step 1, and loads the options"""
1256
1262
  # Get the current folder
1257
1263
  folder = os.getcwd()
1258
1264
 
@@ -1278,8 +1284,8 @@ def get_settings():
1278
1284
  settings['TruPower'] = settings['TruPower'].lower() == 'true'
1279
1285
 
1280
1286
  # Return the settings
1281
- return settings.get('meta_path'), settings.get('spectra_path'), settings.get('filetype'), \
1282
- settings.get('prefix'), settings.get('prefix_str'), settings.get('file_ext'), settings.get('TruPower')
1287
+ return settings.get('meta_path'), settings.get('spectra_path'), settings.get('spectra_filetype'), \
1288
+ settings.get('prefix'), settings.get('prefix_str'), settings.get('spectra_file_ext'), settings.get('meta_file_ext'),settings.get('TruPower')
1283
1289
 
1284
1290
 
1285
1291