def test_sph2cart(): sph = np.asarray([ [0., 0., 1], [np.pi, 0., 1.], [np.pi/2, 0., 1.], [-np.pi/2, 0., 1.], [0., np.pi/2, 1.], [0., -np.pi/2, 1.], [np.pi/4, np.arcsin(1. / np.sqrt(3)), np.sqrt(3)], [-3*np.pi/4, -np.arcsin(1. / np.sqrt(3)), np.sqrt(3)], ]) cart = np.asarray([ [1., 0., 0.], [-1., 0., 0.], [0., 1., 0.], [0., -1., 0.], [0., 0., 1.], [0., 0., -1.], [1., 1., 1.], [-1., -1., -1.] ]) assert np.allclose(cart, sph2cart(sph)) # Specific 1D case sph = np.asarray([0., 0., 1]) cart = np.asarray([1., 0., 0.]) assert sph2cart(sph).ndim == 1 assert np.allclose(cart, sph2cart(sph)) # Error with higher dimensions with pytest.raises(ValueError): sph2cart(np.ones((1, 1, 1)))
room = np.array([10.2, 7.1, 3.2]) rt60 = rt60_bands(rt60_0, nBands, rt60_decay) abs_wall = srs.find_abs_coeffs_from_rt(room, rt60)[0] # Critical distance for the room _, d_critical, _ = srs.room_stats(room, abs_wall, verbose=False) # Receiver position rec = (room / 2)[np.newaxis] # center of the room nRec = rec.shape[0] # d_critical distance with defined angular position azi = azi + np.pi # TODO: fix in srs library!!! src_sph = np.array([azi, np.pi / 2 - incl, d_critical.mean()]) src_cart = masp.sph2cart(src_sph) src = rec + src_cart nSrc = src.shape[0] # SH orders for receivers rec_orders = np.array([1]) maxlim = rt60_0 # just stop if the echogram goes beyond that time ( or just set it to max(rt60) ) limits = np.ones(nBands) * maxlim # hardcoded! abs_echograms = srs.compute_echograms_sh(room, src, rec, abs_wall, limits, rec_orders) irs = srs.render_rirs_sh(abs_echograms, band_centerfreqs, fs).squeeze().T # Normalize as SN3D irs *= np.sqrt(4 * np.pi) irs *= np.asarray([1, 1. / np.sqrt(3), 1. / np.sqrt(3),