screamlab 0.3.0__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. {screamlab-0.3.0/screamlab.egg-info → screamlab-0.3.2}/PKG-INFO +1 -1
  2. screamlab-0.3.2/VERSION +1 -0
  3. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/dataset.cpython-310.pyc +0 -0
  4. screamlab-0.3.2/screamlab/__pycache__/dataset.cpython-313.pyc +0 -0
  5. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/functions.cpython-310.pyc +0 -0
  6. screamlab-0.3.2/screamlab/__pycache__/io.cpython-310.pyc +0 -0
  7. screamlab-0.3.2/screamlab/__pycache__/settings.cpython-310.pyc +0 -0
  8. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/settings.cpython-313.pyc +0 -0
  9. screamlab-0.3.2/screamlab/__pycache__/utils.cpython-310.pyc +0 -0
  10. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/dataset.py +67 -22
  11. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/functions.py +189 -4
  12. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/io.py +114 -36
  13. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/settings.py +21 -10
  14. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/utils.py +307 -7
  15. {screamlab-0.3.0 → screamlab-0.3.2/screamlab.egg-info}/PKG-INFO +1 -1
  16. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab.egg-info/SOURCES.txt +1 -0
  17. {screamlab-0.3.0 → screamlab-0.3.2}/tests/test_exporter_with_real_data.py +2 -2
  18. screamlab-0.3.2/tests/test_exporter_with_real_data_pseudo_2D.py +92 -0
  19. {screamlab-0.3.0 → screamlab-0.3.2}/tests/test_utils.py +12 -9
  20. screamlab-0.3.0/VERSION +0 -1
  21. screamlab-0.3.0/screamlab/__pycache__/dataset.cpython-313.pyc +0 -0
  22. screamlab-0.3.0/screamlab/__pycache__/io.cpython-310.pyc +0 -0
  23. screamlab-0.3.0/screamlab/__pycache__/settings.cpython-310.pyc +0 -0
  24. screamlab-0.3.0/screamlab/__pycache__/utils.cpython-310.pyc +0 -0
  25. {screamlab-0.3.0 → screamlab-0.3.2}/LICENSE +0 -0
  26. {screamlab-0.3.0 → screamlab-0.3.2}/MANIFEST.in +0 -0
  27. {screamlab-0.3.0 → screamlab-0.3.2}/README.rst +0 -0
  28. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__init__.py +0 -0
  29. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/__init__.cpython-310.pyc +0 -0
  30. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/__init__.cpython-312.pyc +0 -0
  31. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/__init__.cpython-313.pyc +0 -0
  32. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/__init__.cpython-38.pyc +0 -0
  33. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/dataset.cpython-312.pyc +0 -0
  34. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/functions.cpython-312.pyc +0 -0
  35. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/functions.cpython-313.pyc +0 -0
  36. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/io.cpython-312.pyc +0 -0
  37. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/io.cpython-313.pyc +0 -0
  38. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/settings.cpython-312.pyc +0 -0
  39. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/utils.cpython-312.pyc +0 -0
  40. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab/__pycache__/utils.cpython-313.pyc +0 -0
  41. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab.egg-info/dependency_links.txt +0 -0
  42. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab.egg-info/requires.txt +0 -0
  43. {screamlab-0.3.0 → screamlab-0.3.2}/screamlab.egg-info/top_level.txt +0 -0
  44. {screamlab-0.3.0 → screamlab-0.3.2}/setup.cfg +0 -0
  45. {screamlab-0.3.0 → screamlab-0.3.2}/setup.py +0 -0
  46. {screamlab-0.3.0 → screamlab-0.3.2}/tests/test_dataset.py +0 -0
  47. {screamlab-0.3.0 → screamlab-0.3.2}/tests/test_io.py +0 -0
  48. {screamlab-0.3.0 → screamlab-0.3.2}/tests/test_settings.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: screamlab
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Package for reproducible evaluation of SCREAM-DNP data.
5
5
  Home-page: https://github.com/FlorianTaube/screamlab
6
6
  Author: Florian Taube
@@ -0,0 +1 @@
1
+ 0.3.2
@@ -15,6 +15,7 @@ Classes:
15
15
  import sys
16
16
  from datetime import datetime
17
17
  import numpy as np
18
+ from lmfit import Parameters
18
19
  from screamlab import io, utils, settings, functions
19
20
 
20
21
 
@@ -74,6 +75,10 @@ class Dataset:
74
75
  f"Start generating result files. ({self.props.output_folder})"
75
76
  )
76
77
  self._print_all()
78
+ print(
79
+ f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}: "
80
+ f"Finished with {self.props.path_to_experiment}"
81
+ )
77
82
 
78
83
  def _start_buildup_fit_from_spectra(self):
79
84
  """Starts buildup fitting using data imported from spectra CSV files."""
@@ -177,7 +182,11 @@ class Dataset:
177
182
  "biexponential_with_offset": utils.BiexpFitterWithOffset,
178
183
  "exponential": utils.ExpFitter,
179
184
  "exponential_with_offset": utils.ExpFitterWithOffset,
180
- "streched_exponential": utils.StrechedExponentialFitter,
185
+ "stretched_exponential": utils.StretchedExponentialFitter,
186
+ "exponential_decay": utils.ExpDecayFitter,
187
+ "exponential_decay_with_offset": utils.ExpDecayFitterWithOffset,
188
+ "stretched_exponential_decay": utils.StretchedExponentialDecayFitter,
189
+ "biexponential_decay": utils.BiexponentialDecayFitter,
181
190
  }
182
191
 
183
192
  for b_type in self.props.buildup_types:
@@ -234,6 +243,21 @@ class Dataset:
234
243
  if f"{peak.peak_label}_{lw}_0" in result.params
235
244
  }
236
245
 
246
+ def _transform_result_format(self, results):
247
+ print(results)
248
+ params_new = Parameters()
249
+ for result in results:
250
+ for name, par in result.params.items():
251
+ params_new.add(
252
+ name,
253
+ value=par.value,
254
+ vary=par.vary,
255
+ min=par.min,
256
+ max=par.max,
257
+ expr=par.expr,
258
+ )
259
+ return params_new
260
+
237
261
 
238
262
  class Spectra:
239
263
  """
@@ -286,7 +310,6 @@ class Peak:
286
310
 
287
311
  :return: A string describing the peak's attributes.
288
312
  """
289
-
290
313
  return (
291
314
  f"Peak center: {self.peak_center}\n"
292
315
  f"Peak label: {self.peak_label}\n"
@@ -301,6 +324,24 @@ class Peak:
301
324
  )
302
325
 
303
326
  def to_string(self, spectrum_fit_type):
327
+ """
328
+ Returns a string representation of the peak.
329
+
330
+ If `spectrum_fit_type` is "numint", detailed peak information
331
+ is returned, including center, label, sign, and integration range.
332
+ Otherwise, the default string representation of the object is returned.
333
+
334
+ Args:
335
+ spectrum_fit_type (str): The type of spectrum fitting.
336
+ Supports "numint" for numerical integration.
337
+
338
+ Returns
339
+ -------
340
+ str: A formatted string with peak information, or the default
341
+ string representation of the object.
342
+
343
+
344
+ """
304
345
  if spectrum_fit_type == "numint":
305
346
  return (
306
347
  f"Peak center: {self.peak_center} ppm\n"
@@ -308,8 +349,7 @@ class Peak:
308
349
  f"Peak sign: {self.peak_sign}\n"
309
350
  f"Numerical integration range: {self.integration_range} ppm\n"
310
351
  )
311
- else:
312
- return str(self)
352
+ return str(self)
313
353
 
314
354
  def _format_fitting_range(self, fit_type):
315
355
  a_max = "0 and inf" if self.peak_sign == "+" else "-inf and 0"
@@ -376,12 +416,9 @@ class Peak:
376
416
  :param args: Tuple containing result and spectra.
377
417
  """
378
418
  result, spectra = args
379
-
380
419
  self._buildup_vals = BuildupList()
381
420
  if isinstance(result, dict):
382
- self._buildup_vals.set_num_int_vals(
383
- result[self], spectra, self.peak_label
384
- )
421
+ self._buildup_vals.set_num_int_vals(result[self], spectra)
385
422
  else:
386
423
  self._buildup_vals.set_vals(result, spectra, self.peak_label)
387
424
 
@@ -668,7 +705,7 @@ class BuildupList:
668
705
  self._set_intensity(result, label, spectra)
669
706
  self._sort_lists()
670
707
 
671
- def set_num_int_vals(self, result, spectra, label):
708
+ def set_num_int_vals(self, result, spectra):
672
709
  """
673
710
  Sets buildup values from numerical integration.
674
711
 
@@ -690,20 +727,26 @@ class BuildupList:
690
727
  last_digid = None
691
728
  self.intensity = []
692
729
  val_list = []
693
- for param in result.params:
694
- if label in param:
695
- if last_digid != param.split("_")[-1]:
696
- if val_list:
697
- self.intensity.append(
698
- self._calc_integral(
699
- val_list, spectra[int(last_digid)]
730
+ res_list = []
731
+ if not isinstance(result, list):
732
+ res_list.append(result)
733
+ else:
734
+ res_list = result
735
+ for single_result in res_list:
736
+ for param in single_result.params:
737
+ if label in param:
738
+ if last_digid != param.split("_")[-1]:
739
+ if val_list:
740
+ self.intensity.append(
741
+ self._calc_integral(
742
+ val_list, spectra[int(last_digid)]
743
+ )
700
744
  )
701
- )
702
- last_digid = param.split("_")[-1]
703
- val_list = []
704
- val_list.append(float(result.params[param].value))
705
- if param.split("_")[-2] == "gamma":
706
- val_list.append("gamma")
745
+ last_digid = param.split("_")[-1]
746
+ val_list = []
747
+ val_list.append(float(single_result.params[param].value))
748
+ if param.split("_")[-2] == "gamma":
749
+ val_list.append("gamma")
707
750
  self.intensity.append(
708
751
  self._calc_integral(val_list, spectra[int(last_digid)])
709
752
  )
@@ -724,6 +767,8 @@ class BuildupList:
724
767
  """
725
768
  simspec = [0 for _ in range(len(spectrum.x_axis))]
726
769
  simspec = functions.calc_peak(spectrum.x_axis, simspec, val_list)
770
+ if hasattr(np, "trapezoid"):
771
+ return np.trapezoid(simspec)
727
772
  return np.trapz(simspec)
728
773
 
729
774
  def _sort_lists(self):
@@ -169,6 +169,95 @@ def calc_stretched_exponential(time_vals, param):
169
169
  )
170
170
 
171
171
 
172
+ def calc_stretchedexpdecay(time_vals, param):
173
+ """
174
+ Compute values of a stretched exponential decay function over time.
175
+
176
+ The function models the equation:
177
+ I(t) = Af * exp((-t / tf)^beta)
178
+
179
+ where:
180
+ - I(t) : The output value at time t
181
+ - A : Amplitude (maximum value the function approaches)
182
+ - tf : Time constant (controls the rate of growth)
183
+ - beta : stretching exponent
184
+
185
+ Returns
186
+ -------
187
+ list: Stretched exponential profile evaluated at t.
188
+
189
+ """
190
+ return list(
191
+ param[0] * np.exp(-((np.asarray(time_vals) / param[1]) ** param[2]))
192
+ )
193
+
194
+
195
+ def calc_biexpdecay(time_vals, param):
196
+ """
197
+ Compute values of a biexponential decay function over time.
198
+
199
+ The function models the equation:
200
+ I(t) = Af * exp(-t / tf)) + As * exp(-t / ts))
201
+
202
+ where:
203
+ - I(t) : The output value at time t
204
+ - Af, As: Amplitudes (maximum value the function approaches)
205
+ - tf, ts: Time constants (controls the rate of growth)
206
+
207
+
208
+ Returns
209
+ -------
210
+ list: Biexponential profile evaluated at t.
211
+
212
+ """
213
+ return list(
214
+ param[0] * np.exp(-np.asarray(time_vals) / param[2])
215
+ + param[1] * np.exp(-np.asarray(time_vals) / param[3])
216
+ )
217
+
218
+
219
+ def calc_expdecay(time_vals, param):
220
+ """
221
+ Compute values of an exponential growth function over time.
222
+
223
+ The function models the equation:
224
+ I(t) = A * exp(-t / t)
225
+
226
+ where:
227
+ - I(t) : The output value at time t
228
+ - A : Amplitude (maximum value the function approaches)
229
+ - t : Time constant (controls the rate of decay)
230
+
231
+ Returns
232
+ -------
233
+ list: Exponential profile evaluated at t.
234
+
235
+ """
236
+ return list(param[0] * np.exp(-np.asarray(time_vals) / param[1]))
237
+
238
+
239
+ def calc_expdecaywithoffset(time_vals, param):
240
+ """
241
+ Compute values of an exponential growth function over time.
242
+
243
+ The function models the equation:
244
+ I(t) = A * exp(-t / t) + I0
245
+
246
+ where:
247
+ - I(t) : The output value at time t
248
+ - A : Amplitude (maximum value the function approaches)
249
+ - t : Time constant (controls the rate of decay)
250
+
251
+ Returns
252
+ -------
253
+ list: Exponential profile evaluated at t.
254
+
255
+ """
256
+ return list(
257
+ param[0] * np.exp(-np.asarray(time_vals) / param[1]) + param[2]
258
+ )
259
+
260
+
172
261
  def calc_biexponential(time_vals, param):
173
262
  """
174
263
  Compute values of a biexponential growth function over time.
@@ -245,7 +334,7 @@ def calc_biexponential_with_offset(time_vals, param):
245
334
  )
246
335
 
247
336
 
248
- def generate_spectra_param_dict(params):
337
+ def generate_spectra_param_dict_global(params):
249
338
  """
250
339
  Generate a dictionary of spectral parameters from a list of parameter names.
251
340
 
@@ -278,6 +367,40 @@ def generate_spectra_param_dict(params):
278
367
  return param_dict
279
368
 
280
369
 
370
+ def generate_spectra_param_dict_individual(params):
371
+ """
372
+ Generate a dictionary of spectral parameters from a list of parameter names.
373
+
374
+ :param params: Dictionary of parameter names and values.
375
+ :return: Dictionary of structured parameter values.
376
+ """
377
+ param_dict = {}
378
+ dict_index = -1
379
+ for list_element in params:
380
+ prefix, lastfix = None, None
381
+ param_value_list = []
382
+ for param in list_element.params:
383
+ parts = re.split(r"_(cen|amp|sigma|gamma)_", param)
384
+ if prefix != parts[0]:
385
+ if param_value_list:
386
+ param_dict[dict_index].append(param_value_list)
387
+ prefix = parts[0]
388
+ param_value_list = []
389
+ if lastfix != parts[2]:
390
+ if param_value_list:
391
+ param_dict[dict_index].append(param_value_list)
392
+ param_value_list = []
393
+ lastfix = parts[2]
394
+ dict_index += 1
395
+ if dict_index not in param_dict:
396
+ param_dict[dict_index] = []
397
+ param_value_list.append(float(list_element.params[param].value))
398
+ if parts[1] == "gamma":
399
+ param_value_list.append("gam")
400
+ param_dict[dict_index].append(param_value_list)
401
+ return param_dict
402
+
403
+
281
404
  def calc_peak(x_axis, simspec, val):
282
405
  """Simulates spectra based on given parameters."""
283
406
  if len(val) == 5:
@@ -303,8 +426,9 @@ def format_mapping():
303
426
  "Sf",
304
427
  "---",
305
428
  "---",
429
+ "---",
306
430
  ],
307
- "streched_exponential": [
431
+ "stretched_exponential": [
308
432
  "Af",
309
433
  "tf",
310
434
  "---",
@@ -315,6 +439,7 @@ def format_mapping():
315
439
  "Sf",
316
440
  "---",
317
441
  "beta",
442
+ "---",
318
443
  ],
319
444
  "exponential_with_offset": [
320
445
  "Af",
@@ -327,6 +452,7 @@ def format_mapping():
327
452
  "Sf",
328
453
  "---",
329
454
  "---",
455
+ "---",
330
456
  ],
331
457
  "biexponential": [
332
458
  "Af",
@@ -339,6 +465,7 @@ def format_mapping():
339
465
  "Sf",
340
466
  "Ss",
341
467
  "---",
468
+ "---",
342
469
  ],
343
470
  "biexponential_with_offset": [
344
471
  "Af",
@@ -351,6 +478,59 @@ def format_mapping():
351
478
  "Sf",
352
479
  "Ss",
353
480
  "---",
481
+ "---",
482
+ ],
483
+ "exponential_decay": [
484
+ "Af",
485
+ "tf",
486
+ "---",
487
+ "---",
488
+ "---",
489
+ "Rf",
490
+ "---",
491
+ "Sf",
492
+ "---",
493
+ "---",
494
+ "---",
495
+ ],
496
+ "exponential_decay_with_offset": [
497
+ "Af",
498
+ "tf",
499
+ "---",
500
+ "---",
501
+ "---",
502
+ "Rf",
503
+ "---",
504
+ "Sf",
505
+ "---",
506
+ "---",
507
+ "I0",
508
+ ],
509
+ "stretched_exponential_decay": [
510
+ "Af",
511
+ "tf",
512
+ "---",
513
+ "---",
514
+ "---",
515
+ "Rf",
516
+ "---",
517
+ "Sf",
518
+ "---",
519
+ "beta",
520
+ "---",
521
+ ],
522
+ "biexponential_decay": [
523
+ "Af",
524
+ "tf",
525
+ "As",
526
+ "ts",
527
+ "---",
528
+ "Rf",
529
+ "Rs",
530
+ "Sf",
531
+ "Ss",
532
+ "---",
533
+ "---",
354
534
  ],
355
535
  }
356
536
 
@@ -368,7 +548,8 @@ def buildup_header():
368
548
  "Rs / 1/s",
369
549
  "Sensitivity1 (Af/sqrt(tf))",
370
550
  "Sensitivity2 (As/sqrt(ts))",
371
- "beta",
551
+ "beta / a.u.",
552
+ "I0 / a.u.",
372
553
  ]
373
554
 
374
555
 
@@ -395,7 +576,11 @@ def return_func_map():
395
576
  "biexponential": calc_biexponential,
396
577
  "exponential_with_offset": calc_exponential_with_offset,
397
578
  "biexponential_with_offset": calc_biexponential_with_offset,
398
- "streched_exponential": calc_stretched_exponential,
579
+ "stretched_exponential": calc_stretched_exponential,
580
+ "exponential_decay": calc_expdecay,
581
+ "exponential_decay_with_offset": calc_expdecaywithoffset,
582
+ "stretched_exponential_decay": calc_stretchedexpdecay,
583
+ "biexponential_decay": calc_biexpdecay,
399
584
  }
400
585
 
401
586