Пример #1
0
 def run(self, in_data):
     sub_wedge_merge = []
     fast_characterisation = {}
     force_zero_rotation_axis_start = False
     if "fastCharacterisation" in in_data:
         fast_characterisation = in_data["fastCharacterisation"]
         force_zero_rotation_axis_start = fast_characterisation.get(
             "forceZeroRotationAxisStart", False)
         is_fast_characterisation = True
         list_subwedge_angles = fast_characterisation["listSubWedgeAngles"]
         no_images_in_subwedge = fast_characterisation["noImagesInSubWedge"]
         first_image_path = fast_characterisation["firstImagePath"]
         image_number = 1
         template = first_image_path.replace("0001", "{0:04d}")
         list_image_path = []
         for subwedge_angle in list_subwedge_angles:
             for sub_wedge_image_number in range(no_images_in_subwedge):
                 image_path = template.format(image_number)
                 list_image_path.append(image_path)
                 image_number += 1
     elif "imagePath" in in_data:
         list_image_path = in_data["imagePath"]
         is_fast_characterisation = False
         list_subwedge_angles = None
         no_images_in_subwedge = None
     else:
         raise RuntimeError(
             "Neither 'imagePath' nor 'fastCharacterisation' in input data."
         )
     sub_wedge_number = 1
     input_read_image_header = {"imagePath": list_image_path}
     read_image_header = ReadImageHeader(inData=input_read_image_header)
     read_image_header.execute()
     if read_image_header.isSuccess():
         list_subwedge = read_image_header.outData["subWedge"]
         global_axis_start = None
         if force_zero_rotation_axis_start:
             for subwedge in list_subwedge:
                 axis_start = subwedge["experimentalCondition"][
                     "goniostat"]["rotationAxisStart"]
                 if global_axis_start is None or global_axis_start > axis_start:
                     global_axis_start = axis_start
         for index_subwedge, subwedge in enumerate(list_subwedge):
             if is_fast_characterisation:
                 # Modify the start angle
                 index_angle = int(index_subwedge / no_images_in_subwedge)
                 angle_subwedge = list_subwedge_angles[index_angle]
                 goniostat = subwedge["experimentalCondition"]["goniostat"]
                 if force_zero_rotation_axis_start:
                     goniostat["rotationAxisStart"] -= global_axis_start
                 goniostat["rotationAxisStart"] = (
                     goniostat["rotationAxisStart"] + angle_subwedge) % 360
                 goniostat["rotationAxisEnd"] = (
                     goniostat["rotationAxisEnd"] + angle_subwedge) % 360
             else:
                 subwedge["subWedgeNumber"] = index_subwedge + 1
         sub_wedge_merge = UtilsSubWedge.subWedgeMerge(list_subwedge)
     out_data = {"subWedge": sub_wedge_merge}
     return out_data
 def test_execute_ReadImageHeader_eiger4m(self):
     referenceDataPath = self.dataPath / 'ReadImageHeader_Eiger4M.json'
     inData = UtilsTest.loadAndSubstitueTestData(referenceDataPath)
     readImageHeader = ReadImageHeader(inData=inData)
     readImageHeader.execute()
     self.assertTrue(readImageHeader.isSuccess())
     outData = readImageHeader.outData
     self.assertIsNotNone(outData)
Пример #3
0
 def readImageHeaders(listImagePath):
     # Read the header(s)
     inDataReadImageHeader = {"imagePath": listImagePath}
     readImageHeader = ReadImageHeader(
         inData=inDataReadImageHeader,
         workingDirectorySuffix=UtilsImage.getPrefix(listImagePath[0]),
     )
     readImageHeader.execute()
     listSubWedge = readImageHeader.outData["subWedge"]
     return listSubWedge
Пример #4
0
 def run(self, inData):
     outData = {}
     hdf5File = pathlib.Path(inData['hdf5File'])
     # Read the header
     inDataReadImageHeader = {
         "imagePath": [inData['hdf5File']],
         "isFastMesh": False
     }
     readImageHeader = ReadImageHeader(inData=inDataReadImageHeader)
     readImageHeader.execute()
     if readImageHeader.isSuccess():
         firstSubWedge = readImageHeader.outData["subWedge"][0]
         experimentalCondition = firstSubWedge["experimentalCondition"]
         detector = experimentalCondition["detector"]
         beam = experimentalCondition["beam"]
         goniostat = experimentalCondition["goniostat"]
         beamX = detector["beamPositionX"] / 2.0 / detector["pixelSizeX"]
         beamY = detector["beamPositionY"] / 2.0 / detector["pixelSizeY"]
         directory = hdf5File.parent
         prefix = UtilsImage.getPrefix(hdf5File)
         hdf5ImageNumber = 1
         if 'master' in str(hdf5File):
             masterFile = hdf5File
         else:
             if UtilsConfig.isEMBL():
                 fileName = '{0}_master.h5'.format(prefix)
             else:
                 fileName = '{0}_{1}_master.h5'.format(
                     prefix, hdf5ImageNumber)
             masterFile = directory / fileName
         image = fabio.open(str(masterFile))
         image.data = image.data.reshape(2181, 2, 2074, 2).sum(3).sum(1)
         cbfImage = image.convert("cbf")
         pilatus_headers = fabio.cbfimage.PilatusHeader(
             "Silicon sensor, thickness 0.000750 m")
         pilatus_headers["Start_angle"] = goniostat["rotationAxisStart"]
         pilatus_headers["Angle_increment"] = goniostat["oscillationWidth"]
         pilatus_headers["Detector"] = "Eiger2 16M binned to 4M"
         pilatus_headers["Pixel_size"] = (detector["pixelSizeY"] * 2,
                                          detector["pixelSizeX"] * 2)
         pilatus_headers["Exposure_time"] = beam["exposureTime"]
         pilatus_headers["Wavelength"] = beam["wavelength"]
         pilatus_headers[
             "Detector_distance"] = detector["distance"] / 1000.0
         pilatus_headers["Beam_xy"] = (beamY, beamX)
         pilatus_headers["Count_cutoff"] = 1009869
         cbfImage.pilatus_headers = pilatus_headers
         directory = inData.get("forcedOutputDirectory",
                                str(self.getWorkingDirectory()))
         cbfImagePath = os.path.join(
             directory,
             os.path.basename(inData['hdf5File']).replace(".h5", ".cbf"))
         cbfImage.save(cbfImagePath)
         outData["outputCBFFile"] = cbfImagePath
     return outData
 def test_executeReadImageHeaderTaskk(self):
     referenceDataPath = self.dataPath / 'ControlReadImageHeader.json'
     inData = UtilsTest.loadAndSubstitueTestData(referenceDataPath)
     readImageHeader = ReadImageHeader(inData=inData)
     readImageHeader.execute()
     self.assertTrue(readImageHeader.isSuccess())
Пример #6
0
 def run(self, inData):
     # Format suffix
     format = inData.get("format", "jpeg")
     if format == "jpeg":
         thumbSuffix = ".jpeg"
     elif format == "jpg":
         thumbSuffix = ".jpg"
     else:
         raise RuntimeError("Unsupported format: {0}".format(format))
     # Loop through all images
     listJPEGTask = []
     listThumbTask = []
     forcedOutputDirectory = inData.get("forcedOutputDirectory", None)
     for imagePath in inData["image"]:
         # Check image file extension
         imageFileName, suffix = os.path.splitext(
             os.path.basename(imagePath))
         if not suffix in [".img", ".marccd", ".mccd", ".cbf", ".h5"]:
             raise RuntimeError(
                 "Unknown image file name extension for pyarch thumbnail generator: %s"
                 % imagePath)
         # Wait for image file
         if suffix == ".h5":
             h5MasterFilePath, h5DataFilePath, h5FileNumber = UtilsImage.getH5FilePath(
                 imagePath, isFastMesh=True)
             waitFilePath = h5DataFilePath
         else:
             waitFilePath = imagePath
         expectedSize = self.getExpectedSize(imagePath)
         hasTimedOut, finalSize = UtilsPath.waitForFile(
             waitFilePath, expectedSize=expectedSize, timeOut=600)
         if hasTimedOut:
             raise RuntimeError(
                 "Waiting for file {0} timed out!".format(imagePath))
         outputFileName = imageFileName + thumbSuffix
         if forcedOutputDirectory is not None:
             outputPath = os.path.join(forcedOutputDirectory,
                                       outputFileName)
         else:
             outputPath = None
         # Create JPEG with resolution rings
         inDataReadHeader = {
             "imagePath": [imagePath],
             "skipNumberOfImages": True,
             "isFastMesh": True
         }
         readHeader = ReadImageHeader(
             inData=inDataReadHeader,
             workingDirectorySuffix=imageFileName,
         )
         readHeader.execute()
         experimentalCondition = readHeader.outData["subWedge"][0][
             "experimentalCondition"]
         detector = experimentalCondition["detector"]
         beam = experimentalCondition["beam"]
         inDataCreateJPEG = {
             "image": imagePath,
             "height": 1024,
             "width": 1024,
             "outputFileName": outputFileName,
             "outputPath": outputPath,
             "doResolutionRings": True,
             "pixelSizeX": detector["pixelSizeX"],
             "pixelSizeY": detector["pixelSizeY"],
             "beamPositionX": detector["beamPositionX"],
             "beamPositionY": detector["beamPositionY"],
             "distance": detector["distance"],
             "wavelength": beam["wavelength"],
         }
         createJPEG = CreateThumbnail(inData=inDataCreateJPEG,
                                      workingDirectorySuffix=imageFileName +
                                      "_JPEG")
         createJPEG.start()
         listJPEGTask.append(createJPEG)
         # Create thumbnail
         outputFileName = imageFileName + ".thumb" + thumbSuffix
         if forcedOutputDirectory is not None:
             outputPath = os.path.join(forcedOutputDirectory,
                                       outputFileName)
         else:
             outputPath = None
         inDataCreateThumb = {
             "image": imagePath,
             "height": 256,
             "width": 256,
             "outputFileName": outputFileName,
             "outputPath": outputPath,
             "doResolutionRings": True,
             "pixelSizeX": detector["pixelSizeX"],
             "pixelSizeY": detector["pixelSizeY"],
             "beamPositionX": detector["beamPositionX"],
             "beamPositionY": detector["beamPositionY"],
             "distance": detector["distance"],
             "wavelength": beam["wavelength"],
         }
         createThumb = CreateThumbnail(
             inData=inDataCreateThumb,
             workingDirectorySuffix=imageFileName + "_thumbnail")
         createThumb.start()
         listThumbTask.append(createThumb)
     outData = {"pathToJPEGImage": [], "pathToThumbImage": []}
     for task in listJPEGTask:
         task.join()
         if forcedOutputDirectory:
             outData["pathToJPEGImage"].append(task.outData["thumbNail"])
         else:
             pyarchPath = self.copyThumbnailToPyarch(task)
             outData["pathToJPEGImage"].append(pyarchPath)
     for task in listThumbTask:
         task.join()
         if forcedOutputDirectory:
             outData["pathToThumbImage"].append(task.outData["thumbNail"])
         else:
             pyarchPath = self.copyThumbnailToPyarch(task)
             outData["pathToThumbImage"].append(pyarchPath)
     return outData
Пример #7
0
 def test_executeReadImageHeaderTask_id23eh1_1(self):
     referenceDataPath = self.dataPath / "id23eh1_1.json"
     inData = UtilsTest.loadAndSubstitueTestData(referenceDataPath)
     readImageHeader = ReadImageHeader(inData=inData)
     readImageHeader.execute()
     self.assertTrue(readImageHeader.isSuccess())
Пример #8
0
 def generateMOSFLMInData(cls, inData):
     if "imagePath" in inData:
         inDataReadImageHeader = {"imagePath": inData["imagePath"]}
         readImageHeader = ReadImageHeader(inData=inDataReadImageHeader)
         readImageHeader.execute()
         listSubWedges = readImageHeader.outData["subWedge"]
     elif "subWedge" in inData:
         listSubWedges = inData["subWedge"]
     else:
         # Here we assume that we have inData in MOSFLM format...
         return inData
     firstSubWedge = listSubWedges[0]
     experimentalCondition = firstSubWedge["experimentalCondition"]
     detector = experimentalCondition["detector"]
     beam = experimentalCondition["beam"]
     goniostat = experimentalCondition["goniostat"]
     detectorType = detector["type"]
     if detectorType.startswith("pilatus"):
         mosflmDetector = "PILATUS"
     elif detectorType.startswith("eiger"):
         mosflmDetector = "EIGER"
     else:
         raise RuntimeError("Unknown detecor type for MOSFLM: " +
                            detectorType)
     listImage = firstSubWedge["image"]
     firstImage = listImage[0]
     firstPath = firstImage["path"]
     mosflmInData = {
         # The MOSFLM beam position convention is opposite to the XDS / CBF/ Dozor convention
         "beam": {
             "x": detector["beamPositionY"],
             "y": detector["beamPositionX"]
         },
         "detector": {
             "numberPixelX": detector["numberPixelX"],
             "numberPixelY": detector["numberPixelY"],
             "pixelSizeX": detector["pixelSizeX"],
             "pixelSizeY": detector["pixelSizeY"],
             "type": mosflmDetector
         },
         "directory": os.path.dirname(firstPath),
         "distance": detector["distance"],
         "template": UtilsImage.getTemplate(firstPath),
         "wavelength": beam["wavelength"]
     }
     listMosflmImage = []
     for subWedge in listSubWedges:
         goniostat = subWedge["experimentalCondition"]["goniostat"]
         rotationAxisStart = goniostat['rotationAxisStart']
         oscillationWidth = goniostat['oscillationWidth']
         imageIndex = 0
         for image in subWedge["image"]:
             number = UtilsImage.getImageNumber(image["path"])
             rotationAxisStart = rotationAxisStart + oscillationWidth * imageIndex
             rotationAxisEnd = rotationAxisStart + oscillationWidth
             mosflmImage = {
                 "number": number,
                 "rotationAxisStart": rotationAxisStart,
                 "rotationAxisEnd": rotationAxisEnd
             }
             listMosflmImage.append(mosflmImage)
     mosflmInData["image"] = listMosflmImage
     return mosflmInData