Exemple #1
0
    def test_that_can_read_and_write_hash_in_sample_log(self):
        # Arrange
        ws1 = self._provide_sample_workspace()
        tag1 = "test"
        value1 = "tested"
        value2 = "tested2"

        # Act + Assert
        hashed_value_1 = get_hash_value(value1)
        hashed_value_2 = get_hash_value(value2)
        self.assertFalse(has_hash(tag1, hashed_value_1, ws1))
        set_hash(tag1, hashed_value_1, ws1)
        self.assertTrue(has_hash(tag1, hashed_value_1, ws1))
        self.assertFalse(has_hash(tag1, hashed_value_2, ws1))
Exemple #2
0
    def test_that_can_read_and_write_hash_in_sample_log(self):
        # Arrange
        ws1 = self._provide_sample_workspace()
        tag1 = "test"
        value1 = "tested"
        value2 = "tested2"

        # Act + Assert
        hashed_value_1 = get_hash_value(value1)
        hashed_value_2 = get_hash_value(value2)
        self.assertFalse(has_hash(tag1, hashed_value_1, ws1))
        set_hash(tag1, hashed_value_1, ws1)
        self.assertTrue(has_hash(tag1, hashed_value_1, ws1))
        self.assertFalse(has_hash(tag1, hashed_value_2, ws1))
Exemple #3
0
def get_state_hash_for_can_reduction(state, partial_type=None):
    """
    Creates a hash for a (modified) state object.

    Note that we need to modify the state object to exclude elements which are not relevant for the can reduction.
    This is primarily the setting of the sample workspaces. This is the only place where we directly alter the value
    of a state object
    @param state: a SANSState object.
    @param partial_type: if it is a partial type, then it needs to be specified here.
    @return: the hash of the state
    """
    def remove_sample_related_information(full_state):
        state_to_hash = deepcopy(full_state)
        state_to_hash.data.sample_scatter = EMPTY_NAME
        state_to_hash.data.sample_scatter_period = ALL_PERIODS
        state_to_hash.data.sample_transmission = EMPTY_NAME
        state_to_hash.data.sample_transmission_period = ALL_PERIODS
        state_to_hash.data.sample_direct = EMPTY_NAME
        state_to_hash.data.sample_direct_period = ALL_PERIODS
        state_to_hash.data.sample_scatter_run_number = 1
        return state_to_hash
    new_state = remove_sample_related_information(state)
    new_state_serialized = new_state.property_manager

    # If we are dealing with a partial output workspace, then mark it as such
    if partial_type is OutputParts.Count:
        state_string = str(new_state_serialized) + "counts"
    elif partial_type is OutputParts.Norm:
        state_string = str(new_state_serialized) + "norm"
    else:
        state_string = str(new_state_serialized)
    return str(get_hash_value(state_string))
def get_state_hash_for_can_reduction(state, reduction_mode, partial_type=None):
    """
    Creates a hash for a (modified) state object.

    Note that we need to modify the state object to exclude elements which are not relevant for the can reduction.
    This is primarily the setting of the sample workspaces. This is the only place where we directly alter the value
    of a state object in the entire reduction workflow. Note that we are not changing the
    :param state: a SANSState object.
    :param reduction_mode: the reduction mode, here it can be LAB or HAb
    :param partial_type: if it is a partial type, then it needs to be specified here.
    :return: the hash of the state
    """
    def remove_sample_related_information(full_state):
        state_to_hash = deepcopy(full_state)

        # Data
        state_to_hash.data.sample_scatter = EMPTY_NAME
        state_to_hash.data.sample_scatter_period = ALL_PERIODS
        state_to_hash.data.sample_transmission = EMPTY_NAME
        state_to_hash.data.sample_transmission_period = ALL_PERIODS
        state_to_hash.data.sample_direct = EMPTY_NAME
        state_to_hash.data.sample_direct_period = ALL_PERIODS
        state_to_hash.data.sample_scatter_run_number = 1

        # Save
        state_to_hash.save.user_specified_output_name = ""

        return state_to_hash

    new_state = remove_sample_related_information(state)
    new_state_serialized = new_state.property_manager
    new_state_serialized = json.dumps(new_state_serialized,
                                      sort_keys=True,
                                      indent=4)

    # Add a tag for the reduction mode
    state_string = str(new_state_serialized)
    if reduction_mode is ISISReductionMode.LAB:
        state_string += "LAB"
    elif reduction_mode is ISISReductionMode.HAB:
        state_string += "HAB"
    else:
        raise RuntimeError(
            "Only LAB and HAB reduction modes are allowed at this point."
            " {} was provided".format(reduction_mode))

    # If we are dealing with a partial output workspace, then mark it as such
    if partial_type is OutputParts.Count:
        state_string += "counts"
    elif partial_type is OutputParts.Norm:
        state_string += "norm"
    elif partial_type is TransmissionType.Calculated:
        state_string += "calculated_transmission"
    elif partial_type is TransmissionType.Unfitted:
        state_string += "unfitted_transmission"
    return str(get_hash_value(state_string))
def get_state_hash_for_can_reduction(state, reduction_mode, partial_type=None):
    """
    Creates a hash for a (modified) state object.

    Note that we need to modify the state object to exclude elements which are not relevant for the can reduction.
    This is primarily the setting of the sample workspaces. This is the only place where we directly alter the value
    of a state object in the entire reduction workflow. Note that we are not changing the
    :param state: a SANSState object.
    :param reduction_mode: the reduction mode, here it can be LAB or HAb
    :param partial_type: if it is a partial type, then it needs to be specified here.
    :return: the hash of the state
    """
    def remove_sample_related_information(full_state):
        state_to_hash = deepcopy(full_state)

        # Data
        state_to_hash.data.sample_scatter = EMPTY_NAME
        state_to_hash.data.sample_scatter_period = ALL_PERIODS
        state_to_hash.data.sample_transmission = EMPTY_NAME
        state_to_hash.data.sample_transmission_period = ALL_PERIODS
        state_to_hash.data.sample_direct = EMPTY_NAME
        state_to_hash.data.sample_direct_period = ALL_PERIODS
        state_to_hash.data.sample_scatter_run_number = 1

        # Save
        state_to_hash.save.user_specified_output_name = ""

        return state_to_hash
    new_state = remove_sample_related_information(state)
    new_state_serialized = new_state.property_manager
    new_state_serialized = json.dumps(new_state_serialized, sort_keys=True, indent=4)

    # Add a tag for the reduction mode
    state_string = str(new_state_serialized)
    if reduction_mode is ISISReductionMode.LAB:
        state_string += "LAB"
    elif reduction_mode is ISISReductionMode.HAB:
        state_string += "HAB"
    else:
        raise RuntimeError("Only LAB and HAB reduction modes are allowed at this point."
                           " {} was provided".format(reduction_mode))

    # If we are dealing with a partial output workspace, then mark it as such
    if partial_type is OutputParts.Count:
        state_string += "counts"
    elif partial_type is OutputParts.Norm:
        state_string += "norm"
    elif partial_type is TransmissionType.Calculated:
        state_string += "calculated_transmission"
    elif partial_type is TransmissionType.Unfitted:
        state_string += "unfitted_transmission"
    return str(get_hash_value(state_string))