Convert complex spherical harmonics to real.
(complex_tot, int_order, ext_order)
| 1955 | |
| 1956 | |
| 1957 | def _bases_complex_to_real(complex_tot, int_order, ext_order): |
| 1958 | """Convert complex spherical harmonics to real.""" |
| 1959 | n_in, n_out = _get_n_moments([int_order, ext_order]) |
| 1960 | complex_in = complex_tot[:, :n_in] |
| 1961 | complex_out = complex_tot[:, n_in:] |
| 1962 | real_tot = np.empty(complex_tot.shape, np.float64) |
| 1963 | real_in = real_tot[:, :n_in] |
| 1964 | real_out = real_tot[:, n_in:] |
| 1965 | for comp, real, exp_order in zip( |
| 1966 | [complex_in, complex_out], [real_in, real_out], [int_order, ext_order] |
| 1967 | ): |
| 1968 | for deg in range(1, exp_order + 1): |
| 1969 | for order in range(deg + 1): |
| 1970 | idx_pos = _deg_ord_idx(deg, order) |
| 1971 | idx_neg = _deg_ord_idx(deg, -order) |
| 1972 | real[:, idx_pos] = _sh_complex_to_real(comp[:, idx_pos], order) |
| 1973 | if order != 0: |
| 1974 | # This extra mult factor baffles me a bit, but it works |
| 1975 | # in round-trip testing, so we'll keep it :( |
| 1976 | mult = -1 if order % 2 == 0 else 1 |
| 1977 | real[:, idx_neg] = mult * _sh_complex_to_real( |
| 1978 | comp[:, idx_neg], -order |
| 1979 | ) |
| 1980 | return real_tot |
| 1981 | |
| 1982 | |
| 1983 | def _bases_real_to_complex(real_tot, int_order, ext_order): |