示例#1
0
 def testCheckParameters(self):
     xsDataInput = XSDataInputBioSaxsSingleSamplev1_0()
     xsDataInput.directory1D = XSDataFile()
     xsDataInput.directory2D = XSDataFile()
     xsDataInput.directoryMisc = XSDataFile()
     xsDataInput.bufferSeries = [XSDataFileSeries()]
     xsDataInput.sampleSeries = [XSDataFileSeries()]
     edPluginExecBioSaxsSingleSamplev1_0 = self.createPlugin()
     edPluginExecBioSaxsSingleSamplev1_0.setDataInput(xsDataInput)
     edPluginExecBioSaxsSingleSamplev1_0.checkParameters()
示例#2
0
    def testCheckParameters(self):
        xsDataInput = XSDataInputBioSaxsReduceFileSeriev1_0()
        xsDataInput.fileSerie = XSDataFileSeries()
        xsDataInput.sample = XSDataBioSaxsSample()
        xsDataInput.experimentSetup = XSDataBioSaxsExperimentSetup()
        xsDataInput.directory1D = XSDataFile()
        xsDataInput.directory2D = XSDataFile()
        xsDataInput.directoryMisc = XSDataFile()
        edPluginExecBioSaxsReduceFileSerie = self.createPlugin()

        edPluginExecBioSaxsReduceFileSerie.setDataInput(xsDataInput)
        edPluginExecBioSaxsReduceFileSerie.checkParameters()
 def testCheckParameters(self):
     """
   complex type XSDataInputBioSaxsSmartMergev1_0 extends XSDataInput  {
 inputFile: XSDataFile []
 absoluteFidelity: XSDataDouble optional 
 relativeFidelity: XSDataDouble optional
 mergedCurve: XSDataFile
     """
     xsDataInput = XSDataInputBioSaxsSmartMergev1_0()
     xsDataInput.inputCurves = [XSDataFile()]
     xsDataInput.absoluteFidelity = XSDataDouble()
     xsDataInput.relativeFidelity = XSDataDouble()
     xsDataInput.mergedCurve = XSDataFile()
     edPluginExecBioSaxsSmartMerge = self.createPlugin()
     edPluginExecBioSaxsSmartMerge.setDataInput(xsDataInput)
     edPluginExecBioSaxsSmartMerge.checkParameters()
 def testCheckParameters(self):
     """
   complex type XSDataInputBioSaxsToSAS extends XSDataInput  {
 inputFile: XSDataFile []
 absoluteFidelity: XSDataDouble optional 
 relativeFidelity: XSDataDouble optional
 mergedCurve: XSDataFile
     """
     xsDataInput = XSDataInputBioSaxsToSASv1_0()
     xsDataInput.subtractedCurve = XSDataFile()
     edPlugin = self.createPlugin()
     edPlugin.setDataInput(xsDataInput)
     edPlugin.checkParameters()
示例#5
0
def fileName2xml(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  
    """
    if not  filename.endswith(".edf"):
        return

    xsd = XSDataInputBioSaxsAsciiExportv1_0()
    xsd.integratedImage = XSDataImage(XSDataString(filename))

    xsd.integratedCurve = XSDataFile(XSDataString(os.path.splitext(filename)[0] + ".dat"))
    return xsd.marshal()
示例#6
0
    def toXml(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  
        """

#        Is the file to process?
        dirname, basename = os.path.split(filename)
        rootDir, dirname = os.path.split(dirname)
        basename, ext = os.path.splitext(basename)
        if not ((dirname.lower() == "raw") and (ext.lower() == ".edf")):
            self.DEBUG("Not processing %s" % filename)
            return

        existing2DImage = os .path.join(rootDir, "2d", basename + ".edf")

        if os.path.isfile(existing2DImage):
#            print existing2DImage
            title = None
            for line in open(existing2DImage):
                if len(line) > 512:
                    break
                else:
                    line = line.strip()
                if line.startswith("title"):
                    title = line.split("=", 1)[-1]
                if line.startswith("Center_1")and (self.beamCenter_1 is None):
                    try:
                        self.experimentSetup.beamCenter_1 = XSDataDouble(float(line.split("=", 1)[-1].split()[0]))
                    except Exception:
                        self.ERROR("Reading from header: not a float " + line)
                elif line.startswith("Center_2")and (self.beamCenter_2 is None):
                    try:
                        self.experimentSetup.beamCenter_2 = XSDataDouble(float(line.split("=", 1)[-1].split()[0]))
                    except Exception:
                        self.ERROR("Reading from header: not a float " + line)
                elif line.startswith("PSize_1")and (self.pixelSize_1 is None):
                    try:
                        self.experimentSetup.pixelSize_1 = XSDataLength(float(line.split("=", 1)[-1].split()[0]))
                    except Exception:
                        self.ERROR("Reading from header: not a float " + line)
                elif line.startswith("PSize_2") and (self.pixelSize_2 is None):
                    try:
                        self.experimentSetup.pixelSize_2 = XSDataLength(float(line.split("=", 1)[-1].split()[0]))
                    except Exception:
                        self.ERROR("Reading from header: not a float " + line)
                elif line.startswith("SampleDistance") and (self.detectorDistance is None) :
                    try:
                        self.experimentSetup.detectorDistance = XSDataLength(float(line.split("=", 1)[-1].split()[0]))
                    except Exception:
                        self.ERROR("Reading from header: not a float " + line)
                elif line.startswith("WaveLength")and (self.wavelength is None):
                    try:
                        self.experimentSetup.wavelength = XSDataWavelength(float(line.split("=", 1)[-1].split()[0]))
                    except Exception:
                        self.ERROR("Reading from header: not a float " + line)
            if title:
                for block in title.split(","):
                    if "=" in block:
                        key, value = block.split("=", 1)
                    elif ":" in block:
                        key, value = block.split(":", 1)
                    else:
                        key = None
                    if key:
                        key = key.strip()
                        value = value.strip()
#                        print key, value
                        if key == "DiodeCurr":
                            try:
                                self.experimentSetup.beamStopDiode = XSDataDouble(float(value))
                            except Exception:
                                self.ERROR("Unable to convert %s to float" % block)
                        elif key == "MachCurr":
                            try:
                                self.experimentSetup.machineCurrent = XSDataDouble(float(value.split()[0]))
                            except Exception:
                                self.ERROR("Unable to convert %s to float" % block)
                        elif key == "Concentration":
                            try:
                                self.sample.concentration = XSDataDouble(float(value.split()[0]))
                            except Exception:
                                self.ERROR("Unable to convert %s to float" % block)
                        elif (key == "Comments") and (self.comment is None):
                                self.sample.comments = XSDataString(value.strip())
                        elif (key == "Code") and (self.code is None) :
                            self.sample.code = XSDataString(value.strip())
                        elif (key == "Mask") and (self.maskFile is None):
                            self.experimentSetup.maskFile = XSDataImage(XSDataString(value.strip()))
                        elif (key == "Normalisation") and (self.normalization is None):
                            try:
                                self.experimentSetup.normalizationFactor = XSDataDouble(float(value.split()[0]))
                            except Exception:
                                self.ERROR("Unable to convert %s to float" % block)


        xsd = XSDataInputBioSaxsProcessOneFilev1_0()
        xsd.rawImage = XSDataImage(XSDataString(filename))
        xsd.rawImageSize = XSDataInteger(self.imageSize)
        xsd.experimentSetup = self.experimentSetup
        xsd.sample = self.sample
        dir1d = os.path.join(rootDir, self.dest1D)
        dir2d = os.path.join(rootDir, self.dest2D)
        dirMisc = os.path.join(rootDir, self.destMisc)
        if not os.path.exists(dir1d):
            os.makedirs(dir1d)
        if not os.path.exists(dir2d):
            os.makedirs(dir2d)
        if not os.path.exists(dirMisc):
            os.makedirs(dirMisc)
        xsd.normalizedImage = XSDataImage(XSDataString(os.path.join(dir2d, basename + ".edf")))
        xsd.integratedImage = XSDataImage(XSDataString(os.path.join(dirMisc, basename + ".ang")))
        xsd.integratedCurve = XSDataFile(XSDataString(os.path.join(dir1d, basename + ".dat")))
#        print xsd.marshal()
        return xsd.marshal()
示例#7
0
    def cliReadParam(self):
        print("Welcome to the Reprocessing of BioSaxs data. Enter '-' to re-use data from headers")

        raw = raw_input(("Sample code [%s]: " % self.code).ljust(LEN_INPUT_STR)).strip()
        if raw != "":
            self.code = raw

        raw = raw_input(("Sample comments [%s]: " % self.comment).ljust(LEN_INPUT_STR)).strip()
        if raw != "":
            self.comment = raw

        ok = False
        while not ok:
            raw = raw_input(("Wavelength (in meter) [%s]: " % self.wavelength).ljust(LEN_INPUT_STR)).strip()
            if raw == "-":
                 ok = True
            elif raw != "":
                try:
                    self.wavelenth = float(raw)
                    ok = True
                except Exception:
                    self.ERROR("Unable to convert to float: %s" % raw)
                    ok = False


        raw = raw_input(("Detector used [%s]:" % self.detector).ljust(LEN_INPUT_STR)).strip()
        if raw != "":
            self.detector = raw.lower()


        ok = False
        while not ok:
            raw = raw_input(("Detector image size in bytes [%s]: " % self.imageSize).ljust(LEN_INPUT_STR)).strip()
            if raw != "":
                try:
                    self.imageSize = float(raw)
                    ok = True
                except Exception:
                    self.ERROR("Unable to convert to float: %s" % raw)
                    ok = False
            else:
                ok = bool(self.imageSize)

        ok = False
        while not ok:
            raw = raw_input(("Mask file  [%s]: " % self.maskFile).ljust(LEN_INPUT_STR)).strip()
            if raw == "-":
                ok = True
            elif raw != "":
                self.maskFile = raw
                ok = True

            if  raw != "-" and ((self.maskFile is None) or (os.path.isfile(self.maskFile) is False)):
                ok = False

        ok = False
        while not ok:
            raw = raw_input(("Sample - Detector distance in meter [%s]: " % self.detectorDistance).ljust(LEN_INPUT_STR)).strip()
            if raw == "-":
                ok = True
            elif raw != "":
                try:
                    self.detectorDistance = float(raw)
                    ok = True
                except Exception:
                    self.ERROR("Unable to convert to float: %s" % raw)
                    ok = False


        ok = False
        while not ok:
            raw = raw_input(("Normalization factor [%s]: " % self.normalization).ljust(LEN_INPUT_STR)).strip()
            if raw == "-":
                ok = True
            elif raw != "":
                try:
                    self.normalization = float(raw)
                    ok = True
                except Exception:
                    self.ERROR("Unable to convert to float: %s" % raw)
                    ok = False

        ok = False
        while not ok:
            raw = raw_input(("Pixel size [%s %s]: " % (self.pixelSize_1, self.pixelSize_2)).ljust(LEN_INPUT_STR)).strip()
            if raw == "-":
                ok = True
            elif raw != "":
                lpx = raw.split()
                if len(lpx) == 1:
                    try:
                        self.pixelSize_1 = float(lpx[0])
                        self.pixelSize_2 = float(lpx[0])
                        ok = True
                    except Exception:
                        self.ERROR("Unable to convert to float: %s" % raw)
                        ok = False
                else:
                    try:
                        self.pixelSize_1 = float(lpx[0])
                        self.pixelSize_2 = float(lpx[1])
                        ok = True
                    except Exception:
                        self.ERROR("Unable to convert to float: %s" % raw)
                        ok = False
            else:
                if isinstance(self.pixelSize_1, (float, int)) and isinstance(self.pixelSize_2, (float, int)):
                     ok = True

        ok = False
        while not ok:
            raw = raw_input(("Beam Center position [%s %s]: " % (self.beamCenter_1, self.beamCenter_2)).ljust(LEN_INPUT_STR)).strip()
            if raw == "-":
                ok = True
            elif raw != "":
                lpx = raw.split()
                if len(lpx) == 1:
                    try:
                        self.beamCenter_1 = float(lpx[0])
                        self.beamCenter_2 = float(lpx[0])
                        ok = True
                    except Exception:
                        self.ERROR("Unable to convert to float: %s" % raw)
                        ok = False
                else:
                    try:
                        self.beamCenter_1 = float(lpx[0])
                        self.beamCenter_2 = float(lpx[1])
                        ok = True
                    except Exception:
                        self.ERROR("Unable to convert to float: %s" % raw)
                        ok = False
            else:
                if isinstance(self.beamCenter_1, (float, int)) and isinstance(self.beamCenter_2, (float, int)):
                     ok = True

        ###########################################
        if self.code is not None:
            self.sample.code = XSDataString(self.code)
        if self.comment is not None:
            self.sample.comment = XSDataString(self.comment)
        if self.detector is not None:
            self.experimentSetup.detector = XSDataString(self.detector)
        if self.detectorDistance is not None:
            self.experimentSetup.detectorDistance = XSDataLength(self.detectorDistance)
        if self.pixelSize_1 is not None:
            self.experimentSetup.pixelSize_1 = XSDataLength(self.pixelSize_1)
        if self.pixelSize_2 is not None:
            self.experimentSetup.pixelSize_2 = XSDataLength(self.pixelSize_2)
        if self.beamCenter_1 is not None:
            self.experimentSetup.beamCenter_1 = XSDataDouble(self.beamCenter_1)
        if self.beamCenter_2 is not None:
            self.experimentSetup.beamCenter_2 = XSDataDouble(self.beamCenter_2)
        if self.maskFile is not None:
            self.experimentSetup.maskFile = XSDataFile(XSDataString(self.maskFile))