neurosynchro.grtrans: helpers for working with grtrans

This module provides helpers for doing radiative transfer integrations with grtrans, including a simple framework for running end-to-end tests.

In order to use this functionality, the Python module radtrans_integrate must be importable. Sadly grtrans doesn’t install itself like a regular Python package, so getting this working can be a pain. Documenting the installation procedure is beyond the scope of this project.

neurosynchro.grtrans.integrate(d, coeffs, psi)[source]

Integrate a ray with grtrans, using reasonable defaults.

Call signature

d
An array giving the location of each sample along the ray, starting from zero, in cm.
coeffs
An array of shape (N, 8) of RT coefficients in the basis where the Stokes U coefficients are always zero. Such arrays are returned by neurosynchro.impl.PhysicalApproximator.compute_all_nontrivial().
psi
An array of angles between the local magnetic field and the observer’s Stokes U axis, in radians.
Return value
An array of shape (4,), giving the Stokes IQUV at the end of the ray.

This function is mainly intended to test what happens if the passed-in coefficients are slightly different due to the neural network approximation. So we don’t provide many knobs or diagnostics here.

Low-level Interfaces to grtrans

neurosynchro.grtrans.integrate_ray_formal(x, j, K)[source]

Use grtrans to integrate one ray using its “formal” (matricant / O-matrix) method.

Call signature

x
1D array, shape (n,). Path length along ray, starting from zero, in cm.
j
Array, shape (n, 4). Emission coefficients: j_{IQUV}, in that order.
K
Array, shape (n, 7). Absorption coefficients and Faraday mixing coefficients: alpha_{IQUV}, rho_{QUV}.
Return value
Array of shape (4, m): Stokes intensities IQUV along parts of the ray with non-zero total emissivities; m <= n.
neurosynchro.grtrans.integrate_ray_lsoda(x, j, K, atol=1e-08, rtol=1e-06, max_step_size=None, frac_max_step_size=0.001, max_steps=100000)[source]

Use grtrans to integrate one ray using its LSODA method.

Call signature

x
1D array, shape (n,). Path length along ray, starting from zero, in cm.
j
Array, shape (n, 4). Emission coefficients: j_{IQUV}, in that order.
K
Array, shape (n, 7). Absorption coefficients and Faraday mixing coefficients: alpha_{IQUV}, rho_{QUV}.
atol
Some kind of tolerance parameter.
rtol
Some kind of tolerance parameter.
max_step_size
The maximum absolute step size. Overrides frac_max_step_size.
frac_max_step_size
If max_step_size is not specified, the maximum step size passed to the integrator is x.max() multiplied by this parameter. Experience shows that (for LSODA at least) this parameter must be pretty small to get good convergence!
max_steps
The maximum number of steps to take.
Return value
Array of shape (4, m): Stokes intensities IQUV along parts of the ray with non-zero total emissivities; m <= n.