def test_points(SR, N): elem = Element() with pytest.raises(KeyError): elem.points bp = bb.BluePrint() bp.insertSegment(0, ramp, (0, 0), dur=N / SR) bp.setSR(SR) wfm = np.linspace(-1, 1, N) elem.addArray(1, wfm, SR) elem.addBluePrint(2, bp) assert elem.points == N elem = Element() bp = bb.BluePrint() bp.insertSegment(0, ramp, (0, 0), dur=N / SR) bp.setSR(SR) wfm = np.linspace(-1, 1, N) elem.addArray(2, wfm, SR) elem.addBluePrint(1, bp) assert elem.points == N
def mixed_element(blueprint_tophat): """ An element with blueprints and arrays """ noise = np.random.randn(blueprint_tophat.points) wiggle = bb.BluePrint() wiggle.insertSegment(0, sine, args=(1, 10, 0, 0), dur=2.5) wiggle.setSR(blueprint_tophat.SR) elem = Element() elem.addBluePrint(1, blueprint_tophat) elem.addArray(2, noise, blueprint_tophat.SR) elem.addBluePrint(3, wiggle) return elem
def test_invalid_durations(SR1, SR2, N, M): """ There are soooo many ways to have invalid durations, here we hit a couple of them """ # differing sample rates elem = Element() bp = bb.BluePrint() bp.insertSegment(0, ramp, (0, 0), dur=N / SR2) bp.setSR(SR2) wfm = np.linspace(-1, 1, N) elem.addArray(1, wfm, SR1) elem.addBluePrint(2, bp) if SR1 == SR2: elem.validateDurations() else: with pytest.raises(ElementDurationError): elem.validateDurations() # differing durations bp1 = bb.BluePrint() bp1.insertSegment(0, ramp, (0, 1), dur=N / SR1) bp1.setSR(SR1) bp2 = bb.BluePrint() bp2.insertSegment(0, ramp, (0, 2), dur=M / SR1) bp2.setSR(SR1) elem = Element() elem.addBluePrint(1, bp1) elem.addBluePrint(2, bp2) if N == M: elem.validateDurations() else: with pytest.raises(ElementDurationError): elem.validateDurations()
def test_addArray(): SR = 1e9 N = 2500 wfm = np.linspace(0, N / SR, N) m1 = np.zeros(N) m2 = np.ones(N) elem = Element() elem.addArray(1, wfm, SR, m1=m1, m2=m2) elem.addArray('2', wfm, SR, m1=m1) elem.addArray('readout_channel', wfm, SR, m2=m2) elem.validateDurations() M = 2400 wfm2 = np.linspace(0, M / SR, M) elem.addArray(3, wfm2, SR) with pytest.raises(ElementDurationError): elem.validateDurations() with pytest.raises(ValueError): elem.addArray(1, wfm, SR, m1=m1[:-1]) with pytest.raises(ValueError): elem.addArray(2, wfm, SR, m2=m2[3:])