def __init__(self, **kwargs):
     MockSet.__init__(self, **kwargs)
     self._samplingRate = pwobj.Float()
     self._hasCtf = pwobj.Boolean(kwargs.get('ctf', False))
     self._isPhaseFlipped = pwobj.Boolean(False)
     self._isAmplitudeCorrected = pwobj.Boolean(False)
     self._acquisition = MockAcquisition()
     self._firstDim = MockImageDim()  # Dimensions of the first image
Example #2
0
 def __init__(self, confs={}, **kwargs):
     pwobj.OrderedObject.__init__(self, **kwargs)
     self.config = ProjectConfig()
     # Store the current view selected by the user
     self.currentProtocolsView = pwobj.String()
     # Store the color mode: 0= Status, 1=Labels, ...
     self.colorMode = pwobj.Integer(ProjectSettings.COLOR_MODE_STATUS)
     self.nodeList = NodeConfigList(
     )  # Store graph nodes positions and other info
     self.labelsList = LabelsList()  # Label list
     self.mapper = None  # This should be set when load, or write
     self.runsView = pwobj.Integer(1)  # by default the graph view
     self.readOnly = pwobj.Boolean(False)
     self.runSelection = pwobj.CsvList(int)  # Store selected runs
     self.dataSelection = pwobj.CsvList(int)  # Store selected runs
     # Some extra settings stored, now mainly used
     # from the webtools
     # Time when the project was created
     self.creationTime = pwobj.String(dt.datetime.now())
     # Number of days that this project is active
     # if None, the project will not expire
     # This is used in webtools where a limited time
     # is allowed for each project
     self.lifeTime = pwobj.Integer()
     # Set a disk quota for the project (in Gb)
     # if None, quota is unlimited
     self.diskQuota = pwobj.Integer()
Example #3
0
    def createOutputStep(self):
        set1 = self.inputSets[0].get()  # 1st set (we use it many times)

        # Read ClassName and create the corresponding EMSet (SetOfParticles...)
        try:
            outputSetFunction = getattr(self, "_create%s" % set1.getClassName())
            outputSet = outputSetFunction()
        except Exception:
            outputSet = set1.create(self._getPath())

        # Copy info from input sets (sampling rate, etc).
        outputSet.copyInfo(set1)  # all sets must have the same info as set1!

        # Renumber from the beginning if either the renumber option is selected
        # or we find duplicated ids in the sets
        cleanIds = not self.ignoreDuplicates.get() and self.duplicatedIds()

        # TODO ROB remove ignoreExtraAttributes condition
        # or implement it. But this will be for Scipion 1.2
        self.ignoreExtraAttributes = pwobj.Boolean(True)
        if self.ignoreExtraAttributes:
            _, commonAttrs = self.commonAttributes()

            # Get the 1st level attributes to be used for the copyAttributes
            copyAttrs = list()
            for attr in commonAttrs:
                if "." not in attr:
                    copyAttrs.append(attr)

        idsList = []
        setNum = 0
        for itemSet in self.inputSets:
            setNum += 1
            for obj in itemSet.get():
                objId = obj.getObjId()
                if self.ignoreDuplicates.get():
                    if objId in idsList:
                        continue
                    idsList.append(objId)

                if self.ignoreExtraAttributes:
                    newObj = itemSet.get().ITEM_TYPE()
                    newObj.copyAttributes(obj, *copyAttrs)

                    self.cleanExtraAttributes(newObj, commonAttrs)
                    if not cleanIds or setNum == 1:
                        newObj.setObjId(objId)
                else:
                    newObj = obj

                if (cleanIds and setNum > 1) or self.renumber.get():
                    newObj.cleanObjId()

                outputSet.append(newObj)

        self._defineOutputs(outputSet=outputSet)
        for itemSet in self.inputSets:
            self._defineSourceRelation(itemSet, outputSet)
Example #4
0
    def __init__(self, location=None, **kwargs):
        """
         Params:
        :param location: Could be a valid location: (index, filename)
        or  filename
        """
        EdBaseObject.__init__(self, **kwargs)
        # Image location is composed by an index and a filename
        self._index = pwobj.Integer(0)
        self._filename = pwobj.String()

        # Detector distance of this image
        self._distance = pwobj.Float()

        # Where oscillation starts and its range
        self._oscStart = pwobj.Float()
        self._oscRange = pwobj.Float()

        # Beam center (in pixels)
        self._beamCenterX = pwobj.Float()
        self._beamCenterY = pwobj.Float()

        # Exposure time (in seconds)
        self._exposureTime = pwobj.Float()

        # TwoTheta
        self._twoTheta = pwobj.Float()

        # Pixel size of the image (in millimeters)
        self._pixelSizeX = pwobj.Float()
        self._pixelSizeY = pwobj.Float()

        # Dimensions of images in this set (number of pixels)
        self._dimX = pwobj.Integer()
        self._dimY = pwobj.Integer()

        # Wavelength
        self._wavelength = pwobj.Float()

        # Detector type
        self._detector = Detector()

        # Experiment time
        self._collectionTime = pwobj.String()

        # Add parameter to state if the image should be ignored in processing
        self._ignore = pwobj.Boolean()

        # Add information about goniometer rotation axis relative to image
        self._rotX = pwobj.Float()
        self._rotY = pwobj.Float()
        self._rotZ = pwobj.Float()

        if location:
            self.setLocation(location)
    def test_Object(self):
        value = 2
        i = pwobj.Integer(value)
        self.assertEqual(value, i.get())
        # compare objects
        i2 = pwobj.Integer(value)
        self.assertEqual(i, i2)
        
        value = 2.
        f = pwobj.Float(value)
        self.assertAlmostEqual(value, f.get())
        
        f.multiply(5)
        self.assertAlmostEqual(value*5, f.get())
        
        a = pwobj.Integer()
        self.assertEqual(a.hasValue(), False)
        c = Complex.createComplex()
        # Check values are correct
        self.assertEqual(c.imag.get(), Complex.cGold.imag)
        self.assertEqual(c.real.get(), Complex.cGold.real)
        
        # Test Boolean logic
        b = pwobj.Boolean(False)
        self.assertTrue(not b.get())

        b.set('True')
        self.assertTrue(b.get())
        
        b = pwobj.Boolean()
        b.set(False)
        self.assertTrue(not b.get())
        
        # CsvList should be empty if set to ''
        l = pwobj.CsvList()
        l.set('')
        self.assertEqual(len(l), 0)

        # Test emptiness
        self.assertIsNotEmpty(b)
Example #6
0
 def __init__(self, text=None, value=None, icon=None, tag=None, **kwargs):
     """Constructor for the Menu config item.
     Arguments:
       text: text to be displayed
       value: internal value associated with the item.
       icon: display an icon with the item
       tag: put some tags to items
     **args: pass other options to base class.
     """
     self.text = pwobj.String(text)
     self.value = pwobj.String(value)
     self.icon = pwobj.String(icon)
     self.tag = pwobj.String(tag)
     self.childs = pwobj.List()
     self.openItem = pwobj.Boolean(kwargs.get('openItem', False))
    def test_SqliteMapper(self):
        fn = self.getOutputPath("basic.sqlite")
        mapper = pwmapper.SqliteMapper(fn)

        # Insert a Float
        f = pwobj.Float(5.4)
        mapper.insert(f)

        # Insert an pwobj.Integer
        i = pwobj.Integer(1)
        mapper.insert(i)

        # Insert two pwobj.Boolean
        b = pwobj.Boolean(False)
        b2 = pwobj.Boolean(True)
        mapper.insert(b)
        mapper.insert(b2)

        # Test storing pointers
        p = pwobj.Pointer(b)
        mapper.insert(p)

        # Store csv list
        strList = ['1', '2', '3']
        csv = pwobj.CsvList()
        csv += strList
        mapper.insert(csv)

        # Test normal List
        iList = pwobj.List()
        mapper.insert(iList)  # Insert the list when empty
        i1 = pwobj.Integer(4)
        i2 = pwobj.Integer(3)
        iList.append(i1)
        iList.append(i2)
        mapper.update(iList)  # now update with some items inside

        pList = pwobj.PointerList()
        p1 = pwobj.Pointer(b)
        # p1.set(b)
        p2 = pwobj.Pointer(b2)
        # p2.set(b2)
        pList.append(p1)
        pList.append(p2)
        mapper.store(pList)

        # Test to add relations
        relName = 'testRelation'
        creator = f
        mapper.insertRelation(relName, creator, i, b)
        mapper.insertRelation(relName, creator, i, b2)

        mapper.insertRelation(relName, creator, b, p)
        mapper.insertRelation(relName, creator, b2, p)

        # Save changes to file
        mapper.commit()
        self.assertEqual(1, mapper.db.getVersion())
        mapper.close()

        # TODO: Maybe some mapper test for backward compatibility can be
        # include in scipion-em, where we already have defined datasets
        # and reference old sqlite files

        # Test using SqliteDb class
        db = pwmapper.SqliteDb()
        db._createConnection(fn, timeout=1000)
        tables = ['Objects', 'Relations']
        self.assertEqual(tables, db.getTables())
        # Test getting the version, for the gold file it should be 0
        self.assertEqual(1, db.getVersion())
        db.close()

        # Reading test
        mapper2 = pwmapper.SqliteMapper(fn, pw.Config.getDomain().getMapperDict())
        print("Checking that Relations table is updated and version to 1")
        self.assertEqual(1, mapper2.db.getVersion())
        # Check that the new column is properly added after updated to version 1
        colNamesGold = [u'id', u'parent_id', u'name', u'classname',
                        u'value', u'label', u'comment', u'object_parent_id',
                        u'object_child_id', u'creation',
                        u'object_parent_extended', u'object_child_extended']
        colNames = [col[1] for col in mapper2.db.getTableColumns('Relations')]
        self.assertEqual(colNamesGold, colNames)

        l = mapper2.selectByClass('Integer')[0]
        self.assertEqual(l.get(), 1)

        f2 = mapper2.selectByClass('Float')[0]
        self.assertEqual(f, f2.get())

        b = mapper2.selectByClass('Boolean')[0]
        self.assertTrue(not b.get())

        p = mapper2.selectByClass('Pointer')[0]
        self.assertEqual(b.get(), p.get())

        csv2 = mapper2.selectByClass('CsvList')[0]
        self.assertTrue(list.__eq__(csv2, strList))

        # Iterate over all objects
        allObj = mapper2.selectAll()
        iterAllObj = mapper2.selectAll(iterate=True)

        for a1, a2 in zip(allObj, iterAllObj):
            # Note compare the scalar objects, which have a well-defined comparison
            if isinstance(a1, pwobj.Scalar):
                self.assertEqual(a1, a2)

        # Test select all batch approach
        allBatch = mapper2.selectAllBatch()

        # Test relations
        childs = mapper2.getRelationChilds(relName, i)
        parents = mapper2.getRelationParents(relName, p)
        # In this case both childs and parent should be the same
        for c, p in zip(childs, parents):
            self.assertEqual(c, p,
                             "Childs of object i, should be the parents of object p")

        relations = mapper2.getRelationsByCreator(creator)
        for row in relations:
            print(dict(row))
Example #8
0
 def __init__(self, **kwargs):
     EMProtocol.__init__(self, **kwargs)
     self.stepsExecutionMode = pwcts.STEPS_PARALLEL
     self.isFirstTime = pwobj.Boolean(False)