Skip to content

Commit 6125967

Browse files
Update warnings to handle parameter input
1 parent 312eb8f commit 6125967

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

src/easydynamics/sample_model/components/damped_harmonic_oscillator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def __init__(
5252
raise ValueError(
5353
"The width of a DampedHarmonicOscillator must be greater than zero."
5454
)
55+
elif isinstance(width, Parameter):
56+
if width.value <= 0:
57+
raise ValueError(
58+
"The width of a DampedHarmonicOscillator must be greater than zero."
59+
)
5560

5661
if isinstance(area, Numeric):
5762
area = float(area)
@@ -61,6 +66,13 @@ def __init__(
6166
name
6267
)
6368
)
69+
elif isinstance(area, Parameter):
70+
if area.value < 0:
71+
warnings.warn(
72+
"The area of the Damped Harmonic Oscillator with name {} is negative, which may not be physically meaningful.".format(
73+
name
74+
)
75+
)
6476

6577
if isinstance(center, Numeric):
6678
center = float(center)

src/easydynamics/sample_model/components/delta_function.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ def __init__(
4646
)
4747
)
4848
area = float(area)
49+
elif isinstance(area, Parameter):
50+
if area.value < 0:
51+
warnings.warn(
52+
"The area of the Delta function with name {} is negative, which may not be physically meaningful.".format(
53+
name
54+
)
55+
)
4956

5057
if isinstance(center, Numeric):
5158
center = float(center)

src/easydynamics/sample_model/components/gaussian.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def __init__(
5050
if width <= 0:
5151
raise ValueError("The width of a Gaussian must be greater than zero.")
5252
width = float(width)
53+
elif isinstance(width, Parameter):
54+
if width.value <= 0:
55+
raise ValueError("The width of a Gaussian must be greater than zero.")
5356

5457
if isinstance(area, Numeric):
5558
if area < 0:
@@ -59,6 +62,13 @@ def __init__(
5962
)
6063
)
6164
area = float(area)
65+
elif isinstance(area, Parameter):
66+
if area.value < 0:
67+
warnings.warn(
68+
"The area of the Gaussian with name {} is negative, which may not be physically meaningful.".format(
69+
name
70+
)
71+
)
6272

6373
super().__init__(name=name)
6474
self._unit = unit # Set the unit for the component

src/easydynamics/sample_model/components/lorentzian.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def __init__(
4747
if width <= 0:
4848
raise ValueError("The width of a Lorentzian must be greater than zero.")
4949
width = float(width)
50+
elif isinstance(width, Parameter):
51+
if width.value <= 0:
52+
raise ValueError("The width of a Lorentzian must be greater than zero.")
5053

5154
if not isinstance(unit, str):
5255
raise TypeError("unit must be a string.")
@@ -59,6 +62,13 @@ def __init__(
5962
)
6063
)
6164
area = float(area)
65+
elif isinstance(area, Parameter):
66+
if area.value < 0:
67+
warnings.warn(
68+
"The area of the Lorentzian with name {} is negative, which may not be physically meaningful.".format(
69+
name
70+
)
71+
)
6272

6373
if isinstance(center, Numeric):
6474
center = float(center)

src/easydynamics/sample_model/components/voigt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,23 @@ def __init__(
5959
"The gaussian_width of a Voigt must be greater than zero."
6060
)
6161
gaussian_width = float(gaussian_width)
62+
elif isinstance(gaussian_width, Parameter):
63+
if gaussian_width.value <= 0:
64+
raise ValueError(
65+
"The gaussian_width of a Voigt must be greater than zero."
66+
)
6267

6368
if isinstance(lorentzian_width, Numeric):
6469
if lorentzian_width <= 0:
6570
raise ValueError(
6671
"The lorentzian_width of a Voigt must be greater than zero."
6772
)
6873
lorentzian_width = float(lorentzian_width)
74+
elif isinstance(lorentzian_width, Parameter):
75+
if lorentzian_width.value <= 0:
76+
raise ValueError(
77+
"The lorentzian_width of a Voigt must be greater than zero."
78+
)
6979

7080
if isinstance(area, Numeric):
7181
if area < 0:
@@ -75,6 +85,13 @@ def __init__(
7585
)
7686
)
7787
area = float(area)
88+
elif isinstance(area, Parameter):
89+
if area.value < 0:
90+
warnings.warn(
91+
"The area of the Voigt profile with name {} is negative, which may not be physically meaningful.".format(
92+
name
93+
)
94+
)
7895

7996
super().__init__(name=name)
8097

0 commit comments

Comments
 (0)