예제 #1
0
def load_bragg_by_filename(file_name):
    """
    Load Bragg diffraction file (including 3-column data file, GSAS file) for Rietveld
    """
    # load with different file type
    base_file_name = os.path.basename(file_name).lower()
    gss_ws_name = os.path.basename(file_name).split('.')[0]
    if base_file_name.endswith('.gss') or base_file_name.endswith(
            '.gsa') or base_file_name.endswith('.gda'):
        simpleapi.LoadGSS(Filename=file_name, OutputWorkspace=gss_ws_name)
    elif base_file_name.endswith('.nxs'):
        simpleapi.LoadNexusProcessed(Filename=file_name,
                                     OutputWorkspace=gss_ws_name)
        simpleapi.ConvertUnits(InputWorkspace=gss_ws_name,
                               OutputWorkspace=gss_ws_name,
                               EMode='Elastic',
                               Target='TOF')
    elif base_file_name.endswith('.dat'):
        simpleapi.LoadAscii(Filename=file_name,
                            OutputWorkspace=gss_ws_name,
                            Unit='TOF')
    else:
        raise RuntimeError('File %s is not of a supported type.' % file_name)

    # check
    assert AnalysisDataService.doesExist(gss_ws_name)
    angle_list = addie.utilities.workspaces.calculate_bank_angle(gss_ws_name)

    return gss_ws_name, angle_list
예제 #2
0
    def load_sq(self, file_name):
        """
        Load S(Q) to a numpy
        Guarantees: the file is loaded to self._currSQX, _currSQY and _currSQE
        Parameters
        ----------
        file_name :: name of the S(Q)

        Returns
        -------
        2-tuple range of Q
        """
        # generate S(Q) workspace name
        sq_ws_name = os.path.basename(file_name).split('.')[0]

        # call mantid LoadAscii
        ext = file_name.upper().split('.')[-1]
        if ext == 'NXS':
            simpleapi.LoadNexusProcessed(Filename=file_name,
                                         OutputWorkspace=sq_ws_name)
            simpleapi.ConvertUnits(InputWorkspace=sq_ws_name,
                                   OutputWorkspace=sq_ws_name,
                                   EMode='Elastic',
                                   Target='MomentumTransfer')
            simpleapi.ConvertToPointData(
                InputWorkspace=sq_ws_name,
                OutputWorkspace=sq_ws_name)  # TODO REMOVE THIS LINE
        elif ext == 'DAT' or ext == 'txt':
            try:
                simpleapi.LoadAscii(Filename=file_name,
                                    OutputWorkspace=sq_ws_name,
                                    Unit='MomentumTransfer')
            except RuntimeError:
                sq_ws_name, q_min, q_max = "InvalidInput", 0, 0
                return sq_ws_name, q_min, q_max
            # The S(Q) file is in fact S(Q)-1 in sq file.  So need to add 1 to
            # the workspace
            out_ws = AnalysisDataService.retrieve(sq_ws_name)
            out_ws += 1

        assert AnalysisDataService.doesExist(
            sq_ws_name), 'Unable to load S(Q) file %s.' % file_name

        # set to the current S(Q) workspace name
        self._currSqWsName = sq_ws_name
        self._sqIndexDict[self._currSqWsName] = 0

        # get range of Q from the loading
        sq_ws = AnalysisDataService.retrieve(sq_ws_name)
        q_min = sq_ws.readX(0)[0]
        q_max = sq_ws.readX(0)[-1]

        return sq_ws_name, q_min, q_max
예제 #3
0
    def load_gr(self, gr_file_name):
        """
        Load an ASCII file containing G(r)
        """
        # check
        assert len(gr_file_name) > 0

        # load
        gr_ws_name = os.path.basename(gr_file_name).split('.')[0]
        simpleapi.LoadAscii(Filename=gr_file_name,
                            OutputWorkspace=gr_ws_name,
                            Unit='Empty')

        # check output
        if not AnalysisDataService.doesExist(gr_ws_name):
            return False, 'Unable to load file %s as target workspace %s cannot be found.' % (
                gr_ws_name, gr_ws_name)

        return True, gr_ws_name
    def mainExec(self):
        """ Main execution body
        """
        # Load data optionally
        if self.loaddata is True:
            # Load data file
            api.LoadAscii(Filename=self.datafilename,
                          OutputWorkspace=self.datawsname,
                          Unit='TOF')

        # Load .irf file and .hkl file optionally
        if self.loadinfofile is True:
            if dir(self).count('latticesize') == 0 or self.latticesize is None:
                raise NotImplementedError(
                    "Lattice size is not defined.  Unable to use option 'LoadInfo'"
                )

            api.CreateLeBailFitInput(
                FullprofParameterFile=self.irffilename,
                MaxHKL=[13, 13, 13],
                LatticeConstant=float(self.latticesize),
                Bank=self.bankid,
                GenerateBraggReflections=True,
                InstrumentParameterWorkspace=str(self.inputparamws),
                BraggPeakParameterWorkspace=str(self.inputbraggws))

        # Process background optionally
        if self.process_bkgd is True:
            # [Background]
            # Remove peaks and get pure background (hopefully)
            api.ProcessBackground(Options='SelectBackgroundPoints',
                                  InputWorkspace=self.dataws,
                                  OutputWorkspace=self.bkgdwsname,
                                  LowerBound=self.startx,
                                  UpperBound=self.endx,
                                  BackgroundType=self.backgroundtype,
                                  BackgroundPoints=self.usrbkgdpoints,
                                  NoiseTolerance='0.10000000000000001')

            # Fit background points
            functionstr = "name=%s,n=%d" % (self.backgroundtype,
                                            self.backgroundorder)
            for iborder in range(self.backgroundorder + 1):
                functionstr = "%s,A%d=%.5f" % (functionstr, iborder, 0.0)
            api.Fit(Function=functionstr,
                    InputWorkspace=self.bkgdwsname,
                    Output=self.bkgdwsname,
                    MaxIterations='1000',
                    Minimizer='Levenberg-MarquardtMD',
                    CreateOutput='1',
                    StartX=self.startx,
                    EndX=self.endx)

        # [Le Bail calculation]
        self.log().debug("Fit range: %f , %f, Outputworkspace = %s" %
                         (self.startx, self.endx, self.outwsname))
        api.LeBailFit(
            Function='Calculation',
            InputWorkspace=self.dataws,
            OutputWorkspace=self.outwsname,
            InputParameterWorkspace=self.inputparamws,
            OutputParameterWorkspace=str(self.inputparamws),
            InputHKLWorkspace=self.inputbraggws,
            OutputPeaksWorkspace=str(self.inputbraggws),
            FitRegion='%f, %f' % (self.startx, self.endx),
            BackgroundType=self.backgroundtype,
            UseInputPeakHeights=False,
            PeakRadius='7',
            BackgroundParametersWorkspace=self.bkgdtablews,
            PeakType=self.profiletype,
        )

        return
예제 #5
0
 def _load(self, inputs):
     """ inputs is a dict mapping filepaths to output names """
     for path, output in iteritems(inputs):
         workspace = mantid.LoadAscii(path, OutputWorkspace=output)
         workspace.getAxis(0).setUnit("Label").setLabel("Energy", "keV")
예제 #6
0
 def _load(self, inputs):
     """ inputs is a dict mapping filepaths to output names """
     for path, output in iteritems(inputs):
         mantid.LoadAscii(path, OutputWorkspace=output)