Esempio 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,
                )
Esempio n. 2
0
    def test_convert(self):

        fform_filename = 'tests/fform/T_d-S_2-S_2(110).p'
        fform = shgpy.load_fform(fform_filename)
        data_filenames_dict = {
            'PP': 'tests/Data/dataPP.csv',
            'PS': 'tests/Data/dataPS.csv',
            'SP': 'tests/Data/dataSP.csv',
            'SS': 'tests/Data/dataSS.csv',
        }
        dat, fdat = shgpy.load_data_and_fourier_transform(
            data_filenames_dict,
            'degrees',
        )
        form = shgpy.fform_to_form(fform)

        t1 = shgpy.dat_to_fdat(dat)
        self.assertIsInstance(t1, type(fdat))
        t2 = shgpy.fdat_to_dat(fdat, 1000)
        self.assertIsInstance(t2, type(dat))
        t3 = shgpy.form_to_dat(
            form,
            self.random_subs_dict(fform.get_free_symbols()),
            1000,
        )
        self.assertIsInstance(t3, type(dat))
        t4 = shgpy.form_to_fform(form)
        self.assertIsInstance(t4, type(fform))
        t5 = shgpy.form_to_fdat(
            form,
            self.random_subs_dict(fform.get_free_symbols()),
        )
        self.assertIsInstance(t5, type(fdat))
        t6 = shgpy.fform_to_fdat(
            fform,
            self.random_subs_dict(fform.get_free_symbols()),
        )
        self.assertIsInstance(t6, type(fdat))
        t7 = shgpy.fform_to_dat(
            fform,
            self.random_subs_dict(fform.get_free_symbols()),
            1000,
        )
        self.assertIsInstance(t7, type(dat))
        t8 = shgpy.fform_to_form(fform)
        self.assertIsInstance(t8, type(form))
Esempio 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(),
         )
Esempio 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(),
            )
Esempio n. 5
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)