def test_findGridSquaresNotUploaded(self): allParams = json.loads( open( "/scisoft/pxsoft/data/cryoem/testRunData/20180423/allParams.json" ).read()) dictGridSquares = UtilsIcat.findGridSquaresNotUploaded(allParams) pprint.pprint(dictGridSquares)
def tes_getStackTraceLog(self): errorMessage = None try: print(1 / 0) except: errorMessage = UtilsIcat.getStackTraceLog() print(errorMessage) self.assertNotEquals(errorMessage, None)
def tes_uploadToIcat(self): listFiles = [ "/data/visitor/mx2005/cm01/20171209/RAW_DATA/baseplate-epu-grid2/Images-Disc1/GridSquare_7259648/Data/FoilHole_7265309_Data_7264706_7264707_20171207_1704-10925.mrc", ] directory = "/data/visitor/mx2005/cm01/20171209/RAW_DATA/baseplate-epu-grid2" proposal = "id310009" sample = "sample1" dataSetName = "GridSquare_7259648_{0}".format(round(time.time())) dictMetadata = { "EM_amplitude_contrast": 0.0, "EM_dose_initial": 1.0, "EM_dose_per_frame": 2.0, "EM_images_count": 3.0, "EM_magnification": 4.0, "EM_position_x": 5.0, "EM_position_y": 6.0, "EM_protein_acronym": 7.0, "EM_sampling_rate": 8.0, "EM_spherical_aberration": 9.0, "EM_voltage": 10.0 } UtilsIcat.uploadToIcat(listFiles, directory, proposal, sample, dataSetName, dictMetadata)
def tes_uploadToIcat(self): listFiles = [ "/data/visitor/mx415/cm01/20180619/RAW_DATA/epu-grid2-ddw49-1_1/Images-Disc1/GridSquare_7728190/Data/FoilHole_7742940_Data_7738968_7738969_20180611_0959.mrc" ] directory = "/data/visitor/mx415/cm01/20180619/RAW_DATA/epu-grid2-ddw49-1_1" proposal = "id000001" sample = "Test" dataSetName = "Test_1_1" dictMetadata = {"EM_voltage": "300000"} listGalleryPath = [ "/data/visitor/mx415/cm01/20180619/RAW_DATA/epu-grid2-ddw49-1_1/Images-Disc1/GridSquare_7728190/GridSquare_20180608_164247.jpg" ] errorMessage = UtilsIcat.uploadToIcat(listFiles, directory, proposal, sample, dataSetName, dictMetadata, listGalleryPath) print(errorMessage)
def archiveGridSquare(self, gridSquareToBeArchived): # Archive remaining movies self.info("Archiving grid square: {0}".format(gridSquareToBeArchived)) listPathsToBeArchived = [] sumPositionX = 0.0 sumPositionY = 0.0 indexPosition = 0 for movieName in self.allParams: if "gridSquare" in self.allParams[movieName] and self.allParams[movieName]["gridSquare"] == gridSquareToBeArchived and not self.allParams[movieName]["archived"]: listPathsToBeArchived.append(self.allParams[movieName]["movieFullPath"]) self.allParams[movieName]["archived"] = True try: sumPositionX += float(self.allParams[movieName]["positionX"]) sumPositionY += float(self.allParams[movieName]["positionY"]) indexPosition += 1 except: pass noImagesToBeArchived = len(listPathsToBeArchived) if noImagesToBeArchived > 0: if indexPosition > 0: meanPositionX = sumPositionX / indexPosition meanPositionY = sumPositionY / indexPosition else: meanPositionX = None meanPositionY = None dictIcatMetaData = dict(self.allParams["EM_meta_data"]) dictIcatMetaData["EM_position_x"] = meanPositionX dictIcatMetaData["EM_position_y"] = meanPositionY directory = dictIcatMetaData["EM_directory"] listGalleryPath = self.allParams[gridSquareToBeArchived]["listGalleryPath"] dataSetName = "{0}_{1}".format(gridSquareToBeArchived, round(time.time())) self.allParams[dataSetName] = dictIcatMetaData self.info("listPathsToBeArchived: {0}".format(pprint.pformat(listPathsToBeArchived))) self.info("directory: {0}".format(directory)) self.info("self.proposal: {0}".format(self.proposal)) self.info("self.sampleAcronym: {0}".format(self.sampleAcronym)) self.info("dataSetName: {0}".format(dataSetName)) self.info("dictIcatMetaData: {0}".format(pprint.pformat(dictIcatMetaData))) errorMessage = UtilsIcat.uploadToIcat(listPathsToBeArchived, directory, self.proposal, self.sampleAcronym, dataSetName, dictIcatMetaData, listGalleryPath) if errorMessage is not None: self.info("ERROR during icat upload!") self.info(errorMessage)
def archiveOldGridSquares(self, gridSquareNotToArchive=None): # Check if there are remaining grid squares to be uploaded: dictGridSquares = UtilsIcat.findGridSquaresNotUploaded(self.allParams, gridSquareNotToArchive) for gridSquareToBeArchived in dictGridSquares: self.archiveGridSquare(gridSquareToBeArchived)