Example #1
0
    def save_to_txt(self, fname, data, phi=None, az_idx=None, perp=True):
        """ Save flattened, extracted data to text (csv) file.

        Args:
            fname (str): Fname/path to save extracted text to
            data (list): List of data types to extract (see above)
            phi (float): Azimuthal angle in rad
            az_idx (int): Azimuthal slice index
            perp (bool): For defined angle/idx, save data perp to this.
        """
        n_lst = [d for d in ['d1', 'd2', 'd3'] if getattr(self, d) is not None]
        d_lst = [getattr(self, d) for d in n_lst]

        for d in data:
            print(d)
            name = name_convert(d, phi, az_idx)
            d_lst.append(self.extract_slice(d, phi=phi, az_idx=az_idx))
            n_lst.append(name)

            if perp:
                a90 = az90(self.phi, az_idx) if az_idx is not None else az_idx
                p90 = phi + np.pi/2 if phi is not None else phi
                name = name_convert(d, p90, a90, perp)
                d_lst.append(self.extract_slice(d, phi=p90, az_idx=a90))
                n_lst.append(name)
        data = np.hstack([d.reshape(d.size, 1) for d in d_lst])
        headers = ','.join(n_lst)
        np.savetxt(fname, data, delimiter=',', header=headers)
Example #2
0
    def save_to_txt(self, fname, data, phi=None, az_idx=None, perp=True):
        """ Save flattened, extracted data to text (csv) file.

        Args:
            fname (str): Fname/path to save extracted text to
            data (list): List of data types to extract (see above)
            phi (float): Azimuthal angle in rad
            az_idx (int): Azimuthal slice index
            perp (bool): For defined angle/idx, save data perp to this.
        """
        n_lst = [d for d in ['d1', 'd2', 'd3'] if getattr(self, d) is not None]
        d_lst = [getattr(self, d) for d in n_lst]

        for d in data:
            print(d)
            name = name_convert(d, phi, az_idx)
            d_lst.append(self.extract_slice(d, phi=phi, az_idx=az_idx))
            n_lst.append(name)

            if perp:
                a90 = az90(self.phi, az_idx) if az_idx is not None else az_idx
                p90 = phi + np.pi / 2 if phi is not None else phi
                name = name_convert(d, p90, a90, perp)
                d_lst.append(self.extract_slice(d, phi=p90, az_idx=a90))
                n_lst.append(name)
        data = np.hstack([d.reshape(d.size, 1) for d in d_lst])
        headers = ','.join(n_lst)
        np.savetxt(fname, data, delimiter=',', header=headers)
Example #3
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 #4
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