-
Notifications
You must be signed in to change notification settings - Fork 1
Add polarimeter #127
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
base: master
Are you sure you want to change the base?
Add polarimeter #127
Conversation
| @dataclass(slots=True) | ||
| class PAX1000IR2(Instrument): | ||
| name: str | ||
| desc: str | ||
| hw_address: str | ||
| parameters: set[str] = field(default_factory=set) | ||
| operations: dict[str, Any] = field(default_factory=dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with other drivers, use an intermediate protocol between Instrument and the wrapper.
| @dataclass(slots=True) | |
| class PAX1000IR2(Instrument): | |
| name: str | |
| desc: str | |
| hw_address: str | |
| parameters: set[str] = field(default_factory=set) | |
| operations: dict[str, Any] = field(default_factory=dict) | |
| @runtime_checkable | |
| @dataclass(slots=True) | |
| class ThorlabsPolarimeterInstrument(Instrument, Protocol): | |
| def __post_init__(self) -> None: | |
| self.operations["read"] = self.read | |
| self.operations["set_wavelength"] = self.set_wavelength | |
| @log_operation | |
| def read(self) -> ThorlabsPolarimeterInfo: ... | |
| @log_operation | |
| def set_wavelength(self, value: float) -> None: ... | |
| @dataclass(slots=True) | |
| class PAX1000IR2(ThorlabsPolarimeterInstrument): | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, seems superfluous for one off drivers like this. If in the future we find there is a lot of shared utility like with motors, we can make a parent class for the group, else no point in my opinion
| msg = f"VISA backend not available: {exc}" | ||
| raise RuntimeError(msg) from exc | ||
|
|
||
| resource_name = self.hw_address or self._discover_resource() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource discovery feels beyond the scope of a slim wrapper. Users can provide a hw_address with the other configuration just like every other Instrument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it quite hard to connect to instruments via visa, I'd prefer this method whenever visa is absolutely necessary, though I prefer using USBTMC when possible.
| @log_operation | ||
| def read(self) -> dict[str, float]: | ||
| if self._instr is None: | ||
| msg = "Start the device first." | ||
| raise DeviceNotStartedError(msg) | ||
| raw_reply = self._read_and_write(QRY_LATEST, expect_response=True) | ||
|
|
||
| token_strs = [p for p in raw_reply.replace(";", ",").split(",") if p] | ||
| parsed_values: list[float | str] = [] | ||
| for token_str in token_strs: | ||
| try: | ||
| parsed_values.append(float(token_str)) | ||
| except (ValueError, TypeError): | ||
| parsed_values.append(token_str) | ||
|
|
||
| def get_float_at(index: int) -> float: | ||
| try: | ||
| value = parsed_values[index] | ||
| return float(value) if isinstance(value, (float, int)) else float(str(value)) | ||
| except (ValueError, TypeError, IndexError): | ||
| return float("nan") | ||
|
|
||
| self._last_theta_deg = get_float_at(9) | ||
| self._last_eta_deg = get_float_at(10) | ||
| self._last_dop = get_float_at(11) | ||
| self._last_power_w = get_float_at(12) | ||
|
|
||
| return { | ||
| "pax_theta_deg": self._last_theta_deg, | ||
| "pax_eta_deg": self._last_eta_deg, | ||
| "pax_dop": self._last_dop, | ||
| "pax_power_w": self._last_power_w, | ||
| "pax_wavelength_nm": self._wavelength_nm_cache, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider my original implementation:
def read(self) -> ThorlabsPolarimeterInfo:
# See https://www.thorlabs.com/_sd.cfm?fileName=MTN007790-D04.pdf&partumber=PAX1000IR2
data_keys = (
"revs",
"timestamp",
"paxOpMode",
"paxFlags",
"paxTIARange",
"adcMin",
"adcMax",
"revTime",
"misAdj",
"theta",
"eta",
"DOP",
"Ptotal",
)
data = self._device.query("SENS:DATA:LAT?").strip().split(",")
hw_status: dict[str, str] = dict(zip(data_keys, data, strict=True))
theta, eta, dop, power = (float(val) for val in data[9:13])
wavelength = float(self._device.query("SENS:CORR:WAV?"))
return ThorlabsPolarimeterInfo(
name=self.name,
desc=self.desc,
hw_address=self.hw_address,
hw_status=hw_status,
theta=theta,
eta=eta,
dop=dop,
power=power,
wavelength=wavelength,
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was what I did originally. Most of that info returned is useless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically in the context of what I want out of the read. And I suppose not most, more like half.
977275e to
7e8e225
Compare
Description
Add polarimeter pax1000IR2
Motivation and Context
Need driver for polarimeter
How have these changes been tested?
Tested each function with device to make sure it works and reads correct values.
Screenshots (if appropriate):
Types of changes
Checklist: