DiadFit 0.0.90__py3-none-any.whl → 1.0.1__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.
@@ -8,6 +8,8 @@ from DiadFit.density_depth_crustal_profiles import *
8
8
  from DiadFit.CO2_EOS import *
9
9
  # This gets us the functions for Monte Carloing
10
10
  from DiadFit.CO2_in_bubble_error import *
11
+ import multiprocessing as mp
12
+ np.random.seed(42)
11
13
 
12
14
  ## Microthermometry error propagation
13
15
 
@@ -346,7 +348,8 @@ def convert_inputs_to_series(T_K, error_T_K, CO2_dens_gcm3, error_CO2_dens_gcm3,
346
348
 
347
349
 
348
350
 
349
- def propagate_FI_uncertainty(sample_ID, CO2_dens_gcm3, T_K, N_dup=1000, EOS='SW96',
351
+ def propagate_FI_uncertainty(sample_ID, CO2_dens_gcm3, T_K, multiprocess='default', cores='default',
352
+ EOS='SW96', N_dup=1000,
350
353
  plot_figure=False, fig_i=0,
351
354
  error_CO2_dens=0, error_type_CO2_dens='Abs', error_dist_CO2_dens='normal',
352
355
  crust_dens_kgm3=None,
@@ -354,7 +357,7 @@ error_CO2_dens=0, error_type_CO2_dens='Abs', error_dist_CO2_dens='normal',
354
357
  model=None, d1=None, d2=None, rho1=None, rho2=None, rho3=None,
355
358
  error_T_K=0, error_type_T_K='Abs', error_dist_T_K='normal',
356
359
  XH2O=None, error_XH2O=0, error_type_XH2O='Abs', error_dist_XH2O='normal', Hloss=True,
357
- neg_values=True
360
+ neg_values=True,
358
361
  ):
359
362
 
360
363
  """
@@ -367,6 +370,11 @@ neg_values=True
367
370
 
368
371
  Parameters
369
372
  -----------------
373
+ multiprocess: 'default' or bool
374
+ Default uses multiprocessing for Duan and Zhang (2006) but not for Span and Wanger or Sterner and Pitzer. This is because these EOS are so fast, making the multiprocess has a time penalty.
375
+ You can override this defualt by specifying True or False.
376
+ cores: 'default'
377
+ By default, if multiprocess, uses default number of cores selected by multiprocess, ca noverride.
370
378
  sample_ID: pd.Series
371
379
  Panda series of sample names. E.g., select a column from your dataframe (df['sample_name'])
372
380
 
@@ -479,7 +487,7 @@ neg_values=True
479
487
 
480
488
 
481
489
  if XH2O is not None:
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')
490
+ print('You have entered a value for XH2O, so we are now using the EOS of Duan and Zhang 200 regardless of what model you selected. If you dont want this, specify XH2O=None')
483
491
  print('Please note, the DZ2006 EOS is about 5-40X slower to run than the SP94 and SW94 EOS')
484
492
 
485
493
  if isinstance(T_K, float) or isinstance(T_K, int) :
@@ -532,154 +540,207 @@ neg_values=True
532
540
 
533
541
  #This loops through each fluid inclusion entered density
534
542
 
543
+ if multiprocess =='default':
544
+ if XH2O is None and EOS!='DZ06':
545
+ print('We are not using multiprocessing based on your selected EOS. You can override this by setting multiprocess=True in the function, but for SP94 and SW96 it might actually be slower')
546
+ multiprocess=False
547
+ else:
548
+ if XH2O is not None:
549
+ multiprocess=True
550
+ print('We are using multiprocessing based on your selected EOS. You can override this by setting multiprocess=False in the function, but it might slow it down a lot')
551
+
552
+ if multiprocess is False:
553
+
535
554
 
536
- for i in tqdm(range(0, len_loop), desc="Processing"):
537
555
 
556
+ for i in tqdm(range(0, len_loop), desc="Processing"):
557
+
558
+
559
+ # This fills in the columns for the single calculation, e.g. no Monte-Carloing from above.
560
+ SingleCalc_D_km[i]=df_ind['Depth (km)'].iloc[i]
561
+ SingleCalc_Press_kbar[i]=df_ind['Pressure (kbar)'].iloc[i]
562
+
563
+ # Now lets get the value, using the function in the CO2_in_bubble_error.py file
564
+ error_T_K_i=get_value(error_T_K, i)
565
+ T_K_i=get_value(T_K, i)
566
+
567
+ CO2_dens_gcm3_i=get_value(CO2_dens_gcm3, i)
568
+ error_CO2_dens_i=get_value(error_CO2_dens, i)
569
+
570
+ crust_dens_kgm3_i=get_value(crust_dens_kgm3, i)
571
+ error_crust_dens_i=get_value(error_crust_dens, i)
572
+ # Now, if XH2O was entered, and isnt None, do the same. Else keeps as None.
573
+ if XH2O is not None:
574
+ error_XH2O_i=get_value(error_XH2O, i)
575
+ XH2O_i=get_value(XH2O, i)
576
+
577
+
578
+
579
+ # This is the function doing the work to actually make the simulations for each variable.
580
+ # For each input variable, it makes a distribution.
581
+
582
+ # If XH2O is None, it doesnt return the column XH2O_with_noise, which helps ID this later.
583
+ if XH2O is None:
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, neg_values=neg_values)
538
590
 
539
- # This fills in the columns for the single calculation, e.g. no Monte-Carloing from above.
540
- SingleCalc_D_km[i]=df_ind['Depth (km)'].iloc[i]
541
- SingleCalc_Press_kbar[i]=df_ind['Pressure (kbar)'].iloc[i]
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)
591
+ if model is None:
592
+ MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
593
+ CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
594
+ crust_dens_kgm3=df_synthetic['crust_dens_with_noise'],
595
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,model=model,
596
+ EOS=EOS )
597
+ else:
598
+ MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
599
+ CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
600
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,
601
+ model=model, EOS=EOS)
549
602
 
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.
553
- if XH2O is not None:
554
- error_XH2O_i=get_value(error_XH2O, i)
555
- XH2O_i=get_value(XH2O, i)
603
+ if XH2O is not None:
604
+
605
+ df_synthetic=calculate_temperature_density_MC(N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3_i,
606
+ 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,
607
+ error_CO2_dens=error_CO2_dens_i, error_type_CO2_dens=error_type_CO2_dens, error_dist_CO2_dens=error_dist_CO2_dens,
608
+ 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,
609
+ 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)
556
610
 
611
+ EOS='DZ06'
612
+
557
613
 
614
+ # Convert to densities for MC
615
+
616
+ if model is None:
617
+ MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
618
+ CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
619
+ crust_dens_kgm3=df_synthetic['crust_dens_with_noise'],
620
+ XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
621
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,model=model,
622
+ EOS=EOS )
623
+ else:
624
+ MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
625
+ CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
626
+ XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
627
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,
628
+ model=model, EOS=EOS)
558
629
 
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.
563
- if XH2O is None:
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 )
630
+
631
+ # Check of
632
+ if sample_ID is None:
633
+ Sample[i]=i
634
+
635
+ elif isinstance(sample_ID, str):
636
+ Sample[i]=sample_ID
577
637
  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)
638
+ Sample[i]=sample_ID.iloc[i]
582
639
 
583
- if XH2O is not None:
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)
590
-
591
-
592
- # Convert to densities for MC
593
-
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 )
640
+ MC_T.insert(0, 'Filename', Sample[i])
641
+
642
+
643
+ if isinstance(CO2_dens_gcm3, pd.Series):
644
+ CO2_density_input[i]=CO2_dens_gcm3.iloc[i]
601
645
  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)
607
-
608
-
609
-
610
-
611
-
612
- # Check of
613
- if sample_ID is None:
614
- Sample[i]=i
615
-
616
- elif isinstance(sample_ID, str):
617
- Sample[i]=sample_ID
618
- else:
619
- Sample[i]=sample_ID.iloc[i]
620
-
621
- MC_T.insert(0, 'Filename', Sample[i])
622
-
623
-
624
- if isinstance(CO2_dens_gcm3, pd.Series):
625
- CO2_density_input[i]=CO2_dens_gcm3.iloc[i]
626
- else:
627
- CO2_density_input=CO2_dens_gcm3
628
-
629
-
630
-
631
-
632
-
633
- All_outputs=pd.concat([All_outputs, MC_T], axis=0)
634
-
635
-
636
- mean_Press_kbar[i]=np.nanmean(MC_T['Pressure (kbar)'])
637
- med_Press_kbar[i]=np.nanmedian(MC_T['Pressure (kbar)'])
638
- std_Press_kbar[i]=np.nanstd(MC_T['Pressure (kbar)'])
639
- var=MC_T['Pressure (kbar)']
640
- std_Press_kbar_IQR[i]=0.5*np.abs((np.percentile(var, 84) -np.percentile(var, 16)))
641
-
642
- mean_D_km[i]=np.nanmean(MC_T['Depth (km)'])
643
- med_D_km[i]=np.nanmedian(MC_T['Depth (km)'])
644
- std_D_km[i]=np.nanstd(MC_T['Depth (km)'])
645
- var=MC_T['Depth (km)']
646
- std_D_km_IQR[i]=0.5*np.abs((np.percentile(var, 84) -np.percentile(var, 16)))
647
-
648
- error_crust_dens_loop[i]=np.nanmean(df_synthetic['error_crust_dens_kgm3'])
649
- error_crust_dens2_loop[i]=np.nanstd(df_synthetic['error_crust_dens_kgm3'])
650
-
651
-
646
+ CO2_density_input=CO2_dens_gcm3
647
+
648
+
649
+ All_outputs=pd.concat([All_outputs, MC_T], axis=0)
650
+
651
+
652
+ mean_Press_kbar[i]=np.nanmean(MC_T['Pressure (kbar)'])
653
+ med_Press_kbar[i]=np.nanmedian(MC_T['Pressure (kbar)'])
654
+ std_Press_kbar[i]=np.nanstd(MC_T['Pressure (kbar)'])
655
+ var=MC_T['Pressure (kbar)']
656
+ std_Press_kbar_IQR[i]=0.5*np.abs((np.percentile(var, 84) -np.percentile(var, 16)))
657
+
658
+ mean_D_km[i]=np.nanmean(MC_T['Depth (km)'])
659
+ med_D_km[i]=np.nanmedian(MC_T['Depth (km)'])
660
+ std_D_km[i]=np.nanstd(MC_T['Depth (km)'])
661
+ var=MC_T['Depth (km)']
662
+ std_D_km_IQR[i]=0.5*np.abs((np.percentile(var, 84) -np.percentile(var, 16)))
663
+
664
+ error_crust_dens_loop[i]=np.nanmean(df_synthetic['error_crust_dens_kgm3'])
665
+
666
+
667
+
668
+
669
+ df_step=pd.DataFrame(data={'Filename': Sample,
670
+ 'CO2_dens_gcm3': CO2_density_input,
671
+ 'SingleCalc_D_km': SingleCalc_D_km,
672
+ 'SingleCalc_P_kbar': SingleCalc_Press_kbar,
673
+ 'Mean_MC_P_kbar': mean_Press_kbar,
674
+ 'Med_MC_P_kbar': med_Press_kbar,
675
+ 'std_dev_MC_P_kbar': std_Press_kbar,
676
+ 'std_dev_MC_P_kbar_from_percentile': std_Press_kbar_IQR,
677
+ 'Mean_MC_D_km': mean_D_km,
678
+ 'Med_MC_D_km': med_D_km,
679
+ 'std_dev_MC_D_km': std_D_km,
680
+ 'std_dev_MC_D_km_from_percentile': std_D_km_IQR,
681
+ 'T_K_input': T_K,
682
+ 'error_T_K': error_T_K,
683
+ 'CO2_dens_gcm3_input': CO2_dens_gcm3,
684
+ 'error_CO2_dens_gcm3': error_CO2_dens,
685
+ 'crust_dens_kgm3_input':crust_dens_kgm3,
686
+ 'error_crust_dens_kgm3': error_crust_dens_loop,
687
+ 'model': model,
688
+ 'EOS': EOS
689
+ })
690
+
691
+ if XH2O is not None:
692
+ df_step['XH2O_input']=XH2O
693
+ df_step['error_XH2O']=error_XH2O
652
694
 
653
695
 
696
+
697
+
698
+ if multiprocess is True:
654
699
 
655
700
 
656
701
 
702
+ # Choose number of processes
703
+
704
+ if cores=='default':
705
+ print("Number of processors: ", mp.cpu_count())
706
+ pool = mp.Pool(mp.cpu_count())
707
+ else:
708
+ pool = mp.Pool(cores)
709
+
710
+
711
+
712
+ args=(sample_ID, df_ind, CO2_dens_gcm3, T_K, N_dup, EOS,
713
+ error_CO2_dens, error_type_CO2_dens, error_dist_CO2_dens,
714
+ crust_dens_kgm3,
715
+ error_crust_dens, error_type_crust_dens, error_dist_crust_dens,
716
+ model, d1, d2, rho1, rho2, rho3,
717
+ error_T_K, error_type_T_K, error_dist_T_K,
718
+ XH2O, error_XH2O, error_type_XH2O, error_dist_XH2O, Hloss,
719
+ neg_values)
657
720
 
658
- df_step=pd.DataFrame(data={'Filename': Sample,
659
- 'CO2_dens_gcm3': CO2_density_input,
660
- 'SingleFI_D_km': SingleCalc_D_km,
661
- 'SingleFI_P_kbar': SingleCalc_Press_kbar,
662
- 'Mean_MC_P_kbar': mean_Press_kbar,
663
- 'Med_MC_P_kbar': med_Press_kbar,
664
- 'std_dev_MC_P_kbar': std_Press_kbar,
665
- 'std_dev_MC_P_kbar_from_percentile': std_Press_kbar_IQR,
666
- 'Mean_MC_D_km': mean_D_km,
667
- 'Med_MC_D_km': med_D_km,
668
- 'std_dev_MC_D_km': std_D_km,
669
- 'std_dev_MC_D_km_from_percentile': std_D_km_IQR,
670
- 'error_T_K': error_T_K,
671
- 'error_CO2_dens_gcm3': error_CO2_dens,
672
- 'error_crust_dens_kgm3': error_crust_dens_loop,
673
- 'T_K': T_K,
674
- 'CO2_dens_gcm3_input': CO2_dens_gcm3,
675
- 'model': model,
676
- 'crust_dens_kgm3':crust_dens_kgm3,
677
- 'EOS': EOS
678
- })
679
- if XH2O is not None:
680
- df_step['error_XH2O']=error_XH2O
681
- df_step['error_type_XH2O']=error_type_XH2O
682
- df_step['error_dist_XH2O']=error_dist_XH2O
721
+
722
+
723
+ results = [pool.apply_async(worker_function, args=(i, *args)) for i in range(len_loop)]
724
+
725
+ pool.close()
726
+ pool.join()
727
+
728
+ # Collect results
729
+ final_results = [r.get() for r in results]
730
+
731
+ # Initialize DataFrames
732
+ df_step = pd.DataFrame(data={'Filename': np.zeros(len_loop, dtype=np.dtype('U100'))})
733
+ All_outputs = pd.DataFrame([])
734
+
735
+ # Populate DataFrames
736
+ for result, MC_T in final_results:
737
+ i = result['i']
738
+ for key, value in result.items():
739
+ df_step.at[i, key] = value
740
+
741
+ All_outputs = pd.concat([All_outputs, MC_T], axis=0)
742
+
743
+
683
744
 
684
745
 
685
746
 
@@ -687,9 +748,9 @@ neg_values=True
687
748
 
688
749
 
689
750
  if plot_figure is True:
690
- df_1_sample=All_outputs.loc[All_outputs['Filename']==All_outputs['Filename'].iloc[fig_i]]
751
+ df_1_sample=All_outputs.loc[All_outputs['Filename']==df_step['Filename'].iloc[fig_i]]
691
752
 
692
- df_1_step=df_step.loc[df_step['Filename']==All_outputs['Filename'].iloc[fig_i]]
753
+ df_1_step=df_step.loc[df_step['Filename']==df_step['Filename'].iloc[fig_i]]
693
754
  fig, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(3, 2, figsize=(12,8))
694
755
 
695
756
 
@@ -741,6 +802,7 @@ neg_values=True
741
802
  ax1.set_title('Input distribution Temp: Normally-distributed, 1σ =' +str(error_T_K_plot) + ' K')
742
803
  if error_dist_T_K=='normal' and error_type_T_K == 'Perc':
743
804
  ax1.set_title('Input distribution Temp: Normally-distributed, 1σ =' +str(error_T_K_plot) + '%')
805
+
744
806
  if df_1_step['error_T_K'][0]!=0:
745
807
  ax1.hist(df_1_sample['MC_T_K'], color='red', ec='k')
746
808
  else:
@@ -763,7 +825,7 @@ neg_values=True
763
825
  if error_dist_crust_dens=='normal' and error_type_crust_dens == 'Perc':
764
826
  ax3.set_title('Input distribution crustal density: Normally-distributed, 1σ =' +str(error_crust_dens_plot) + '%')
765
827
  if model is None and df_1_step['error_crust_dens_kgm3'][0]!=0:
766
- ax3.hist(df_1_sample['input_crust_dens_kgm3'], facecolor='white', ec='k')
828
+ ax3.hist(df_1_sample['MC_crust_dens_kgm3'], facecolor='white', ec='k')
767
829
  else:
768
830
  ax3.plot([0, 0], [0, N_dup], '-r')
769
831
  ax3.ticklabel_format(useOffset=False)
@@ -803,6 +865,10 @@ neg_values=True
803
865
  #return df_step, All_outputs, fig
804
866
 
805
867
  return df_step, All_outputs,fig if 'fig' in locals() else None
868
+
869
+
870
+
871
+
806
872
 
807
873
 
808
874
  ## Actual functions doing the conversions
@@ -883,7 +949,7 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
883
949
  df=pd.DataFrame(data={'Pressure (kbar)': Pressure['P_kbar'],
884
950
  'Pressure (MPa)': Pressure['P_MPa'],
885
951
  'Depth (km)': Depth_km,
886
- 'input_crust_dens_kgm3': crust_dens_kgm3,
952
+ 'MC_crust_dens_kgm3': crust_dens_kgm3,
887
953
  'model': model,
888
954
  'MC_T_K': T_K,
889
955
  'MC_CO2_dens_gcm3': CO2_dens_gcm3}, index=[0])
@@ -894,7 +960,7 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
894
960
  df=pd.DataFrame(data={'Pressure (kbar)': Pressure['P_kbar'],
895
961
  'Pressure (MPa)': Pressure['P_MPa'],
896
962
  'Depth (km)': Depth_km,
897
- 'input_crust_dens_kgm3': crust_dens_kgm3,
963
+ 'MC_crust_dens_kgm3': crust_dens_kgm3,
898
964
  'model': model,
899
965
  'MC_T_K': T_K,
900
966
  'MC_CO2_dens_gcm3': CO2_dens_gcm3})
@@ -906,7 +972,7 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
906
972
  'Pressure (kbar)': [Pressure['P_kbar']],
907
973
  'Pressure (MPa)': [Pressure['P_MPa']],
908
974
  'Depth (km)': [Depth_km] if isinstance(Depth_km, float) else Depth_km,
909
- 'input_crust_dens_kgm3': [crust_dens_kgm3],
975
+ 'MC_crust_dens_kgm3': [crust_dens_kgm3],
910
976
  'model': [model],
911
977
  'MC_T_K': [T_K],
912
978
  'MC_CO2_dens_gcm3': [CO2_dens_gcm3]
@@ -932,7 +998,7 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
932
998
  df=pd.DataFrame(data={'Pressure (kbar)': P_kbar_calc,
933
999
  'Pressure (MPa)': 100*P_kbar_calc,
934
1000
  'Depth (km)': Depth_km,
935
- 'input_crust_dens_kgm3': crust_dens_kgm3,
1001
+ 'MC_crust_dens_kgm3': crust_dens_kgm3,
936
1002
  'model': model,
937
1003
  'MC_T_K': T_K,
938
1004
  'MC_CO2_dens_gcm3': CO2_dens_gcm3,
@@ -944,7 +1010,7 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
944
1010
  df=pd.DataFrame(data={'Pressure (kbar)': P_kbar_calc,
945
1011
  'Pressure (MPa)': 100*P_kbar_calc,
946
1012
  'Depth (km)': Depth_km,
947
- 'input_crust_dens_kgm3': crust_dens_kgm3,
1013
+ 'MC_crust_dens_kgm3': crust_dens_kgm3,
948
1014
  'model': model,
949
1015
  'MC_T_K': T_K,
950
1016
  'MC_CO2_dens_gcm3': CO2_dens_gcm3,
@@ -955,11 +1021,160 @@ def convert_co2_dens_press_depth(EOS='SW96', T_K=None,
955
1021
  df.replace([np.inf, -np.inf], np.nan, inplace=True)
956
1022
 
957
1023
  return df
1024
+
1025
+
1026
+ ## Now lets try to parallize it
1027
+
1028
+ def worker_function(i, sample_ID, df_ind, CO2_dens_gcm3, T_K, N_dup, EOS,
1029
+ error_CO2_dens, error_type_CO2_dens, error_dist_CO2_dens,
1030
+ crust_dens_kgm3,
1031
+ error_crust_dens, error_type_crust_dens, error_dist_crust_dens,
1032
+ model, d1, d2, rho1, rho2, rho3,
1033
+ error_T_K, error_type_T_K, error_dist_T_K,
1034
+ XH2O, error_XH2O, error_type_XH2O, error_dist_XH2O, Hloss,
1035
+ neg_values
1036
+ ):
1037
+
1038
+
1039
+ # This fills in the columns for the single calculation, e.g. no Monte-Carloing from above.
1040
+ SingleCalc_D_km=df_ind['Depth (km)'].iloc[i]
1041
+ SingleCalc_Press_kbar=df_ind['Pressure (kbar)'].iloc[i]
1042
+
1043
+ # Now lets get the value, using the function in the CO2_in_bubble_error.py file
1044
+ T_K_i=get_value(T_K, i)
1045
+ error_T_K_i=get_value(error_T_K, i)
1046
+
1047
+
1048
+ CO2_dens_gcm3_i=get_value(CO2_dens_gcm3, i)
1049
+ error_CO2_dens_i=get_value(error_CO2_dens, i)
1050
+
1051
+ crust_dens_kgm3_i=get_value(crust_dens_kgm3, i)
1052
+ error_crust_dens_i=get_value(error_crust_dens, i)
1053
+ # Now, if XH2O was entered, and isnt None, do the same. Else keeps as None.
1054
+ if XH2O is not None:
1055
+ error_XH2O_i=get_value(error_XH2O, i)
1056
+ XH2O_i=get_value(XH2O, i)
1057
+ else:
1058
+ error_XH2O_i=0
1059
+
1060
+ if sample_ID is None:
1061
+ Sample[i]=i
958
1062
 
1063
+ elif isinstance(sample_ID, str):
1064
+ Sample=sample_ID
1065
+ else:
1066
+ Sample=sample_ID.iloc[i]
1067
+
959
1068
 
960
1069
 
1070
+ # This is the function doing the work to actually make the simulations for each variable.
1071
+ # For each input variable, it makes a distribution.
1072
+
1073
+ # If XH2O is None, it doesnt return the column XH2O_with_noise, which helps ID this later.
1074
+ if XH2O is None:
1075
+
1076
+ df_synthetic=calculate_temperature_density_MC(N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3_i,
1077
+ 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,
1078
+ error_CO2_dens=error_CO2_dens_i, error_type_CO2_dens=error_type_CO2_dens, error_dist_CO2_dens=error_dist_CO2_dens,
1079
+ 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,
1080
+ model=model, neg_values=neg_values)
1081
+
1082
+ if model is None:
1083
+ MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
1084
+ CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
1085
+ crust_dens_kgm3=df_synthetic['crust_dens_with_noise'],
1086
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,model=model,
1087
+ EOS=EOS )
1088
+ else:
1089
+ MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
1090
+ CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
1091
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,
1092
+ model=model, EOS=EOS)
961
1093
 
1094
+ if XH2O is not None:
1095
+
1096
+ df_synthetic=calculate_temperature_density_MC(N_dup=N_dup, CO2_dens_gcm3=CO2_dens_gcm3_i,
1097
+ 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,
1098
+ error_CO2_dens=error_CO2_dens_i, error_type_CO2_dens=error_type_CO2_dens, error_dist_CO2_dens=error_dist_CO2_dens,
1099
+ 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,
1100
+ 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)
962
1101
 
1102
+ EOS='DZ06'
1103
+
1104
+
1105
+ # Convert to densities for MC
963
1106
 
1107
+ if model is None:
1108
+ MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
1109
+ CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
1110
+ crust_dens_kgm3=df_synthetic['crust_dens_with_noise'],
1111
+ XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
1112
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,model=model,
1113
+ EOS=EOS )
1114
+ else:
1115
+ MC_T=convert_co2_dens_press_depth(T_K=df_synthetic['T_K_with_noise'],
1116
+ CO2_dens_gcm3=df_synthetic['CO2_dens_with_noise'],
1117
+ XH2O=df_synthetic['XH2O_with_noise'], Hloss=Hloss,
1118
+ d1=d1, d2=d2, rho1=rho1, rho2=rho2, rho3=rho3,
1119
+ model=model, EOS=EOS)
964
1120
 
965
1121
 
1122
+
1123
+
1124
+
1125
+ # Check of
1126
+ if sample_ID is None:
1127
+ Sample=i
1128
+
1129
+ elif isinstance(sample_ID, str):
1130
+ Sample=sample_ID
1131
+ else:
1132
+ Sample=sample_ID.iloc[i]
1133
+
1134
+ MC_T.insert(0, 'Filename', Sample)
1135
+
1136
+
1137
+
1138
+ CO2_density_input=CO2_dens_gcm3_i
1139
+
1140
+
1141
+
1142
+
1143
+ # Collect results
1144
+ result = {
1145
+ 'i': i,
1146
+ 'Filename': Sample,
1147
+ 'CO2_density_input': CO2_dens_gcm3_i,
1148
+ 'SingleCalc_D_km': df_ind['Depth (km)'].iloc[i],
1149
+ 'SingleCalc_P_kbar': df_ind['Pressure (kbar)'].iloc[i],
1150
+ 'Mean_MC_P_kbar': np.nanmean(MC_T['Pressure (kbar)']),
1151
+ 'Med_MC_P_kbar': np.nanmedian(MC_T['Pressure (kbar)']),
1152
+ 'std_dev_MC_P_kbar': np.nanstd(MC_T['Pressure (kbar)']),
1153
+ 'std_dev_MC_P_kbar_from_percentile': 0.5*np.abs((np.percentile(MC_T['Pressure (kbar)'], 84) -np.percentile(MC_T['Pressure (kbar)'], 16))),
1154
+ 'Mean_MC_D_km': np.nanmean(MC_T['Depth (km)']),
1155
+ 'Med_MC_D_km': np.nanmedian(MC_T['Depth (km)']),
1156
+ 'std_dev_MC_D_km': np.nanstd(MC_T['Depth (km)']),
1157
+ 'std_dev_MC_D_km_from_percentile': 0.5*np.abs((np.percentile(MC_T['Depth (km)'], 84) -np.percentile(MC_T['Depth (km)'], 16))),
1158
+ 'T_K_input': T_K_i,
1159
+ 'error_T_K': error_T_K_i,
1160
+ 'CO2_dens_gcm3_input': CO2_dens_gcm3_i,
1161
+ 'error_CO2_dens_gcm3': error_CO2_dens_i,
1162
+ 'crust_dens_kgm3_input':crust_dens_kgm3_i,
1163
+ 'error_crust_dens_kgm3': error_crust_dens_i,
1164
+ 'model': model,
1165
+ 'EOS': EOS
1166
+
1167
+ }
1168
+ if XH2O is not None:
1169
+ result['XH2O_input']=XH2O_i
1170
+ result['error_XH2O']=error_XH2O_i
1171
+
1172
+ return result, MC_T
1173
+
1174
+
1175
+
1176
+
1177
+
1178
+
1179
+
1180
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: DiadFit
3
- Version: 0.0.90
3
+ Version: 1.0.1
4
4
  Summary: DiadFit
5
5
  Home-page: https://github.com/PennyWieser/DiadFit
6
6
  Author: Penny Wieser
@@ -9,13 +9,13 @@ License: UNKNOWN
9
9
  Platform: UNKNOWN
10
10
  Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.7
12
+ Requires-Python: >=3.8
13
13
  Description-Content-Type: text/markdown
14
14
  Requires-Dist: pandas
15
15
  Requires-Dist: numpy <2
16
16
  Requires-Dist: matplotlib
17
17
  Requires-Dist: scikit-learn
18
- Requires-Dist: scipy
18
+ Requires-Dist: scipy >1.6
19
19
  Requires-Dist: lmfit >=1.1.0
20
20
  Requires-Dist: tqdm
21
21
  Requires-Dist: python-docx