Skip to content

Commit 0f10cfd

Browse files
refactor linspace
1 parent 454a4cf commit 0f10cfd

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
### Upcoming
22

33
- new upload calibration dialog
4+
- new OD calibrations are of type `od600` (instead of `od`). Nothing needs to change for the user.
5+
46

57
#### Bug fixes
68
- stirring calibration was using too many points from the lower bound, this is fixed.

pioreactor/calibrations/utils.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,18 @@ def curve_callable(x):
6666
raise NotImplementedError()
6767

6868

69-
def linspace(start: float, stop: float, num: int = 50) -> list[float]:
70-
assert start != stop
71-
assert num > 0
72-
73-
def linspace_(start: float, stop: float, num: int = 50):
74-
num = int(num)
75-
start = start * 1.0
76-
stop = stop * 1.0
77-
78-
step = (stop - start) / (num - 1)
79-
80-
for i in range(num):
81-
yield start + step * i
82-
83-
return list(linspace_(start, stop, num))
69+
def linspace(start: float, stop: float, num: int = 50, *, precision: int = 3) -> list[float]:
70+
"""
71+
Return ``num`` evenly-spaced values from *start* to *stop*, rounded to *precision*
72+
decimal places (default = 3).
73+
"""
74+
if num <= 0:
75+
raise ValueError("num must be > 0")
76+
if num == 1: # avoid division-by-zero
77+
return [round(start, precision)]
78+
79+
step = (stop - start) / (num - 1)
80+
return [round(start + step * i, precision) for i in range(num)]
8481

8582

8683
def plot_data(

0 commit comments

Comments
 (0)