-
Notifications
You must be signed in to change notification settings - Fork 5
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
Accept array-like instead of just lists #11
Comments
sure, seems reasonable to me: you could do that by modifying from pydantic import validator
class ZPlan(BaseModel):
go_up: bool
_normrel = validator("relative", pre=True, allow_reuse=True, check_fields=False)(list)
_normabs = validator("absolute", pre=True, allow_reuse=True, check_fields=False)(list)
... wanna add that in a PR? maybe look for some other |
side note: there is a builtin plan for In [20]: from useq._z import ZRelativePositions, ZTopBottom
In [21]: a = ZRelativePositions(relative=np.arange(-1.5, 1.6, 0.5).tolist())
In [22]: b = ZTopBottom(bottom=-1.5, top=1.5, step=0.5)
In [23]: list(a) == list(b)
Out[23]: True
|
I think there is a key difference there in that
So it's less helpful than |
ah yes! :) indeed it is, sorry my bad. In [26]: c = ZAboveBelow(above=1.5, below=-1.5, step=0.5)
In [27]: list(c)
Out[27]: [-1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5] |
btw, if the different constructors and argument names feel weird, the primary benefit here is that you could define an experiment declaratively using yaml # this one can only be `ZRangeAround`
z_plan:
range: 1.0
step: 0.5
# this one can only be `ZAboveBelow`
z_plan:
above: 1.5
below: -1.5
step: 0.5 ... and the amazing pydantic is smart enough to know that |
It would be nice to in general accept numpy arrays instead of specifying lists. For example specifying a z_plan with a numpy array breaks:
ref: https://numpy.org/devdocs/reference/typing.html
The text was updated successfully, but these errors were encountered: