Skip to content

Commit

Permalink
changes sample_count_rate function to return a single count rate valu…
Browse files Browse the repository at this point in the history
…e. This is a somewhat breaking change and will require subsequent changes to other components
  • Loading branch information
gadamc committed Feb 3, 2023
1 parent f1c8f66 commit 08551d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
24 changes: 9 additions & 15 deletions src/qt3utils/datagenerators/daqsamplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,23 @@ def sample_counts(self, n_samples = 1) -> np.ndarray:
def sample_count_rate(self, data_counts: np.ndarray):
"""
Converts the output of sample_counts to a count rate. Expects data_counts to be a 2d numpy array
of [[counts, clock_samples], [counts, clock_samples], ...] as is returned by sample_counts.
Under normal conditions, will return a numpy array of size n_samples, with values
equal to the estimated count rate.
Under normal conditions, will return a single value
However, there are two possible outcomes if there are errors with the data (which can be caused by NIDAQ errors)
1. return a numpy array of count rate measurements of size 0 < N < n_samples (if there's partial error)
2. return a numpy array of size N = n_samples with value of np.nan if no data are returned
If the NiDAQ is configured properly and sufficient time is allowed for data to be
acquired per batch, it's very unlikely that any errors will occur.
If the sum of all clock_samples is 0, will return np.nan.
"""

_data = data_counts[np.where(data_counts[:, 1] > 0)] #removes all rows where no data were acquired
if _data.shape[0] > 0:
return self.clock_rate * _data[:, 0]/_data[:, 1]
_data = np.sum(data_counts, axis=0)
if _data[1] > 0:
return self.clock_rate * _data[0]/_data[1]
else:
return np.nan*np.ones(len(data_counts))
return np.nan


def yield_count_rate(self):
while self.running:
count_data = self.sample_counts()
yield np.mean(self.sample_count_rate(count_data))
yield self.sample_count_rate(count_data)


class RandomRateCounter(RateCounterBase):
Expand Down
18 changes: 9 additions & 9 deletions src/qt3utils/datagenerators/piezoscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ def move_y(self):

@abc.abstractmethod
def sample_counts(self):
'''
must return an array-like object
'''
"""
expectation is to return [[counts, clock_samples], [counts, clock_samples], ...] as is returned by daqsamplers.sample_counts.
"""
pass

@abc.abstractmethod
def sample_count_rate(self):
'''
must return an array-like object
'''
"""
must return a single floating point value
"""
pass

@abc.abstractmethod
Expand All @@ -101,7 +101,7 @@ def scan_axis(self, axis, min, max, step_size):
if self.stage_controller:
logger.info(f'go to position {axis}: {val:.2f}')
self.stage_controller.go_to_position(**{axis:val})
cr = np.mean(self.sample_count_rate())
cr = self.sample_count_rate()
scan.append(cr)
logger.info(f'count rate: {cr}')
if self.stage_controller:
Expand Down Expand Up @@ -201,7 +201,7 @@ def __init__(self, stage_controller = None):
super().__init__(stage_controller)
self.default_offset = 350
self.signal_noise_amp = 0.2
self.possible_offset_values = np.arange(5000, 100000, 1000)
self.possible_offset_values = np.arange(5000, 100000, 1000) # these create the "bright" positions

self.current_offset = self.default_offset
self.clock_period = 0.09302010 # a totally random number
Expand All @@ -224,4 +224,4 @@ def sample_counts(self):
def sample_count_rate(self, data_counts = None):
if data_counts is None:
data_counts = self.sample_counts()
return data_counts / self.clock_period
return np.sum(data_counts) / self.clock_period

0 comments on commit 08551d4

Please sign in to comment.