shgpy.fformgen module

Module for generating Fourier formulas.

This module provides the necessary routines for generating Fourier formulas; that is, ndarrays of sympy.Expr where each element is a formula for a given Fourier component. The key benefit of working with Fourier formulas rather than phi-space formulas is that all of the fitting is easier – instead of fitting a dataset to a complicated trigonometric formula involving terms like cos(3*phi), sin**4(phi), etc., we simply fit the Fourier transform of the data to the Fourier transform of the oritinal fitting formula. This results not only in a drastic simplification of the fitting routines, but also it turns out that computing the Fourier transform of a particular formula is a problem that can be computed mostly ahead of time.

The way that this plays out in shgpy is that we compute the Fourier transform of the uncontracted part of the response function – that is, the part of the response function which does not depend on the particular form of the susceptbility tensor. This is conveniently the only part which depends on phi. The result is a large (Fourier transformed) tensor which we can save to a file on your machine using pickle. This is done in generate_uncontracted_fourier_transforms() and generate_uncontracted_fourier_transforms_symb(), depending on whether the angle of incidence is hardcoded or a sympy.Symbol instance.

Then, at runtime one can choose the susceptibility tensor they want to fit (i.e. using tensor_definitions) and simply contract it (using generate_contracted_fourier_transforms()) with the pickled formula to produce a Fourier formula. This can then be manipulated and fitted at will (see fformfit).

See the tutorial for more details.

shgpy.fformgen.generate_contracted_fourier_transforms(save_filename, uncontracted_filename_prefix, chi_dipole, chi_quadrupole, M=16, ndigits=None)

Generate contracted Fourier transforms.

Parameters:
save_filenamestr or file object

Filename to save the pickled Fourier formula to.

uncontracted_filename_prefixstr

The filename prefix of the pickled uncontracted Fourier transforms generated by generate_uncontracted_fourier_transforms().

chi_dipolendarray

Dipole susceptibility tensor

chi_quadupolendarray

Quadrupole susceptibility tensor

Mint, optional

Number of Fourier frequencies to compute. Default is 16. The Fourier formulas produced with this function have 2*M+1 elements each.

ndigitsint, optional

Number of digits to round to for each term in the Fourier formula. If None, no rounding is done. Default is None.

Raises:
ValueError

If not all parameters of chi_dipole and chi_quadrupole hardcoded as real, i.e. you must specifically indicate the real and imaginary parts of each variable in chi_dipole and chi_quadrupole (see make_tensor_complex() and make_tensor_real()).

Notes

Saves contracted Fourier transforms using pickle to save_filename.

shgpy.fformgen.generate_contracted_fourier_transforms_complex(*args, **kwargs)
shgpy.fformgen.generate_uncontracted_fourier_transforms(aoi, uncontracted_filename_prefix, M=16)

Generate uncontracted Fourier transforms.

Parameters:
aoifloat

Angle of incidence (in radians). This is hardcoded in this function but can be left as a free parameter in generate_uncontracted_fourier_transforms_symb().

uncontracted_filename_prefixstr

Filename prefix for where to save the pickled Fourier transforms. The pickle objects are saved to uncontracted_filename_prefix+'_pp', uncontracted_filename_prefix+'_ps', etc.

Mint, optional

Number of Fourier frequencies to compute. Default is 16. The Fourier formulas produced with this function have 2*M+1 elements each.

Notes

Saves uncontracted Fourier transforms using pickle to the specified filenames.

shgpy.fformgen.generate_uncontracted_fourier_transforms_symb(uncontracted_filename_prefix, M=16)

Generate uncontracted Fourier transforms with symbolic angle of incidence.

Parameters:
uncontracted_filename_prefixstr

Filename prefix for where to save the pickled Fourier transforms. The pickle objects are saved to uncontracted_filename_prefix+'_pp', uncontracted_filename_prefix+'_ps', etc.

Mint, optional

Number of Fourier frequencies to compute. Default is 16. The Fourier formulas produced with this function have 2*M+1 elements each.

Notes

Saves uncontracted Fourier transforms using pickle to the specified filenames. The angle of incidence is hardcoded to be the sympy.Symbol theta defined in shg_symbols.