Ejemplo n.º 1
0
    def test_formgen(self):
        t_dip = shgpy.make_tensor_real(td.dipole['T_d'])
        t_quad = shgpy.make_tensor_real(td.quadrupole['T_d'])
        form1 = formgen_just_dipole(t_dip, S.theta)
        form2 = formgen_dipole_quadrupole(t_dip, t_quad, S.theta)

        t_dip = shgpy.make_tensor_complex(td.dipole['T_d'])
        t_quad = shgpy.make_tensor_complex(td.quadrupole['T_d'])
        form3 = formgen_just_dipole(t_dip, S.theta)
        form4 = formgen_dipole_quadrupole(t_dip, t_quad, S.theta)
        forms = [form1, form2, form3, form4]
        for form in forms:
            form.apply_phase_shift(S.psi, S.phi)
            dat = shgpy.form_to_dat(
                form,
                {
                    k: random.uniform(-1, 1)
                    for k in form.get_free_symbols() if k != S.phi
                },
                1000,
            )
            if MANUAL:
                easy_plot(
                    [dat],
                    [{
                        'linestyle': '-',
                        'color': 'blue'
                    }],
                    dat.get_keys(),
                    show_plot=False,
                )
Ejemplo n.º 2
0
    def test_least_squares(self):
        ret1 = least_squares_fit(self.fform, self.fdat, self.guess_dict)
        ret2 = least_squares_fit_with_bounds(
            self.fform,
            self.fdat,
            self.guess_dict,
            self.bounds_dict,
        )
        for ret in [ret1, ret2]:
            self.assertAlmostEqual(abs(ret.xdict[S.psi]), 1.59, delta=0.1)
            self.assertAlmostEqual(
                abs(ret.xdict[shgpy.map_to_real(S.zyx)]),
                1.23,
                delta=0.1,
            )

        fit_dat = shgpy.fform_to_dat(self.fform, ret1.xdict, 1000)
        if MANUAL:
            easy_plot(
                [self.dat, fit_dat],
                [
                    {
                        'linestyle': ' ',
                        'markerfacecolor': 'none',
                        'color': 'blue',
                        'marker': 'o',
                    },
                    {
                        'linestyle': '-',
                        'color': 'blue',
                    },
                ],
                ['PP', 'PS', 'SP', 'SS'],
                show_plot=True,
                filename=None,
                show_legend=False,
            )
            easy_polar_plot(
                [self.dat, fit_dat],
                [
                    {
                        'linestyle': ' ',
                        'markerfacecolor': 'none',
                        'color': 'blue',
                        'marker': 'o'
                    },
                    {
                        'linestyle': '-',
                        'color': 'blue',
                    },
                ],
                ['PP', 'PS', 'SP', 'SS'],
                show_plot=True,
                filename=None,
                show_legend=False,
            )
Ejemplo n.º 3
0
 def test_form_to_dat(self):
     form = shgpy.fform_to_form(self.fform)
     dat = shgpy.form_to_dat(
         form,
         {
             k: random.uniform(-1, 1)
             for k in form.get_free_symbols() if k != S.phi
         },
         1000,
     )
     if MANUAL:
         easy_plot(
             [dat],
             [{
                 'linestyle': '-',
                 'color': 'blue'
             }],
             dat.get_keys(),
         )
Ejemplo n.º 4
0
    def test_generate_contracted_fourier_transforms(self):

        t_dip = shgpy.make_tensor_real(
            shgpy.transform(
                shgpy.particularize(td.dipole['T_d']),
                shgpy.rotation_matrix_from_two_vectors(
                    np.array([1, 1, 0]),
                    np.array([0, 0, 1]),
                ),
            ), )
        t_quad = shgpy.make_tensor_real(
            np.zeros(shape=(3, 3, 3, 3), dtype=object), )
        save_filename = 'tests/fform/T_d-S_2-S_2(110)-particularized.p'
        shgpy.fformgen.generate_contracted_fourier_transforms(
            save_filename,
            'tests/fform/uft10deg',
            t_dip,
            t_quad,
            ndigits=4,
        )
        fform = shgpy.load_fform(save_filename)
        fform.apply_phase_shift(S.psi)
        form = shgpy.fform_to_form(fform)
        dat = shgpy.form_to_dat(
            form,
            {
                k: random.uniform(-1, 1)
                for k in form.get_free_symbols() if k != S.phi
            },
            1000,
        )
        if MANUAL:
            easy_plot(
                [dat],
                [{
                    'linestyle': '-',
                    'color': 'blue'
                }],
                dat.get_keys(),
            )
Ejemplo n.º 5
0
    def test_normal_loading(self):

        data_filenames_dict = {
            'PP': 'tests/Data/dataPP.csv',
            'SP': 'tests/Data/dataPS.csv',
        }
        dat = shgpy.load_data(data_filenames_dict, 'degrees')
        if MANUAL:
            easy_plot(
                [dat],
                [
                    {
                        'linestyle': '-',
                        'marker': 'o',
                        'markerfacecolor': 'none',
                        'color': 'blue'
                    },
                ],
                dat.get_keys(),
            )
        dat, fdat = shgpy.load_data_and_fourier_transform(
            data_filenames_dict,
            'degrees',
        )
Ejemplo n.º 6
0
import random

import shgpy
import shgpy.tensor_definitions as td
from shgpy.formgen import formgen_just_dipole
from shgpy.plotter import easy_plot
import shgpy.shg_symbols as S

mylogger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

R = shgpy.rotation_matrix_from_two_vectors(
    np.array([1, 1, 0]),
    np.array([0, 0, 1]),
)

t_dipole = shgpy.particularize(td.dipole['T_d'])
t_dipole = shgpy.make_tensor_real(t_dipole)
t_dipole = shgpy.transform(t_dipole, R)

t_quad = np.zeros(shape=(3,3,3,3), dtype=sp.Expr)

form = formgen_just_dipole(t_dipole, 0.1745)

subs_dict = {}
for fs in form.get_free_symbols():
    if fs != S.phi:
        subs_dict[fs] = random.uniform(-1, 1)
dat = shgpy.form_to_dat(form, subs_dict, 1000)
easy_plot([dat], [{'linestyle':'-', 'color':'blue'}], dat.get_keys(), show_plot=True)
Ejemplo n.º 7
0
    'PP':'Data/dataPP.csv',
    'PS':'Data/dataPS.csv',
    'SP':'Data/dataSP.csv',
    'SS':'Data/dataSS.csv',
}

dat = shgpy.load_data(data_filenames_dict, 'degrees')

easy_plot(
    list_of_dats=[dat],
    list_of_param_dicts=[
        {
            'linestyle':'-',
            'color':'blue',
            'markerfacecolor':'none',
            'marker':'o',
        },
    ],
    pcs_to_include=['PP', 'PS'],
    show_plot=True,
    filename=None,
    show_legend=False,
)

dat.scale_data(100)
dat.phase_shift_data(np.pi/2, 'radians')
easy_plot(
    list_of_dats=[dat],
    list_of_param_dicts=[
        {
            'linestyle':'-',