def test_AxonMapSpatial(engine): # AxonMapSpatial automatically sets `rho`, `axlambda`: model = AxonMapSpatial(engine=engine, xystep=5) # User can set `rho`: model.rho = 123 npt.assert_equal(model.rho, 123) model.build(rho=987) npt.assert_equal(model.rho, 987) # Converting ret <=> dva npt.assert_almost_equal(model.ret2dva(0), 0) npt.assert_almost_equal(model.dva2ret(0), 0) # Nothing in, None out: npt.assert_equal(model.predict_percept(ArgusI()), None) # Zero in = zero out: implant = ArgusI(stim=np.zeros(16)) percept = model.predict_percept(implant) npt.assert_equal(isinstance(percept, Percept), True) npt.assert_equal(percept.shape, list(model.grid.x.shape) + [1]) npt.assert_almost_equal(percept.data, 0) # Multiple frames are processed independently: model = AxonMapSpatial(engine=engine, rho=200, axlambda=100, xystep=5) model.build() percept = model.predict_percept(ArgusI(stim={'A1': [1, 0], 'B3': [0, 2]})) npt.assert_equal(percept.shape, list(model.grid.x.shape) + [2]) pmax = percept.data.max(axis=(0, 1)) npt.assert_almost_equal(percept.data[2, 3, 0], pmax[0]) npt.assert_almost_equal(percept.data[2, 3, 1], 0) npt.assert_almost_equal(percept.data[3, 4, 0], 0) npt.assert_almost_equal(percept.data[3, 4, 1], pmax[1])
def test_AxonMapSpatial(engine): # AxonMapSpatial automatically sets `rho`, `axlambda`: model = AxonMapSpatial(engine=engine, xystep=5) # User can set `rho`: model.rho = 123 npt.assert_equal(model.rho, 123) model.build(rho=987) npt.assert_equal(model.rho, 987) # Converting ret <=> dva npt.assert_equal(isinstance(model.retinotopy, Watson2014Map), True) npt.assert_almost_equal(model.retinotopy.ret2dva(0, 0), (0, 0)) npt.assert_almost_equal(model.retinotopy.dva2ret(0, 0), (0, 0)) model2 = AxonMapSpatial(retinotopy=Watson2014DisplaceMap()) npt.assert_equal(isinstance(model2.retinotopy, Watson2014DisplaceMap), True) # Nothing in, None out: npt.assert_equal(model.predict_percept(ArgusI()), None) # Zero in = zero out: implant = ArgusI(stim=np.zeros(16)) percept = model.predict_percept(implant) npt.assert_equal(isinstance(percept, Percept), True) npt.assert_equal(percept.shape, list(model.grid.x.shape) + [1]) npt.assert_almost_equal(percept.data, 0) npt.assert_equal(percept.time, None) # Lambda cannot be too small: with pytest.raises(ValueError): AxonMapSpatial(axlambda=9).build() # Multiple frames are processed independently: model = AxonMapSpatial(engine=engine, rho=200, axlambda=100, xystep=5, xrange=(-20, 20), yrange=(-15, 15)) model.build() # Axon map jax predict_percept not implemented yet if engine == 'jax': with pytest.raises(NotImplementedError): percept = model.predict_percept( ArgusII(stim={ 'A1': [1, 0], 'B3': [0, 2] })) return percept = model.predict_percept(ArgusI(stim={'A1': [1, 0], 'B3': [0, 2]})) npt.assert_equal(percept.shape, list(model.grid.x.shape) + [2]) pmax = percept.data.max(axis=(0, 1)) npt.assert_almost_equal(percept.data[2, 3, 0], pmax[0]) npt.assert_almost_equal(percept.data[2, 3, 1], 0) npt.assert_almost_equal(percept.data[3, 4, 0], 0) npt.assert_almost_equal(percept.data[3, 4, 1], pmax[1]) npt.assert_almost_equal(percept.time, [0, 1])
def test_AxonMapModel_predict_percept(engine): model = AxonMapModel(xystep=0.55, axlambda=100, rho=100, thresh_percept=0, engine=engine, xrange=(-20, 20), yrange=(-15, 15), n_axons=500) model.build() # Single-electrode stim: img_stim = np.zeros(60) img_stim[47] = 1 percept = model.predict_percept(ArgusII(stim=img_stim)) # Single bright pixel, rest of arc is less bright: npt.assert_equal(np.sum(percept.data > 0.8), 1) npt.assert_equal(np.sum(percept.data > 0.6), 2) npt.assert_equal(np.sum(percept.data > 0.1), 7) npt.assert_equal(np.sum(percept.data > 0.0001), 32) # Overall only a few bright pixels: npt.assert_almost_equal(np.sum(percept.data), 3.31321, decimal=3) # Brightest pixel is in lower right: npt.assert_almost_equal(percept.data[33, 46, 0], np.max(percept.data)) # Top half is empty: npt.assert_almost_equal(np.sum(percept.data[:27, :, 0]), 0) # Same for lower band: npt.assert_almost_equal(np.sum(percept.data[39:, :, 0]), 0) # Full Argus II with small lambda: 60 bright spots model = AxonMapModel(engine='serial', xystep=1, rho=100, axlambda=40, xrange=(-20, 20), yrange=(-15, 15), n_axons=500) model.build() percept = model.predict_percept(ArgusII(stim=np.ones(60))) # Most spots are pretty bright, but there are 2 dimmer ones (due to their # location on the retina): npt.assert_equal(np.sum(percept.data > 0.5), 28) npt.assert_equal(np.sum(percept.data > 0.275), 56) # Model gives same outcome as Spatial: spatial = AxonMapSpatial(engine='serial', xystep=1, rho=100, axlambda=40) spatial.build() spatial_percept = model.predict_percept(ArgusII(stim=np.ones(60))) npt.assert_almost_equal(percept.data, spatial_percept.data) npt.assert_equal(percept.time, None)
def test_deepcopy_AxonMapSpatial(): original = AxonMapSpatial() copied = copy.deepcopy(original) # Assert these are two different objects npt.assert_equal(id(original) != id(copied), True) # Assert these objects are equivalent npt.assert_equal(original.__dict__ == copied.__dict__, True) npt.assert_equal(original == copied, True) # Assert building one object does not affect the copied original.build() npt.assert_equal(copied.is_built, False) npt.assert_equal(original.__dict__ != copied.__dict__, True) # Assert destroying the original doesn't affect the copied original = None npt.assert_equal(copied is not None, True)
def test_AxonMapModel_predict_percept(engine): model = AxonMapModel(xystep=0.55, axlambda=100, rho=100, thresh_percept=0, engine=engine, xrange=(-20, 20), yrange=(-15, 15), n_axons=500) model.build() # Single-electrode stim: img_stim = np.zeros(60) img_stim[47] = 1 # Axon map jax predict_percept not implemented yet if engine == 'jax': with pytest.raises(NotImplementedError): percept = model.predict_percept(ArgusII(stim=img_stim)) return percept = model.predict_percept(ArgusII(stim=img_stim)) # Single bright pixel, rest of arc is less bright: npt.assert_equal(np.sum(percept.data > 0.8), 1) npt.assert_equal(np.sum(percept.data > 0.6), 2) npt.assert_equal(np.sum(percept.data > 0.1), 7) npt.assert_equal(np.sum(percept.data > 0.0001), 31) # Overall only a few bright pixels: npt.assert_almost_equal(np.sum(percept.data), 3.3087, decimal=3) # Brightest pixel is in lower right: npt.assert_almost_equal(percept.data[33, 46, 0], np.max(percept.data)) # Top half is empty: npt.assert_almost_equal(np.sum(percept.data[:27, :, 0]), 0) # Same for lower band: npt.assert_almost_equal(np.sum(percept.data[39:, :, 0]), 0) # Full Argus II with small lambda: 60 bright spots model = AxonMapModel(engine='serial', xystep=1, rho=100, axlambda=40, xrange=(-20, 20), yrange=(-15, 15), n_axons=500) model.build() percept = model.predict_percept(ArgusII(stim=np.ones(60))) # Most spots are pretty bright, but there are 2 dimmer ones (due to their # location on the retina): npt.assert_equal(np.sum(percept.data > 0.5), 28) npt.assert_equal(np.sum(percept.data > 0.275), 56) # Model gives same outcome as Spatial: spatial = AxonMapSpatial(engine='serial', xystep=1, rho=100, axlambda=40, xrange=(-20, 20), yrange=(-15, 15), n_axons=500) spatial.build() spatial_percept = spatial.predict_percept(ArgusII(stim=np.ones(60))) npt.assert_almost_equal(percept.data, spatial_percept.data) npt.assert_equal(percept.time, None) # Warning for nonzero electrode-retina distances implant = ArgusI(stim=np.ones(16), z=10) msg = ("Nonzero electrode-retina distances do not have any effect on the " "model output.") assert_warns_msg(UserWarning, model.predict_percept, msg, implant)