Пример #1
0
 def test_getShiftData(self):
     mrcFilePath = "/scisoft/pxsoft/data/cryoem/testRunData/20171113/Runs/000056_ProtMotionCorr/extra/FoilHole_9208892_Data_9209286_9209287_20171109_1540-0539_aligned_mic.mrc"
     dictResult = UtilsPath.getShiftData(mrcFilePath)
     dictRef = {
         'averageMotionPerFrame': 6.3,
         'noPoints': 40,
         'totalMotion': 250.6
     }
     self.assertEqual(dictRef, dictResult)
    def uploadAlignMovies(self, prot):
        self.info("ESRF ISPyB upload motion corr results")
        for micrograph in self.iter_updated_set(prot.outputMicrographs):
            micrographFullPath = os.path.join(self.currentDir, micrograph.getFileName())
            #self.info("Motion corr micrographFullPath: {0}".format(micrographFullPath))
            dictFileNameParameters = UtilsPath.getMovieFileNameParametersFromMotioncorrPath(micrographFullPath)
            movieName = dictFileNameParameters["movieName"]
            #self.info("Motion corr movie name: {0}".format(movieName))
            if movieName in self.allParams and not "motionCorrectionId" in self.allParams[movieName]:
                self.info("Align movies: movie {0}".format(os.path.basename(self.allParams[movieName]["movieFullPath"])))
                movieFullPath = self.allParams[movieName]["movieFullPath"]
                dictResult = UtilsPath.getAlignMoviesPngLogFilePath(micrographFullPath)
                driftPlotFullPath = dictResult["globalShiftPng"]
                if "doseWeightMrc" in dictResult:
                    correctedDoseMicrographFullPath = dictResult["doseWeightMrc"]
                else:
                    correctedDoseMicrographFullPath = None
                if "thumbnailPng" in dictResult:
                    micrographSnapshotFullPath = dictResult["thumbnailPng"]
                else:
                    micrographSnapshotFullPath = None
                dictShift = UtilsPath.getShiftData(micrographFullPath)
                if "totalMotion" in dictShift:
                    totalMotion = dictShift["totalMotion"]
                else:
                    totalMotion = None
                if "averageMotionPerFrame" in dictShift:
                    averageMotionPerFrame = dictShift["averageMotionPerFrame"]
                else:
                    averageMotionPerFrame = None
                logFileFullPath = dictResult["logFileFullPath"]
                firstFrame = 1
                lastFrame = self.allParams[movieName]["imagesCount"]
                dosePerFrame = self.allParams[movieName]["dosePerFrame"]
                doseWeight = None
                driftPlotPyarchPath = UtilsPath.copyToPyarchPath(driftPlotFullPath)
                micrographPyarchPath = None
                correctedDoseMicrographPyarchPath = None
                micrographSnapshotPyarchPath = UtilsPath.copyToPyarchPath(micrographSnapshotFullPath)
                logFilePyarchPath = UtilsPath.copyToPyarchPath(logFileFullPath)
                
                shutil.copy(micrographFullPath, self.allParams[movieName]["processDir"])
                shutil.copy(correctedDoseMicrographFullPath, self.allParams[movieName]["processDir"])
                shutil.copy(logFileFullPath, self.allParams[movieName]["processDir"])
                try:
                    motionCorrectionObject = self.client.service.addMotionCorrection(proposal=self.proposal, 
                                                movieFullPath=movieFullPath,
                                                firstFrame=firstFrame,
                                                lastFrame=lastFrame,
                                                dosePerFrame=dosePerFrame,
                                                doseWeight=doseWeight,
                                                totalMotion=totalMotion,
                                                averageMotionPerFrame=averageMotionPerFrame,
                                                driftPlotFullPath=driftPlotPyarchPath,
                                                micrographFullPath=micrographPyarchPath,
                                                correctedDoseMicrographFullPath=correctedDoseMicrographPyarchPath,
                                                micrographSnapshotFullPath=micrographSnapshotPyarchPath,
                                                logFileFullPath=logFilePyarchPath)
                except:
                    self.info("ERROR uploading motion correction for movie {0}".format(movieFullPath))
                    traceback.print_exc()
                    motionCorrectionObject = None

                if motionCorrectionObject is not None:
                    motionCorrectionId = motionCorrectionObject.motionCorrectionId
                else:
                    self.info("ERROR: motionCorrectionObject is None!")
                    motionCorrectionId = None
                    
                self.allParams[movieName]["motionCorrectionId"] = motionCorrectionId
                self.allParams[movieName]["totalMotion"] = totalMotion
                self.allParams[movieName]["averageMotionPerFrame"] = averageMotionPerFrame
                
                self.info("Align movies done, motionCorrectionId = {0}".format(motionCorrectionId))