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

Minor optimizations to match tests in instrumentation kit. #50

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions nion/usim_device/CameraDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,20 @@ def __direct_acquire(self, cancel_event: threading.Event, do_sync: bool = False)
# if do_sync is True, the scan device will sync with its acquisition thread before
# advancing the pixel. this avoids race conditions of when the pixel count gets reset.
# this will be set only for the first frame in a sequence.
start = time.time()
start = time.perf_counter()
readout_area = self.readout_area
binning_shape = Geometry.IntSize(self.__binning, self.__binning if self.__symmetric_binning else 1)
# scan device is only set during synchronized acquisition
if self.__scan_device:
self.__scan_device.advance_pixel(do_sync=do_sync)
xdata = self.__simulator.get_frame_data(Geometry.IntRect.from_tlbr(*readout_area), binning_shape, self.__exposure, self.__instrument.scan_context, self.__instrument.probe_position)
self.__acquired_one_event.set()
elapsed = time.time() - start
elapsed = time.perf_counter() - start
wait_s = max(self.__exposure - elapsed, 0)
if not cancel_event.wait(wait_s):
actual_elapsed_s = time.perf_counter() - start
if actual_elapsed_s < self.__exposure:
time.sleep(self.__exposure - actual_elapsed_s) # adjust in case the wait returns early (observed on python 3.13/windows)
# thread event was not triggered during wait; signal that we have data
xdata._set_timestamp(DateTime.utcnow())
self.__xdata_buffer = xdata
Expand Down
6 changes: 3 additions & 3 deletions nion/usim_device/InstrumentDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def __getattr__(self, attr: str) -> typing.Any:
class DriftController:

def __init__(self) -> None:
self.__start_time = time.time()
self.__start_time = time.perf_counter()

@property
def offset_m(self) -> Geometry.FloatPoint:
Expand All @@ -380,8 +380,8 @@ def offset_m(self) -> Geometry.FloatPoint:
period_x_s = 90 * 4
phase_y_rad = 7
phase_x_rad = 10
return Geometry.FloatPoint(y=max_drift_y_m * math.cos((time.time() - self.__start_time - phase_y_rad) * 2 * math.pi / period_y_s),
x=max_drift_x_m * math.sin((time.time() - self.__start_time + phase_x_rad) * 2 * math.pi / period_x_s))
return Geometry.FloatPoint(y=max_drift_y_m * math.cos((time.perf_counter() - self.__start_time - phase_y_rad) * 2 * math.pi / period_y_s),
x=max_drift_x_m * math.sin((time.perf_counter() - self.__start_time + phase_x_rad) * 2 * math.pi / period_x_s))


class ValueManager(Observable.Observable, InstrumentDevice.ValueManagerLike):
Expand Down
Loading