Skip to content

Commit

Permalink
fix spacers states
Browse files Browse the repository at this point in the history
  • Loading branch information
oliche committed Nov 8, 2022
1 parent f48c931 commit 8614434
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions iblrig/spacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def times(self):
# upsweep
t = np.linspace(self.dt_start, self.dt_end, self.n_pulses) + self.tup
# downsweep
t = np.r_[t[:-1], np.flipud(t)]
t = np.r_[t, np.flipud(t[1:])]
t = np.cumsum(t)
return t

Expand All @@ -68,7 +68,7 @@ def generate_template(self, fs=1000):
sig = np.cumsum(sig)
return sig

def add_spacer_states(self, sma, next_state="exit"):
def add_spacer_states(self, sma=None, next_state="exit"):
"""
Add spacer states to a state machine
:param sma: pybpodapi.state_machine.StateMachine object
Expand All @@ -77,7 +77,11 @@ def add_spacer_states(self, sma, next_state="exit"):
"""
assert next_state is not None
t = self.times
dt = np.diff(t, append=t[-1] + self.tup)
for i, time in enumerate(t):
if sma is None:
print(i, time, dt[i])
continue
next_loop = f"spacer_high_{i + 1:02d}" if i < len(t) - 1 else next_state
sma.add_state(
state_name=f"spacer_high_{i:02d}",
Expand All @@ -87,7 +91,7 @@ def add_spacer_states(self, sma, next_state="exit"):
)
sma.add_state(
state_name=f"spacer_low_{i:02d}",
state_timer=time,
state_timer=dt[i],
state_change_conditions={"Tup": next_loop},
output_actions=[],
)
2 changes: 1 addition & 1 deletion test_iblrig/test_spacers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TestSpacer(unittest.TestCase):

def test_spacer(self):
spacer = Spacer(dt_start=.02, dt_end=.4, n_pulses=8, tup=.05)
self.AssertEqual(spacer.times.size, 15)
np.testing.assert_equal(spacer.times.size, 15)
sig = spacer.generate_template(fs=1000)
ac = np.correlate(sig, sig, 'full') / np.sum(sig**2)
# import matplotlib.pyplot as plt
Expand Down

0 comments on commit 8614434

Please sign in to comment.