예제 #1
0
파일: test_catalog.py 프로젝트: bbarad/Pyto
    def makeInstance(self):
        """
        Returns an istance of Catalog()
        """

        curr_dir, base = os.path.split(__file__)
        rel_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=rel_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')

        return catal
예제 #2
0
    def test_read_layers_cleft(self):
        """
        Tests read(mode='layers_cleft')
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # read all
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers_cleft')

        # test meta-properties
        for category in ['first', 'second']:
            np_test.assert_equal(cleft_lay[category].indexed,
                                 self.indexed.union(['normalVolume']))
            np_test.assert_equal(cleft_lay[category].properties,
                                 self.properties.union(set(['normalVolume'])))

        # test normalized mean
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='normalMean'),
            [0, 5, -2, -1, 0, 1, 2, 7, 1])
예제 #3
0
파일: test_catalog.py 프로젝트: bbarad/Pyto
    def testAdd(self):
        """
        Tests add()
        """

        # read catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        abs_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=abs_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')

        # add new property
        new_values = {'exp_1': 'new_1', 'exp_3': 'new_3'}
        catal.add(name='new', values=new_values)
        np_test.assert_equal(catal._db['new']['exp_1'], 'new_1')
        np_test.assert_equal(catal._db['new'].get('exp_2', "none"), 'none')
        np_test.assert_equal(catal._db['new']['exp_3'], 'new_3')
        np_test.assert_equal(catal._db['new'].get('exp_4', "none"), 'none')
        #print catal._db

        # add an existing property, overwrite
        new_values = {'exp_2': 'new_2', 'exp_3': 'new_33'}
        catal.add(name='new', values=new_values, overwrite=True)
        np_test.assert_equal(catal._db['new']['exp_1'], 'new_1')
        np_test.assert_equal(catal._db['new']['exp_2'], 'new_2')
        np_test.assert_equal(catal._db['new']['exp_3'], 'new_33')
        np_test.assert_equal(catal._db['new'].get('exp_4', "none"), 'none')

        # add an existing property, not overwrite
        new_values = {'exp_2': 'new_2', 'exp_5': 'new_55'}
        np_test.assert_raises(
            ValueError, catal.add, **{
                'name': 'new',
                'values': new_values,
                'overwrite': False
            })

        # test other features
        np_test.assert_equal(catal._db['feature']['exp_1'], 'good')
        np_test.assert_equal(catal._db['feature']['exp_2'], 'bad')
        np_test.assert_equal(catal._db['feature']['exp_3'], 'good')
        np_test.assert_equal(catal._db['feature']['exp_4'], 'bad')
예제 #4
0
    def test_read_order(self):
        """
        Tests read(order)
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # make order and read
        order = {'first': ['exp_3', 'exp_2'], 'second': ['exp_4']}
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers',
                                      order=order)

        # test catalog properties
        np_test.assert_equal(cleft_lay.first.identifiers, ['exp_3', 'exp_2'])
        np_test.assert_equal(cleft_lay.second.identifiers, ['exp_4'])

        # data
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_2', property='mean'),
            self.mean_0 + 1)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_3', property='mean'),
            self.mean_0 + 2)
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_4', property='mean'),
            self.mean_0 + 3)

        # make order and read
        order = {'first': ['exp_3', 'exp_5'], 'second': ['exp_4', 'exp_1']}
        print("Now a warning should appear:")
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers',
                                      order=order)

        # test catalog properties
        np_test.assert_equal(cleft_lay.first.identifiers, ['exp_3'])
        np_test.assert_equal(cleft_lay.second.identifiers, ['exp_4', 'exp_1'])
예제 #5
0
    def testGetBoundarySurfaces(self):
        """
        Tests getBoundarySurfaces()
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # read all
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers')

        #  test simple
        cleft_lay.getBoundarySurfaces(names=['surfaceBound1', 'surfaceBound2'],
                                      surface='volume')
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_2',
                                     property='surfaceBound1'), 6)
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_2',
                                     property='surfaceBound2'), 6)
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_3',
                                     property='surfaceBound1'), 6)
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='surfaceBound1'), 6)

        #  test factor = 10
        cleft_lay.getBoundarySurfaces(names=['surfaceBound1', 'surfaceBound2'],
                                      factor=10,
                                      surface='volume')
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_3',
                                     property='surfaceBound2'), 60)
예제 #6
0
    def test_read_layers_on_columns(self):
        """
        Tests read(mode='layers_on_columns')
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # read all
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers')
        cleft_layoncol = CleftRegions.read(files=catal.results_obj,
                                           catalog=catal,
                                           mode='layers_on_columns',
                                           reference=cleft_lay)

        # test meta-properties
        for category in ['first', 'second']:
            np_test.assert_equal(cleft_layoncol[category].indexed,
                                 self.indexed)
            np_test.assert_equal(cleft_layoncol[category].properties,
                                 self.properties_layers_on_columns)

        # ids
        np_test.assert_equal(
            cleft_layoncol.first.cleftIds,
            [list(range(3, 8)), list(range(3, 8))])

        # data
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_1', property='mean'),
            self.mean_0)
예제 #7
0
파일: test_catalog.py 프로젝트: bbarad/Pyto
    def testRead(self):
        """
        Tests read
        """

        ###################################################
        #
        # Absolute path to catalogs directory
        #

        curr_dir, base = os.path.split(os.path.abspath(__file__))
        abs_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=abs_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        #print 'catal._db: ', catal._db

        # test feature
        np_test.assert_equal(catal._db['feature']['exp_1'], 'good')
        np_test.assert_equal(catal._db['feature']['exp_2'], 'bad')
        np_test.assert_equal(catal._db['feature']['exp_3'], 'good')
        np_test.assert_equal(catal._db['feature']['exp_4'], 'bad')

        # test results
        desired = os.path.realpath(
            os.path.join(curr_dir, 'catalogs_b', 'results_1.dat'))
        np_test.assert_equal(
            os.path.realpath(catal._db['results_file']['exp_1']), desired)
        desired = os.path.realpath(
            os.path.join(curr_dir, 'catalogs_b', 'results_2.dat'))
        np_test.assert_equal(
            os.path.realpath(catal._db['results_file']['exp_2']), desired)
        desired = os.path.realpath(
            os.path.join(curr_dir, 'catalogs_a', 'results_3.dat'))
        np_test.assert_equal(
            os.path.realpath(catal._db['results_file']['exp_3']), desired)
        desired = os.path.realpath(
            os.path.join(curr_dir, 'catalogs_a', 'catalogs_c', 'res',
                         'results_4.dat'))
        np_test.assert_equal(
            os.path.realpath(catal._db['results_file']['exp_4']), desired)

        ###################################################
        #
        # Absolute path to catalogs directory, test identifiers
        #

        catal = Catalog()
        catal.read(dir=abs_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed',
                   identifiers=['exp_2', 'exp_3'])

        # test feature
        np_test.assert_equal(catal._db['feature'].get('exp_1', 'foo'), 'foo')
        np_test.assert_equal(catal._db['feature']['exp_2'], 'bad')
        np_test.assert_equal(catal._db['feature']['exp_3'], 'good')
        np_test.assert_equal(catal._db['feature'].get('exp_4', 'foo'), 'foo')

        ###################################################
        #
        # Absolute path to catalogs directory
        #

        curr_dir, base = os.path.split(__file__)
        rel_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=rel_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        #print 'catal._db: ', catal._db

        # test results
        desired = os.path.realpath(
            os.path.join(curr_dir, 'catalogs_b', 'results_1.dat'))
        np_test.assert_equal(catal._db['results_file']['exp_1'], desired)
        desired = os.path.realpath(
            os.path.join(curr_dir, 'catalogs_b', 'results_2.dat'))
        np_test.assert_equal(catal._db['results_file']['exp_2'], desired)
        desired = os.path.realpath(
            os.path.join(curr_dir, 'catalogs_a', 'results_3.dat'))
        np_test.assert_equal(catal._db['results_file']['exp_3'], desired)
        desired = os.path.realpath(
            os.path.join(curr_dir, 'catalogs_a', 'catalogs_c', 'res',
                         'results_4.dat'))
        np_test.assert_equal(catal._db['results_file']['exp_4'], desired)
예제 #8
0
    def testGetRelative(self):
        """
        Tests getRelative()
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # read layers
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers')

        # test regions
        cleft_lay.getRelative(fraction=0.5,
                              new='half',
                              name='mean',
                              region=['bound', 'cleft'])
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1', property='half'),
            (33 / 4. + 5) / 2)

        cleft_lay.getRelative(fraction=0.3,
                              new='point_three',
                              name='mean',
                              region=['bound', 'cleft'])
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_2',
                                     property='point_three'),
            37 / 4. + (6 - 37 / 4.) * 0.3)

        # test regions with volume
        cleft_lay.getRelative(fraction=0.5,
                              new='half',
                              name='mean',
                              region=['bound', 'cleft'],
                              weight='volume')
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1', property='half'),
            (33 / 4. + 5) / 2)

        cleft_lay.second.setValue(identifier='exp_1',
                                  property='volumeX',
                                  value=numpy.array(
                                      [6, 6, 6, 6, 6, 10, 10, 6, 6]))
        cleft_lay.second.setValue(identifier='exp_4',
                                  property='volumeX',
                                  value=numpy.array(
                                      [6, 6, 6, 6, 6, 10, 10, 6, 6]))
        cleft_lay.getRelative(fraction=0.5,
                              new='half',
                              name='mean',
                              region=['bound', 'cleft'],
                              weight='volumeX',
                              categories=['second'])
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1', property='half'),
            (33 / 4. + (130 + 12 * 6) / 38.) / 2)

        # test ids
        cleft_lay.getRelative(fraction=0.5,
                              new='half',
                              ids=[[1, 2, 8, 9], [3, 4, 5, 6, 7]])
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1', property='half'),
            (33 / 4. + 5) / 2)
예제 #9
0
    def testNormalizeByMean(self):
        """
        Tests normalizeByMean() for layers, layers on columns and columns
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # make cleft layers
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers')

        # absolute, specified ids
        cleft_lay.normalizeByMean(name='mean',
                                  normalName='normalized',
                                  ids=[3, 4, 5],
                                  mode='absolute')
        np_test.assert_equal('normalized' in cleft_lay.first.properties, True)
        np_test.assert_equal('normalized' in cleft_lay.second.properties, True)
        np_test.assert_equal('normMean' in cleft_lay.first.properties, False)
        np_test.assert_equal('normMean' in cleft_lay.second.properties, False)
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='normalized'),
            [1, 6, -1, 0, 1, 2, 3, 8, 2])
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_4',
                                      property='normalized'),
            [1, 6, -1, 0, 1, 2, 3, 8, 2])

        # absolute, specified ids, reference
        cleft_lay.normalizeByMean(name='mean',
                                  normalName='normalized',
                                  ids=[3, 4, 5],
                                  mode='absolute',
                                  reference=cleft_lay)
        np_test.assert_equal('normalized' in cleft_lay.first.properties, True)
        np_test.assert_equal('normalized' in cleft_lay.second.properties, True)
        np_test.assert_equal('normMean' in cleft_lay.first.properties, False)
        np_test.assert_equal('normMean' in cleft_lay.second.properties, False)
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='normalized'),
            [1, 6, -1, 0, 1, 2, 3, 8, 2])
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_4',
                                      property='normalized'),
            [1, 6, -1, 0, 1, 2, 3, 8, 2])

        # relative, all ids
        cleft_lay.normalizeByMean(name='mean',
                                  normalName='normalized',
                                  mode='relative')
        np_test.assert_equal('normalized' in cleft_lay.first.properties, True)
        np_test.assert_equal('normalized' in cleft_lay.second.properties, True)
        np_test.assert_equal('normMean' in cleft_lay.first.properties, False)
        np_test.assert_equal('normMean' in cleft_lay.second.properties, False)
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='normalized'),
            (self.mean_0 - self.mean_0.mean()) / self.mean_0.mean())
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_2',
                                     property='normalized'),
            (self.mean_0 - self.mean_0.mean()) / (self.mean_0.mean() + 1))

        # relative, all ids, reference
        cleft_lay.normalizeByMean(name='mean',
                                  normalName='normalized',
                                  mode='relative',
                                  reference=cleft_lay)
        np_test.assert_equal('normalized' in cleft_lay.first.properties, True)
        np_test.assert_equal('normalized' in cleft_lay.second.properties, True)
        np_test.assert_equal('normMean' in cleft_lay.first.properties, False)
        np_test.assert_equal('normMean' in cleft_lay.second.properties, False)
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='normalized'),
            (self.mean_0 - self.mean_0.mean()) / self.mean_0.mean())
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_2',
                                     property='normalized'),
            (self.mean_0 - self.mean_0.mean()) / (self.mean_0.mean() + 1))

        # 0to1, regions
        cleft_lay.normalizeByMean(name='mean',
                                  normalName='normal0to1',
                                  region=['bound', 'cleft'],
                                  mode='0to1')
        np_test.assert_equal('normal0to1' in cleft_lay.first.properties, True)
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='normal0to1'),
            (common.cleft_layers_density_mean - 33 / 4.) / (5 - 33 / 4.))
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_2',
                                     property='normal0to1'),
            (common.cleft_layers_density_mean - 33 / 4.) / (5 - 33 / 4.))

        # 0to1, regions, with reference
        cleft_lay.normalizeByMean(name='mean',
                                  normalName='normal0to1',
                                  region=['bound', 'cleft'],
                                  mode='0to1',
                                  reference=cleft_lay)
        np_test.assert_equal('normal0to1' in cleft_lay.first.properties, True)
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='normal0to1'),
            (common.cleft_layers_density_mean - 33 / 4.) / (5 - 33 / 4.))
        np_test.assert_almost_equal(
            cleft_lay.first.getValue(identifier='exp_2',
                                     property='normal0to1'),
            (common.cleft_layers_density_mean - 33 / 4.) / (5 - 33 / 4.))

        # 0to1, ids
        cleft_lay.normalizeByMean(name='mean',
                                  normalName='normal0to1',
                                  ids=[[1, 2, 8, 9], [3, 4, 5, 6, 7]],
                                  mode='0to1')
        np_test.assert_equal('normal0to1' in cleft_lay.first.properties, True)
        np_test.assert_almost_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='normal0to1'),
            (common.cleft_layers_density_mean - 33 / 4.) / (5 - 33 / 4.))

        # 0to1 layers on columns, simple
        cleft_layoncol = CleftRegions.read(files=catal.results_obj,
                                           catalog=catal,
                                           mode='layers_on_columns',
                                           reference=cleft_lay)
        np_test.assert_almost_equal(
            cleft_layoncol.second.getValue(identifier='exp_1',
                                           property='normalMean'),
            (common.cleft_layers_density_mean - 33 / 4.) / (5 - 33 / 4.))

        # make another layers with simple values
        cleft_lay_2 = CleftRegions.read(files=catal.results_obj,
                                        catalog=catal,
                                        mode='layers')
        cleft_lay_2.second.setValue(identifier='exp_1',
                                    property='mean',
                                    value=numpy.array(
                                        [0., 0, 10, 10, 10, 10, 10, 0, 0.]))
        cleft_lay_2.first.setValue(identifier='exp_2',
                                   property='mean',
                                   value=numpy.array(
                                       [0., 0, 10, 10, 10, 10, 10, 0, 0.]))
        cleft_lay_2.second.setValue(identifier='exp_4',
                                    property='mean',
                                    value=numpy.array(
                                        [0., 0, 10, 10, 10, 10, 10, 0, 0.]))

        # 0to1, layers on columns, with reference 0
        cleft_layoncol.normalizeByMean(name='mean',
                                       normalName='nor',
                                       ids=[[1, 2, 8, 9], [3, 4, 5, 6, 7]],
                                       mode='0to1',
                                       reference=[cleft_lay_2, None])
        np_test.assert_almost_equal(
            cleft_layoncol.second.getValue(identifier='exp_1', property='nor'),
            (common.cleft_layers_density_mean - 0.) / (5.))
        np_test.assert_almost_equal(
            cleft_layoncol.first.getValue(identifier='exp_2', property='nor'),
            (common.cleft_layers_density_mean + 1 - 0.) / (6.))

        # 0to1, layers on columns, with references 0 and 1
        cleft_layoncol.normalizeByMean(name='mean',
                                       normalName='nor',
                                       ids=[[1, 2, 8, 9], [3, 4, 5, 6, 7]],
                                       mode='0to1',
                                       reference=[cleft_lay_2, cleft_lay_2])
        np_test.assert_almost_equal(
            cleft_layoncol.second.getValue(identifier='exp_1', property='nor'),
            (common.cleft_layers_density_mean - 0.) / (10.))

        # 0to1, layers on columns, with references 0 and 1, shortcut
        cleft_layoncol.normalizeByMean(name='mean',
                                       normalName='nor',
                                       ids=[[1, 2, 8, 9], [3, 4, 5, 6, 7]],
                                       mode='0to1',
                                       reference=cleft_lay_2)
        np_test.assert_almost_equal(
            cleft_layoncol.second.getValue(identifier='exp_1', property='nor'),
            (common.cleft_layers_density_mean - 0.) / (10.))

        # absolute, columns, with references 0 and 1
        cleft_col = CleftRegions.read(files=catal.cleft_columns_obj,
                                      catalog=catal,
                                      mode='columns',
                                      reference=cleft_lay_2)
        cleft_col.normalizeByMean(name='mean',
                                  normalName='nor',
                                  ids=[1, 2, 8, 9],
                                  mode='absolute',
                                  reference=cleft_lay_2)
        np_test.assert_almost_equal(
            cleft_col.second.getValue(identifier='exp_1', property='nor'),
            common.cleft_columns_density_mean)

        # 0to1, columns, with references 0 and 1
        cleft_col = CleftRegions.read(files=catal.cleft_columns_obj,
                                      catalog=catal,
                                      mode='columns',
                                      reference=cleft_lay_2)
        cleft_col.normalizeByMean(name='mean',
                                  normalName='nor',
                                  ids=[[1, 2, 8, 9], [3, 4, 5, 6, 7]],
                                  mode='0to1',
                                  reference=[cleft_lay_2, cleft_lay_2])
        np_test.assert_almost_equal(
            cleft_col.second.getValue(identifier='exp_1', property='nor'),
            (common.cleft_columns_density_mean - 0.) / (10.))
        np_test.assert_almost_equal(
            cleft_col.second.getValue(identifier='exp_4', property='nor'),
            (common.cleft_columns_density_mean + 3 - 0.) / (10.))
예제 #10
0
    def test_read_columns(self):
        """
        Tests read(mode='columns')
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # read all
        cleft_col = CleftRegions.read(files=catal.cleft_columns_obj,
                                      catalog=catal,
                                      mode='columns')

        # test meta-properties
        for category in ['first', 'second']:
            np_test.assert_equal(cleft_col[category].indexed,
                                 self.indexed_columns)
            np_test.assert_equal(cleft_col[category].properties,
                                 self.properties_columns)

        # read columns with layers as reference
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers')
        cleft_col = CleftRegions.read(files=catal.cleft_columns_obj,
                                      catalog=catal,
                                      mode='columns',
                                      reference=cleft_lay)

        # test meta-properties
        for category in ['first', 'second']:
            np_test.assert_equal(
                cleft_col[category].indexed,
                self.indexed_columns.union(set(['normalMean'])))
            np_test.assert_equal(
                cleft_col[category].properties,
                self.properties_columns.union(set(['normalMean'])))

        # test catalog properties
        np_test.assert_equal(set(cleft_col.first.identifiers),
                             set(['exp_2', 'exp_3']))
        np_test.assert_equal(set(cleft_col.second.identifiers),
                             set(['exp_1', 'exp_4']))

        # test category
        for category in ['first', 'second']:
            np_test.assert_equal(cleft_col[category].ids,
                                 [self.ids_columns, self.ids_columns])

        # identifiers
        np_test.assert_equal(set(cleft_col.first.identifiers),
                             set(['exp_2', 'exp_3']))
        np_test.assert_equal(set(cleft_col.second.identifiers),
                             set(['exp_1', 'exp_4']))

        # data
        np_test.assert_equal(
            cleft_col.second.getValue(identifier='exp_1', property='mean'),
            self.mean_0_columns)
        np_test.assert_equal(
            cleft_col.first.getValue(identifier='exp_2', property='mean'),
            self.mean_0_columns + 1)
        np_test.assert_equal(
            cleft_col.first.getValue(identifier='exp_3', property='mean'),
            self.mean_0_columns + 2)
        np_test.assert_equal(
            cleft_col.second.getValue(identifier='exp_4', property='mean'),
            self.mean_0_columns + 3)
        np_test.assert_equal(
            cleft_col.first.getValue(identifier='exp_2', property='volume'),
            self.volume_columns)
예제 #11
0
    def test_read_layers(self):
        """
        Tests read(mode='layers')
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # read all
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers')

        # test meta-properties
        for category in ['first', 'second']:
            np_test.assert_equal(cleft_lay[category].indexed, self.indexed)
            np_test.assert_equal(cleft_lay[category].properties,
                                 self.properties.union(set(['normalMean'])))

        # test catalog properties
        np_test.assert_equal(set(cleft_lay.first.identifiers),
                             set(['exp_2', 'exp_3']))
        np_test.assert_equal(set(cleft_lay.second.identifiers),
                             set(['exp_1', 'exp_4']))

        # test category
        for category in ['first', 'second']:
            np_test.assert_equal(cleft_lay[category].ids, [self.ids, self.ids])
            np_test.assert_equal(cleft_lay[category].width,
                                 [self.width, self.width])

        # identifiers
        np_test.assert_equal(set(cleft_lay.first.identifiers),
                             set(['exp_2', 'exp_3']))
        np_test.assert_equal(set(cleft_lay.second.identifiers),
                             set(['exp_1', 'exp_4']))

        # data
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_1', property='mean'),
            self.mean_0)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_2', property='mean'),
            self.mean_0 + 1)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_3', property='mean'),
            self.mean_0 + 2)
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_4', property='mean'),
            self.mean_0 + 3)

        # ids
        np_test.assert_equal(
            cleft_lay.first.cleftIds,
            [list(range(3, 8)), list(range(3, 8))])
        np_test.assert_equal(cleft_lay.first.bound1Ids, [[1, 2], [1, 2]])
        np_test.assert_equal(cleft_lay.first.bound2Ids, [[8, 9], [8, 9]])
        np_test.assert_equal(cleft_lay.first.boundIds,
                             [[1, 2, 8, 9], [1, 2, 8, 9]])
예제 #12
0
    def test_read(self):
        """
        Tests read(mode=None)
        """

        # make catalog
        curr_dir, base = os.path.split(os.path.abspath(__file__))
        cat_dir = os.path.join(curr_dir, common.rel_catalogs_dir)
        catal = Catalog()
        catal.read(dir=cat_dir,
                   catalog=r'catalog_[0-9]*\.',
                   type='distributed')
        catal.makeGroups(feature='category')

        # read all
        cleft_lay = CleftRegions.read(files=catal.results_obj,
                                      catalog=catal,
                                      mode='layers')

        # test meta-properties
        for category in ['first', 'second']:
            np_test.assert_equal(cleft_lay[category].indexed, self.indexed)
            np_test.assert_equal(cleft_lay[category].properties,
                                 self.properties)

        # test catalog properties
        np_test.assert_equal(set(cleft_lay.first.identifiers),
                             set(['exp_2', 'exp_3']))
        np_test.assert_equal(set(cleft_lay.second.identifiers),
                             set(['exp_1', 'exp_4']))

        # test category
        for category in ['first', 'second']:
            np_test.assert_equal(cleft_lay[category].ids, [self.ids, self.ids])
            np_test.assert_equal(cleft_lay[category].width,
                                 [self.width, self.width])

        # identifiers
        np_test.assert_equal(set(cleft_lay.first.identifiers),
                             set(['exp_2', 'exp_3']))
        np_test.assert_equal(set(cleft_lay.second.identifiers),
                             set(['exp_1', 'exp_4']))

        # data
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_1', property='mean'),
            self.mean_0)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_2', property='mean'),
            self.mean_0 + 1)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_3', property='mean'),
            self.mean_0 + 2)
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_4', property='mean'),
            self.mean_0 + 3)

        # width and volume in nm
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_1', property='width_nm'),
            self.width * 3.1)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_2', property='width_nm'),
            self.width * 3.2)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_3', property='width_nm'),
            self.width * 3.3)
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_4', property='width_nm'),
            self.width * 3.4)
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_1',
                                      property='volume_nm'),
            self.volume * 3.1**3)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_2', property='volume_nm'),
            self.volume * 3.2**3)
        np_test.assert_equal(
            cleft_lay.first.getValue(identifier='exp_3', property='volume_nm'),
            self.volume * 3.3**3)
        np_test.assert_equal(
            cleft_lay.second.getValue(identifier='exp_4',
                                      property='volume_nm'),
            self.volume * 3.4**3)