Ejemplo n.º 1
0
    def test_LoadSubsetFromFile(self):
        """Calculate one feature family, store to sig, load sig, and use to create larger fs"""

        img_filename = "lymphoma_eosin_channel_MCL_test_img_sj-05-3362-R2_001_E.tif"
        orig_img_filepath = pychrm_test_dir + sep + img_filename

        full_list = list((
            'Pixel Intensity Statistics () [3]',
            'Pixel Intensity Statistics (Fourier ()) [3]',
        ))

        tempdir = mkdtemp()

        from shutil import copy

        try:
            # copy the tiff to the tempdir so the .sig files end up there too
            copy(orig_img_filepath, tempdir)
            input_img_path = tempdir + sep + img_filename

            kwargs = {}
            kwargs['source_filepath'] = input_img_path
            kwargs['tile_num_cols'] = 6
            kwargs['tile_num_rows'] = 5
            kwargs['tiling_scheme'] = '5x6'
            kwargs['tile_col_index'] = 0
            kwargs['tile_row_index'] = 0
            kwargs['feature_names'] = full_list[1:]

            fv1 = FeatureVector(**kwargs).GenerateFeatures(quiet=False)

            # modify the sig value and write to sig file to make sure subsequent loading
            # used the value from disk and not recalculated it:
            fv1.values[0] = -9999
            fv1.ToSigFile(quiet=False)

            # Now, ask for more features:
            kwargs['feature_names'] = full_list
            fv2 = FeatureVector(**kwargs)
            with self.assertRaises(IncompleteFeatureSetError):
                fv2.LoadSigFile()

            #import pdb; pdb.set_trace()
            fv2.GenerateFeatures()
            #self.assertEqual( fv1.values[0], fv2.values[0] )

        finally:
            rmtree(tempdir)