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.
- DiadFit/CO2_EOS.py +17 -10
- DiadFit/CO2_H2O_EOS.py +110 -26
- DiadFit/_version.py +1 -1
- DiadFit/cosmicray_filter.py +2 -1
- DiadFit/densimeters.py +36 -7
- DiadFit/diads.py +228 -160
- DiadFit/error_propagation.py +252 -107
- DiadFit/importing_data_files.py +17 -11
- DiadFit/ne_lines.py +471 -440
- {DiadFit-0.0.81.dist-info → DiadFit-0.0.84.dist-info}/METADATA +3 -3
- {DiadFit-0.0.81.dist-info → DiadFit-0.0.84.dist-info}/RECORD +13 -13
- {DiadFit-0.0.81.dist-info → DiadFit-0.0.84.dist-info}/WHEEL +0 -0
- {DiadFit-0.0.81.dist-info → DiadFit-0.0.84.dist-info}/top_level.txt +0 -0
DiadFit/diads.py
CHANGED
@@ -19,6 +19,10 @@ from numpy import trapz
|
|
19
19
|
from scipy.integrate import simps
|
20
20
|
from scipy.interpolate import interp1d
|
21
21
|
|
22
|
+
# Allowed models
|
23
|
+
|
24
|
+
allowed_models = ["VoigtModel", "PseudoVoigtModel", "Pearson4Model", "SkewedVoigtModel"]
|
25
|
+
|
22
26
|
# For debuggin
|
23
27
|
|
24
28
|
#import warnings
|
@@ -236,8 +240,8 @@ def identify_diad_peaks(*, config: diad_id_config=diad_id_config(), path=None, f
|
|
236
240
|
diad2_HB2_max_offset=23+spec_res
|
237
241
|
|
238
242
|
# Spacing of HB from main peak.
|
239
|
-
diad1_HB1_min_offset=19
|
240
|
-
diad1_HB1_max_offset=
|
243
|
+
diad1_HB1_min_offset=19-spec_res
|
244
|
+
diad1_HB1_max_offset=23+spec_res
|
241
245
|
|
242
246
|
# Spacing of c13 from main peak
|
243
247
|
diad2_C13_min_offset=16.5-spec_res
|
@@ -1269,14 +1273,8 @@ min_cent=None, max_cent=None, min_sigma=None, max_sigma=None, amplitude=100, min
|
|
1269
1273
|
params: Peak fit parameters
|
1270
1274
|
|
1271
1275
|
"""
|
1272
|
-
|
1273
|
-
Model_combo=VoigtModel(prefix=prefix)#+ConstantModel(prefix=prefix) #Stops getting results
|
1274
|
-
|
1275
|
-
if model_name == "PseudoVoigtModel":
|
1276
|
-
Model_combo=PseudoVoigtModel(prefix=prefix)#+ConstantModel(prefix=prefix) #Stops getting results
|
1276
|
+
Model_combo = globals()[model_name](prefix=prefix)
|
1277
1277
|
|
1278
|
-
if model_name== "Pearson4Model":
|
1279
|
-
Model_combo=Pearson4Model(prefix=prefix)#+ConstantModel(prefix=prefix) #Stops getting results
|
1280
1278
|
peak = Model_combo
|
1281
1279
|
pars = peak.make_params()
|
1282
1280
|
|
@@ -1308,7 +1306,83 @@ min_cent=None, max_cent=None, min_sigma=None, max_sigma=None, amplitude=100, min
|
|
1308
1306
|
## Overall function for fitting diads in 1 single step
|
1309
1307
|
@dataclass
|
1310
1308
|
class diad1_fit_config:
|
1309
|
+
"""
|
1310
|
+
Configuration class for fitting Diad 1
|
1311
|
+
|
1312
|
+
This class stores configuration parameters for fitting Diad 1 and associated peaks.
|
1313
|
+
The class allows for easy customization of the fitting process.
|
1314
|
+
|
1315
|
+
Attributes:
|
1316
|
+
model_name (str): Default 'PseudoVoigtModel'.
|
1317
|
+
Model name for peak fitting. Choose from
|
1318
|
+
'PseudoVoigtModel', 'VoigtModel', 'GaussianModel', 'LorentzianModel', etc.
|
1319
|
+
|
1320
|
+
fit_peaks (int): Default 2
|
1321
|
+
Number of peaks to fit. 2 = Diad + HB, 1 = Diad.
|
1322
|
+
|
1323
|
+
N_poly_bck_diad1 (float): Default = 1
|
1324
|
+
Degree of polynomial for background subtraction. Default 1.
|
1325
|
+
|
1326
|
+
lower_bck_diad1 (Tuple[float, float]):
|
1327
|
+
Lower boundary for background fitting in cm-1. Default (1180, 1220)
|
1328
|
+
|
1329
|
+
upper_bck_diad1 (Tuple[float, float]):
|
1330
|
+
Upper boundary for background fitting in cm-1 Default (1300, 1350).
|
1331
|
+
|
1332
|
+
fit_gauss (Optional[bool]): Default True
|
1333
|
+
Fit a Gaussian peak if True. Helpful for very elevated spectra
|
1334
|
+
|
1335
|
+
gauss_amp (Optional[float]): Default = 1000
|
1336
|
+
Gaussian peak amplitude if `fit_gauss` is True. Default 1000.
|
1337
|
+
We find 2X HB intensity is a good guess on many instruments
|
1338
|
+
|
1339
|
+
diad_sigma (float): Default = 0.2
|
1340
|
+
Sigma of diad peak.
|
1341
|
+
|
1342
|
+
diad_sigma_min_allowance (float): Default = 0.2
|
1343
|
+
Tolerance on entered sigma. Means minimum allowed sigma is 0.2*sigma
|
1344
|
+
|
1345
|
+
diad_sigma_max_allowance (float): Default = 5
|
1346
|
+
Tolerance on entered sigma. Means minimum allowed sigma is 5*sigma
|
1347
|
+
|
1348
|
+
|
1349
|
+
diad_prom (float): Default = 100
|
1350
|
+
Peak amplitude for of the diad. Suggest users obtain from the estimated peak parameter dataframe
|
1311
1351
|
|
1352
|
+
HB_prom (float): Default = 20
|
1353
|
+
Peak amplitude for HB. Suggest users obtain from the estimated peak parameter dataframe
|
1354
|
+
|
1355
|
+
HB_sigma_min_allowance (float): Default = 0.05
|
1356
|
+
Means HB sigma cant be less than 0.05* sigma of first fitting peak (diad).
|
1357
|
+
|
1358
|
+
HB_sigma_max_allowance (float): Default = 3:
|
1359
|
+
Means HB sigma cant exceed 3* sigma of first fitting peak (diad)
|
1360
|
+
|
1361
|
+
HB_amp_min_allowance (float): Default =0.01
|
1362
|
+
Means HB amplitude cant be less than 0.01*amplitude of first fitted peak (diad).
|
1363
|
+
|
1364
|
+
HB_amp_max_allowance (float): Default = 1
|
1365
|
+
Means HB amplitude cant be more than 1*amplitude of first fitted peak (diad).
|
1366
|
+
|
1367
|
+
x_range_baseline (float): Default 75.
|
1368
|
+
Means that x axis of baseline shows diad position +- 75 x units.
|
1369
|
+
|
1370
|
+
y_range_baseline (float): Y-axis range for baseline display. Default 100.
|
1371
|
+
Shows a y axis scale that is 100 y units above the minimum baseline value, and 100 units above the maximum value
|
1372
|
+
|
1373
|
+
dpi (float): Default 200
|
1374
|
+
Figure resolution in dots per inch. Default 200.
|
1375
|
+
|
1376
|
+
x_range_residual (float): Default 20.
|
1377
|
+
Shows x values +-20 either side of the diad peak position in the residual plot.
|
1378
|
+
|
1379
|
+
return_other_params (bool): Return non-fitted parameters if True. Default False.
|
1380
|
+
|
1381
|
+
Methods:
|
1382
|
+
update_par(**kwargs):
|
1383
|
+
Updates configuration parameters. Raises AttributeError for unknown attributes.
|
1384
|
+
|
1385
|
+
"""
|
1312
1386
|
# What model to use
|
1313
1387
|
model_name: str = 'PseudoVoigtModel'
|
1314
1388
|
fit_peaks:int = 2
|
@@ -1351,10 +1425,100 @@ class diad1_fit_config:
|
|
1351
1425
|
# Do you want to return other parameters?
|
1352
1426
|
return_other_params: bool =False
|
1353
1427
|
|
1428
|
+
def update_par(self, **kwargs):
|
1429
|
+
for key, value in kwargs.items():
|
1430
|
+
if hasattr(self, key):
|
1431
|
+
setattr(self, key, value)
|
1432
|
+
else:
|
1433
|
+
raise AttributeError(f"'diad1_fit_config' object has no attribute '{key}'")
|
1434
|
+
|
1435
|
+
|
1354
1436
|
|
1355
1437
|
|
1356
1438
|
@dataclass
|
1357
1439
|
class diad2_fit_config:
|
1440
|
+
|
1441
|
+
"""
|
1442
|
+
Configuration class for fitting Diad 2
|
1443
|
+
|
1444
|
+
This class stores configuration parameters for fitting Diad 2 and associated peaks.
|
1445
|
+
The class allows for easy customization of the fitting process.
|
1446
|
+
|
1447
|
+
Attributes:
|
1448
|
+
model_name (str): Default 'PseudoVoigtModel'.
|
1449
|
+
Model name for peak fitting. Choose from
|
1450
|
+
'PseudoVoigtModel', 'VoigtModel', 'GaussianModel', 'LorentzianModel', etc.
|
1451
|
+
|
1452
|
+
fit_peaks (int): Default 2
|
1453
|
+
Number of peaks to fit. 3 = HB + Diad + C13, 2 = Diad + HB, 1 = Diad.
|
1454
|
+
|
1455
|
+
N_poly_bck_diad2 (float): Default = 1
|
1456
|
+
Degree of polynomial for background subtraction. Default 1.
|
1457
|
+
|
1458
|
+
lower_bck_diad2 (Tuple[float, float]):
|
1459
|
+
Lower boundary for background fitting in cm-1. Default (1300, 1360)
|
1460
|
+
|
1461
|
+
upper_bck_diad2 (Tuple[float, float]):
|
1462
|
+
Upper boundary for background fitting in cm-1 Default (1440, 1470)
|
1463
|
+
|
1464
|
+
fit_gauss (Optional[bool]): Default True
|
1465
|
+
Fit a Gaussian peak if True. Helpful for very elevated spectra
|
1466
|
+
|
1467
|
+
gauss_amp (Optional[float]): Default = 1000
|
1468
|
+
Gaussian peak amplitude if `fit_gauss` is True. Default 1000.
|
1469
|
+
We find 2X HB intensity is a good guess on many instruments
|
1470
|
+
|
1471
|
+
diad_sigma (float): Default = 0.2
|
1472
|
+
Sigma of diad peak.
|
1473
|
+
|
1474
|
+
diad_sigma_min_allowance (float): Default = 0.2
|
1475
|
+
Tolerance on entered sigma. Means minimum allowed sigma is 0.2*sigma
|
1476
|
+
|
1477
|
+
diad_sigma_max_allowance (float): Default = 5
|
1478
|
+
Tolerance on entered sigma. Means minimum allowed sigma is 5*sigma
|
1479
|
+
|
1480
|
+
|
1481
|
+
diad_prom (float): Default = 100
|
1482
|
+
Peak amplitude for of the diad. Suggest users obtain from the estimated peak parameter dataframe
|
1483
|
+
|
1484
|
+
HB_prom (float): Default = 20
|
1485
|
+
Peak amplitude for HB. Suggest users obtain from the estimated peak parameter dataframe
|
1486
|
+
|
1487
|
+
C13_prom (float): Default = 10
|
1488
|
+
Peak amplitude for C13. Suggest users obtain from the estimated peak parameter dataframe
|
1489
|
+
|
1490
|
+
HB_sigma_min_allowance (float): Default = 0.05
|
1491
|
+
Means HB sigma cant be less than 0.05* sigma of first fitting peak (diad).
|
1492
|
+
|
1493
|
+
HB_sigma_max_allowance (float): Default = 3:
|
1494
|
+
Means HB sigma cant exceed 3* sigma of first fitting peak (diad)
|
1495
|
+
|
1496
|
+
HB_amp_min_allowance (float): Default =0.01
|
1497
|
+
Means HB amplitude cant be less than 0.01*amplitude of first fitted peak (diad).
|
1498
|
+
|
1499
|
+
HB_amp_max_allowance (float): Default = 1
|
1500
|
+
Means HB amplitude cant be more than 1*amplitude of first fitted peak (diad).
|
1501
|
+
|
1502
|
+
x_range_baseline (float): Default 75.
|
1503
|
+
Means that x axis of baseline shows diad position +- 75 x units.
|
1504
|
+
|
1505
|
+
y_range_baseline (float): Y-axis range for baseline display. Default 100.
|
1506
|
+
Shows a y axis scale that is 100 y units above the minimum baseline value, and 100 units above the maximum value
|
1507
|
+
|
1508
|
+
dpi (float): Default 200
|
1509
|
+
Figure resolution in dots per inch. Default 200.
|
1510
|
+
|
1511
|
+
x_range_residual (float): Default 20.
|
1512
|
+
Shows x values +-20 either side of the diad peak position in the residual plot.
|
1513
|
+
|
1514
|
+
return_other_params (bool): Return non-fitted parameters if True. Default False.
|
1515
|
+
|
1516
|
+
Methods:
|
1517
|
+
update_par(**kwargs):
|
1518
|
+
Updates configuration parameters. Raises AttributeError for unknown attributes.
|
1519
|
+
|
1520
|
+
"""
|
1521
|
+
|
1358
1522
|
# Do you need a gaussian? Set position here if so
|
1359
1523
|
|
1360
1524
|
# What model to use
|
@@ -1382,6 +1546,7 @@ class diad2_fit_config:
|
|
1382
1546
|
# Peak amplitude
|
1383
1547
|
diad_prom: float = 100
|
1384
1548
|
HB_prom: float = 20
|
1549
|
+
C13_prom: float=10
|
1385
1550
|
HB_sigma_min_allowance=0.05
|
1386
1551
|
HB_sigma_max_allowance=3
|
1387
1552
|
HB_amp_min_allowance=0.01
|
@@ -1398,9 +1563,14 @@ class diad2_fit_config:
|
|
1398
1563
|
# Do you want to return other parameters?
|
1399
1564
|
return_other_params: bool =False
|
1400
1565
|
|
1401
|
-
C13_prom: float=10
|
1402
1566
|
|
1403
1567
|
|
1568
|
+
def update_par(self, **kwargs):
|
1569
|
+
for key, value in kwargs.items():
|
1570
|
+
if hasattr(self, key):
|
1571
|
+
setattr(self, key, value)
|
1572
|
+
else:
|
1573
|
+
raise AttributeError(f"'diad2_fit_config' object has no attribute '{key}'")
|
1404
1574
|
|
1405
1575
|
## Testing generic model
|
1406
1576
|
|
@@ -1504,16 +1674,10 @@ def fit_gaussian_voigt_generic_diad(config1, *, diad1=False, diad2=False, path=N
|
|
1504
1674
|
C13_initial_guess=C13_pos
|
1505
1675
|
|
1506
1676
|
|
1677
|
+
model_ini = globals()[config1.model_name]()
|
1678
|
+
|
1507
1679
|
|
1508
1680
|
|
1509
|
-
if config1.model_name=="VoigtModel":
|
1510
|
-
model_ini = VoigtModel()#+ ConstantModel()
|
1511
|
-
elif config1.model_name=="PseudoVoigtModel":
|
1512
|
-
model_ini = PseudoVoigtModel()#+ ConstantModel()
|
1513
|
-
elif config1.model_name=='Pearson4Model':
|
1514
|
-
model_ini = Pearson4Model()#+ ConstantModel()
|
1515
|
-
else:
|
1516
|
-
TypeError('Choice of model not yet supported - select VoigtModel, PseudoVoigtModel or Pearson4Model')
|
1517
1681
|
|
1518
1682
|
# Create initial peak params
|
1519
1683
|
# Set peak position to 2 spectral res units either side of the initial guess made above
|
@@ -1541,13 +1705,7 @@ def fit_gaussian_voigt_generic_diad(config1, *, diad1=False, diad2=False, path=N
|
|
1541
1705
|
|
1542
1706
|
# If there is 1 peak, e.g. if have a Nan for hotband
|
1543
1707
|
if fit_peaks==1:
|
1544
|
-
|
1545
|
-
model_F = VoigtModel(prefix='lz1_') #+ ConstantModel(prefix='c1')
|
1546
|
-
if config1.model_name=='PseudoVoigtModel':
|
1547
|
-
model_F = PseudoVoigtModel(prefix='lz1_') + ConstantModel(prefix='c1')
|
1548
|
-
if config1.model_name=='Pearson4Model':
|
1549
|
-
model_F = Pearson4Model(prefix='lz1_') + ConstantModel(prefix='c1')
|
1550
|
-
|
1708
|
+
model_F = globals()[config1.model_name](prefix='lz1_')
|
1551
1709
|
pars1 = model_F.make_params()
|
1552
1710
|
pars1['lz1_'+ 'amplitude'].set(calc_diad_amplitude, min=0, max=calc_diad_amplitude*10)
|
1553
1711
|
pars1['lz1_'+ 'center'].set(Center_ini, min=Center_ini-5*spec_res, max=Center_ini+5*spec_res)
|
@@ -1558,13 +1716,8 @@ def fit_gaussian_voigt_generic_diad(config1, *, diad1=False, diad2=False, path=N
|
|
1558
1716
|
|
1559
1717
|
# If there is more than one peak
|
1560
1718
|
else:
|
1561
|
-
#
|
1562
|
-
|
1563
|
-
model1 = VoigtModel(prefix='lz1_')# + ConstantModel(prefix='c1')
|
1564
|
-
if config1.model_name=='PseudoVoigtModel':
|
1565
|
-
model1 = PseudoVoigtModel(prefix='lz1_') #+ ConstantModel(prefix='c1')
|
1566
|
-
if config1.model_name=='Pearson4Model':
|
1567
|
-
model1 = Pearson4Model(prefix='lz1_') #+ ConstantModel(prefix='c1')
|
1719
|
+
# Previous versions had a constant for PV and P4 but not Voigt. Now removed for all
|
1720
|
+
model1 = globals()[config1.model_name](prefix='lz1_')
|
1568
1721
|
pars1 = model1.make_params()
|
1569
1722
|
pars1['lz1_'+ 'amplitude'].set(calc_diad_amplitude, min=0, max=calc_diad_amplitude*10)
|
1570
1723
|
|
@@ -1584,12 +1737,8 @@ def fit_gaussian_voigt_generic_diad(config1, *, diad1=False, diad2=False, path=N
|
|
1584
1737
|
|
1585
1738
|
# Second wee peak
|
1586
1739
|
prefix='lz2_'
|
1587
|
-
|
1588
|
-
|
1589
|
-
if config1.model_name=='PseudoVoigtModel':
|
1590
|
-
peak = PseudoVoigtModel(prefix='lz2_')# + ConstantModel(prefix='c1')
|
1591
|
-
if config1.model_name=='Pearson4Model':
|
1592
|
-
peak = Pearson4Model(prefix='lz2_')# + ConstantModel(prefix='c1')
|
1740
|
+
|
1741
|
+
peak = globals()[config1.model_name](prefix='lz2_')
|
1593
1742
|
|
1594
1743
|
|
1595
1744
|
pars = peak.make_params()
|
@@ -1839,7 +1988,6 @@ def fit_gaussian_voigt_generic_diad(config1, *, diad1=False, diad2=False, path=N
|
|
1839
1988
|
Peak1_Prop_Lor=result.best_values.get('lz1_fraction')
|
1840
1989
|
Peak1_fwhm=result.params['lz1_fwhm'].value
|
1841
1990
|
|
1842
|
-
Center_pk2_error=result.params.get('lz1_center')
|
1843
1991
|
|
1844
1992
|
error_pk2 = result.params['lz1_center'].stderr
|
1845
1993
|
|
@@ -2292,60 +2440,13 @@ def fit_diad_2_w_bck(*, config1: diad2_fit_config=diad2_fit_config(), config2: d
|
|
2292
2440
|
|
2293
2441
|
|
2294
2442
|
Parameters
|
2295
|
-
|
2296
|
-
config1: by default uses diad2_fit_config(). Options to edit within this:
|
2297
|
-
|
2298
|
-
N_poly_bck_diad2: int
|
2299
|
-
degree of polynomial to fit to the background.
|
2300
|
-
|
2301
|
-
model_name: str
|
2302
|
-
What type of peak you want to fit, either 'PseudoVoigtModel' or 'VoigtModel'
|
2303
|
-
|
2304
|
-
fit_peaks: int
|
2305
|
-
Number of peaks to fit. 1 = just diad, 2= diad and Hotband, 3= diad, hotband, C13
|
2306
|
-
|
2307
|
-
lower_bck_diad2, upper_bck_diad2: [float, float]
|
2308
|
-
background position to left and right of overal diad region (inc diad+-HB+-C13)
|
2309
|
-
|
2310
|
-
fit_gauss: bool
|
2311
|
-
If True, fits a gaussian peak
|
2312
|
-
|
2313
|
-
gauss_amp: float
|
2314
|
-
Estimate of amplitude of Gaussian peak (we find a good first guess is 2* the absolute prominence of the HB peak)
|
2315
|
-
|
2316
|
-
diad_sigma, HB_sigma: float
|
2317
|
-
Estimate of the amplitude of the diad peak/HB peak
|
2318
|
-
|
2319
|
-
diad_prom, HB_prom, C13_prom: float
|
2320
|
-
Estimate of prominence of peak. Used alongside sigma to estimate the amplitude of the diad to aid peak fitting.
|
2321
|
-
|
2322
|
-
|
2323
|
-
diad_sigma_min_allowance, diad_sigma_min_allowance: float
|
2324
|
-
HB_sigma_min_allowance, HB_sigma_max_allowance: float
|
2325
|
-
Factor that sigma of peak is allowed to deviate from 1st guess (e.g. max=2, 2* guess, min=0.5, 0.5 * guess).
|
2326
|
-
|
2327
|
-
diad_amp_min_allowance, diad_amp_min_allowance: float
|
2328
|
-
HB_amp_min_allowance, HB_amp_max_allowance: float
|
2329
|
-
Factor that the amplitude of peak is allowed to deviate from 1st guess (e.g. max=2, 2* guess, min=0.5, 0.5 * guess).
|
2443
|
+
------------------
|
2330
2444
|
|
2331
|
-
|
2332
|
-
|
2445
|
+
diad_id_config()
|
2446
|
+
Dataclass of parameters used to look for peaks. Uses any excluded ranges from this.
|
2333
2447
|
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
y_range_baseline: float or None
|
2338
|
-
Sets y axis of baseline plot as minimum balue of baseline region -y_range_baseline/3,
|
2339
|
-
and the upper value as max value of baseline region + y_range_baseline
|
2340
|
-
Baseline region is the defined region of baseline minus any points outside the sigma filter
|
2341
|
-
|
2342
|
-
x_range_residual: float
|
2343
|
-
Distance either side of diad center to show on residual plot.
|
2344
|
-
|
2345
|
-
dpi: float
|
2346
|
-
dpi to save figure at of overall fits
|
2347
|
-
|
2348
|
-
config2: diad_id_config() file. Only thing it uses from this is any excluded ranges
|
2448
|
+
diad2_fit_config()
|
2449
|
+
Dataclass of parameters used to find peaks. Use help on this dataclass to get options.
|
2349
2450
|
|
2350
2451
|
path: str
|
2351
2452
|
Folder user wishes to read data from
|
@@ -2360,28 +2461,28 @@ def fit_diad_2_w_bck(*, config1: diad2_fit_config=diad2_fit_config(), config2: d
|
|
2360
2461
|
plot_figure: bool
|
2361
2462
|
if True, saves figure
|
2362
2463
|
|
2464
|
+
close_fig: bool
|
2465
|
+
if True, displays figure in Notebook. If False, closes it (you can still find it saved)
|
2466
|
+
|
2363
2467
|
Diad_pos: float
|
2364
|
-
Estimate of diad position
|
2468
|
+
Estimate of diad peak position
|
2365
2469
|
|
2366
2470
|
HB_pos: float
|
2367
|
-
Estimate of HB position
|
2471
|
+
Estimate of HB peak position
|
2368
2472
|
|
2369
2473
|
C13_pos: float
|
2370
|
-
Estimate of C13 position
|
2474
|
+
Estimate of C13 peak position
|
2371
2475
|
|
2372
|
-
close_fig: bool
|
2373
|
-
if True, displays figure in Notebook. If False, closes it (you can still find it saved)
|
2374
2476
|
|
2375
|
-
|
2376
|
-
|
2377
|
-
|
2477
|
+
Returns
|
2478
|
+
------------
|
2479
|
+
if return_other_params is False (default)
|
2480
|
+
returns a dataframe of peak parameters
|
2481
|
+
if True, also returns:
|
2378
2482
|
result: fit parameters
|
2379
2483
|
y_best_fit: best fit to all curves in y
|
2380
2484
|
x_lin: linspace of best fit coordinates in x.
|
2381
2485
|
|
2382
|
-
Returns
|
2383
|
-
------------
|
2384
|
-
see above. Depends in returns_other_params
|
2385
2486
|
|
2386
2487
|
|
2387
2488
|
|
@@ -2390,6 +2491,13 @@ def fit_diad_2_w_bck(*, config1: diad2_fit_config=diad2_fit_config(), config2: d
|
|
2390
2491
|
if 'CRR' in filename:
|
2391
2492
|
filetype='headless_txt'
|
2392
2493
|
|
2494
|
+
model=config1.model_name
|
2495
|
+
|
2496
|
+
if model not in allowed_models:
|
2497
|
+
raise ValueError(f"Unsupported model: {model}. Supported models are: {', '.join(allowed_models)}")
|
2498
|
+
|
2499
|
+
|
2500
|
+
|
2393
2501
|
# Check number of peaks makes sense
|
2394
2502
|
fit_peaks=config1.fit_peaks
|
2395
2503
|
if diad_array is None:
|
@@ -2761,6 +2869,7 @@ def fit_diad_2_w_bck(*, config1: diad2_fit_config=diad2_fit_config(), config2: d
|
|
2761
2869
|
df_out['Diad2_Asym70']=Skew80['Skewness_diad2']
|
2762
2870
|
df_out['Diad2_Yuan2017_sym_factor']=(df_out['Diad2_fwhm'])*(df_out['Diad2_Asym50']-1)
|
2763
2871
|
df_out['Diad2_Remigi2021_BSF']=df_out['Diad2_fwhm']/df_out['Diad2_Combofit_Height']
|
2872
|
+
df_out['Diad2_PDF_Model']=model
|
2764
2873
|
|
2765
2874
|
|
2766
2875
|
if config1.return_other_params is False:
|
@@ -2782,57 +2891,12 @@ def fit_diad_1_w_bck(*, config1: diad1_fit_config=diad1_fit_config(), config2: d
|
|
2782
2891
|
|
2783
2892
|
Parameters
|
2784
2893
|
-----------
|
2785
|
-
|
2786
|
-
|
2787
|
-
N_poly_bck_diad1: int
|
2788
|
-
degree of polynomial to fit to the background.
|
2789
|
-
|
2790
|
-
model_name: str
|
2791
|
-
What type of peak you want to fit, either 'PseudoVoigtModel' or 'VoigtModel'
|
2792
|
-
|
2793
|
-
fit_peaks: int
|
2794
|
-
Number of peaks to fit. 1 = just diad, 2= diad
|
2795
|
-
|
2796
|
-
lower_bck_diad1, upper_bck_diad1: [float, float]
|
2797
|
-
background position to left and right of overal diad region (inc diad+-HB+-C13)
|
2798
|
-
|
2799
|
-
fit_gauss: bool
|
2800
|
-
If True, fits a gaussian peak
|
2801
|
-
|
2802
|
-
gauss_amp: float
|
2803
|
-
Estimate of amplitude of Gaussian peak (we find a good first guess is 2* the absolute prominence of the HB peak)
|
2804
|
-
|
2805
|
-
diad_sigma, HB_sigma: float
|
2806
|
-
Estimate of the amplitude of the diad peak/HB peak
|
2807
|
-
|
2808
|
-
diad_prom, HB_prom, C13_prom: float
|
2809
|
-
Estimate of prominence of peak. Used alongside sigma to estimate the amplitude of the diad to aid peak fitting.
|
2810
|
-
|
2894
|
+
diad_id_config()
|
2895
|
+
Dataclass of parameters used to look for peaks. Uses any excluded ranges from this.
|
2811
2896
|
|
2812
|
-
|
2813
|
-
|
2814
|
-
Factor that sigma of peak is allowed to deviate from 1st guess (e.g. max=2, 2* guess, min=0.5, 0.5 * guess).
|
2897
|
+
diad1_fit_config()
|
2898
|
+
Dataclass of parameters used to find peaks. Use help on this dataclass to get options
|
2815
2899
|
|
2816
|
-
diad_amp_min_allowance, diad_amp_min_allowance: float
|
2817
|
-
HB_amp_min_allowance, HB_amp_max_allowance: float
|
2818
|
-
Factor that the amplitude of peak is allowed to deviate from 1st guess (e.g. max=2, 2* guess, min=0.5, 0.5 * guess).
|
2819
|
-
|
2820
|
-
|
2821
|
-
x_range_baseline: float or None
|
2822
|
-
Sets x limit of plot showing baselines to diad center - x_range_baseline, and +x_range_baseline
|
2823
|
-
|
2824
|
-
y_range_baseline: float or None
|
2825
|
-
Sets y axis of baseline plot as minimum balue of baseline region -y_range_baseline/3,
|
2826
|
-
and the upper value as max value of baseline region + y_range_baseline
|
2827
|
-
Baseline region is the defined region of baseline minus any points outside the sigma filter
|
2828
|
-
|
2829
|
-
x_range_residual: float
|
2830
|
-
Distance either side of diad center to show on residual plot.
|
2831
|
-
|
2832
|
-
dpi: float
|
2833
|
-
dpi to save figure at of overall fits
|
2834
|
-
|
2835
|
-
config2: diad_id_config() file. Only thing it uses from this is any excluded ranges
|
2836
2900
|
|
2837
2901
|
path: str
|
2838
2902
|
Folder user wishes to read data from
|
@@ -2857,22 +2921,26 @@ def fit_diad_1_w_bck(*, config1: diad1_fit_config=diad1_fit_config(), config2: d
|
|
2857
2921
|
close_fig: bool
|
2858
2922
|
if True, displays figure in Notebook. If False, closes it (you can still find it saved)
|
2859
2923
|
|
2860
|
-
|
2861
|
-
|
2862
|
-
|
2924
|
+
Returns
|
2925
|
+
------------
|
2926
|
+
if return_other_params is False (default)
|
2927
|
+
returns a dataframe of peak parameters
|
2928
|
+
if True, also returns:
|
2863
2929
|
result: fit parameters
|
2864
2930
|
y_best_fit: best fit to all curves in y
|
2865
2931
|
x_lin: linspace of best fit coordinates in x.
|
2866
2932
|
|
2867
|
-
Returns
|
2868
|
-
------------
|
2869
|
-
see above. Depends in returns_other_params
|
2870
|
-
|
2871
2933
|
|
2872
2934
|
"""
|
2935
|
+
|
2873
2936
|
if 'CRR' in filename:
|
2874
2937
|
filetype='headless_txt'
|
2875
2938
|
|
2939
|
+
model=config1.model_name
|
2940
|
+
|
2941
|
+
if model not in allowed_models:
|
2942
|
+
raise ValueError(f"Unsupported model: {model}. Supported models are: {', '.join(allowed_models)}")
|
2943
|
+
|
2876
2944
|
fit_peaks=config1.fit_peaks
|
2877
2945
|
|
2878
2946
|
if fit_peaks==2:
|
@@ -3212,7 +3280,7 @@ def fit_diad_1_w_bck(*, config1: diad1_fit_config=diad1_fit_config(), config2: d
|
|
3212
3280
|
df_out['Diad1_Remigi2021_BSF']=df_out['Diad1_fwhm']/df_out['Diad1_Combofit_Height']
|
3213
3281
|
|
3214
3282
|
|
3215
|
-
|
3283
|
+
df_out['Diad1_PDF_Model']=model
|
3216
3284
|
|
3217
3285
|
if config1.return_other_params is False:
|
3218
3286
|
return df_out
|
@@ -3288,7 +3356,7 @@ to_clipboard=False, path=None):
|
|
3288
3356
|
'HB1_Cent', 'HB1_Area', 'HB1_Sigma', 'HB2_Cent', 'HB2_Area', 'HB2_Sigma', 'C13_Cent', 'C13_Area', 'C13_Sigma',
|
3289
3357
|
'Diad2_Gauss_Cent', 'Diad2_Gauss_Area','Diad2_Gauss_Sigma', 'Diad1_Gauss_Cent', 'Diad1_Gauss_Area','Diad1_Gauss_Sigma', 'Diad1_Asym50', 'Diad1_Asym70', 'Diad1_Yuan2017_sym_factor',
|
3290
3358
|
'Diad1_Remigi2021_BSF','Diad2_Asym50', 'Diad2_Asym70', 'Diad2_Yuan2017_sym_factor',
|
3291
|
-
'Diad2_Remigi2021_BSF']
|
3359
|
+
'Diad2_Remigi2021_BSF', 'Diad1_PDF_Model', 'Diad2_PDF_Model']
|
3292
3360
|
|
3293
3361
|
|
3294
3362
|
|