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

datetime.timedelta not precise enough for all nimi-python use cases #744

Closed
marcoskirsch opened this issue Feb 17, 2018 · 4 comments · Fixed by #1449
Closed

datetime.timedelta not precise enough for all nimi-python use cases #744

marcoskirsch opened this issue Feb 17, 2018 · 4 comments · Fixed by #1449

Comments

@marcoskirsch
Copy link
Member

marcoskirsch commented Feb 17, 2018

#659 is merged which is great because it's slick. However, it introduced one problem: Python's built-in datetime.timedelta is not precise enough for all of nimi-python's use cases.

For example:
The NI-SCOPE attribute NISCOPE_ATTR_END_OF_RECORD_TO_ADVANCE_TRIGGER_HOLDOFF is specified as a ViReal64 (which is a double) in the C API and can have values with resolution greater than a microsecond.
But in the Python API this corresponds to niscope.Session.end_of_record_to_advance_trigger_holdoff which is a datetime.timedelta and can only be specified in resolution of microseconds but not smaller.

@marcoskirsch
Copy link
Member Author

marcoskirsch commented Feb 17, 2018

So how to solve this?

Using float in the Python APIs like before #659 would be an un-pythonic step back.

What would be really neat, is a drop-in, duck-type replacement for datetime.timedelta that supports resolutions higher than than the built-in class. Then nimi-python could switch to using that wherever appropriate.

@Fladolcetta Fladolcetta added this to the nimi-python 0.9 release milestone Mar 19, 2018
@Fladolcetta Fladolcetta modified the milestones: nimi-python 0.9 release (NI-TClk), Post 1.0 Release Apr 12, 2018
@Fladolcetta
Copy link
Contributor

The workaround is to use a float in seconds via #796

@bilderbuchi
Copy link

Maybe numpy datetime would be a good fit: https://docs.scipy.org/doc/numpy/reference/arrays.datetime.html#datetime-units

@ni-jfitzger
Copy link
Collaborator

Additional examples of this problem for niscope:

There may be others; I haven't gone over the API and devices with a fine-toothed comb.
Of these, Time Per Record is the most important and most common, by a long shot. It is supported by all devices and is commonly used for horizontal configuration, though NI examples tend to steer users toward alternative settings. It's not unreasonable that a user would configure a scope in such a way that Time Per Record would be less than 1 us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants