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()
def __init__(self, **kwargs): EdBaseObject.__init__(self, **kwargs) self._spotId = pwobj.Integer() self._bbox = pwobj.CsvList() self._flag = pwobj.Integer() self._intensitySumValue = pwobj.Float() self._intensitySumVariance = pwobj.Float() self._nSignal = pwobj.Integer() self._panel = pwobj.Integer() self._shoebox = None self._xyzobsPxValue = pwobj.CsvList() self._xyzobsPxVariance = pwobj.CsvList()
def _setAlignmentInfo(self, movie, obj): """ Set alignment info such as plot and psd filename, and the cumulative shifts values. Params: movie: Pass the reference movie obj: should pass either the created micrograph or movie """ obj.plotCart = Image() obj.plotCart.setFileName(self._getPlotCart(movie)) if self.doComputePSD: obj.psdCorr = Image() obj.psdCorr.setFileName(self._getPsdCorr(movie)) meanX, meanY = self._loadMeanShifts(movie) obj._xmipp_OFMeanX = pwobj.CsvList() obj._xmipp_OFMeanX.set(meanX) obj._xmipp_OFMeanY = pwobj.CsvList() obj._xmipp_OFMeanY.set(meanY)
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)
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))
def __init__(self, **kwargs): ProtMonitor.__init__(self, **kwargs) self._runIds = pwobj.CsvList(pType=int)
def rotateAstimatism(self, tsObjId): getTMTS = self.getTMSetOfTiltSeries.get()[tsObjId] tsId = getTMTS.getTsId() # inputCtfTomoSeries = self.inputSetOfCtfTomoSeries.get()[tsObjId] match = False for inputCtfTomoSeries in self.inputSetOfCtfTomoSeries.get(): if tsId == inputCtfTomoSeries.getTsId(): match = True self.getOutputSetOfCTFTomoSeries() newCTFTomoSeries = tomoObj.CTFTomoSeries() newCTFTomoSeries.copyInfo(inputCtfTomoSeries) newCTFTomoSeries.setTiltSeries(getTMTS) newCTFTomoSeries.setTsId(tsId) newCTFTomoSeries.setObjId(tsObjId) newCTFTomoSeries.setIMODDefocusFileFlag(inputCtfTomoSeries.getIMODDefocusFileFlag()) newCTFTomoSeries.setNumberOfEstimationsInRange(inputCtfTomoSeries.getNumberOfEstimationsInRange()) self.outputSetOfCTFTomoSeries.append(newCTFTomoSeries) for index, (tiltImageGetTM, inputCtfTomo) in enumerate(zip(getTMTS, inputCtfTomoSeries)): newCTFTomo = tomoObj.CTFTomo() newCTFTomo.copyInfo(inputCtfTomo) rotationAngle = utils.calculateRotationAngleFromTM(tiltImageGetTM) if newCTFTomo.hasAstigmatismInfoAsList(): defocusAngleList = pwobj.CsvList(pType=float) for angle in inputCtfTomo.getDefocusAngleList().split(','): defocusAngleList.append(pwobj.Float(round(float(angle)+rotationAngle,2))) newCTFTomo.setDefocusAngleList(defocusAngleList) newCTFTomo.completeInfoFromList() else: newCTFTomo.setDefocusAngle(pwobj.Float(inputCtfTomo.getDefocusAngle() + rotationAngle)) newCTFTomo.standardize() newCTFTomoSeries.append(newCTFTomo) newCTFTomoSeries.setNumberOfEstimationsInRangeFromDefocusList() newCTFTomoSeries.setIsDefocusUDeviationInRange(inputCtfTomoSeries.getIsDefocusUDeviationInRange()) newCTFTomoSeries.setIsDefocusVDeviationInRange(inputCtfTomoSeries.getIsDefocusVDeviationInRange()) if not (newCTFTomoSeries.getIsDefocusUDeviationInRange() and newCTFTomoSeries.getIsDefocusVDeviationInRange()): newCTFTomoSeries.setEnabled(False) newCTFTomoSeries.write(properties=False) self.outputSetOfCTFTomoSeries.update(newCTFTomoSeries) self.outputSetOfCTFTomoSeries.write() self._store() if not match: raise Exception("There is no matching CtfTomoSeries for a tilt-series %s" % (tsId))
def __init__(self, **kwargs): EMProtocol.__init__(self, **kwargs) self._runIds = pwobj.CsvList(pType=int) self.childs = []
def _floatList(key): fl = pwobj.CsvList(pType=float) fl.set(kwargs.get(key, [])) return fl
def importSetOfCtfTomoSeries(self): inputSetOfTiltSeries = self.inputSetOfTiltSeries.get() self.getOutputSetOfCTFTomoSeries() for ts in inputSetOfTiltSeries: tsId = ts.getTsId() tsFileName = ts.getFirstItem().parseFileName(extension='') for ctfFile, _ in self.iterFiles(): defocusFilePath = ctfFile defocusFileName = os.path.basename( os.path.splitext(ctfFile)[0]) if tsFileName == defocusFileName: print("Parsing file: " + defocusFilePath) defocusFileFlag = utils.getDefocusFileFlag(defocusFilePath) newCTFTomoSeries = tomoObj.CTFTomoSeries() newCTFTomoSeries.copyInfo(ts) newCTFTomoSeries.setTiltSeries(ts) newCTFTomoSeries.setTsId(tsId) newCTFTomoSeries.setIMODDefocusFileFlag(defocusFileFlag) # We need to create now all the attributes of this object in order to append it to the set and be # able to update it posteriorly. newCTFTomoSeries.setNumberOfEstimationsInRange(None) self.outputSetOfCTFTomoSeries.append(newCTFTomoSeries) if defocusFileFlag == 0: " Plain estimation " defocusUDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 1: " Astigmatism estimation " defocusUDict, defocusVDict, defocusAngleDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 4: " Phase-shift information " defocusUDict, phaseShiftDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 5: " Astigmatism and phase shift estimation " defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 37: " Astigmatism, phase shift and cut-on frequency estimation " defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) else: raise Exception( "Defocus file flag do not supported. Only supported formats corresponding to flags 0, " "1, 4, 5, and 37.") for index, _ in enumerate(ts): newCTFTomo = tomoObj.CTFTomo() newCTFTomo.setIndex(pwobj.Integer(index + 1)) if defocusFileFlag == 0: " Plain estimation " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) elif defocusFileFlag == 1: " Astigmatism estimation " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusAngleList( defocusAngleDict[index + 1]) elif defocusFileFlag == 4: " Phase-shift information " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList( pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) elif defocusFileFlag == 5: " Astigmatism and phase shift estimation " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusAngleList( defocusAngleDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList( pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) elif defocusFileFlag == 37: " Astigmatism, phase shift and cut-on frequency estimation " newCTFTomo._defocusUList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList( pType=float) newCTFTomo.setDefocusAngleList( defocusAngleDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList( pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) newCTFTomo._cutOnFreqList = pwobj.CsvList( pType=float) newCTFTomo.setCutOnFreqList(cutOnFreqDict[index + 1]) defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) newCTFTomo.completeInfoFromList() newCTFTomoSeries.append(newCTFTomo) newCTFTomoSeries.setNumberOfEstimationsInRangeFromDefocusList( ) newCTFTomoSeries.write(properties=False) self.outputSetOfCTFTomoSeries.update(newCTFTomoSeries) self.outputSetOfCTFTomoSeries.write() self._store()
def createOutputStep(self, tsObjId, outputSetName): ts = self._getTiltSeries(tsObjId) tsId = ts.getTsId() objId = ts.getObjId() self.outputSetName = outputSetName extraPrefix = self._getExtraPath(tsId) defocusFilePath = os.path.join( extraPrefix, ts.getFirstItem().parseFileName(extension=".defocus")) if os.path.exists(defocusFilePath): self.getOutputSetOfCTFTomoSeries(self.outputSetName) defocusFileFlag = utils.getDefocusFileFlag(defocusFilePath) newCTFTomoSeries = tomoObj.CTFTomoSeries() newCTFTomoSeries.copyInfo(ts) newCTFTomoSeries.setTiltSeries(ts) newCTFTomoSeries.setTsId(tsId) newCTFTomoSeries.setObjId(objId) newCTFTomoSeries.setIMODDefocusFileFlag(defocusFileFlag) # We need to create now all the attributes of this object in order # to append it to the set and be able to update it posteriorly. " newCTFTomoSeries.setNumberOfEstimationsInRange(None) output = getattr(self, self.outputSetName) output.append(newCTFTomoSeries) if defocusFileFlag == 0: " Plain estimation " defocusUDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 1: " Astigmatism estimation " defocusUDict, defocusVDict, defocusAngleDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 4: " Phase-shift information " defocusUDict, phaseShiftDict = utils.readCTFEstimationInfoFile( defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 5: " Astigmatism and phase shift estimation " defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) elif defocusFileFlag == 37: " Astigmatism, phase shift and cut-on frequency estimation " defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) else: raise Exception( "Defocus file flag do not supported. Only supported formats corresponding to flags 0, " "1, 4, 5, and 37.") for index, _ in enumerate(ts): newCTFTomo = tomoObj.CTFTomo() newCTFTomo.setIndex(pwobj.Integer(index + 1)) if defocusFileFlag == 0: " Plain estimation " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) elif defocusFileFlag == 1: " Astigmatism estimation " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusAngleList(defocusAngleDict[index + 1]) elif defocusFileFlag == 4: " Phase-shift information " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList(pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) elif defocusFileFlag == 5: " Astigmatism and phase shift estimation " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusAngleList(defocusAngleDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList(pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) elif defocusFileFlag == 37: " Astigmatism, phase shift and cut-on frequency estimation " newCTFTomo._defocusUList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusUList(defocusUDict[index + 1]) newCTFTomo._defocusVList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusVList(defocusVDict[index + 1]) newCTFTomo._defocusAngleList = pwobj.CsvList(pType=float) newCTFTomo.setDefocusAngleList(defocusAngleDict[index + 1]) newCTFTomo._phaseShiftList = pwobj.CsvList(pType=float) newCTFTomo.setPhaseShiftList(phaseShiftDict[index + 1]) newCTFTomo._cutOnFreqList = pwobj.CsvList(pType=float) newCTFTomo.setCutOnFreqList(cutOnFreqDict[index + 1]) defocusUDict, defocusVDict, defocusAngleDict, phaseShiftDict, cutOnFreqDict = \ utils.readCTFEstimationInfoFile(defocusFilePath, flag=defocusFileFlag) newCTFTomo.completeInfoFromList() newCTFTomoSeries.append(newCTFTomo) newCTFTomoSeries.setNumberOfEstimationsInRangeFromDefocusList() newCTFTomoSeries.calculateDefocusUDeviation( defocusUTolerance=self.defocusUTolerance) newCTFTomoSeries.calculateDefocusVDeviation( defocusVTolerance=self.defocusVTolerance) if not (newCTFTomoSeries.getIsDefocusUDeviationInRange() and newCTFTomoSeries.getIsDefocusVDeviationInRange()): newCTFTomoSeries.setEnabled(False) newCTFTomoSeries.write(properties=False) output.update(newCTFTomoSeries) output.write() self._store()
def __init__(self, **args): pwobj.Object.__init__(self, **args) self.csv = pwobj.CsvList()