Skip to content

Commit 83f0736

Browse files
committed
WaveformGenerator: Rename 'load_equation' to 'load_function'
1 parent f29a9b4 commit 83f0736

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

pslab/instrument/analog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class AnalogOutput:
207207
wavetype : {'sine', 'tria', 'custom'}
208208
Type of waveform on this pin. 'sine' is a sine wave with amplitude
209209
3.3 V, 'tria' is a triangle wave with amplitude 3.3 V, 'custom' is any
210-
other waveform set with :meth:`load_equation` or :meth:`load_table`.
210+
other waveform set with :meth:`load_function` or :meth:`load_table`.
211211
"""
212212

213213
RANGE = (-3.3, 3.3)

pslab/instrument/waveform_generator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ class WaveformGenerator:
103103
Reduce the amplitude on SI1:
104104
105105
>>> import numpy as np
106-
>>> wavegen.load_equation("SI1", lambda x: 1.5*np.sin(x), [0, 2*np.pi])
106+
>>> wavegen.load_function("SI1", lambda x: 1.5*np.sin(x), [0, 2*np.pi])
107107
108108
Output two superimposed sine waves on SI2:
109109
110-
>>> wavegen.load_equation("SI2", lambda x: 2*np.sin(x) + np.sin(5*x), [0, 2*np.pi])
110+
>>> wavegen.load_function("SI2", lambda x: 2*np.sin(x) + np.sin(5*x), [0, 2*np.pi])
111111
"""
112112

113113
_HIGHRES_TABLE_SIZE = 512
@@ -232,10 +232,10 @@ def _get_table_size(self, frequency: float) -> int:
232232

233233
return table_size
234234

235-
def load_equation(
235+
def load_function(
236236
self, channel: str, function: Union[str, Callable], span: List[float] = None
237237
):
238-
"""Load a custom waveform equation.
238+
"""Load a custom waveform function.
239239
240240
Parameters
241241
----------
@@ -251,7 +251,8 @@ def load_equation(
251251
for a sine wave or triangle wave with amplitude 3.3 V.
252252
span : List[float], optional
253253
The minimum and maximum x values between which to evaluate
254-
'function'. Omit if 'function' is 'sine' or 'tria'.
254+
'function'. Should typically correspond to one period. Omit if
255+
'function' is 'sine' or 'tria'.
255256
"""
256257
if function == "sine":
257258

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def test_collect_json_file(collect, tmp_path):
188188

189189
def test_wave_load_table(wave, mocker):
190190
wavegen = WaveformGenerator(mocker.Mock())
191-
wavegen.load_equation("SI1", "tria")
191+
wavegen.load_function("SI1", "tria")
192192

193193
def tria(x):
194194
return AnalogOutput.RANGE[1] * (abs(x % 4 - 2) - 1)
@@ -210,7 +210,7 @@ def test_wave_load_table_expand(wave):
210210

211211
def test_wave_load_tablefile(wave, mocker, tmp_path):
212212
wavegen = WaveformGenerator(mocker.Mock())
213-
wavegen.load_equation("SI1", "tria")
213+
wavegen.load_function("SI1", "tria")
214214

215215
def tria(x):
216216
return AnalogOutput.RANGE[1] * (abs(x % 4 - 2) - 1)

tests/test_waveform_generator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def scope(handler: SerialHandler) -> Oscilloscope:
5959

6060
def test_sine_wave(wave: WaveformGenerator, scope: Oscilloscope):
6161
frequency = 500
62-
wave.load_equation("SI1", "sine")
62+
wave.load_function("SI1", "sine")
6363
wave.generate("SI1", frequency)
6464
time.sleep(0.1)
6565
x, y = scope.capture(1, 10000, 1, trigger=0)
@@ -85,7 +85,7 @@ def expected_f(x, amplitude, frequency, phase):
8585

8686
def test_triangle_wave(wave: WaveformGenerator, scope: Oscilloscope):
8787
frequency = 2000
88-
wave.load_equation("SI1", "tria")
88+
wave.load_function("SI1", "tria")
8989
wave.generate("SI1", frequency)
9090
time.sleep(0.1)
9191
x, y = scope.capture(1, 10000, 1, trigger=0)
@@ -119,7 +119,7 @@ def test_superposition(wave: WaveformGenerator, scope: Oscilloscope):
119119
def super_sine(x):
120120
return amplitude1 * np.sin(x) + amplitude2 * np.sin(5 * x)
121121

122-
wave.load_equation("SI1", super_sine, [0, 2 * np.pi])
122+
wave.load_function("SI1", super_sine, [0, 2 * np.pi])
123123
wave.generate("SI1", frequency)
124124
time.sleep(0.1)
125125
x, y = scope.capture(1, 10000, 1, trigger=0)
@@ -153,8 +153,8 @@ def expected_f(x, amplitude1, amplitude2, frequency, phase):
153153
def test_sine_phase(wave: WaveformGenerator, scope: Oscilloscope):
154154
frequency = 500
155155
phase = 90
156-
wave.load_equation("SI1", "sine")
157-
wave.load_equation("SI2", "sine")
156+
wave.load_function("SI1", "sine")
157+
wave.load_function("SI2", "sine")
158158
wave.generate(["SI1", "SI2"], frequency, phase)
159159
time.sleep(0.1)
160160
x, y1, y2 = scope.capture(2, 5000, 2, trigger=0)

0 commit comments

Comments
 (0)