コード例 #1
0
    def __init__(self, file_name):
        super(SANSFileInformationISISNexus, self).__init__(file_name)
        # Setup instrument name
        instrument_name = get_instrument_name_for_isis_nexus(
            self._full_file_name)
        self._instrument = SANSInstrument.from_string(instrument_name)

        # Setup the facility
        self._facility = get_facility(self._instrument)

        # Setup date
        self._date = get_date_for_isis_nexus(self._full_file_name)

        # Setup number of periods
        self._number_of_periods = get_number_of_periods_for_isis_nexus(
            self._full_file_name)

        # Setup run number
        self._run_number = get_run_number_for_isis_nexus(self._full_file_name)

        # Setup event mode check
        self._is_event_mode = get_event_mode_information(self._full_file_name)

        # Get geometry details
        height, width, thickness, shape = get_geometry_information_isis_nexus(
            self._full_file_name)
        self._height = height if height is not None else 1.
        self._width = width if width is not None else 1.
        self._thickness = thickness if thickness is not None else 1.
        self._shape = shape if shape is not None else SampleShape.Disc
コード例 #2
0
def get_component_name(workspace, detector_type):
    instrument = workspace.getInstrument()
    instrument_name = instrument.getName().strip()
    instrument_name = instrument_name.upper()
    instrument = SANSInstrument.from_string(instrument_name)
    return convert_instrument_and_detector_type_to_bank_name(
        instrument, detector_type)
コード例 #3
0
    def __init__(self, file_name):
        super(SANSFileInformationRaw, self).__init__(file_name)
        # Setup instrument name
        instrument_name = get_instrument_name_for_raw(self._full_file_name)
        self._instrument = SANSInstrument.from_string(instrument_name)

        # Setup the facility
        self._facility = get_facility(self._instrument)

        # Setup date
        self._date = get_date_for_raw(self._full_file_name)

        # Setup number of periods
        self._number_of_periods = get_number_of_periods_for_raw(
            self._full_file_name)

        # Setup run number
        self._run_number = get_run_number_for_raw(self._full_file_name)

        # Set geometry
        # Raw files don't have the sample information, so set to default
        height, width, thickness, shape = get_geometry_information_raw(
            self._full_file_name)
        self._height = height if height is not None else 1.
        self._width = width if width is not None else 1.
        self._thickness = thickness if thickness is not None else 1.
        self._shape = shape if shape is not None else SampleShape.Disc
コード例 #4
0
    def __init__(self, file_name):
        super(SANSFileInformationRaw, self).__init__(file_name)
        # Setup instrument name
        instrument_name = get_instrument_name_for_raw(self._full_file_name)
        self._instrument = SANSInstrument.from_string(instrument_name)

        # Setup the facility
        self._facility = get_facility(self._instrument)

        # Setup date
        self._date = get_date_for_raw(self._full_file_name)

        # Setup number of periods
        self._number_of_periods = get_number_of_periods_for_raw(self._full_file_name)

        # Setup run number
        self._run_number = get_run_number_for_raw(self._full_file_name)

        # Set geometry
        # Raw files don't have the sample information, so set to default
        height, width, thickness, shape = get_geometry_information_raw(self._full_file_name)
        self._height = height if height is not None else 1.
        self._width = width if width is not None else 1.
        self._thickness = thickness if thickness is not None else 1.
        self._shape = shape if shape is not None else SampleShape.Disc
コード例 #5
0
    def __init__(self, file_name):
        super(SANSFileInformationISISNexus, self).__init__(file_name)
        # Setup instrument name
        instrument_name = get_instrument_name_for_isis_nexus(self._full_file_name)
        self._instrument = SANSInstrument.from_string(instrument_name)

        # Setup the facility
        self._facility = get_facility(self._instrument)

        # Setup date
        self._date = get_date_for_isis_nexus(self._full_file_name)

        # Setup number of periods
        self._number_of_periods = get_number_of_periods_for_isis_nexus(self._full_file_name)

        # Setup run number
        self._run_number = get_run_number_for_isis_nexus(self._full_file_name)

        # Setup event mode check
        self._is_event_mode = get_event_mode_information(self._full_file_name)

        # Get geometry details
        height, width, thickness, shape = get_geometry_information_isis_nexus(self._full_file_name)
        self._height = height if height is not None else 1.
        self._width = width if width is not None else 1.
        self._thickness = thickness if thickness is not None else 1.
        self._shape = shape if shape is not None else SampleShape.Disc
コード例 #6
0
 def instrument(self):
     # Use impl so that it throws as mandatory key we later rely on
     try:
         instrument = self._get_val_impl(["instrument", "name"],
                                         dict_to_parse=self._input)
     except KeyError:
         raise KeyError("instrument.name is missing")
     return SANSInstrument(instrument)
コード例 #7
0
    def __init__(self, file_name):
        super(SANSFileInformationRaw, self).__init__(file_name)
        # Setup instrument name
        self._full_file_name = SANSFileInformation.get_full_file_name(self._file_name)
        instrument_name = get_instrument_name_for_raw(self._full_file_name)
        self._instrument = SANSInstrument.from_string(instrument_name)

        # Setup date
        self._date = get_date_for_raw(self._full_file_name)

        # Setup number of periods
        self._number_of_periods = get_number_of_periods_for_raw(self._full_file_name)

        # Setup run number
        self._run_number = get_run_number_for_raw(self._full_file_name)
コード例 #8
0
    def __init__(self, file_name):
        super(SANSFileInformationISISNexus, self).__init__(file_name)
        # Setup instrument name
        self._full_file_name = SANSFileInformation.get_full_file_name(self._file_name)
        instrument_name = get_instrument_name_for_isis_nexus(self._full_file_name)
        self._instrument = SANSInstrument.from_string(instrument_name)

        # Setup date
        self._date = get_date_for_isis_nexus(self._full_file_name)

        # Setup number of periods
        self._number_of_periods = get_number_of_periods_for_isis_nexus(self._full_file_name)

        # Setup run number
        self._run_number = get_run_number_for_isis_nexus(self._full_file_name)

        # Setup event mode check
        self._is_event_mode = get_event_mode_information(self._full_file_name)
コード例 #9
0
 def create_mover(workspace):
     # Get selection
     run_number = workspace.getRunNumber()
     instrument = workspace.getInstrument()
     instrument_name = instrument.getName()
     instrument_name = sanitise_instrument_name(instrument_name)
     instrument_type = SANSInstrument.from_string(instrument_name)
     if SANSMoveLOQ.is_correct(instrument_type, run_number):
         mover = SANSMoveLOQ()
     elif SANSMoveSANS2D.is_correct(instrument_type, run_number):
         mover = SANSMoveSANS2D()
     elif SANSMoveLARMOROldStyle.is_correct(instrument_type, run_number):
         mover = SANSMoveLARMOROldStyle()
     elif SANSMoveLARMORNewStyle.is_correct(instrument_type, run_number):
         mover = SANSMoveLARMORNewStyle()
     else:
         mover = None
         NotImplementedError("SANSLoaderFactory: Other instruments are not implemented yet.")
     return mover
コード例 #10
0
ファイル: move_workspaces.py プロジェクト: DanNixon/mantid
 def create_mover(workspace):
     # Get selection
     run_number = workspace.getRunNumber()
     instrument = workspace.getInstrument()
     instrument_name = instrument.getName()
     instrument_name = sanitise_instrument_name(instrument_name)
     instrument_type = SANSInstrument.from_string(instrument_name)
     if SANSMoveLOQ.is_correct(instrument_type, run_number):
         mover = SANSMoveLOQ()
     elif SANSMoveSANS2D.is_correct(instrument_type, run_number):
         mover = SANSMoveSANS2D()
     elif SANSMoveLARMOROldStyle.is_correct(instrument_type, run_number):
         mover = SANSMoveLARMOROldStyle()
     elif SANSMoveLARMORNewStyle.is_correct(instrument_type, run_number):
         mover = SANSMoveLARMORNewStyle()
     elif SANSMoveZOOM.is_correct(instrument_type, run_number):
         mover = SANSMoveZOOM()
     else:
         mover = None
         NotImplementedError("SANSLoaderFactory: Other instruments are not implemented yet.")
     return mover
コード例 #11
0
 def __init__(self, inst):
     if isinstance(inst, str):
         self.instrument_string = inst
     else:
         self.instrument_string = SANSInstrument.to_string(inst)
コード例 #12
0
def get_instrument_paths_for_sans_file(file_name):
    """
    Gets the Instrument Definition File (IDF) path and the Instrument Parameter Path (IPF) path associated with a file.

    :param file_name: the file name is a name fo a SANS data file, e.g. SANS2D0001234
    :return: the IDF path and the IPF path
    """
    def get_file_location(path):
        return os.path.dirname(path)

    def get_ipf_equivalent_name(path):
        # If XXX_Definition_Yyy.xml is the IDF name, then the equivalent  IPF name is: XXX_Parameters_Yyy.xml
        base_file_name = os.path.basename(path)
        return base_file_name.replace("Definition", "Parameters")

    def get_ipf_standard_name(path):
        # If XXX_Definition_Yyy.xml is the IDF name, then the standard IPF name is: XXX_Parameters.xml
        base_file_name = os.path.basename(path)
        elements = base_file_name.split("_")
        return elements[0] + "_Parameters.xml"

    def check_for_files(directory, path):
        # Check if XXX_Parameters_Yyy.xml exists in the same folder
        ipf_equivalent_name = get_ipf_equivalent_name(path)
        ipf_equivalent = os.path.join(directory, ipf_equivalent_name)
        if os.path.exists(ipf_equivalent):
            return ipf_equivalent

        # Check if XXX_Parameters.xml exists in the same folder
        ipf_standard_name = get_ipf_standard_name(path)
        ipf_standard = os.path.join(directory, ipf_standard_name)
        if os.path.exists(ipf_standard):
            return ipf_standard
        # Does not seem to be in the folder
        return None

    def get_ipf_for_rule_1(path):
        # Check if can be found in the same folder
        directory = get_file_location(path)
        return check_for_files(directory, path)

    def get_ipf_for_rule_2(path):
        # Check if can be found in the instrument folder
        directory = ConfigService.getInstrumentDirectory()
        return check_for_files(directory, path)

    # Get the measurement date
    file_information_factory = SANSFileInformationFactory()
    file_information = file_information_factory.create_sans_file_information(file_name)
    measurement_time = file_information.get_date()
    # For some odd reason the __str__ method of DateAndTime adds a space which we need to strip here. It seems
    # to be on purpose though since the export method is called IS08601StringPlusSpace --> hence we need to strip it
    # ourselves
    measurement_time_as_string = str(measurement_time).strip()

    # Get the instrument
    instrument = file_information.get_instrument()
    instrument_as_string = SANSInstrument.to_string(instrument)

    # Get the idf file path
    idf_path = ExperimentInfo.getInstrumentFilename(instrument_as_string, measurement_time_as_string)
    idf_path = os.path.normpath(idf_path)

    if not os.path.exists(idf_path):
        raise RuntimeError("SANSFileInformation: The instrument definition file {0} does not seem to "
                           "exist.".format(str(idf_path)))

    # Get the ipf path. This is slightly more complicated. See the Mantid documentation for the naming rules. Currently
    # they are:
    # 1. If the IDF is not in the instrument folder and there is another X_Parameters.xml in the same folder,
    #    this one in the same folder will be used instead of any parameter file in the instrument folder.
    # 2. If you want one parameter file for your IDF file, name your IDF file X_Definition_Yyy.xml and the parameter
    #    file X_Parameters_Yyy.xml , where Yyy is any combination a characters you find appropriate. If your IDF
    #    file is not in the instrument folder, the parameter file can be in either the same folder or in the instrument
    #    folder, but it can only be in the instrument folder, if the same folder has no X_Parameters.xml or
    #    X_Parameters_Yyy.xml file. If there is no X_Parameters_Yyy.xml file, X_Parameters.xml would be used.
    ipf_rule1 = get_ipf_for_rule_1(idf_path)
    if ipf_rule1:
        return idf_path, ipf_rule1

    ipf_rule2 = get_ipf_for_rule_2(idf_path)
    if ipf_rule2:
        return idf_path, ipf_rule2

    raise RuntimeError("SANSFileInformation: There does not seem to be a corresponding instrument parameter file "
                       "available for {0}".format(str(idf_path)))
コード例 #13
0
def get_instrument_paths_for_sans_file(file_name=None, file_information=None):
    """
    Gets the Instrument Definition File (IDF) path and the Instrument Parameter Path (IPF) path associated with a file.

    :param file_name: the file name is a name fo a SANS data file, e.g. SANS2D0001234. This or the file_information
                      has to be specified.
    :param file_information: a file_information object. either this or the file_name has to be specified.
    :return: the IDF path and the IPF path
    """
    def get_file_location(path):
        return os.path.dirname(path)

    def get_ipf_equivalent_name(path):
        # If XXX_Definition_Yyy.xml is the IDF name, then the equivalent  IPF name is: XXX_Parameters_Yyy.xml
        base_file_name = os.path.basename(path)
        return base_file_name.replace(DEFINITION, PARAMETERS)

    def get_ipf_standard_name(path):
        # If XXX_Definition_Yyy.xml is the IDF name, then the standard IPF name is: XXX_Parameters.xml
        base_file_name = os.path.basename(path)
        elements = base_file_name.split("_")
        return elements[0] + PARAMETERS_XML_SUFFIX

    def check_for_files(directory, path):
        # Check if XXX_Parameters_Yyy.xml exists in the same folder
        ipf_equivalent_name = get_ipf_equivalent_name(path)
        ipf_equivalent = os.path.join(directory, ipf_equivalent_name)
        if os.path.exists(ipf_equivalent):
            return ipf_equivalent

        # Check if XXX_Parameters.xml exists in the same folder
        ipf_standard_name = get_ipf_standard_name(path)
        ipf_standard = os.path.join(directory, ipf_standard_name)
        if os.path.exists(ipf_standard):
            return ipf_standard
        # Does not seem to be in the folder
        return None

    def get_ipf_for_rule_1(path):
        # Check if can be found in the same folder
        directory = get_file_location(path)
        return check_for_files(directory, path)

    def get_ipf_for_rule_2(path):
        # Check if can be found in the instrument folder
        directory = ConfigService.getInstrumentDirectory()
        return check_for_files(directory, path)

    # Get the measurement date
    if not isinstance(file_information, SANSFileInformation):
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(
            file_name)
    measurement_time = file_information.get_date()

    # For some odd reason the __str__ method of DateAndTime adds a space which we need to strip here. It seems
    # to be on purpose though since the export method is called IS08601StringPlusSpace --> hence we need to strip it
    # ourselves
    measurement_time_as_string = str(measurement_time).strip()

    # Get the instrument
    instrument = file_information.get_instrument()
    instrument_as_string = SANSInstrument.to_string(instrument)

    # Get the idf file path
    # IMPORTANT NOTE: I profiled the call to ExperimentInfo.getInstrumentFilename and it dominates
    #                 the state creation. Ironically this routine is exported from C++. The problem is
    #                 that we are performing XML parsing on the C++ side, which is costly. There is a
    #                 movement currently towards making the IDF redundant and storing instrument info
    #                 as native nexus information.
    # TODO for optimization: Add the IDF path to a global cache layer which takes the
    #                        instrument name and the from-to dates
    idf_path = ExperimentInfo.getInstrumentFilename(
        instrument_as_string, measurement_time_as_string)
    idf_path = os.path.normpath(idf_path)

    if not os.path.exists(idf_path):
        raise RuntimeError(
            "SANSFileInformation: The instrument definition file {0} does not seem to "
            "exist.".format(str(idf_path)))

    # Get the ipf path. This is slightly more complicated. See the Mantid documentation for the naming rules. Currently
    # they are:
    # 1. If the IDF is not in the instrument folder and there is another X_Parameters.xml in the same folder,
    #    this one in the same folder will be used instead of any parameter file in the instrument folder.
    # 2. If you want one parameter file for your IDF file, name your IDF file X_Definition_Yyy.xml and the parameter
    #    file X_Parameters_Yyy.xml , where Yyy is any combination a characters you find appropriate. If your IDF
    #    file is not in the instrument folder, the parameter file can be in either the same folder or in the instrument
    #    folder, but it can only be in the instrument folder, if the same folder has no X_Parameters.xml or
    #    X_Parameters_Yyy.xml file. If there is no X_Parameters_Yyy.xml file, X_Parameters.xml would be used.
    ipf_rule1 = get_ipf_for_rule_1(idf_path)
    if ipf_rule1:
        return idf_path, ipf_rule1

    ipf_rule2 = get_ipf_for_rule_2(idf_path)
    if ipf_rule2:
        return idf_path, ipf_rule2

    raise RuntimeError(
        "SANSFileInformation: There does not seem to be a corresponding instrument parameter file "
        "available for {0}".format(str(idf_path)))
コード例 #14
0
def get_instrument_paths_for_sans_file(file_name=None, file_information=None):
    """
    Gets the Instrument Definition File (IDF) path and the Instrument Parameter Path (IPF) path associated with a file.

    :param file_name: the file name is a name fo a SANS data file, e.g. SANS2D0001234. This or the file_information
                      has to be specified.
    :param file_information: a file_information object. either this or the file_name has to be specified.
    :return: the IDF path and the IPF path
    """
    def get_file_location(path):
        return os.path.dirname(path)

    def get_ipf_equivalent_name(path):
        # If XXX_Definition_Yyy.xml is the IDF name, then the equivalent  IPF name is: XXX_Parameters_Yyy.xml
        base_file_name = os.path.basename(path)
        return base_file_name.replace(DEFINITION, PARAMETERS)

    def get_ipf_standard_name(path):
        # If XXX_Definition_Yyy.xml is the IDF name, then the standard IPF name is: XXX_Parameters.xml
        base_file_name = os.path.basename(path)
        elements = base_file_name.split("_")
        return elements[0] + PARAMETERS_XML_SUFFIX

    def check_for_files(directory, path):
        # Check if XXX_Parameters_Yyy.xml exists in the same folder
        ipf_equivalent_name = get_ipf_equivalent_name(path)
        ipf_equivalent = os.path.join(directory, ipf_equivalent_name)
        if os.path.exists(ipf_equivalent):
            return ipf_equivalent

        # Check if XXX_Parameters.xml exists in the same folder
        ipf_standard_name = get_ipf_standard_name(path)
        ipf_standard = os.path.join(directory, ipf_standard_name)
        if os.path.exists(ipf_standard):
            return ipf_standard
        # Does not seem to be in the folder
        return None

    def get_ipf_for_rule_1(path):
        # Check if can be found in the same folder
        directory = get_file_location(path)
        return check_for_files(directory, path)

    def get_ipf_for_rule_2(path):
        # Check if can be found in the instrument folder
        directory = ConfigService.getInstrumentDirectory()
        return check_for_files(directory, path)

    # Get the measurement date
    if not isinstance(file_information, SANSFileInformation):
        file_information_factory = SANSFileInformationFactory()
        file_information = file_information_factory.create_sans_file_information(file_name)
    measurement_time = file_information.get_date()

    # For some odd reason the __str__ method of DateAndTime adds a space which we need to strip here. It seems
    # to be on purpose though since the export method is called IS08601StringPlusSpace --> hence we need to strip it
    # ourselves
    measurement_time_as_string = str(measurement_time).strip()

    # Get the instrument
    instrument = file_information.get_instrument()
    instrument_as_string = SANSInstrument.to_string(instrument)

    # Get the idf file path
    # IMPORTANT NOTE: I profiled the call to ExperimentInfo.getInstrumentFilename and it dominates
    #                 the state creation. Ironically this routine is exported from C++. The problem is
    #                 that we are performing XML parsing on the C++ side, which is costly. There is a
    #                 movement currently towards making the IDF redundant and storing instrument info
    #                 as native nexus information.
    # TODO for optimization: Add the IDF path to a global cache layer which takes the
    #                        instrument name and the from-to dates
    idf_path = ExperimentInfo.getInstrumentFilename(instrument_as_string, measurement_time_as_string)
    idf_path = os.path.normpath(idf_path)

    if not os.path.exists(idf_path):
        raise RuntimeError("SANSFileInformation: The instrument definition file {0} does not seem to "
                           "exist.".format(str(idf_path)))

    # Get the ipf path. This is slightly more complicated. See the Mantid documentation for the naming rules. Currently
    # they are:
    # 1. If the IDF is not in the instrument folder and there is another X_Parameters.xml in the same folder,
    #    this one in the same folder will be used instead of any parameter file in the instrument folder.
    # 2. If you want one parameter file for your IDF file, name your IDF file X_Definition_Yyy.xml and the parameter
    #    file X_Parameters_Yyy.xml , where Yyy is any combination a characters you find appropriate. If your IDF
    #    file is not in the instrument folder, the parameter file can be in either the same folder or in the instrument
    #    folder, but it can only be in the instrument folder, if the same folder has no X_Parameters.xml or
    #    X_Parameters_Yyy.xml file. If there is no X_Parameters_Yyy.xml file, X_Parameters.xml would be used.
    ipf_rule1 = get_ipf_for_rule_1(idf_path)
    if ipf_rule1:
        return idf_path, ipf_rule1

    ipf_rule2 = get_ipf_for_rule_2(idf_path)
    if ipf_rule2:
        return idf_path, ipf_rule2

    raise RuntimeError("SANSFileInformation: There does not seem to be a corresponding instrument parameter file "
                       "available for {0}".format(str(idf_path)))
コード例 #15
0
ファイル: crop_helper.py プロジェクト: mantidproject/mantid
def get_component_name(workspace, detector_type):
    instrument = workspace.getInstrument()
    instrument_name = instrument.getName().strip()
    instrument_name = instrument_name.upper()
    instrument = SANSInstrument.from_string(instrument_name)
    return convert_instrument_and_detector_type_to_bank_name(instrument, detector_type)
コード例 #16
0
 def __init__(self, inst):
     if isinstance(inst, str):
         self.instrument_string = inst
     else:
         self.instrument_string = SANSInstrument.to_string(inst)