def test_partition_fail(self): """Check that partition fails with the expected error.""" path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'test_data', 'Test_detector.h5') detector = subspace.read_detector(path) with self.assertRaises(IndexError): detector.partition(dimension=40)
def test_create_nonmultiplexed_unaligned(self): """Test creation of a non-multiplexed detector.""" # Test a non-multiplexed version detector = subspace.Detector() templates = copy.deepcopy(self.templates) templates = [template.select(station='TMWZ') for template in templates] detector.construct(streams=templates, lowcut=2, highcut=9, filt_order=4, sampling_rate=20, multiplex=False, name=str('Tester'), align=False, shift_len=0) for u in detector.data: identity = np.dot(u.T, u).astype(np.float16) self.assertTrue(np.allclose( identity, np.diag(np.ones(len(identity), dtype=np.float16)))) comparison_detector = subspace.read_detector( os.path.join( os.path.abspath(os.path.dirname(__file__)), 'test_data', 'subspace', 'master_detector_unaligned.h5')) for key in ['name', 'sampling_rate', 'multiplex', 'lowcut', 'highcut', 'filt_order', 'dimension', 'stachans']: # print(key) self.assertEqual(comparison_detector.__getattribute__(key), detector.__getattribute__(key)) for key in ['data', 'u', 'v', 'sigma']: # print(key) list_item = detector.__getattribute__(key) other_list = comparison_detector.__getattribute__(key) self.assertEqual(len(list_item), len(other_list)) for item, other_item in zip(list_item, other_list): if not np.allclose(np.abs(item), np.abs(other_item)): print(item) print(other_item) self.assertTrue(np.allclose(np.abs(item), np.abs(other_item), atol=0.001)) # Finally check that the __eq__ method works if all the above passes. self.assertEqual(detector, comparison_detector)
def test_energy_capture(self): """Check that the energy capture calc works okay""" path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'test_data', 'Test_detector.h5') detector = subspace.read_detector(path) energy = detector.energy_capture() self.assertTrue(0 < energy < 100) self.assertEqual(round(energy), 60)
def test_read_func(self): """Check that the read function works too.""" path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'test_data', 'Test_detector.h5') detector = subspace.read_detector(path) _detector = subspace.Detector() _detector.read(path) self.assertEqual(detector, _detector)