예제 #1
0
파일: dgs_utils.py 프로젝트: mcvine/mantid
 def _load_param_file(self, inst_name):
     InstrumentParameters.instrument_name = inst_name
     if IS_IN_MANTIDPLOT:
         idf_loc = config.getInstrumentDirectory()
         idf_pattern = os.path.join(idf_loc, "%s_Definition*.xml") % inst_name
         import glob
         idf_files = glob.glob(idf_pattern)
         emptyInst = LoadEmptyInstrument(Filename=str(idf_files[0]))
         InstrumentParameters._instrument = emptyInst.getInstrument()
         AnalysisDataService.remove(str(emptyInst)) # Don't need to keep workspace
예제 #2
0
 def _load_param_file(self, inst_name):
     InstrumentParameters.instrument_name = inst_name
     if IS_IN_MANTIDPLOT:
         idf_loc = config.getInstrumentDirectory()
         idf_pattern = os.path.join(idf_loc, "%s_Definition*.xml") % inst_name
         import glob
         idf_files = glob.glob(idf_pattern)
         emptyInst = LoadEmptyInstrument(Filename=str(idf_files[0]))
         InstrumentParameters._instrument = emptyInst.getInstrument()
         AnalysisDataService.remove(str(emptyInst)) # Don't need to keep workspace
    def _create_waves_indirect_elastic(self, workspace):
        """
        Creates a wavelength workspace, from the workspace with the specified input workspace
        name, using an Elastic instrument definition file. E-Mode must be Indirect and the y-axis
        of the input workspace must be in units of Q.

        :param workspace:   The input workspace.
        :return:            The output wavelength workspace.
        """
        self._indirect_elastic = True
        self._q_values = workspace.getAxis(1).extractValues()
        instrument_name = workspace.getInstrument().getName()
        isis_instrument = instrument_name == "IRIS" or instrument_name == "OSIRIS"

        # ---------- Load Elastic Instrument Definition File ----------

        if isis_instrument:
            idf_name = instrument_name + '_elastic_Definition.xml'

            idf_path = os.path.join(config.getInstrumentDirectory(), idf_name)
            logger.information('IDF = %s' % idf_path)

            load_alg = self.createChildAlgorithm("LoadInstrument",
                                                 enableLogging=True)
            load_alg.setProperty("Workspace", workspace)
            load_alg.setProperty("Filename", idf_path)
            load_alg.setProperty("RewriteSpectraMap", True)
            load_alg.execute()

        # ---------- Create Spectra Axis -----------

        # Replace y-axis with spectra axis
        workspace.replaceAxis(1, SpectraAxis.create(workspace))
        e_fixed = float(self._efixed)
        logger.information('Efixed = %f' % e_fixed)

        # ---------- Set Instrument Parameters ----------

        sip_alg = self.createChildAlgorithm("SetInstrumentParameter",
                                            enableLogging=False)
        sip_alg.setProperty("Workspace", workspace)
        sip_alg.setProperty("ParameterName", 'EFixed')
        sip_alg.setProperty("ParameterType", 'Number')
        sip_alg.setProperty("Value", str(e_fixed))
        sip_alg.execute()

        # ---------- Calculate Wavelength ----------

        wave = math.sqrt(81.787 / e_fixed)
        logger.information('Wavelength = %f' % wave)
        workspace.getAxis(0).setUnit('Wavelength')

        # ---------- Format Input Workspace ---------

        convert_alg = self.createChildAlgorithm("ConvertToHistogram",
                                                enableLogging=False)
        convert_alg.setProperty("InputWorkspace", workspace)
        convert_alg.execute()

        workspace = self._crop_ws(
            convert_alg.getProperty("OutputWorkspace").value)

        # --------- Set wavelengths as X-values in Output Workspace ----------

        waves = (0.01 * np.arange(-1, workspace.blocksize())) + wave
        logger.information('Waves : ' + str(waves))
        nhist = workspace.getNumberHistograms()
        for idx in range(nhist):
            workspace.setX(idx, waves)

        if isis_instrument:
            self._update_instrument_angles(workspace, self._q_values, wave)

        return workspace
    def _create_waves_indirect_elastic(self, workspace):
        """
        Creates a wavelength workspace, from the workspace with the specified input workspace
        name, using an Elastic instrument definition file. E-Mode must be Indirect and the y-axis
        of the input workspace must be in units of Q.

        :param workspace:   The input workspace.
        :return:            The output wavelength workspace.
        """
        self._indirect_elastic = True
        self._q_values = workspace.getAxis(1).extractValues()
        instrument_name = workspace.getInstrument().getName()
        isis_instrument = instrument_name == "IRIS" or instrument_name == "OSIRIS"

        # ---------- Load Elastic Instrument Definition File ----------

        if isis_instrument:
            idf_name = instrument_name + '_elastic_Definition.xml'

            idf_path = os.path.join(config.getInstrumentDirectory(), idf_name)
            logger.information('IDF = %s' % idf_path)

            load_alg = self.createChildAlgorithm("LoadInstrument", enableLogging=True)
            load_alg.setProperty("Workspace", workspace)
            load_alg.setProperty("Filename", idf_path)
            load_alg.setProperty("RewriteSpectraMap", True)
            load_alg.execute()

        # ---------- Create Spectra Axis -----------

        # Replace y-axis with spectra axis
        workspace.replaceAxis(1, SpectraAxis.create(workspace))
        e_fixed = float(self._efixed)
        logger.information('Efixed = %f' % e_fixed)

        # ---------- Set Instrument Parameters ----------

        sip_alg = self.createChildAlgorithm("SetInstrumentParameter", enableLogging=False)
        sip_alg.setProperty("Workspace", workspace)
        sip_alg.setProperty("ParameterName", 'EFixed')
        sip_alg.setProperty("ParameterType", 'Number')
        sip_alg.setProperty("Value", str(e_fixed))
        sip_alg.execute()

        # ---------- Calculate Wavelength ----------

        wave = math.sqrt(81.787 / e_fixed)
        logger.information('Wavelength = %f' % wave)
        workspace.getAxis(0).setUnit('Wavelength')

        # ---------- Format Input Workspace ---------

        convert_alg = self.createChildAlgorithm("ConvertToHistogram", enableLogging=False)
        convert_alg.setProperty("InputWorkspace", workspace)
        convert_alg.execute()

        workspace = self._crop_ws(convert_alg.getProperty("OutputWorkspace").value)

        # --------- Set wavelengths as X-values in Output Workspace ----------

        waves = (0.01 * np.arange(-1, workspace.blocksize())) + wave
        logger.information('Waves : ' + str(waves))
        nhist = workspace.getNumberHistograms()
        for idx in range(nhist):
            workspace.setX(idx, waves)

        if isis_instrument:
            self._update_instrument_angles(workspace, self._q_values, wave)

        return workspace