Beispiel #1
0
 def findMaskPoints(self, image, mask, subscriber=0):
     """
     Returns a table of masked points with each row
     giving a tuple (coordinate_1, ..., coordindate_n, value).
     """
     self.check(image, mask)
     subscriber %= 10.0
     index = (mask.data == FEATURE_COLOR).nonzero()
     zVal = image.data[index]
     subscriber %= 60.0
     fields = []
     for dim, coord in enumerate(index):
         newField = FieldContainer(
             image.dimensions[dim].data[coord],
             image.dimensions[dim].unit,
             longname=image.dimensions[dim].longname + " %i" % dim,
             shortname=image.dimensions[dim].shortname)
         fields.append(newField)
     fields.append(
         FieldContainer(zVal,
                        image.unit,
                        longname=image.longname,
                        shortname=image.shortname))
     res = SampleContainer(
         fields, u"Points from %s at %s" % (image.longname, mask.longname),
         u"X1")
     res.seal()
     subscriber %= 100.0
     return res
Beispiel #2
0
def makeSC(column_data, longnames, shortnames, longname, shortname, attributes={}):
    unzipped = zip(*column_data)
    assert len(unzipped) == len(longnames) == len(shortnames)

    def get_column_fc(col, ln, sn):
        try:
            from pyphant.quantities import Quantity

            unit = Quantity(1.0, col[0].unit)
            data = [quant.value for quant in col]
        except (KeyError, AttributeError):
            unit = 1
            data = col
        from numpy import array
        from pyphant.core.DataContainer import FieldContainer

        fc = FieldContainer(data=array(data), unit=unit, longname=ln, shortname=sn)
        return fc

    columns = [get_column_fc(col, ln, sn) for col, ln, sn in zip(unzipped, longnames, shortnames)]
    from pyphant.core.DataContainer import SampleContainer

    sc = SampleContainer(longname=longname, shortname=shortname, attributes=attributes, columns=columns)
    sc.seal()
    return sc
Beispiel #3
0
class SampleContainerTestCase(ContainerTestCase):
    def setUp(self):
        super(SampleContainerTestCase, self).setUp()
        self.independent = FieldContainer(
            0.3 * numpy.linspace(0, 1, self.testData.shape[0]),
            longname='independent variable',
            shortname='x',
            unit=Quantity('1 mg'),
            attributes=copy.copy(self.attributes).update({'independent':
                                                          True}))
        self.dependent = FieldContainer(9.81 * self.independent.data,
                                        dimensions=[self.independent],
                                        longname='dependent variable',
                                        shortname='f',
                                        unit=Quantity('9.81 nN'),
                                        attributes=copy.copy(
                                            self.attributes).update(
                                                {'independent': False}))
        self.sample = SampleContainer([self.dependent, self.field],
                                      longname='Sample',
                                      shortname='X',
                                      attributes=copy.copy(
                                          self.attributes).update(
                                              {'isSample': 'It seems so.'}))
        self.sample.seal()

    def testSaveRestore(self):
        self.eln.create_group(self.eln.root, 'testSaveRestoreSample')
        saveSample(self.eln, self.eln.root.testSaveRestoreSample, self.sample)
        restoredSample = loadSample(self.eln,
                                    self.eln.root.testSaveRestoreSample)
        self.assertEqual(restoredSample, self.sample)
Beispiel #4
0
 def findMaskPoints(self, image, mask, subscriber=0):
     """
     Returns a table of masked points with each row
     giving a tuple (coordinate_1, ..., coordindate_n, value).
     """
     self.check(image, mask)
     subscriber %= 10.0
     index = (mask.data == FEATURE_COLOR).nonzero()
     zVal = image.data[index]
     subscriber %= 60.0
     fields = []
     for dim, coord in enumerate(index):
         newField = FieldContainer(
             image.dimensions[dim].data[coord],
             image.dimensions[dim].unit,
             longname=image.dimensions[dim].longname + " %i" % dim,
             shortname=image.dimensions[dim].shortname
             )
         fields.append(newField)
     fields.append(FieldContainer(zVal, image.unit,
                                  longname=image.longname,
                                  shortname=image.shortname)
                   )
     res = SampleContainer(
         fields,
         u"Points from %s at %s"%(image.longname, mask.longname),
         u"X1"
         )
     res.seal()
     subscriber %= 100.0
     return res
Beispiel #5
0
 def checkExpected(self, columns, result):
     expected = SampleContainer(columns,
                                longname='Table',
                                shortname='T',
                                attributes=deepcopy(result.attributes))
     expected.seal()
     self.assertEqual(result, expected)
Beispiel #6
0
def makeSC(column_data,
           longnames,
           shortnames,
           longname,
           shortname,
           attributes=None):
    if attributes is None:
        attributes = {}
    unzipped = zip(*column_data)
    assert len(unzipped) == len(longnames) == len(shortnames)

    def get_column_fc(col, ln, sn):
        try:
            from pyphant.quantities import Quantity
            unit = Quantity(1.0, col[0].unit)
            data = [quant.value for quant in col]
        except (KeyError, AttributeError):
            unit = 1
            data = col
        from numpy import array
        from pyphant.core.DataContainer import FieldContainer
        fc = FieldContainer(data=array(data),
                            unit=unit,
                            longname=ln,
                            shortname=sn)
        return fc
    columns = [get_column_fc(col, ln, sn) for col, ln, sn \
               in zip(unzipped, longnames, shortnames)]
    from pyphant.core.DataContainer import SampleContainer
    sc = SampleContainer(longname=longname,
                         shortname=shortname,
                         attributes=attributes,
                         columns=columns)
    sc.seal()
    return sc
Beispiel #7
0
 def testSCwithSCColumn(self):
     fc_child1 = FieldContainer(longname='fc_child1', data=N.ones((10, 10)))
     fc_child2 = FieldContainer(longname='fc_child2', data=N.ones((20, 20)))
     sc_child = SampleContainer(longname='sc_child', columns=[fc_child1])
     sc_parent = SampleContainer(longname='sc_parent',
                                 columns=[sc_child, fc_child2])
     sc_parent.seal()
     km = KnowledgeManager.getInstance()
     km.registerDataContainer(sc_parent, temporary=True)
     lnlist = km.search(['longname'], {'col_of': {'longname': 'sc_parent'}})
     lnlist = [entry[0] for entry in lnlist]
     assert len(lnlist) == 2
     assert 'fc_child2' in lnlist
     assert 'sc_child' in lnlist
 def testSCwithSCColumn(self):
     fc_child1 = FieldContainer(longname='fc_child1', data=N.ones((10, 10)))
     fc_child2 = FieldContainer(longname='fc_child2', data=N.ones((20, 20)))
     sc_child = SampleContainer(longname='sc_child', columns=[fc_child1])
     sc_parent = SampleContainer(longname='sc_parent', columns=[sc_child,
                                                                fc_child2])
     sc_parent.seal()
     km = KnowledgeManager.getInstance()
     km.registerDataContainer(sc_parent, temporary=True)
     lnlist = km.search(['longname'], {'col_of':{'longname':'sc_parent'}})
     lnlist = [entry[0] for entry in lnlist]
     assert len(lnlist) == 2
     assert 'fc_child2' in lnlist
     assert 'sc_child' in lnlist
Beispiel #9
0
class SampleContainerTestCase(unittest.TestCase):
    def setUp(self):
        data = NPArray([10.0, -103.5, 1000.43, 0.0, 10.0])
        unit = PQ('3s')
        error = NPArray([0.1, 0.2, 4.5, 0.1, 0.2])
        longname = u'Test: FieldContainer H5FileHandler'
        shortname = u'TestH5FC'
        attributes = {'custom1': u'testing1...', 'custom2': u'testing2...'}
        self.fc = FieldContainer(data, unit, error, None, None, longname,
                                 shortname, attributes)
        self.fc.seal()
        fc2 = FieldContainer(NPArray([4003.2, 5.3, 600.9]), PQ('0.2m'), None,
                             None, None, 'FieldContainer 2', 'FC2')
        fc2.seal()
        columns = [self.fc, fc2]
        longname = u'Test: SampleContainer H5FileHandler'
        shortname = u'TestH5SC'
        self.sc = SampleContainer(columns, longname, shortname, attributes)
        self.sc.seal()
Beispiel #10
0
class SampleContainerTestCase(unittest.TestCase):
    def setUp(self):
        data = NPArray([10.0, -103.5, 1000.43, 0.0, 10.0])
        unit = PQ('3s')
        error = NPArray([0.1, 0.2, 4.5, 0.1, 0.2])
        longname = u'Test: FieldContainer H5FileHandler'
        shortname = u'TestH5FC'
        attributes = {'custom1':u'testing1...', 'custom2':u'testing2...'}
        self.fc = FieldContainer(data, unit, error, None, None, longname,
                                 shortname, attributes)
        self.fc.seal()
        fc2 = FieldContainer(NPArray([4003.2, 5.3, 600.9]), PQ('0.2m'), None,
                             None, None, 'FieldContainer 2', 'FC2')
        fc2.seal()
        columns = [self.fc, fc2]
        longname = u'Test: SampleContainer H5FileHandler'
        shortname = u'TestH5SC'
        self.sc = SampleContainer(columns, longname, shortname, attributes)
        self.sc.seal()
class SampleContainerInSampleContainerTestCase(SampleContainerTestCase):
    def setUp(self):
        super(SampleContainerInSampleContainerTestCase,self).setUp()
        sample1 = SampleContainer([self.dependent,self.field],longname='First Sample',shortname='X',
                                      attributes = copy.copy(self.attributes).update({'isSample':'It seems so.'}))
        self.independent2 = FieldContainer(0.3*numpy.linspace(0,1,self.testData.shape[0]*10),
                                          longname='independent variable',
                                          shortname='x',
                                          unit = Quantity('1 mg'),
                                          attributes = copy.copy(self.attributes).update({'independent':True}))
        self.dependent2 = FieldContainer(9.81*self.independent2.data,
                                        dimensions=[self.independent2],
                                        longname='dependent variable',
                                        shortname='f',
                                        unit = Quantity('9.81 nN'),
                                        attributes = copy.copy(self.attributes).update({'independent':False}))

        sample2 = SampleContainer([self.dependent2,self.independent2],longname='Second Sample',shortname='Y',
                                      attributes = copy.copy(self.attributes).update({'sample Nr.': 2}))
        self.sample = SampleContainer([sample1,sample2],longname='SampleContainer with Samples',shortname='(X,Y)',
                                      attributes = copy.copy(self.attributes).update({'isSample':'It seems so.'}))
        self.sample.seal()
class SampleContainerTestCase(ContainerTestCase):
    def setUp(self):
        super(SampleContainerTestCase,self).setUp()
        self.independent = FieldContainer(0.3*numpy.linspace(0,1,self.testData.shape[0]),
                                          longname='independent variable',
                                          shortname='x',
                                          unit = Quantity('1 mg'),
                                          attributes = copy.copy(self.attributes).update({'independent':True}))
        self.dependent = FieldContainer(9.81*self.independent.data,
                                        dimensions=[self.independent],
                                        longname='dependent variable',
                                        shortname='f',
                                        unit = Quantity('9.81 nN'),
                                        attributes = copy.copy(self.attributes).update({'independent':False}))
        self.sample = SampleContainer([self.dependent,self.field],longname='Sample',shortname='X',
                                      attributes = copy.copy(self.attributes).update({'isSample':'It seems so.'}))
        self.sample.seal()

    def testSaveRestore(self):
        self.eln.createGroup(self.eln.root,'testSaveRestoreSample')
        saveSample(self.eln,self.eln.root.testSaveRestoreSample,self.sample)
        restoredSample = loadSample(self.eln,self.eln.root.testSaveRestoreSample)
        self.assertEqual(restoredSample,self.sample)
Beispiel #13
0
 def checkExpected(self, columns, result):
     expected = SampleContainer(columns, longname="Table", shortname="T", attributes=deepcopy(result.attributes))
     expected.seal()
     self.assertEqual(result, expected)
 def testStringSample(self):
     # string = numpy.rec.fromrecords([(s,) for s in [u'Hello',u'World!',u'Bäh!']])
     #        strings =
     uField = FieldContainer(scipy.array([u"Hello", u"World!", u"Bäh!"]), longname=u"Text", shortname="\gamma")
     sample = SampleContainer([uField])
     sample.seal()