DiadFit 1.0.2__py3-none-any.whl → 1.0.8__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.
@@ -1352,6 +1352,158 @@ def get_settings():
1352
1352
  # Return the settings
1353
1353
  return settings.get('meta_path'), settings.get('spectra_path'), settings.get('spectra_filetype'), \
1354
1354
  settings.get('prefix'), settings.get('prefix_str'), settings.get('spectra_file_ext'), settings.get('meta_file_ext'),settings.get('TruPower')
1355
+
1356
+ ## Give nice column names
1357
+
1358
+ ## Lets do the look up code.
1359
+ #
1360
+
1361
+ def add_column_name_descriptions(df):
1362
+
1363
+ """ Adds a new to inputted dataframe, with a description of what the diadfit columns mean underneath
1364
+
1365
+ Parameters
1366
+ -------------------
1367
+ df: pandas dataframe, including some columns from DiadFit (can have other columns too)
1368
+
1369
+ Returns
1370
+ ----------------------
1371
+ df: A dataframe with a new row, with descriptions for columns matching our reference key.
1372
+
1373
+
1374
+
1375
+ """
1376
+ lookup_key = {
1377
+ 'filename': 'name of file',
1378
+ 'Density g/cm3': 'Density of CO2 in g/cm3',
1379
+ 'σ Density g/cm3': '1 sigma error on density (combined from peak fitting, Ne correction model, and densimeter equation)',
1380
+ 'σ Density g/cm3 (from Ne+peakfit)': '1 sigma error on density (from just peak fitting + Ne correction model)',
1381
+ 'σ Density g/cm3 (from densimeter)': '1 sigma error on density (from just the densimeter equation)',
1382
+ 'Corrected_Splitting': 'Splitting in cm-1 after correcting for instrument drift',
1383
+ 'Corrected_Splitting_σ': '1 sigma error on splitting (combined from peak fitting, Ne correction model)',
1384
+ 'Corrected_Splitting_σ_Ne': '1 sigma error on splitting just from Ne correction model',
1385
+ 'Corrected_Splitting_σ_peak_fit': '1 sigma error on splitting just from peak fitting',
1386
+ 'power (mW)': 'Laser power used in mW measured by WITEC TruPower',
1387
+ 'Spectral Center': 'Spectral Center used for analysis',
1388
+ 'in range': 'Y or N - Is the corrected splitting within the calibration range of the densimeter?',
1389
+ 'Notes': 'Which segment of the densimeter was used (e.g. which of several polynomials)',
1390
+ 'LowD_RT': 'Density calculated using the low density part of the Room Temp densimeter',
1391
+ 'HighD_RT': 'Density calculated using the high density part of the Room Temp densimeter',
1392
+ 'LowD_SC': 'Density calculated using the low density segment of the 37C densimeter',
1393
+ 'LowD_SC_σ': 'Error on density calculated using the low density segment of the 37C densimeter',
1394
+ 'MedD_RC': 'Density calculated using the medium density segment of the 37C densimeter',
1395
+ 'MedD_SC_σ': 'Error on density calculated using the medium density segment of the 37C densimeter',
1396
+ 'HighD_SC': 'Density calculated using the high density segment of the 37C densimeter',
1397
+ 'HighD_SC_σ': 'Error on density calculated using the high density segment of the 37C densimeter',
1398
+ 'Temperature': 'User entered Temp description: SupCrit or RoomT ',
1399
+ 'Splitting': 'Distance between fitted peak centers of Diad 1 and Diad 2 (cm-1)',
1400
+ 'Split_σ': 'Error on splitting',
1401
+ 'Diad1_Combofit_Cent': 'Fitted peak center (cm-1) of Diad1 (combined fit of diad, HB, gaussian background etc. )',
1402
+ 'Diad1_cent_err': 'Error on peak center of Diad1 (cm-1, calculated using lmfit)',
1403
+ 'Diad1_Combofit_Height': 'Height (intensity) of Diad1 combined fit',
1404
+ 'Diad1_Voigt_Cent': 'Fitted peak center (cm-1) of Diad1 for just the main peak',
1405
+ 'Diad1_Voigt_Area': 'Fitted area of Diad1 for just the main peak',
1406
+ 'Diad1_Voigt_Sigma': 'Fitted sigma of Diad1 for just the main peak',
1407
+ 'Diad1_Residual': 'Residual of fit to Diad1 (see DiadFit paper for explanation)',
1408
+ 'Diad1_Prop_Lor': 'Proportion of Lorentzian in Psuedovoigt peak for Diad1',
1409
+ 'Diad1_fwhm': 'Full Width Half Maximum of the fit to Diad1',
1410
+ 'Diad1_refit': 'Notes any warnings that flagged during iterative fitting',
1411
+ 'Diad2_Combofit_Cent': 'Fitted peak center (cm-1) of Diad2 (combined fit of diad, HB, gaussian background etc. )',
1412
+ 'Diad2_cent_err': 'Error on peak center of Diad2 (cm-1, calculated using lmfit)',
1413
+ 'Diad2_Combofit_Height': 'Height (intensity) of Diad2 combined fit',
1414
+ 'Diad2_Voigt_Cent': 'Fitted peak center (cm-1) of Diad2 for just the main peak',
1415
+ 'Diad2_Voigt_Area': 'Fitted area of Diad2 for just the main peak',
1416
+ 'Diad2_Voigt_Sigma': 'Fitted sigma of Diad2 for just the main peak',
1417
+ 'Diad2_Residual': 'Residual of fit to Diad2 (see DiadFit paper for explanation)',
1418
+ 'Diad2_Prop_Lor': 'Proportion of Lorentzian in Psuedovoigt peak for Diad2',
1419
+ 'Diad2_fwhm': 'Full Width Half Maximum of the fit to Diad2',
1420
+ 'Diad2_refit': 'Notes any warnings that flagged during iterative fitting',
1421
+ 'HB1_Cent': 'Fitted peak center of HB1 (cm-1)',
1422
+ 'HB1_Area': 'Fitted area of HB1',
1423
+ 'HB1_Sigma': 'Fitted sigma of HB1',
1424
+ 'HB2_Cent': 'Fitted peak center of HB2 (cm-1)',
1425
+ 'HB2_Area': 'Fitted area of HB2',
1426
+ 'HB2_Sigma': 'Fitted sigma of HB2',
1427
+ 'C13_Cent': 'Fitted peak center of the C13 peak (cm-1)',
1428
+ 'C13_Area': 'Fitted area of the C13 peak',
1429
+ 'C13_Sigma': 'Fitted sigma of the C13 peak',
1430
+ 'Diad2_Gauss_Cent': 'Fitted peak center (cm-1) of the Gaussian background on Diad2 (if used)',
1431
+ 'Diad2_Gauss_Area': 'Fitted area of the Gaussian background on Diad2',
1432
+ 'Diad2_Gauss_Sigma': 'Fitted sigma of the Gaussian backgroun on Diad2',
1433
+ 'Diad1_Gauss_Cent': 'Fitted peak center (cm-1) of the Gaussian background on Diad1 (if used)',
1434
+ 'Diad1_Gauss_Area': 'Fitted area of the Gaussian background on Diad1',
1435
+ 'Diad1_Gauss_Sigma': 'Fitted sigma of the Gaussian backgroun on Diad1',
1436
+ 'Diad1_Asym50': 'Asymmetry of Diad1 using a 50% intensity cut off (see DeVitre et al. 2023, Volcanica)',
1437
+ 'Diad1_Asym70': 'Asymmetry of Diad1 using a 70% intensity cut off (see DeVitre et al. 2023, Volcanica)',
1438
+ 'Diad1_Yuan2017_sym_factor': 'Symmetry factor of Diad1 following Yuan 2017',
1439
+ 'Diad1_Remigi2021_BSF': 'BSF factor of Diad1 following Remigi (2021)',
1440
+ 'Diad2_Asym50': 'Asymmetry of Diad2 using a 50% intensity cut off (see DeVitre et al. 2023, Volcanica)',
1441
+ 'Diad2_Asym70': 'Asymmetry of Diad2 using a 70% intensity cut off (see DeVitre et al. 2023, Volcanica)',
1442
+ 'Diad2_Yuan2017_sym_factor': 'Symmetry factor of Diad2 following Yuan 2017',
1443
+ 'Diad2_Remigi2021_BSF': 'BSF factor of Diad2 following Remigi (2021)',
1444
+ 'Diad1_PDF_Model': 'Name of the probability density function used to fit Diad1',
1445
+ 'Diad2_PDF_Model': 'Name of the probability density function used to fit Diad2',
1446
+ 'Standard': 'Is the analysis a standard (Yes/No)',
1447
+ 'date': 'Full date of analysis',
1448
+ 'Month': 'Month of analysis',
1449
+ 'Day': 'Day of the week of analysis',
1450
+ 'Int_time (s)': 'Integration time of each individual spectra in s',
1451
+ 'accumulations':'How many individual spectra are collected and averaged for a single reported spectra',
1452
+ 'Mag (X)': 'Objective used during analysis',
1453
+ 'duration': 'Duration of analysis as a string from WITEC',
1454
+ '24hr_time': 'Time converted to a 24 hr clock',
1455
+ 'sec since midnight': 'time of acquisition as seconds after midnight on the day of analysis',
1456
+ 'Peak_Cent_SO2': 'Fitted peak center (cm-1) of the SO2 peak',
1457
+ 'Peak_Area_SO2': 'Fitted peak area (cm-1) of the SO2 peak',
1458
+ 'Peak_Height_SO2': 'Fitted peak height (cm-1) of the SO2 peak',
1459
+ 'Model_name_x': 'Model used to fit the SO2 peak',
1460
+ 'Peak_Cent_Carb': 'Fitted peak center (cm-1) of the Carb peak',
1461
+ 'Peak_Area_Carb': 'Fitted peak area (cm-1) of the Carb peak',
1462
+ 'Peak_Height_Carb': 'Fitted peak height (cm-1) of the Carb peak',
1463
+ 'Model_name_y': 'Model used to fit the SO2 peak',
1464
+ 'Carb_Diad_Ratio': 'Area of carbonate peak divided by sum of area of Diad1 and Diad2 ',
1465
+ 'SO2_Diad_Ratio': 'Area of the SO2 peak divided by sum of area of Diad1 and Diad2',
1466
+ 'SO2_mol_ratio': 'Molar proportion of SO2 in the gas species',
1467
+ 'time': 'seconds after midnight used for Ne correction ',
1468
+ 'preferred_values': 'Preferred value for Ne correction',
1469
+ 'lower_values': 'Preferred value - 1 sigma for Ne correction',
1470
+ 'upper_values': 'Preferred value + 1 sigma for Ne correction',
1471
+
1472
+ 'SingleCalc_D_km': 'Depth calculated using the preferred (average) value for the input parameters of the MC simulation',
1473
+ 'SingleCalc_P_kbar': 'Pressure calculated using the preferred (average) value for the input parameters of the MC simulation',
1474
+ 'Mean_MC_P_kbar': 'Mean pressure calculated by averaging all the MC simulations for a single FI',
1475
+ 'Med_MC_P_kbar':'Median pressure calculated by averaging all the MC simulations for a single FI',
1476
+ 'std_dev_MC_P_kbar':'Std deviation of pressure calculated from all the MC simulations for a single FI',
1477
+ 'std_dev_MC_P_kbar_from_percentile':'Std deviation of pressure calculated from 84th-16th quantile/2 calculated from all the MC simulations for a single FI',
1478
+ 'Mean_MC_D_km': 'Mean depth calculated by averaging all the MC simulations for a single FI',
1479
+ 'Med_MC_D_km':'Median depth calculated by averaging all the MC simulations for a single FI',
1480
+ 'std_dev_MC_D_km':'Std deviation of depth calculated from all the MC simulations for a single FI',
1481
+ 'std_dev_MC_D_km_from_percentile':'Std deviation of depth calculated from 84th-16th quantile/2 calculated from all the MC simulations for a single FI',
1482
+ 'error_T_K': 'Input error in K for the Monte Carlo simulation',
1483
+ 'CO2_dens_gcm3_input': 'Input CO2 content in g/cm3 for the Monte Carlo simulation',
1484
+ 'error_CO2_dens_gcm3': 'Input CO2 error in g/cm3 for the Monte Carlo simulation',
1485
+ 'crust_dens_kgm3_input': 'Selected crustal density for the Monte Carlo simulation',
1486
+ 'error_crust_dens_kgm3':'Input crustal density error for the Monte Carlo simulation',
1487
+ 'model': 'Selected model to convert pressure to depth in the crust',
1488
+ 'EOS': 'Selected EOS to convert density to pressure'
1489
+
1490
+ }
1491
+
1492
+ # Create a list of descriptions based on the lookup key
1493
+ description_row = [lookup_key.get(col, '') for col in df.columns]
1494
+
1495
+ # Create a new DataFrame from the description row
1496
+ description_df = pd.DataFrame([description_row], columns=df.columns)
1497
+
1498
+ # Use pd.concat to combine the description row and original DataFrame
1499
+ df_with_descriptions = pd.concat([description_df, df], ignore_index=True)
1500
+
1501
+ # Display the DataFrame with descriptions
1502
+ df_with_descriptions
1503
+
1504
+ return df_with_descriptions
1505
+
1506
+
1355
1507
 
1356
1508
 
1357
1509
 
@@ -1,5 +1,6 @@
1
1
  import math
2
2
  import pandas as pd
3
+ import numpy as np
3
4
 
4
5
  def calculate_sigma(wavelength, vi_dict, T_K):
5
6
  """
@@ -85,3 +86,98 @@ def calculate_CO2_SO2_ratio(*, peak_area_SO2, peak_area_diad1, peak_area_diad2,w
85
86
 
86
87
 
87
88
  return pd.DataFrame(mol_perc)
89
+
90
+
91
+
92
+ ## Math for converting back and forth between Raman scattering cross sections
93
+
94
+ def calculate_wavelength_dependent_cross_section(wavelength_nm, T_C, Raman_shift_cm, wavelength_independent_cross_section ):
95
+ """ This function calculates the wavelength dependent cross section (lower case sigma) from the wavelength independent Raman scattering efficiency (Upper case sigma)
96
+
97
+ Parameters
98
+ ----------------
99
+ wavelength_nm:
100
+ laser wavelength used in nm to calculate the wavelength dependent cross section
101
+
102
+ wavelength_independent_cross_section:
103
+ Wavelength independent cross section
104
+
105
+ T_K:
106
+ absolute temperature in Kelvin
107
+
108
+ Raman_shift_cm:
109
+ Raman shift in cm-1 of peak of interest (e.g. 1151 for SO$_2$)
110
+
111
+ Returns
112
+ -----------------
113
+ Wavelength dependent cross section
114
+
115
+ """
116
+ Wavelength_cm1=1/wavelength_nm*10000000
117
+ constant =1-np.exp(((-6.626*10**-27)*(2.998*10**10)*Raman_shift_cm)/((1.381*10**-16)*(273.15+T_C)))
118
+ Wavelength_dependent = wavelength_independent_cross_section/(((Wavelength_cm1-Raman_shift_cm)**(-4)/(Wavelength_cm1-2331)**(-4))*constant)
119
+ return Wavelength_dependent
120
+
121
+ def calculate_wavelength_independent_cross_section(wavelength_nm, T_C, Raman_shift_cm, wavelength_dependent_cross_section ):
122
+ """ This function calculates the wavelength independent cross section (capital Sigma) from the wavelength dependent Raman scattering efficiency (lower case sigma)
123
+
124
+ Parameters
125
+ ----------------
126
+ wavelength_nm:
127
+ laser wavelength used in nm to calculate the wavelength dependent cross section
128
+
129
+ wavelength_dependent_cross_section:
130
+ Wavelength dependent cross section
131
+
132
+ T_K:
133
+ absolute temperature in Kelvin
134
+
135
+ Raman_shift_cm:
136
+ Raman shift in cm-1 of peak of interest (e.g. 1151 for SO$_2$)
137
+
138
+ Returns
139
+ -----------------
140
+ Wavelength independent cross section
141
+
142
+ """
143
+ Wavelength_cm1=1/wavelength_nm*10000000
144
+ constant =1-np.exp(((-6.626*10**-27)*(2.998*10**10)*Raman_shift_cm)/((1.381*10**-16)*(273.15+T_C)))
145
+ Wavelength_independent = wavelength_dependent_cross_section*((Wavelength_cm1-Raman_shift_cm)**(-4)/(Wavelength_cm1-2331)**(-4)*constant)
146
+ return Wavelength_independent
147
+
148
+ def convert_cross_section_wavelength1_wavelength2(wavelength_nm_1,wavelength_nm_2, Raman_shift_cm, wavelength_dependent_cross_section_wavelength1, T_C):
149
+ """ This function calculates the wavelength dependent cross section (lower case sigma) for laser wavelength 2 from the wavelength-dependent cross section for laser wavelength 1.
150
+
151
+
152
+ Parameters
153
+ ----------------
154
+ wavelength_nm_1:
155
+ laser wavelength used in nm to calculate the wavelength dependent cross section
156
+
157
+ wavelength_nm_2:
158
+ laser wavelength of the system of interest you are trying to calculate the wavelength dependent cross section for
159
+
160
+ wavelength_dependent_cross_section_wavelength1:
161
+ Wavelength dependent cross section
162
+
163
+ T_K:
164
+ absolute temperature in Kelvin
165
+
166
+ Raman_shift_cm:
167
+ Raman shift in cm-1 of peak of interest (e.g. 1151 for SO$_2$)
168
+
169
+ Returns
170
+ -----------------
171
+ Wavelength dependent cross section for wavelength2
172
+
173
+ """
174
+
175
+ # First calculate the independent cross section
176
+ ind_cross_sec=calculate_wavelength_independent_cross_section(wavelength_nm=wavelength_nm_1, T_C=T_C, Raman_shift_cm=Raman_shift_cm,
177
+ wavelength_dependent_cross_section =wavelength_dependent_cross_section_wavelength1)
178
+ print(ind_cross_sec)
179
+ dep_cross_sec=calculate_wavelength_dependent_cross_section(wavelength_nm=wavelength_nm_2, T_C=T_C, Raman_shift_cm=Raman_shift_cm, wavelength_independent_cross_section =ind_cross_sec)
180
+
181
+ return dep_cross_sec
182
+
183
+
DiadFit/ne_lines.py CHANGED
@@ -348,6 +348,11 @@ def calculate_Ne_line_positions(wavelength=532.05, cut_off_intensity=2000):
348
348
 
349
349
  Intensity=np.array([
350
350
 
351
+
352
+
353
+
354
+
355
+
351
356
  1500,
352
357
  12,
353
358
  500,
@@ -1531,9 +1536,9 @@ plot_figure=True, loop=True,
1531
1536
 
1532
1537
  df_combo=df
1533
1538
  pk1_peak_cent_values = df_combo['pk1_peak_cent'].values
1534
- pk1_peak_cent_errors = df_combo['error_pk1'].fillna(0).values
1539
+ pk1_peak_cent_errors = df_combo['error_pk1'].fillna(0).infer_objects().values
1535
1540
  pk2_peak_cent_values = df_combo['pk2_peak_cent'].values
1536
- pk2_peak_cent_errors = df_combo['error_pk2'].fillna(0).values
1541
+ pk2_peak_cent_errors = df_combo['error_pk2'].fillna(0).infer_objects().values
1537
1542
 
1538
1543
  constant=df_combo['deltaNe']
1539
1544
 
@@ -1568,7 +1573,7 @@ def plot_Ne_corrections(df=None, x_axis=None, x_label='index', marker='o', mec='
1568
1573
 
1569
1574
  # Pk1 center vs. X
1570
1575
 
1571
- ax5.errorbar(x, df['pk1_peak_cent'], xerr=0, yerr=df['error_pk1'].fillna(0),
1576
+ ax5.errorbar(x, df['pk1_peak_cent'], xerr=0, yerr=df['error_pk1'].fillna(0).infer_objects(),
1572
1577
  fmt='o', ecolor='k', elinewidth=0.8, mfc='b', ms=5, mec='k', capsize=3)
1573
1578
  ax5.set_xlabel(x_label)
1574
1579
  ax5.set_ylabel('Peak 1 center')
@@ -1576,15 +1581,15 @@ def plot_Ne_corrections(df=None, x_axis=None, x_label='index', marker='o', mec='
1576
1581
  # Pk2 center vs. X
1577
1582
 
1578
1583
  ax6.plot(x, df['pk2_peak_cent'], marker, mec='k', mfc='r')
1579
- ax6.errorbar(x, df['pk2_peak_cent'], xerr=0, yerr=df['error_pk2'].fillna(0),
1584
+ ax6.errorbar(x, df['pk2_peak_cent'], xerr=0, yerr=df['error_pk2'].fillna(0).infer_objects(),
1580
1585
  fmt='o', ecolor='k', elinewidth=0.8, mfc='r', ms=5, mec='k', capsize=3)
1581
1586
 
1582
1587
  ax6.set_xlabel(x_label)
1583
1588
  ax6.set_ylabel('Peak 2 center')
1584
1589
 
1585
1590
  #
1586
- ax3.errorbar(df['Ne_Corr'], df['pk2_peak_cent'], xerr=df['1σ_Ne_Corr'].fillna(0),
1587
- yerr=df['error_pk2'].fillna(0),
1591
+ ax3.errorbar(df['Ne_Corr'], df['pk2_peak_cent'], xerr=df['1σ_Ne_Corr'].fillna(0).infer_objects(),
1592
+ yerr=df['error_pk2'].fillna(0).infer_objects(),
1588
1593
  fmt='o', ecolor='k', elinewidth=0.8, mfc='b', ms=5, mec='k', capsize=3)
1589
1594
 
1590
1595
 
@@ -1592,14 +1597,14 @@ def plot_Ne_corrections(df=None, x_axis=None, x_label='index', marker='o', mec='
1592
1597
  ax3.set_ylabel('Peak 2 center')
1593
1598
 
1594
1599
 
1595
- ax4.errorbar(df['Ne_Corr'], df['pk1_peak_cent'], xerr=df['1σ_Ne_Corr'].fillna(0),
1596
- yerr=df['error_pk1'].fillna(0),
1600
+ ax4.errorbar(df['Ne_Corr'], df['pk1_peak_cent'], xerr=df['1σ_Ne_Corr'].fillna(0).infer_objects(),
1601
+ yerr=df['error_pk1'].fillna(0).infer_objects(),
1597
1602
  fmt='o', ecolor='k', elinewidth=0.8, mfc='b', ms=5, mec='k', capsize=3)
1598
1603
  ax4.set_xlabel('Ne Correction factor')
1599
1604
  ax4.set_ylabel('Peak 1 center')
1600
1605
 
1601
1606
  # Ne correction factor vs. time
1602
- ax1.errorbar(x, df['Ne_Corr'], xerr=0, yerr=df['1σ_Ne_Corr'].fillna(0),
1607
+ ax1.errorbar(x, df['Ne_Corr'], xerr=0, yerr=df['1σ_Ne_Corr'].fillna(0).infer_objects(),
1603
1608
  fmt='o', ecolor='k', elinewidth=0.8, mfc='grey', ms=5, mec='k',capsize=3)
1604
1609
 
1605
1610
  ax1.set_ylabel('Ne Correction factor')