Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: ensure np.interp gets an increasing sequence in LUTs #1282

Merged
merged 12 commits into from
Oct 16, 2024
Merged
24 changes: 20 additions & 4 deletions pcdsdevices/pseudopos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,18 @@ def forward(self, pseudo_pos: tuple) -> tuple:
pseudo_field, = self.PseudoPosition._fields
real_field, = self.RealPosition._fields

xp = self._table_data_by_name[pseudo_field]
fp = self._table_data_by_name[real_field]

# xp must be increasing
if not xp[1] > xp[0]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very intolerant of noise in the signal, are we confident we won't jitter enough to trigger this by accident?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These come from fixed values in a text file that can look something like this:

50        71
55        41.5
60        18.8
65        6
70        1.3
75        0.5

Since they are fixed values there won't be any jitter, but I think it's worth adding a more thorough check so we can throw a warning if the values aren't monotonic

xp = xp[::-1]
fp = fp[::-1]

real_value = np.interp(
values[pseudo_field],
self._table_data_by_name[pseudo_field],
self._table_data_by_name[real_field]
xp,
fp,
)
return self.RealPosition(**{real_field: real_value})

Expand All @@ -1040,10 +1048,18 @@ def inverse(self, real_pos: tuple) -> tuple:
pseudo_field, = self.PseudoPosition._fields
real_field, = self.RealPosition._fields

xp = self._table_data_by_name[real_field]
fp = self._table_data_by_name[pseudo_field]

# xp must be increasing
if not xp[1] > xp[0]:
xp = xp[::-1]
fp = fp[::-1]

pseudo_value = np.interp(
values[real_field],
self._table_data_by_name[real_field],
self._table_data_by_name[pseudo_field]
xp,
fp,
)
return self.PseudoPosition(**{pseudo_field: pseudo_value})

Expand Down