def test_process_before_load(self): ''' Cannot process before loading data ''' feat = SectorFeature('test') self.assertFalse(feat.loaded) self.assertRaises(ValueError, lambda: feat.process())
def test_process_with_dvh(self): ''' Can list specific DVH values to compute ''' # Set up a schema validator com_schema = { 'bounds': And(np.ndarray, lambda x: x.shape == (1, 2)), 'mean': And([float], lambda x: len(x) == 1), 'min': And([float], lambda x: len(x) == 1), 'max': And([float], lambda x: len(x) == 1), 'dvh': And([np.ndarray], lambda x: np.all([d.shape == (6, 2) for d in x]), lambda x: len(x) == 1) } validator = Schema(com_schema) # Compute features dvh_vals = [0, 0.2, 0.4, 0.6, 0.8, 1] feat = SectorFeature('test', mask=self.mask, dose=self.dg, dvh=dvh_vals) output = feat.process() # Check the output schema try: self.assertTrue(validator.validate(output) is not SchemaError) except SchemaError: self.fail('Output does not match given schema')
def test_load_feature(self): ''' Can initialize with mask and dose grid ''' feat = SectorFeature('test') feat.load(self.mask, self.dg) self.assertTrue(feat.mask is not None) self.assertTrue(feat.dose is not None) self.assertTrue(feat.loaded)
def test_process_dose(self): ''' DVH feature class computes mean, min, max, and dvh ''' v = Schema([DoseMask]) feat = SectorFeature('test', mask=self.mask, dose=self.dg) output = feat.process_dose() try: self.assertTrue(v.validate(output) is not SchemaError) except SchemaError: self.fail('Output does not match given schema')
def test_process_mask(self): ''' DVH feature class has trivial mask processing ''' v = Schema([Mask]) feat = SectorFeature('test', mask=self.mask, dose=self.dg) output = feat.process_mask() try: self.assertTrue(v.validate(output) is not SchemaError) except SchemaError: self.fail('Output does not match given schema')
def test_create_with_featuretype(self): ''' Can specify a certain feature type ''' feat = SectorFeature('test', feature_type='sample_type') self.assertFalse(feat.loaded) self.assertEqual(feat.type, 'sample_type')
def test_create_feature_with_values(self): ''' Can initialize with mask and dose grid ''' feat = SectorFeature('test', mask=self.mask, dose=self.dg) self.assertTrue(feat.mask is not None) self.assertTrue(feat.dose is not None) self.assertTrue(feat.loaded)
def test_check_elements(self): ''' Make sure the Feature object has all the required attributes ''' feat = SectorFeature('test') elem_list = [ 'id', 'type', 'output', 'dose', 'mask', 'feature_mask', 'feature_dosemask', 'loaded' ] self.assertTrue(isinstance(feat, SectorFeature)) for elem in elem_list: self.assertTrue(hasattr(feat, elem))
def __helper_test_process(self, a, n): ''' Helper method to validate slice feature ''' # Create a schema validator com_schema = { 'bounds': And(np.ndarray, lambda x: x.shape == (n, 2)), 'mean': And([float], lambda x: len(x) == n), 'min': And([float], lambda x: len(x) == n), 'max': And([float], lambda x: len(x) == n), 'dvh': And([np.ndarray], lambda x: len(x) == n) } validator = Schema(com_schema) # Compute features feat = SectorFeature('test', mask=self.mask, dose=self.dg, angles=a) output = feat.process() # Check the output schema try: self.assertTrue(validator.validate(output) is not SchemaError) except SchemaError: self.fail('Output does not match given schema')
def test_values_before_load(self): ''' Cannot get values before loading data ''' feat = SectorFeature('test') self.assertRaises(ValueError, lambda: feat.values)
def test_bad_angles_2(self): ''' Initialize with malformed angles ''' self.assertRaises(ValueError, lambda: SectorFeature('test', angles=[[0, 90, 180]]))
def test_good_angles_2(self): ''' Initialize with malformed angles ''' feat = SectorFeature('test', angles=[[0, 90], [180, 270]]) self.assertEqual(feat.angles.shape, (2, 2))