Ejemplo n.º 1
0
    def _focus_run(self, ws, vanadium_ws, bank, indices, prog):
        """
        Focuses the input workspace by running EnggFocus as a child algorithm, which will produce a
        single spectrum workspace.

        @param ws :: workspace to focus
        @param vanadium_ws :: workspace with Vanadium run for corrections
        @param bank :: the focusing will be applied on the detectors of this bank
        @param indices :: list of indices to consider, as an alternative to bank (bank and indices are
        mutually exclusive)

        @return focused (summed) workspace
        """
        prog.report("Initialising EnggFocus")

        engg_focus_params = dict()

        detector_positions = self.getProperty('DetectorPositions').value
        if detector_positions:
            engg_focus_params["DetectorPositions"] = detector_positions

        if vanadium_ws:
            engg_focus_params["VanadiumWorkspace"] = vanadium_ws

        van_integration_ws = self.getProperty('VanIntegrationWorkspace').value
        if van_integration_ws:
            engg_focus_params["VanIntegrationWorkspace"] = van_integration_ws

        van_curves_ws = self.getProperty('VanCurvesWorkspace').value
        if van_curves_ws:
            engg_focus_params['VanCurvesWorkspace'] = van_curves_ws

        prog.report("Running EnggFocus")
        return mantid.EnggFocus(InputWorkspace=ws, Bank=bank, SpectrumNumbers=indices, StoreInADS=False,
                                startProgress=0.3, endProgress=0.6, **engg_focus_params)
Ejemplo n.º 2
0
def focus_whole(run_number, van_curves, van_int, focus_directory,
                focus_general, do_pre_process, params, time_period):
    """
    focus a whole run with no cropping

    @param run_number :: the run nuumber to focus
    @param van_curves :: the path to the vanadium curves file
    @param van_int :: the path to the integrated vanadium file
    @param focus_directory :: the user specific focus directory to save to
    @param focus_general :: the general focus directory to save to
    @param do_pre_process :: whether or not to pre-process the run before focussing it
    @param params :: the rebin parameters for pre-processing
    @param time_period :: the time period for pre-processing

    """
    van_curves_ws, van_integrated_ws, ws_to_focus = _prepare_focus(
        run_number, van_curves, van_int, do_pre_process, params, time_period)
    # loop through both banks, focus and save them
    for i in range(1, 3):
        output_ws = "engg_focus_output_bank_{}".format(i)
        simple.EnggFocus(InputWorkspace=ws_to_focus,
                         OutputWorkspace=output_ws,
                         VanIntegrationWorkspace=van_integrated_ws,
                         VanCurvesWorkspace=van_curves_ws,
                         Bank=str(i))
        _save_out(run_number, focus_directory, focus_general, output_ws,
                  "ENGINX_{}_{}", str(i))
Ejemplo n.º 3
0
def focus_cropped(run_number, van_curves, van_int, focus_directory,
                  focus_general, do_pre_process, params, time_period, crop_on,
                  use_spectra):
    """
    focus a partial run, cropping either on banks or on specific spectra

    @param van_curves :: the path to the vanadium curves file
    @param van_int :: the path to the integrated vanadium file
    @param run_number :: the run nuumber to focus
    @param focus_directory :: the user specific focus directory to save to
    @param focus_general :: the general focus directory to save to
    @param do_pre_process :: whether or not to pre-process the run before focussing it
    @param params :: the rebin parameters for pre-processing
    @param time_period :: the time period for pre-processing
    @param crop_on :: the bank or spectra to crop on
    @param use_spectra :: whether to focus by spectra or banks

    """
    van_curves_ws, van_integrated_ws, ws_to_focus = _prepare_focus(
        run_number, van_curves, van_int, do_pre_process, params, time_period)
    output_ws = "engg_focus_output{0}{1}"
    # check whether to crop on bank or spectra
    if not use_spectra:
        # get the bank to crop on, focus and save it out
        bank = {"North": "1", "South": "2"}
        output_ws = output_ws.format("_bank_", bank.get(crop_on))
        simple.EnggFocus(InputWorkspace=ws_to_focus,
                         OutputWorkspace=output_ws,
                         VanIntegrationWorkspace=van_integrated_ws,
                         VanCurvesWorkspace=van_curves_ws,
                         Bank=bank.get(crop_on))
        _save_out(run_number, focus_directory, focus_general, output_ws,
                  "ENGINX_{}_{}", crop_on)
    else:
        # crop on the spectra passed in, focus and save it out
        output_ws = output_ws.format("", "")
        simple.EnggFocus(InputWorkspace=ws_to_focus,
                         OutputWorkspace=output_ws,
                         VanIntegrationWorkspace=van_integrated_ws,
                         VanCurvesWorkspace=van_curves_ws,
                         SpectrumNumbers=crop_on)
        _save_out(run_number, focus_directory, focus_general, output_ws,
                  "ENGINX_{}_bank_{}", "cropped")
Ejemplo n.º 4
0
def focus_texture_mode(run_number, van_curves, van_int, focus_directory,
                       focus_general, do_pre_process, params, time_period,
                       dg_file):
    """
    perform a texture mode focusing using the grouping csv file

    @param run_number :: the run nuumber to focus
    @param van_curves :: the path to the vanadium curves file
    @param van_int :: the path to the integrated vanadium file
    @param focus_directory :: the user specific focus directory to save to
    @param focus_general :: the general focus directory to save to
    @param do_pre_process :: whether or not to pre-process the run before focussing it
    @param params :: the rebin parameters for pre-processing
    @param time_period :: the time period for pre-processing
    @param dg_file :: the grouping file to use for texture mode

    """
    van_curves_ws, van_integrated_ws, ws_to_focus = _prepare_focus(
        run_number, van_curves, van_int, do_pre_process, params, time_period)
    banks = {}
    # read the csv file to work out the banks
    # ensure csv reading works on python 2 or 3
    if not six.PY2:
        with open(dg_file, 'r', newline='', encoding='utf-8') as grouping_file:
            group_reader = csv.reader(_decomment_csv(grouping_file),
                                      delimiter=',')

            for row in group_reader:
                banks.update({row[0]: ','.join(row[1:])})
    else:
        with open(dg_file, 'r') as grouping_file:
            group_reader = csv.reader(_decomment_csv(grouping_file),
                                      delimiter=',')

            for row in group_reader:
                banks.update({row[0]: ','.join(row[1:])})

    # loop through the banks described in the csv, focusing and saing them out
    for bank in banks:
        output_ws = "engg_focusing_output_ws_texture_bank_{}"
        output_ws = output_ws.format(bank)
        simple.EnggFocus(InputWorkspace=ws_to_focus,
                         OutputWorkspace=output_ws,
                         VanIntegrationWorkspace=van_integrated_ws,
                         VanCurvesWorkspace=van_curves_ws,
                         SpectrumNumbers=banks.get(bank))
        _save_out(run_number, focus_directory, focus_general, output_ws,
                  "ENGINX_{}_texture_{}{{}}", bank)