예제 #1
0
 def test_process_with_dvh(self):
     '''
     Can list specific DVH values to compute
     '''
     # Set up a schema validator
     com_schema = {
         'mean':
         And([float], lambda x: len(x) == 2),
         'min':
         And([float], lambda x: len(x) == 2),
         'max':
         And([float], lambda x: len(x) == 2),
         'dvh':
         And([np.ndarray], lambda x: np.all([d.shape == (6, 2) for d in x]),
             lambda x: len(x) == 2)
     }
     validator = Schema(com_schema)
     # Compute features
     dvh_vals = [0, 0.2, 0.4, 0.6, 0.8, 1]
     feat = SliceFeature('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')
예제 #2
0
 def test_process_before_load(self):
     '''
     Cannot process before loading data
     '''
     feat = SliceFeature('test')
     self.assertFalse(feat.loaded)
     self.assertRaises(ValueError, lambda: feat.process())
예제 #3
0
 def test_load_feature(self):
     '''
     Can initialize with mask and dose grid
     '''
     feat = SliceFeature('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)
예제 #4
0
 def test_process_dose(self):
     '''
     DVH feature class computes mean, min, max, and dvh
     '''
     v = Schema([DoseMask])
     feat = SliceFeature('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')
예제 #5
0
 def test_process_mask(self):
     '''
     DVH feature class has trivial mask processing
     '''
     v = Schema([Mask])
     feat = SliceFeature('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')
예제 #6
0
 def test_create_with_featuretype(self):
     '''
     Can specify a certain feature type
     '''
     feat = SliceFeature('test', feature_type='sample_type')
     self.assertFalse(feat.loaded)
     self.assertEqual(feat.type, 'sample_type')
예제 #7
0
 def test_create_feature_with_values(self):
     '''
     Can initialize with mask and dose grid
     '''
     feat = SliceFeature('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)
예제 #8
0
 def test_create_with_numslices_axis(self):
     '''
     Can specify a certain feature type
     '''
     feat = SliceFeature('test',
                         num_slices=5,
                         axis='x',
                         feature_type='sample_type')
     self.assertEqual(feat.num_slices, 5)
     self.assertEqual(feat.axis, 'x')
예제 #9
0
 def test_check_elements(self):
     '''
     Make sure the Feature object has all the required attributes
     '''
     feat = SliceFeature('test')
     elem_list = [
         'id', 'type', 'output', 'dose', 'mask', 'feature_mask',
         'feature_dosemask', 'loaded'
     ]
     self.assertTrue(isinstance(feat, SliceFeature))
     for elem in elem_list:
         self.assertTrue(hasattr(feat, elem))
예제 #10
0
 def __helper_test_process(self, n, a):
     '''
     Helper method to validate slice feature
     '''
     com_schema = {
         '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 = SliceFeature('test',
                         num_slices=n,
                         axis=a,
                         mask=self.mask,
                         dose=self.dg)
     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')
예제 #11
0
 def test_create_with_numslices(self):
     '''
     Can specify a certain feature type
     '''
     feat = SliceFeature('test', num_slices=4, feature_type='sample_type')
     self.assertEqual(feat.num_slices, 4)
예제 #12
0
 def test_values_before_load(self):
     '''
     Cannot get values before loading data
     '''
     feat = SliceFeature('test')
     self.assertRaises(ValueError, lambda: feat.values)