gravelamps.interpolator.interpolator

Functions handling the basic interpolator used throughout Gravelamps

gravelamps.interpolator.interpolator.generate_complex_interpolator(grid_x: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], grid_y: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], data_real: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], data_imag: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], **kwargs) Callable

Generates a complex interpolator from the specified grid and real and imaginary components of the data.

This is done by adding together the separate interpolators for each of the components. Additional keyword arguments are passed to RectBivariateSpline.

Parameters:
grid_x: ArrayLike

X-dimension values.

grid_y: ArrayLike

Y-dimension values.

data_real: ArrayLike.

Real component of values filling the grid.

data_imag: ArrayLike

Imaginary component of values filling the grid.

Returns:
complex_interpolator: Callable

Complex interpolator that can be called with arguments x and y corresponding to the input grid.

gravelamps.interpolator.interpolator.generate_data_from_amplification(dimensionless_frequency_file: str, source_position_file: str, amplification_factor_real_file: str, amplification_factor_imag_file: str, lens_module: ModuleType, **kwargs) None

Generate amplification factor data files using the amplification function of the given module.

The resultant data will be saved to the files given in the file_dict argument’s amplification_factor_real and amplification_factor_imag keys. These will contain the real and imaginary components of the amplification factor respectively.

Parameters:
dimensionless_frequency_file: str

Path to file containing dimensionless frequency grid values.

source_position_file: str

Path to file containing source position grid values.

amplification_factor_real_file: str

Path to file to save real component of amplification factor values.

amplification_factor_imag_file: str

Path to file to save imaginary component of amplification factor values.

lens_module: ModuleType

Implementation of the lens model. Must have an amplification attribute.

**kwargs: dict

Additional keyword arguments that are passed directly to the amplification function.

Raises:
AttributeError

If lens_module is missing the amplification attribute.

gravelamps.interpolator.interpolator.generate_posterior_interpolator(posterior_samples: dict, model_settings: dict) Callable

Generate an ND interpolator that produces the joint probability of the parameters occurring simultaneously.

Parameters:
posterior_samples: dict

Posterior values for the model specific lens parameters.

model_settings: dict

Model specific settings.

Returns:
posterior_interpolator: Callable

Spline interpolator producing joint probability. Will have signature specified in model_settings.

gravelamps.interpolator.interpolator.read_and_validate_interpolator_files(file_dict: dict) dict

Extracts interpolator grid and data files from the file dictionary.

Gets the “dimensionless_frequency”, “source_position”, “amplification_factor_real”, and “amplification_factor_imag” entries of the file dictionary, reads them in and validates the resulting arrays placing them in the respective keys of the output dictionary.

Parameters:
file_dict: dict

Should contain the keys “dimensionless_frequency”, “sourve_position”, “amplification_factor_real”, and “amplification_factor_imag” which should have values corresponding to filepaths for each file.

Returns:
dict

Contains the same keys as the input which contains the arrays read from each file.

Raises:
KeyError

If one of the aforementioned keys is not found in the settings dictionary.

FileNotFoundError

If one of the paths specified in the dictionary cannot be found.

ValueError

If the data and grid shapes are not compatible.