Skip to content

Commit

Permalink
Add assert statements to catch undefined components in system functio…
Browse files Browse the repository at this point in the history
…n calls #95
  • Loading branch information
abeerfatima authored Jun 11, 2022
1 parent 852976b commit b9fbb54
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions payload_designer/luts/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@ def __init__(self, path: Path, name: str = None):
self.name = name

def get_table(self):
assert self.x is not None, "x must be specified."
assert self.y is not None, "y must be specified."

data = {f"X [{self.x.unit}]": self.x.value, f"Y [{self.y.unit}]": self.y.value}

df = pd.DataFrame.from_dict(data)

return df

def __str__(self):
assert self.name is not None, "Name must be specified."
df = self.get_table()
return f"LUT ({self.name})\n{df.to_string(index=False)}"

def _repr_html_(self):
assert self.name is not None, "Name must be specified."
df = self.get_table()
return f"LUT ({self.name})\n{df.to_html(index=False)}"

Expand All @@ -59,6 +64,8 @@ def __call__(self, x):
array-like: The interpolated y values.
"""
assert self.x is not None, "x must be specified."
assert self.y is not None, "y must be specified."
return np.interp(x=x, xp=self.x, fp=self.y)


Expand Down

0 comments on commit b9fbb54

Please sign in to comment.