示例#1
0
 def save(self, filename):
     """
     Save configuration to file
     """
     if isinstance(self.reference, int):
         reference = self.reference
     else:
         reference = -1
     xsdi = XSDataInputFullFieldXAS(HDF5File=XSDataFile(XSDataString(self.HDF5)),
                                    internalHDF5Path=XSDataString(self.internalHdf5),
                                    measureOffset=self.getXSDMeasureOffset(),
                                    reference=XSDataInteger(reference),
                                    dark=self.getXsdDark())
     with open(filename, "wb") as xmlFile:
         xmlFile.write(xsdi.marshal())
示例#2
0
 def load(self, filename):
     """
     Retrieve information from XML file
     """
     xsdi = XSDataInputFullFieldXAS.parseFile(filename)
     self.HDF5 = xsdi.HDF5File.path.value
     self.internalHdf5 = xsdi.internalHDF5Path.value
     self.measureOffset = {}
     mo = xsdi.measureOffset
     if mo:
         if mo.alwaysVersusRef:
             self.measureOffset[
                 "alwaysVersusRef"] = mo.alwaysVersusRef.value
         if mo.cropBorders:
             self.measureOffset["cropBorders"] = [
                 i.value for i in mo.cropBorders
             ]
         if mo.smoothBorders:
             self.measureOffset["smoothBorders"] = [
                 i.value for i in mo.smoothBorders
             ]
         if mo.sobelFilter:
             self.measureOffset["sobelFilter"] = mo.sobelFilter.value
         if mo.useSift:
             self.measureOffset["useSift"] = mo.useSift.value
         if mo.removeBackground:
             self.measureOffset[
                 "removeBackground"] = mo.removeBackground.value
     self.reference = xsdi.reference.value
     self.darks = [{
         "path": i.path.value,
         "exposureTime": i.exposureTime.value
     } for i in xsdi.dark]
 def testCheckParameters(self):
     xsDataInput = XSDataInputFullFieldXAS(index=XSDataInteger(0),
                                           HDF5File=XSDataFile(),
                                           internalHDF5Path=XSDataString())
     edPluginExecFullFieldXAS = self.createPlugin()
     edPluginExecFullFieldXAS.setDataInput(xsDataInput)
     edPluginExecFullFieldXAS.checkParameters()
示例#4
0
 def error(self, strXMLin):
     """
     This is an example of XMLerr function ... it prints only the name of the file created
     @param srXMLin: The XML string used to launch the job
     @type strXMLin: python string with the input XML
     @rtype: None
     @return: None     
     """
     if isinstance(strXMLin, (str, unicode)):
         xsd = XSDataInputFullFieldXAS.parseString(strXMLin)
     else:
         xsd = strXMLin
     filenames = [i.path.value for i in xsd.getData()]
     EDVerbose.ERROR("Error in the processing of: \n %s" % "\n".join(filenames))
     self._lstErrorFile.append(filenames)
示例#5
0
 def error(self, strXMLin):
     """
     This is an example of XMLerr function ... it prints only the name of the file created
     @param srXMLin: The XML string used to launch the job
     @type strXMLin: python string with the input XML
     @rtype: None
     @return: None     
     """
     if isinstance(strXMLin, (str, unicode)):
         xsd = XSDataInputFullFieldXAS.parseString(strXMLin)
     else:
         xsd = strXMLin
     filenames = [ i.path.value for i in xsd.getData()]
     EDVerbose.ERROR("Error in the processing of: \n %s" % "\n".join(filenames))
     self._lstErrorFile.append(filenames)
示例#6
0
 def load(self, filename):
     """
     Retrieve information from XML file
     """
     xsdi = XSDataInputFullFieldXAS.parseFile(filename)
     self.HDF5 = xsdi.HDF5File.path.value
     self.internalHdf5 = xsdi.internalHDF5Path.value
     self.measureOffset = {}
     mo = xsdi.measureOffset
     if mo:
         if mo.alwaysVersusRef:
             self.measureOffset["alwaysVersusRef"] = mo.alwaysVersusRef.value
         if mo.cropBorders:
             self.measureOffset["cropBorders"] = [i.value for i in mo.cropBorders]
         if mo.smoothBorders:
             self.measureOffset["smoothBorders"] = [i.value for i in mo.smoothBorders]
         if mo.sobelFilter:
             self.measureOffset["sobelFilter"] = mo.sobelFilter.value
         if mo.useSift:
             self.measureOffset["useSift"] = mo.useSift.value
         if mo.removeBackground:
             self.measureOffset["removeBackground"] = mo.removeBackground.value
     self.reference = xsdi.reference.value
     self.darks = [{"path": i.path.value, "exposureTime": i.exposureTime.value} for i in xsdi.dark]
示例#7
0
    def makeXML(self, filename):
        """Here we create the XML string to be passed to the EDNA plugin from the input filename
        This can / should be modified by the final user
        
        @param filename: full path of the input file
        @type filename: python string representing the path
        @rtype: XML string
        @return: python string  
        """
        self.header = None
        dirname, basename = os.path.split(filename)
        if not basename.startswith(self.prefix):
            return
        if self.normalizedSuffix and basename.endswith(self.normalizedSuffix):
            return
        if basename.startswith(self.flatPrefix):
            return
        if not basename.endswith(self.suffix):
            return

        if self.fScaleData:
            fScaleData = self.fScaleData
        else:
            fScaleData = self.getNbFrames(filename)
        if not fScaleData:
            fScaleData = 1.0

        if self.fScaleDark:
            fScaleDark = self.fScaleDark
        else:
            fScaleDark = self.getNbFrames(self.darks[0]["path"])
        if not fScaleDark:
            fScaleDark = 1.0

        if isinstance(self.reference, int):
            reference = self.reference
        else:
            reference = -1

        xsd = XSDataInputFullFieldXAS(
            HDF5File=XSDataFile(path=XSDataString(self.HDF5)),
            internalHDF5Path=XSDataString(self.internalHdf5),
            measureOffset=self.getXSDMeasureOffset(),
            dark=self.getXsdDark(),
            reference=XSDataInteger(reference),
            data=[XSDataImageExt(path=XSDataString(filename), exposureTime=XSDataTime(self.getExposureTime(filename)))],
            dataScaleFactor=XSDataDouble(fScaleData),
            darkScaleFactor=XSDataDouble(fScaleDark),
        )
        if self.dontAlign:
            xsd.dontAlign = XSDataBoolean(self.dontAlign)
        extendedPrefix = ""
        number = ""
        started = False
        if self.lstSubscanSize:
            subScanDigit = []
            for i in basename[len(self.prefix) :]:
                if started and i == "_":
                    if len(number) > 0:
                        subScanDigit.append(number)
                        number = ""
                    continue
                if started and not i.isdigit():
                    if number:
                        subScanDigit.append(number)
                    number = ""
                    break
                if not started:
                    if i.isdigit():
                        started = True
                    else:
                        extendedPrefix += i
                if started:
                    number += i

            if not subScanDigit:
                print ("ERROR: no index guessed !!!")
                return ""
            elif len(subScanDigit) == 1:
                index = int(subScanDigit[0])
            else:  # len(subScanDigit) > 1:
                index = 0
                for i in range(int(subScanDigit[0])):
                    index += self.lstSubscanSize[i]
                index += int(subScanDigit[1])
                extendedPrefix += "_".join(subScanDigit[:2])
        else:
            for i in basename[len(self.prefix) :]:
                extendedPrefix += i
                if started and not i.isdigit():
                    break
                if not started and i.isdigit():
                    started = True
                if started:
                    number += i
            index = int(number)
        xsd.index = XSDataInteger(index)

        if self.normalizedSuffix:
            pr = os.path.splitext(os.path.abspath(filename))[0]
            xsd.saveNormalized = XSDataFile(path=XSDataString(pr + self.normalizedSuffix))
        energy = self.getEnergy(filename)
        if energy is not None:
            xsd.energy = XSDataDouble(energy)

        flatprefix = self.flatPrefix + extendedPrefix
        listFlats = []
        for oneFile in os.listdir(dirname):
            if oneFile.startswith(flatprefix) and oneFile.endswith(self.suffix):
                oneCompleteFile = os.path.abspath(os.path.join(dirname, oneFile))
                xsdFileFlat1 = XSDataImageExt(
                    path=XSDataString(oneCompleteFile), exposureTime=XSDataTime(self.getExposureTime(oneCompleteFile))
                )
                listFlats.append(xsdFileFlat1)
        xsd.flat = listFlats
        if len(listFlats) != 2:
            EDVerbose.WARNING("Not exactly 2 flats were found:" + " ".join([a.path.value for a in listFlats]))
            EDVerbose.WARNING("Those are the flat prefix ans suffix: %s\t%s" % (flatprefix, self.suffix))

        if self.fScaleFlat:
            fScaleFlat = self.fScaleFlat
        else:
            fScaleFlat = self.getNbFrames(oneCompleteFile)
        if not fScaleFlat:
            fScaleFlat = 1.0
        xsd.flatScaleFactor = XSDataDouble(fScaleFlat)
        return xsd.marshal()
示例#8
0
    def makeXML(self, filename):
        """Here we create the XML string to be passed to the EDNA plugin from the input filename
        This can / should be modified by the final user
        
        @param filename: full path of the input file
        @type filename: python string representing the path
        @rtype: XML string
        @return: python string  
        """
        self.header = None
        dirname, basename = os.path.split(filename)
        if not basename.startswith(self.prefix):
            return
        if self.normalizedSuffix and basename.endswith(self.normalizedSuffix):
            return
        if basename.startswith(self.flatPrefix):
            return
        if not basename.endswith(self.suffix):
            return

        if self.fScaleData:
            fScaleData = self.fScaleData
        else:
             fScaleData = self.getNbFrames(filename)
        if not fScaleData:
            fScaleData = 1.0

        if self.fScaleDark:
            fScaleDark = self.fScaleDark
        else:
             fScaleDark = self.getNbFrames(self.darks[0]["path"])
        if not fScaleDark:
            fScaleDark = 1.0

        if isinstance(self.reference, int):
            reference = self.reference
        else:
            reference = -1

        xsd = XSDataInputFullFieldXAS(HDF5File=XSDataFile(path=XSDataString(self.HDF5)),
                                      internalHDF5Path=XSDataString(self.internalHdf5),
                                      measureOffset=self.getXSDMeasureOffset(),
                                      dark=self.getXsdDark(),
                                      reference=XSDataInteger(reference),
                                      data=[XSDataImageExt(path=XSDataString(filename),
                                                             exposureTime=XSDataTime(self.getExposureTime(filename)))],
                                      dataScaleFactor=XSDataDouble(fScaleData),
                                      darkScaleFactor=XSDataDouble(fScaleDark),
                                      )
        if self.dontAlign:
            xsd.dontAlign = XSDataBoolean(self.dontAlign)
        extendedPrefix = ""
        number = ""
        started = False
        if self.lstSubscanSize:
            subScanDigit = []
            for i in basename[len(self.prefix):]:
                if started and i == "_":
                    if len(number) > 0:
                        subScanDigit.append(number)
                        number = ""
                    continue
                if started and not i.isdigit():
                    if number:
                        subScanDigit.append(number)
                    number = ""
                    break
                if not started:
                    if i.isdigit():
                        started = True
                    else:
                        extendedPrefix += i
                if started:
                    number += i

            if not subScanDigit:
                print("ERROR: no index guessed !!!")
                return ""
            elif len(subScanDigit) == 1:
                index = int(subScanDigit[0])
            else:# len(subScanDigit) > 1:
                index = 0
                for i in range(int(subScanDigit[0])):
                    index += self.lstSubscanSize[i]
                index += int(subScanDigit[1])
                extendedPrefix += "_".join(subScanDigit[:2])
        else:
            for i in basename[len(self.prefix):]:
                extendedPrefix += i
                if started and not i.isdigit():
                    break
                if not started and i.isdigit():
                    started = True
                if started:
                    number += i
            index = int(number)
        xsd.index = XSDataInteger(index)

        if self.normalizedSuffix:
            pr = os.path.splitext(os.path.abspath(filename))[0]
            xsd.saveNormalized = XSDataFile(path=XSDataString(pr + self.normalizedSuffix))
        energy = self.getEnergy(filename)
        if energy is not None:
            xsd.energy = XSDataDouble(energy)


        flatprefix = self.flatPrefix + extendedPrefix
        listFlats = []
        for oneFile in os.listdir(dirname):
            if oneFile.startswith(flatprefix) and oneFile.endswith(self.suffix):
                oneCompleteFile = os.path.abspath(os.path.join(dirname, oneFile))
                xsdFileFlat1 = XSDataImageExt(path=XSDataString(oneCompleteFile),
                                              exposureTime=XSDataTime(self.getExposureTime(oneCompleteFile)))
                listFlats.append(xsdFileFlat1)
        xsd.flat = listFlats
        if len(listFlats) != 2:
            EDVerbose.WARNING("Not exactly 2 flats were found:" + " ".join([a.path.value for a in listFlats ]))
            EDVerbose.WARNING("Those are the flat prefix ans suffix: %s\t%s" % (flatprefix, self.suffix))

        if self.fScaleFlat:
            fScaleFlat = self.fScaleFlat
        else:
             fScaleFlat = self.getNbFrames(oneCompleteFile)
        if not fScaleFlat:
            fScaleFlat = 1.0
        xsd.flatScaleFactor = XSDataDouble(fScaleFlat)
        return xsd.marshal()