Exemple #1
0
    def doSuccessReadHeader(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "*** EDPluginControlDiffractionCTv1_0.doSuccessReadHeader")
        self.retrieveSuccessMessages(
            _edPlugin, "EDPluginControlDiffractionCTv1_0.doSuccessReadHeader")
        # Translate dictionary to image and instrument objects
        xsDataInputPowderIntegration = XSDataInputPowderIntegration()
        self.m_xsDataDiffractionCTInstrument = XSDataDiffractionCTInstrument()
        self.m_xsDataDiffractionCTImage = XSDataDiffractionCTImage()
        xsDataDictionaryHeader = self.m_edPluginReadHeader.getDataOutput(
        ).getDictionary()
        for xsDataKeyValuePair in xsDataDictionaryHeader.getKeyValuePair():
            strKey = str(xsDataKeyValuePair.getKey().getValue())
            strValue = str(xsDataKeyValuePair.getValue().getValue())
            if (strKey == "_diffrn_radiation_wavelength"):
                self.m_xsDataDiffractionCTInstrument.set_diffrn_radiation_wavelength(
                    XSDataWavelength(float(strValue)))
            elif (strKey == "_pd_instr_dist_spec/detc"):
                self.m_xsDataDiffractionCTInstrument.set_pd_instr_dist_spec_detc(
                    XSDataLength(float(strValue)))
            elif (strKey == "_pd_meas_2theta_range_max"):
                self.m_xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_max(
                    XSDataAngle(float(strValue)))
            elif (strKey == "_pd_meas_2theta_range_min"):
                self.m_xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_min(
                    XSDataAngle(float(strValue)))
            elif (strKey == "_pd_meas_2theta_range_inc"):
                self.m_xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_inc(
                    XSDataAngle(float(strValue)))
            elif (strKey == "_synchrotron_photon-flux"):
                self.m_xsDataDiffractionCTInstrument.set_synchrotron_photon_flux(
                    XSDataFlux(float(strValue)))
            elif (strKey == "_synchrotron_ring-intensity"):
                self.m_xsDataDiffractionCTInstrument.set_synchrotron_ring_intensity(
                    XSDataDouble(float(strValue)))
            elif (strKey == "_tomo_scan_ampl"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_scan_ampl(
                    XSDataAngle(float(strValue)))
            elif (strKey == "_tomo_scan_type"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_scan_type(
                    XSDataString(strValue))
            elif (strKey == "_tomo_spec_displ_rotation"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation(
                    XSDataAngle(float(strValue)))
            elif (strKey == "_tomo_spec_displ_rotation_inc"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation_inc(
                    XSDataAngle(float(strValue)))
            elif (strKey == "_tomo_spec_displ_x"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_x(
                    XSDataLength(float(strValue)))
            elif (strKey == "_tomo_spec_displ_x_inc"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_inc(
                    XSDataLength(float(strValue)))
            elif (strKey == "_tomo_spec_displ_x_max"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_max(
                    XSDataLength(float(strValue)))
            elif (strKey == "_tomo_spec_displ_x_min"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_min(
                    XSDataLength(float(strValue)))
            elif (strKey == "_tomo_spec_displ_z"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_z(
                    XSDataLength(float(strValue)))
            elif (strKey == "_tomo_spec_displ_z_inc"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_inc(
                    XSDataLength(float(strValue)))
            elif (strKey == "_tomo_spec_displ_z_max"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_max(
                    XSDataLength(float(strValue)))
            elif (strKey == "_tomo_spec_displ_z_min"):
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_min(
                    XSDataLength(float(strValue)))
            elif (strKey == "_pd_instr_special_details_tilt_angle"):
                self.m_xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_angle(
                    XSDataAngle(float(strValue)))
            elif (strKey == "_pd_instr_special_details_tilt_rotation"):
                self.m_xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_rotation(
                    XSDataAngle(float(strValue)))
            elif (strKey == "_array_element_size[1]"):
                self.m_xsDataDiffractionCTImage.set_array_element_size_1(
                    XSDataLength(float(strValue)))
            elif (strKey == "_array_element_size[2]"):
                self.m_xsDataDiffractionCTImage.set_array_element_size_2(
                    XSDataLength(float(strValue)))
            elif (strKey == "_diffrn_detector_element.center[1]"):
                self.m_xsDataDiffractionCTImage.set_diffrn_detector_element_center_1(
                    XSDataLength(float(strValue)))
            elif (strKey == "_diffrn_detector_element.center[2]"):
                self.m_xsDataDiffractionCTImage.set_diffrn_detector_element_center_2(
                    XSDataLength(float(strValue)))

## Here the tricky case of lists ....
#            elif strKey.startswith("_pd_sum_2theta_range_max"):
#                if strKey.find("[")>0:
#                    pyintIndex = int(strKey.split("[")[1].split("]")[0]) - 1 #gets the int that is between []
#                else:
#                    pyintIndex = 0
#                while len(self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max()) < pyintIndex + 1:
#                    self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max().append(None)
#                self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max()[pyintIndex] = XSDataAngle(float(strValue))
#            elif strKey.startswith("_pd_sum_2theta_range_min"):
#                if strKey.find("[")>0:
#                    pyintIndex = int(strKey.split("[")[1].split("]")[0]) - 1 #gets the int that is between []
#                else:
#                    pyintIndex = 0
#                while len(self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min()) < pyintIndex + 1:
#                    self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min().append(None)
#                self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min()[pyintIndex] = XSDataAngle(float(strValue))
##end  Seems OK 20091023
            elif (strKey == "_file_correction_image_dark-current"):
                xsDataFileDark = XSDataFile()
                xsDataFileDark.setPath(XSDataString(strValue))
                self.m_xsDataDiffractionCTImage.set_file_correction_image_dark_current(
                    xsDataFileDark)
            elif (strKey == "_file_correction_image_flat-field"):
                xsDataFileFlat = XSDataFile()
                xsDataFileFlat.setPath(XSDataString(strValue))
                self.m_xsDataDiffractionCTImage.set_file_correction_image_flat_field(
                    xsDataFileFlat)
            elif (strKey == "_file_correction_image-mask"):
                xsDataFileMask = XSDataFile()
                xsDataFileMask.setPath(XSDataString(strValue))
                self.m_xsDataDiffractionCTImage.set_file_correction_image_mask(
                    xsDataFileMask)
            elif (strKey == "_file_correction_spline_spatial-distortion"):
                xsDataFileSpatialDist = XSDataFile()
                xsDataFileSpatialDist.setPath(XSDataString(strValue))
                self.m_xsDataDiffractionCTImage.set_file_correction_spline_spatial_distortion(
                    xsDataFileSpatialDist)
        xsDataInputPowderIntegration.setImageParameters(
            self.m_xsDataDiffractionCTImage)
        xsDataInputPowderIntegration.setInstrumentParameters(
            self.m_xsDataDiffractionCTInstrument)
        xsDataInputPowderIntegration.setImageFile(self.m_xsDataFileInputImage)
        self.m_edPluginPowderIntegration.setDataInput(
            xsDataInputPowderIntegration)
        self.m_edPluginPowderIntegration.executeSynchronous()
    def doSuccessReadHeader(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlDiffractionCTv1_2.doSuccessReadHeader")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlDiffractionCTv1_2.doSuccessReadHeader")
        # Translate dictionary to image and instrument objects
        xsDataInputPowderIntegration = XSDataInputPowderIntegration()
        self.xsDataDiffractionCTInstrument = XSDataDiffractionCTInstrument()
        self.xsDataDiffractionCTImage = XSDataDiffractionCTImage()
        xsdOut = _edPlugin.getDataOutput()
        if xsdOut is None:
            strErr = "EDPluginControlDiffractionCTv1_2.doSuccessReadHeader: xsdataResult is None"
            EDVerbose.ERROR(strErr)
            self.setFailure()
            raise RuntimeError(strErr)
        xsDataDictionaryHeader = xsdOut.getDictionary()
        for xsDataKeyValuePair in xsDataDictionaryHeader.getKeyValuePair():
            strKey = str(xsDataKeyValuePair.getKey().getValue())
            lstValue = xsDataKeyValuePair.getValue().getValue().split()
            if len(lstValue) == 2:
                strValue = lstValue[0]
                strUnit = lstValue[1]
            else:
                strValue = xsDataKeyValuePair.getValue().getValue()
                strUnit = None

            if (strKey == "_diffrn_radiation_wavelength"):
                xsd = EDUtilsUnit.toXSD(XSDataWavelength, strValue)
                self.xsDataDiffractionCTInstrument.set_diffrn_radiation_wavelength(xsd)
            elif (strKey == "_pd_instr_dist_spec/detc"):
                xsd = EDUtilsUnit.toXSD(XSDataLength, strValue)
                self.xsDataDiffractionCTInstrument.set_pd_instr_dist_spec_detc(xsd)
            elif (strKey == "_pd_meas_2theta_range_max"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_max(xsd)
            elif (strKey == "_pd_meas_2theta_range_min"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_min(xsd)
            elif (strKey == "_pd_meas_2theta_range_inc"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_inc(xsd)
            elif (strKey == "_synchrotron_photon-flux"):
                self.xsDataDiffractionCTInstrument.set_synchrotron_photon_flux(XSDataFlux(float(strValue)))
            elif (strKey == "_synchrotron_ring-intensity"):
                self.xsDataDiffractionCTInstrument.set_synchrotron_ring_intensity(XSDataDouble(float(strValue)))
            elif (strKey == "_tomo_scan_ampl"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_scan_ampl(xsd)
            elif (strKey == "_tomo_scan_type"):
                self.xsDataDiffractionCTInstrument.set_tomo_scan_type(XSDataString(strValue))
            elif (strKey == "_tomo_spec_displ_rotation"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation(xsd)
            elif (strKey == "_tomo_spec_displ_rotation_inc"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation_inc(xsd)
            elif (strKey == "_tomo_spec_displ_x"):
                xsd = EDUtilsUnit.toXSD(XSDataLength, strValue)
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x(xsd)
            elif (strKey == "_tomo_spec_displ_x_inc"):
                xsd = EDUtilsUnit.toXSD(XSDataLength, strValue)
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_inc(xsd)
            elif (strKey == "_tomo_spec_displ_x_max"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_max(xsd)
            elif (strKey == "_tomo_spec_displ_x_min"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_min(xsd)
            elif (strKey == "_tomo_spec_displ_z"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z(xsd)
            elif (strKey == "_tomo_spec_displ_z_inc"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_inc(xsd)
            elif (strKey == "_tomo_spec_displ_z_max"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_max(xsd)
            elif (strKey == "_tomo_spec_displ_z_min"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_min(xsd)
            elif (strKey == "_pd_instr_special_details_tilt_angle"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_angle(xsd)
            elif (strKey == "_pd_instr_special_details_tilt_rotation"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_rotation(xsd)
            elif (strKey == "_array_element_size[1]"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "m"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_array_element_size_1(xsd)
            elif (strKey == "_array_element_size[2]"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "m"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_array_element_size_2(xsd)
            elif (strKey == "_diffrn_detector_element.center[1]"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_diffrn_detector_element_center_1(xsd)
            elif (strKey == "_diffrn_detector_element.center[2]"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_diffrn_detector_element_center_2(xsd)
            elif (strKey == "_file_correction_image_dark-current"):
                    xsDataFileDark = XSDataFile()
                    xsDataFileDark.setPath(XSDataString(strValue))
                    self.xsDataDiffractionCTImage.set_file_correction_image_dark_current(xsDataFileDark)
            elif (strKey == "_file_correction_image_flat-field"):
                xsDataFileFlat = XSDataFile()
                xsDataFileFlat.setPath(XSDataString(strValue))
                self.xsDataDiffractionCTImage.set_file_correction_image_flat_field(xsDataFileFlat)
            elif (strKey == "_file_correction_image-mask"):
                xsDataFileMask = XSDataFile()
                xsDataFileMask.setPath(XSDataString(strValue))
                self.xsDataDiffractionCTImage.set_file_correction_image_mask(xsDataFileMask)
            elif (strKey == "_file_correction_spline_spatial-distortion"):
                xsDataFileSpatialDist = XSDataFile()
                xsDataFileSpatialDist.setPath(XSDataString(strValue))
                self.xsDataDiffractionCTImage.set_file_correction_spline_spatial_distortion(xsDataFileSpatialDist)

        if self.xsdForceImageParam is not None:
            self.forceImageParam(self.xsdForceImageParam)

        if self.xsdForceScanParam is not None:
            self.forceScanParam(self.xsdForceScanParam)


        xsDataInputPowderIntegration.setImageParameters(self.xsDataDiffractionCTImage)
        xsDataInputPowderIntegration.setInstrumentParameters(self.xsDataDiffractionCTInstrument)
        xsDataInputPowderIntegration.setImageFile(self.xsDataFileInputImage)


# Set the destination directory for output  XRPD file

        strDestinationDirectory = os.path.join(self.getDataInput().getDestinationDirectory().getPath().getValue(), \
                                               self.getDataInput().getPowderDiffractionSubdirectory().getValue())

        if self.xsDataDiffractionCTInstrument.get_tomo_scan_type().getValue().lower() in  ["flat", "spiral"]:
            pyintLineNumber = int(abs(self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_rotation().getValue()) / self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_rotation_inc().getValue())
        elif self.xsDataDiffractionCTInstrument.get_tomo_scan_type().getValue().lower() == "mapping": #I agree mappings are not sinograms but the really looks like, no ? 
            pyintLineNumber = int(abs(self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z().getValue() - self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z_min().getValue()) / self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z_inc().getValue())
        else:
            pyintLineNumber = None
        try:
            strDestinationDirectory = "%s%04i" % (strDestinationDirectory, pyintLineNumber)
        except TypeError:
            pass #if pyintLineNumber is none: do not add suffix


        xsDataInputPowderIntegration.setDestinationDir(XSDataFile(XSDataString(strDestinationDirectory)))
        self.edPluginPowderIntegration.setDataInput(xsDataInputPowderIntegration)
    def doSuccessReadHeader(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlDiffractionCTv1_1.doSuccessReadHeader")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlDiffractionCTv1_1.doSuccessReadHeader")
        # Translate dictionary to image and instrument objects
        xsDataInputPowderIntegration = XSDataInputPowderIntegration()
        self.xsDataDiffractionCTInstrument = XSDataDiffractionCTInstrument()
        self.xsDataDiffractionCTImage = XSDataDiffractionCTImage()
        xsDataDictionaryHeader = self.edPluginReadHeader.getDataOutput().getDictionary()
        for xsDataKeyValuePair in xsDataDictionaryHeader.getKeyValuePair():
            strKey = str(xsDataKeyValuePair.getKey().getValue())
            lstValue = xsDataKeyValuePair.getValue().getValue().split()
            if len(lstValue) == 2:
                strValue = lstValue[0]
                strUnit = lstValue[1]
            else:
                strValue = xsDataKeyValuePair.getValue().getValue()
                strUnit = None

            if (strKey == "_diffrn_radiation_wavelength"):
                xsd = EDUtilsUnit.toXSD(XSDataWavelength, strValue)
#                if strUnit is None: strUnit = "A"
#                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_diffrn_radiation_wavelength(xsd)
            elif (strKey == "_pd_instr_dist_spec/detc"):
                xsd = EDUtilsUnit.toXSD(XSDataLength, strValue)
#                if strUnit is None: strUnit = "mm"
#                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_pd_instr_dist_spec_detc(xsd)
            elif (strKey == "_pd_meas_2theta_range_max"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_max(xsd)
            elif (strKey == "_pd_meas_2theta_range_min"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_min(xsd)
            elif (strKey == "_pd_meas_2theta_range_inc"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_inc(xsd)
            elif (strKey == "_synchrotron_photon-flux"):
                self.xsDataDiffractionCTInstrument.set_synchrotron_photon_flux(XSDataFlux(float(strValue)))
            elif (strKey == "_synchrotron_ring-intensity"):
                self.xsDataDiffractionCTInstrument.set_synchrotron_ring_intensity(XSDataDouble(float(strValue)))
            elif (strKey == "_tomo_scan_ampl"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_scan_ampl(xsd)
            elif (strKey == "_tomo_scan_type"):
                self.xsDataDiffractionCTInstrument.set_tomo_scan_type(XSDataString(strValue))
            elif (strKey == "_tomo_spec_displ_rotation"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation(xsd)
            elif (strKey == "_tomo_spec_displ_rotation_inc"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation_inc(xsd)
            elif (strKey == "_tomo_spec_displ_x"):
                xsd = EDUtilsUnit.toXSD(XSDataLength, strValue)
#                if strUnit is None: strUnit = "mm"
#                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x(xsd)
            elif (strKey == "_tomo_spec_displ_x_inc"):
                xsd = EDUtilsUnit.toXSD(XSDataLength, strValue)
#                if strUnit is None: strUnit = "mm"
#                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_inc(xsd)
            elif (strKey == "_tomo_spec_displ_x_max"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_max(xsd)
            elif (strKey == "_tomo_spec_displ_x_min"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_min(xsd)
            elif (strKey == "_tomo_spec_displ_z"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z(xsd)
            elif (strKey == "_tomo_spec_displ_z_inc"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_inc(xsd)
            elif (strKey == "_tomo_spec_displ_z_max"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_max(xsd)
            elif (strKey == "_tomo_spec_displ_z_min"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_min(xsd)
            elif (strKey == "_pd_instr_special_details_tilt_angle"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_angle(xsd)
            elif (strKey == "_pd_instr_special_details_tilt_rotation"):
                xsd = XSDataAngle(float(strValue))
                if strUnit is None: strUnit = "deg"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_rotation(xsd)
            elif (strKey == "_array_element_size[1]"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "m"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_array_element_size_1(xsd)
            elif (strKey == "_array_element_size[2]"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "m"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_array_element_size_2(xsd)
            elif (strKey == "_diffrn_detector_element.center[1]"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_diffrn_detector_element_center_1(xsd)
            elif (strKey == "_diffrn_detector_element.center[2]"):
                xsd = XSDataLength(float(strValue))
                if strUnit is None: strUnit = "mm"
                xsd.setUnit(XSDataString(strUnit))
                self.xsDataDiffractionCTImage.set_diffrn_detector_element_center_2(xsd)
#            elif strKey.startswith("_pd_sum_2theta_range_max"):
#                if strKey.find("[") > 0:
#                    pyintIndex = int(strKey.split("[")[1].split("]")[0]) - 1 #gets the int that is between []
#                else:
#                    pyintIndex = 0
#                while len(self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max()) < pyintIndex + 1:
#                    self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max().append(None)
#                xsd = XSDataAngle(float(strValue))
#                if strUnit is None: strUnit = "deg"
#                xsd.setUnit(XSDataString(strUnit))
#                self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max()[pyintIndex] = xsd
#            elif strKey.startswith("_pd_sum_2theta_range_min"):
#                if strKey.find("[") > 0:
#                    pyintIndex = int(strKey.split("[")[1].split("]")[0]) - 1 #gets the int that is between []
#                else:
#                    pyintIndex = 0
#                while len(self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min()) < pyintIndex + 1:
#                    self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min().append(None)
#                xsd = XSDataAngle(float(strValue))
#                if strUnit is None: strUnit = "deg"
#                xsd.setUnit(XSDataString(strUnit))
#                self.xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min()[pyintIndex] = xsd
            elif (strKey == "_file_correction_image_dark-current"):
                    xsDataFileDark = XSDataFile()
                    xsDataFileDark.setPath(XSDataString(strValue))
                    self.xsDataDiffractionCTImage.set_file_correction_image_dark_current(xsDataFileDark)
            elif (strKey == "_file_correction_image_flat-field"):
                xsDataFileFlat = XSDataFile()
                xsDataFileFlat.setPath(XSDataString(strValue))
                self.xsDataDiffractionCTImage.set_file_correction_image_flat_field(xsDataFileFlat)
            elif (strKey == "_file_correction_image-mask"):
                xsDataFileMask = XSDataFile()
                xsDataFileMask.setPath(XSDataString(strValue))
                self.xsDataDiffractionCTImage.set_file_correction_image_mask(xsDataFileMask)
            elif (strKey == "_file_correction_spline_spatial-distortion"):
                xsDataFileSpatialDist = XSDataFile()
                xsDataFileSpatialDist.setPath(XSDataString(strValue))
                self.xsDataDiffractionCTImage.set_file_correction_spline_spatial_distortion(xsDataFileSpatialDist)

        if self.xsdForceImageParam is not None:
            self.forceImageParam(self.xsdForceImageParam)

        if self.xsdForceScanParam is not None:
            self.forceScanParam(self.xsdForceScanParam)


        xsDataInputPowderIntegration.setImageParameters(self.xsDataDiffractionCTImage)
        xsDataInputPowderIntegration.setInstrumentParameters(self.xsDataDiffractionCTInstrument)
        xsDataInputPowderIntegration.setImageFile(self.xsDataFileInputImage)


# Set the destination directory for output  XRPD file

        strDestinationDirectory = os.path.join(self.getDataInput().getDestinationDirectory().getPath().getValue(), \
                                               self.getDataInput().getPowderDiffractionSubdirectory().getValue())

        if self.xsDataDiffractionCTInstrument.get_tomo_scan_type().getValue().lower() in  ["flat", "spiral"]:
            pyintLineNumber = int(abs(self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_rotation().getValue()) / self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_rotation_inc().getValue())
        elif self.xsDataDiffractionCTInstrument.get_tomo_scan_type().getValue().lower() == "mapping": #I agree mappings are not sinograms but the really looks like, no ? 
            pyintLineNumber = int(abs(self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z().getValue() - self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z_min().getValue()) / self.xsDataDiffractionCTInstrument.get_tomo_spec_displ_z_inc().getValue())
        else:
            pyintLineNumber = None
        try:
            strDestinationDirectory = "%s%04i" % (strDestinationDirectory, pyintLineNumber)
        except TypeError:
            pass #if pyintLineNumber is none: do not add suffix


        xsDataInputPowderIntegration.setDestinationDir(XSDataFile(XSDataString(strDestinationDirectory)))



        self.edPluginPowderIntegration.setDataInput(xsDataInputPowderIntegration)
        self.edPluginPowderIntegration.executeSynchronous()
    def doSuccessReadHeader(self, _edPlugin=None):
        EDVerbose.DEBUG("*** EDPluginControlDiffractionCTv1_0.doSuccessReadHeader")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlDiffractionCTv1_0.doSuccessReadHeader")
        # Translate dictionary to image and instrument objects
        xsDataInputPowderIntegration = XSDataInputPowderIntegration()
        self.m_xsDataDiffractionCTInstrument = XSDataDiffractionCTInstrument()
        self.m_xsDataDiffractionCTImage = XSDataDiffractionCTImage()
        xsDataDictionaryHeader = self.m_edPluginReadHeader.getDataOutput().getDictionary()
        for xsDataKeyValuePair in xsDataDictionaryHeader.getKeyValuePair():
            strKey = str(xsDataKeyValuePair.getKey().getValue())
            strValue = str(xsDataKeyValuePair.getValue().getValue())
            if strKey == "_diffrn_radiation_wavelength":
                self.m_xsDataDiffractionCTInstrument.set_diffrn_radiation_wavelength(XSDataWavelength(float(strValue)))
            elif strKey == "_pd_instr_dist_spec/detc":
                self.m_xsDataDiffractionCTInstrument.set_pd_instr_dist_spec_detc(XSDataLength(float(strValue)))
            elif strKey == "_pd_meas_2theta_range_max":
                self.m_xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_max(XSDataAngle(float(strValue)))
            elif strKey == "_pd_meas_2theta_range_min":
                self.m_xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_min(XSDataAngle(float(strValue)))
            elif strKey == "_pd_meas_2theta_range_inc":
                self.m_xsDataDiffractionCTInstrument.set_pd_meas_2theta_range_inc(XSDataAngle(float(strValue)))
            elif strKey == "_synchrotron_photon-flux":
                self.m_xsDataDiffractionCTInstrument.set_synchrotron_photon_flux(XSDataFlux(float(strValue)))
            elif strKey == "_synchrotron_ring-intensity":
                self.m_xsDataDiffractionCTInstrument.set_synchrotron_ring_intensity(XSDataDouble(float(strValue)))
            elif strKey == "_tomo_scan_ampl":
                self.m_xsDataDiffractionCTInstrument.set_tomo_scan_ampl(XSDataAngle(float(strValue)))
            elif strKey == "_tomo_scan_type":
                self.m_xsDataDiffractionCTInstrument.set_tomo_scan_type(XSDataString(strValue))
            elif strKey == "_tomo_spec_displ_rotation":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation(XSDataAngle(float(strValue)))
            elif strKey == "_tomo_spec_displ_rotation_inc":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_rotation_inc(XSDataAngle(float(strValue)))
            elif strKey == "_tomo_spec_displ_x":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_x(XSDataLength(float(strValue)))
            elif strKey == "_tomo_spec_displ_x_inc":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_inc(XSDataLength(float(strValue)))
            elif strKey == "_tomo_spec_displ_x_max":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_max(XSDataLength(float(strValue)))
            elif strKey == "_tomo_spec_displ_x_min":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_x_min(XSDataLength(float(strValue)))
            elif strKey == "_tomo_spec_displ_z":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_z(XSDataLength(float(strValue)))
            elif strKey == "_tomo_spec_displ_z_inc":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_inc(XSDataLength(float(strValue)))
            elif strKey == "_tomo_spec_displ_z_max":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_max(XSDataLength(float(strValue)))
            elif strKey == "_tomo_spec_displ_z_min":
                self.m_xsDataDiffractionCTInstrument.set_tomo_spec_displ_z_min(XSDataLength(float(strValue)))
            elif strKey == "_pd_instr_special_details_tilt_angle":
                self.m_xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_angle(XSDataAngle(float(strValue)))
            elif strKey == "_pd_instr_special_details_tilt_rotation":
                self.m_xsDataDiffractionCTImage.set_pd_instr_special_details_tilt_rotation(XSDataAngle(float(strValue)))
            elif strKey == "_array_element_size[1]":
                self.m_xsDataDiffractionCTImage.set_array_element_size_1(XSDataLength(float(strValue)))
            elif strKey == "_array_element_size[2]":
                self.m_xsDataDiffractionCTImage.set_array_element_size_2(XSDataLength(float(strValue)))
            elif strKey == "_diffrn_detector_element.center[1]":
                self.m_xsDataDiffractionCTImage.set_diffrn_detector_element_center_1(XSDataLength(float(strValue)))
            elif strKey == "_diffrn_detector_element.center[2]":
                self.m_xsDataDiffractionCTImage.set_diffrn_detector_element_center_2(XSDataLength(float(strValue)))

            ## Here the tricky case of lists ....
            #            elif strKey.startswith("_pd_sum_2theta_range_max"):
            #                if strKey.find("[")>0:
            #                    pyintIndex = int(strKey.split("[")[1].split("]")[0]) - 1 #gets the int that is between []
            #                else:
            #                    pyintIndex = 0
            #                while len(self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max()) < pyintIndex + 1:
            #                    self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max().append(None)
            #                self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_max()[pyintIndex] = XSDataAngle(float(strValue))
            #            elif strKey.startswith("_pd_sum_2theta_range_min"):
            #                if strKey.find("[")>0:
            #                    pyintIndex = int(strKey.split("[")[1].split("]")[0]) - 1 #gets the int that is between []
            #                else:
            #                    pyintIndex = 0
            #                while len(self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min()) < pyintIndex + 1:
            #                    self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min().append(None)
            #                self.m_xsDataDiffractionCTInstrument.get_pd_sum_2theta_range_min()[pyintIndex] = XSDataAngle(float(strValue))
            ##end  Seems OK 20091023
            elif strKey == "_file_correction_image_dark-current":
                xsDataFileDark = XSDataFile()
                xsDataFileDark.setPath(XSDataString(strValue))
                self.m_xsDataDiffractionCTImage.set_file_correction_image_dark_current(xsDataFileDark)
            elif strKey == "_file_correction_image_flat-field":
                xsDataFileFlat = XSDataFile()
                xsDataFileFlat.setPath(XSDataString(strValue))
                self.m_xsDataDiffractionCTImage.set_file_correction_image_flat_field(xsDataFileFlat)
            elif strKey == "_file_correction_image-mask":
                xsDataFileMask = XSDataFile()
                xsDataFileMask.setPath(XSDataString(strValue))
                self.m_xsDataDiffractionCTImage.set_file_correction_image_mask(xsDataFileMask)
            elif strKey == "_file_correction_spline_spatial-distortion":
                xsDataFileSpatialDist = XSDataFile()
                xsDataFileSpatialDist.setPath(XSDataString(strValue))
                self.m_xsDataDiffractionCTImage.set_file_correction_spline_spatial_distortion(xsDataFileSpatialDist)
        xsDataInputPowderIntegration.setImageParameters(self.m_xsDataDiffractionCTImage)
        xsDataInputPowderIntegration.setInstrumentParameters(self.m_xsDataDiffractionCTInstrument)
        xsDataInputPowderIntegration.setImageFile(self.m_xsDataFileInputImage)
        self.m_edPluginPowderIntegration.setDataInput(xsDataInputPowderIntegration)
        self.m_edPluginPowderIntegration.executeSynchronous()