Example #1
0
    def extract_slice(self, data='strain', phi=None, az_idx=None, z_idx=None):
        """ Extract 2D data slice wrt. azimuthal slice index or angle (phi).

        The extracted data is defined using the data variable (str), which
        must be one of the following: peaks, peaks error, fwhm, fwhm error,
        strain, strain error, shear strain, stress, shear stress.

        Certain combinations of data type and azimuthal index/phi will not
        work (e.g. can't extract peaks wrt. phi only wrt. az. index).

        Note: must define EITHER phi or az_idx

        Args:
            data (str): Data type to extract (see above)
            phi (float): Azimuthal angle in rad
            az_idx (int): Azimuthal slice index
            z_idx (int): Index of slice height in 3D array
        """
        complex_check(data, self.analysis_state, phi, az_idx)
        command = text_cleaning(data)
        az_command = 'phi' if phi is not None else 'az_idx'

        if az_command == 'az_idx':
            az_idx = int(az_idx)
            if 'stress' not in command:
                data_command = {
                    'peaks': self.peaks,
                    'peaks error': self.peaks_err,
                    'fwhm': self.fwhm,
                    'fwhm error': self.fwhm_err,
                    'strain': self.strain,
                    'strain error': self.strain_err
                }

                data = data_command[command][..., az_idx]
            else:
                d = self.strain if 'err' not in command else self.strain_err
                e_xx, e_yy = d[..., az_idx], d[..., az90(self.phi, az_idx)]
                data = self.stress_eqn(e_xx, e_yy, self.E, self.v)

        else:
            tensor = self.strain_tensor
            tensor = tensor[..., 0], tensor[..., 1], tensor[..., 2]
            shear = True if 'shear' in command else False
            stress = True if 'stress' in command else False

            if shear:
                e_xy = shear_transformation(phi, *tensor)
                data = self.G * e_xy if stress else e_xy

            elif stress:
                e_xx = strain_transformation(phi, *tensor)
                e_yy = strain_transformation(phi + np.pi / 2, *tensor)
                data = self.stress_eqn(e_xx, e_yy, self.E, self.v)

            else:
                data = strain_transformation(phi, *tensor)
        data = data[z_idx] if z_idx is not None else data
        return data
Example #2
0
    def extract_slice(self, data='strain', phi=None, az_idx=None, z_idx=None):
        """ Extract 2D data slice wrt. azimuthal slice index or angle (phi).

        The extracted data is defined using the data variable (str), which
        must be one of the following: peaks, peaks error, fwhm, fwhm error,
        strain, strain error, shear strain, stress, shear stress.

        Certain combinations of data type and azimuthal index/phi will not
        work (e.g. can't extract peaks wrt. phi only wrt. az. index).

        Note: must define EITHER phi or az_idx

        Args:
            data (str): Data type to extract (see above)
            phi (float): Azimuthal angle in rad
            az_idx (int): Azimuthal slice index
            z_idx (int): Index of slice height in 3D array
        """
        complex_check(data, self.analysis_state, phi, az_idx)
        command = text_cleaning(data)
        az_command = 'phi' if phi is not None else 'az_idx'

        if az_command == 'az_idx':
            az_idx = int(az_idx)
            if 'stress' not in command:
                data_command = {'peaks': self.peaks,
                                'peaks error': self.peaks_err,
                                'fwhm': self.fwhm,
                                'fwhm error': self.fwhm_err,
                                'strain': self.strain,
                                'strain error': self.strain_err}

                data = data_command[command][..., az_idx]
            else:
                d = self.strain if 'err' not in command else self.strain_err
                e_xx, e_yy = d[..., az_idx], d[..., az90(self.phi, az_idx)]
                data = self.stress_eqn(e_xx, e_yy, self.E, self.v)

        else:
            tensor = self.strain_tensor
            tensor = tensor[..., 0], tensor[..., 1], tensor[..., 2]
            shear = True if 'shear' in command else False
            stress = True if 'stress' in command else False

            if shear:
                e_xy = shear_transformation(phi, *tensor)
                data = self.G * e_xy if stress else e_xy

            elif stress:
                e_xx = strain_transformation(phi, *tensor)
                e_yy = strain_transformation(phi + np.pi / 2, *tensor)
                data = self.stress_eqn(e_xx, e_yy, self.E, self.v)

            else:
                data = strain_transformation(phi, *tensor)
        data = data[z_idx] if z_idx is not None else data
        return data
Example #3
0
def test_clean():

    examples = {'peak': 'peaks',
                'peak_err': 'peaks error',
                'strain': 'strain',
                'stress': 'stress',
                'strain error': 'strain error',
                'shears_strians': 'shear strain',
                'stresses-err': 'stress error',
                'shears-stresses': 'shear stress'}

    for example in examples:
        cleaned = cp.text_cleaning(example)
        answer = examples[example]
        assert cleaned == answer, 'Clean: {}, Ans: {}'.format(cleaned, answer)