Skip to content

Commit 82778b2

Browse files
Add setters and getters for gaussian
1 parent c80742d commit 82778b2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/easydynamics/sample_model/components/gaussian.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,48 @@ def __init__(
8383
name=name + " width", value=width, unit=unit, min=MINIMUM_WIDTH
8484
)
8585

86+
@property
87+
def area(self) -> Parameter:
88+
"""Return the area parameter."""
89+
return self._area
90+
91+
@area.setter
92+
def area(self, value: Numeric, unit: Optional[Union[str, sc.Unit]] = None):
93+
"""Set the area parameter."""
94+
if not isinstance(value, Numeric):
95+
raise TypeError("area must be a number.")
96+
self._area.value = float(value)
97+
if unit is not None:
98+
self._area._unit = unit
99+
100+
@property
101+
def center(self) -> Parameter:
102+
"""Return the center parameter."""
103+
return self._center
104+
105+
@center.setter
106+
def center(self, value: Numeric, unit: Optional[Union[str, sc.Unit]] = None):
107+
"""Set the center parameter."""
108+
if not isinstance(value, Numeric):
109+
raise TypeError("center must be a number.")
110+
self._center.value = float(value)
111+
if unit is not None:
112+
self._center._unit = unit
113+
114+
@property
115+
def width(self) -> Parameter:
116+
"""Return the width parameter."""
117+
return self._width
118+
119+
@width.setter
120+
def width(self, value: Numeric, unit: Optional[Union[str, sc.Unit]] = None):
121+
"""Set the width parameter."""
122+
if not isinstance(value, Numeric):
123+
raise TypeError("width must be a number.")
124+
self._width.value = float(value)
125+
if unit is not None:
126+
self._width._unit = unit
127+
86128
def evaluate(self, x: Union[Numeric, sc.Variable]) -> Union[float, np.ndarray]:
87129
"""Evaluate the Gaussian at the given x values.
88130
If x is a scipp Variable, the unit of the Gaussian will be converted to match x.

0 commit comments

Comments
 (0)