Skip to content

Commit

Permalink
Separate capture length parsing and capture length set command
Browse files Browse the repository at this point in the history
This allows to get rid of the warning in case _parse_capture_length is
reused in other methods.
  • Loading branch information
sohailc committed Jun 25, 2018
1 parent 2365639 commit 78ee2cb
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions qcodes/instrument_drivers/stanford_research/SR86x.py
Expand Up @@ -170,15 +170,34 @@ def _set_capture_len_parser(self, capture_len_in_kb: int) -> int:
Returns:
capture_len_in_kb (int)
"""
if capture_len_in_kb % 2:
log.warning("the capture length needs to be even. Setting to {}".format(capture_len_in_kb + 1))
capture_len_in_kb += 1
return self._parse_capture_length(capture_len_in_kb, issue_warning=True)

if not self.min_capture_length_in_kb <= capture_len_in_kb <= self.max_capture_length_in_kb:
def _parse_capture_length(self, capture_length_in_kb: int, issue_warning: bool=False) -> int:
"""
Parse the capture length in kB according to the way buffer treats it. This method checks for the range
of the input value, and throws an error if the range is not satisfied. Additionally, if the input value
is odd, it is made even (and a warning is issued, if desired) since the capture length can only be set
in even numbers.
This method intended for use in other methods inside this class for calculation purposes. Setting issue_warning
argument to True allows this method to be used as well for set commands of the instrument parameters.
Args:
capture_length_in_kb (int): The desired capture length in kB.
issue_warning (bool): If True, a warning is issued when setting capture length to an odd number
Returns:
capture_len_in_kb (int)
"""
if capture_length_in_kb % 2:
if issue_warning:
log.warning("the capture length needs to be even. Setting to {}".format(capture_length_in_kb + 1))
capture_length_in_kb += 1

if not self.min_capture_length_in_kb <= capture_length_in_kb <= self.max_capture_length_in_kb:
raise ValueError(f"the capture length should be between "
f"{self.min_capture_length_in_kb} and {self.max_capture_length_in_kb}")

return capture_len_in_kb
return capture_length_in_kb

def set_capture_rate_to_maximum(self) -> None:
"""
Expand Down Expand Up @@ -256,7 +275,7 @@ def _calc_capture_size_in_kb(self, sample_count: int) ->int:
"""
n_variables = self._get_number_of_capture_variables()
total_size_in_kb = int(np.ceil(n_variables * sample_count * self.bytes_per_sample / 1024))
return self._set_capture_len_parser(total_size_in_kb)
return self._parse_capture_length(total_size_in_kb, issue_warning=False)

def get_capture_data(self, sample_count: int) -> dict:
"""
Expand Down

0 comments on commit 78ee2cb

Please sign in to comment.