예제 #1
0
def _get_diffracted_intensity(range_theta, range_stl, phase):
    assert phase.type == "Phase", "Must be Phase!"
    # Check probability model, if invalid return zeros instead of the actual pattern:
    if not phase.valid_probs:
        logger.debug("- calc: get_diffracted_intensity reports: 'Invalid probability found!'")
        return np.zeros_like(range_stl)
    else:
        # Calculate CSDS distribution
        CSDS_arr, CSDS_real_mean = calculate_distribution(phase.CSDS)

        # Get absolute scale
        abs_scale = get_absolute_scale(phase.components, CSDS_real_mean, phase.W)

        # Create a helper function to 'expand' certain arrays, for
        # results which are independent of the 2-theta range
        stl_dim = range_stl.shape[0]
        repeat_to_stl = lambda arr: np.repeat(arr[np.newaxis, ...], stl_dim, axis=0)

        # Repeat junction probabilities & weight fractions
        W = repeat_to_stl(phase.W).astype(np.complex_)
        P = repeat_to_stl(phase.P).astype(np.complex_)

        # Repeat & get SFa and SFb (transpose conjugate) structure factor matrices:
        SF, PF = get_structure_factors(range_stl, phase.G, phase.components)
        SFa = np.repeat(SF[..., np.newaxis, :], SF.shape[1], axis=1)
        SFb = np.transpose(np.conjugate(SFa), axes=(0, 2, 1))

        # Calculate the repetition factor for R+ probabilities:
        rank = P.shape[1]
        reps = rank / phase.G

        # Calculate the structure factor matrix:
        F = np.repeat(np.repeat(np.multiply(SFb, SFa), reps, axis=2), reps, axis=1)

        # Create Q phase factor matrices:
        PF = np.repeat(PF[..., np.newaxis, :], PF.shape[1], axis=1)
        Q = np.multiply(np.repeat(np.repeat(PF, reps, axis=2), reps, axis=1), P)
        Qn = get_Q_matrices(Q, phase.CSDS.maximum)

        # Calculate the intensity:
        sub_total = np.zeros(Q.shape, dtype=np.complex)
        for n in range(phase.CSDS.minimum, phase.CSDS.maximum + 1):
            progression_factor = 0
            for m in range(n + 1, phase.CSDS.maximum + 1):
                progression_factor += (m - n) * CSDS_arr[m]
            sub_total += 2 * progression_factor * Qn[n - 1, ...]

        CSDS_I = repeat_to_stl(np.identity(rank, dtype=np.complex) * CSDS_real_mean)
        sub_total = (CSDS_I + sub_total)
        sub_total = mmult(mmult(F, W), sub_total)
        intensity = np.real(np.trace(sub_total, axis1=2, axis2=1))

        return intensity * abs_scale
예제 #2
0
 def test_calculate_distribution(self):
     result = calculate_distribution(
         self.CSDS_data
     )
     self.assertIsNotNone(result)
     self.assertEquals(len(result), 2)
예제 #3
0
파일: test_CSDS.py 프로젝트: fbocches/PyXRD
 def test_calculate_distribution(self):
     result = calculate_distribution(self.CSDS_data)
     self.assertIsNotNone(result)
     self.assertEquals(len(result), 2)
예제 #4
0
 def _update_distribution(self):
     type(self).maximum._set(
         self, int(settings.LOG_NORMAL_MAX_CSDS_FACTOR * self.average))
     self._distrib = calculate_distribution(self.data_object)
예제 #5
0
파일: CSDS.py 프로젝트: Python3pkg/PyXRD
 def _update_distribution(self):
     self._distrib = calculate_distribution(self.data_object)
예제 #6
0
파일: phases.py 프로젝트: openafox/PyXRD
def _get_diffracted_intensity(range_theta, range_stl, phase):
    assert phase.type == "Phase", "Must be Phase!"
    # Check probability model, if invalid return zeros instead of the actual pattern:
    if not phase.valid_probs:
        logger.debug(
            "- calc: get_diffracted_intensity reports: 'Invalid probability found!'"
        )
        return np.zeros_like(range_stl)
    else:
        # Calculate CSDS distribution
        CSDS_arr, CSDS_real_mean = calculate_distribution(phase.CSDS)

        # Get absolute scale
        abs_scale = get_absolute_scale(phase.components, CSDS_real_mean,
                                       phase.W)

        # Create a helper function to 'expand' certain arrays, for
        # results which are independent of the 2-theta range
        stl_dim = range_stl.shape[0]
        repeat_to_stl = lambda arr: np.repeat(
            arr[np.newaxis, ...], stl_dim, axis=0)

        # Repeat junction probabilities & weight fractions
        W = repeat_to_stl(phase.W).astype(np.complex_)
        P = repeat_to_stl(phase.P).astype(np.complex_)

        # Repeat & get SFa and SFb (transpose conjugate) structure factor matrices:
        SF, PF = get_structure_factors(range_stl, phase.G, phase.components)
        SFa = np.repeat(SF[..., np.newaxis, :], SF.shape[1], axis=1)
        SFb = np.transpose(np.conjugate(SFa), axes=(0, 2, 1))

        # Calculate the repetition factor for R+ probabilities:
        rank = P.shape[1]
        reps = rank / phase.G

        # Calculate the structure factor matrix:
        F = np.repeat(np.repeat(np.multiply(SFb, SFa), reps, axis=2),
                      reps,
                      axis=1)

        # Create Q phase factor matrices:
        PF = np.repeat(PF[..., np.newaxis, :], PF.shape[1], axis=1)
        Q = np.multiply(np.repeat(np.repeat(PF, reps, axis=2), reps, axis=1),
                        P)
        Qn = get_Q_matrices(Q, phase.CSDS.maximum)

        # Calculate the intensity:
        sub_total = np.zeros(Q.shape, dtype=np.complex)
        for n in range(phase.CSDS.minimum, phase.CSDS.maximum + 1):
            progression_factor = 0
            for m in range(n + 1, phase.CSDS.maximum + 1):
                progression_factor += (m - n) * CSDS_arr[m]
            sub_total += 2 * progression_factor * Qn[n - 1, ...]

        CSDS_I = repeat_to_stl(
            np.identity(rank, dtype=np.complex) * CSDS_real_mean)
        sub_total = (CSDS_I + sub_total)
        sub_total = mmult(mmult(F, W), sub_total)
        intensity = np.real(np.trace(sub_total, axis1=2, axis2=1))

        return intensity * abs_scale
예제 #7
0
 def _update_distribution(self):
     self._distrib = calculate_distribution(self.data_object)
예제 #8
0
파일: CSDS.py 프로젝트: mathijs-dumon/PyXRD
 def _update_distribution(self):
     type(self).maximum._set(self, int(settings.LOG_NORMAL_MAX_CSDS_FACTOR * self.average))
     self._distrib = calculate_distribution(self.data_object)