Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions autogalaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from autoconf.dictable import from_dict, from_json, output_to_json, to_dict
from autoarray.dataset import preprocess # noqa

# from autoarray.dataset.interferometer.w_tilde import (
# load_curvature_preload_if_compatible,
# )
from autoarray.dataset.imaging.dataset import Imaging # noqa
from autoarray.dataset.interferometer.dataset import Interferometer # noqa
from autoarray.dataset.dataset_model import DatasetModel
Expand Down
12 changes: 6 additions & 6 deletions autogalaxy/abstract_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ def perform_inversion(self) -> bool:
return self.model_obj.perform_inversion

@property
def w_tilde(self) -> Optional[aa.WTildeImaging]:
def sparse_operator(self) -> Optional[aa.ImagingSparseOperator]:
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint specifies aa.ImagingSparseOperator but this is an abstract class used by both FitImaging and FitInterferometer (which would need InterferometerSparseLinAlg according to the PR description). The type hint should be more generic or use a Union type to accommodate both imaging and interferometer sparse operators.

Copilot uses AI. Check for mistakes.
"""
Only call the `w_tilde` property of a dataset used to perform efficient linear algebra calcualtions if
the SettingsInversion()` object has `use_w_tilde=True`, to avoid unnecessary computation.
Only call the `sparse_operator` property of a dataset used to perform efficient linear algebra calculations if
the SettingsInversion()` object has `use_sparse_operator=True`, to avoid unnecessary computation.

Returns
-------
The w-tilde matrix if the w-tilde formalism is being used for this inversion.
The sparse operator used for efficient linear algebra calculations for this inversion, if enabled.
"""
if self.dataset.w_tilde is not None:
if self.dataset.sparse_operator is not None:
if self.total_mappers > 0:
return self.dataset.w_tilde
return self.dataset.sparse_operator

@property
def inversion(self) -> Optional[aa.Inversion]:
Expand Down
3 changes: 0 additions & 3 deletions autogalaxy/aggregator/agg_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ def preloads_from(
in order to perform the fit. The main purpose is to use the same image-plane mesh centres for pixelization where
the mesh is computed in the image-plane (see `agg_util.mesh_grids_of_planes_list_from`).

The preloads may also switch off `w_tilde` so fits are computed faster locally as they do not need to recompute
w_tilde.

Parameters
----------
preloads_cls
Expand Down
2 changes: 1 addition & 1 deletion autogalaxy/imaging/fit_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def galaxies_to_inversion(self) -> GalaxiesToInversion:
noise_map=self.noise_map,
grids=self.grids,
psf=self.dataset.psf,
w_tilde=self.w_tilde,
sparse_operator=self.dataset.sparse_operator,
)

return GalaxiesToInversion(
Expand Down
2 changes: 1 addition & 1 deletion autogalaxy/interferometer/fit_interferometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def galaxies_to_inversion(self) -> GalaxiesToInversion:
noise_map=self.noise_map,
grids=self.grids,
transformer=self.dataset.transformer,
w_tilde=self.w_tilde,
sparse_operator=self.dataset.sparse_operator,
)

return GalaxiesToInversion(
Expand Down
4 changes: 4 additions & 0 deletions autogalaxy/profiles/mass/dark/mcr_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def kappa_s_and_scale_radius_for_ludlow(
if isinstance(mass_at_200, (float, np.ndarray, np.float64)):
xp = np
else:
import jax.numpy as jnp

xp = jnp

# ------------------------------------
Expand Down Expand Up @@ -217,6 +219,8 @@ def kappa_s_scale_radius_and_core_radius_for_ludlow(
if isinstance(mass_at_200, (float, np.ndarray, np.float64)):
xp = np
else:
import jax.numpy as jnp

xp = jnp

# ------------------------------------
Expand Down
18 changes: 12 additions & 6 deletions autogalaxy/profiles/mass/stellar/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def zeta_from(self, grid: aa.type.Grid2DLike, xp=np):
q = self.axis_ratio(xp)
q2 = q**2.0

ind_pos_y = grid.array[:, 0] >=0
ind_pos_y = grid.array[:, 0] >= 0
shape_grid = np.shape(grid)
output_grid = np.zeros((shape_grid[0]), dtype=np.complex128)

Expand All @@ -208,18 +208,24 @@ def zeta_from(self, grid: aa.type.Grid2DLike, xp=np):
z1_1 = xs_1 + 1j * ys_1
z2_1 = q * xs_1 + 1j * ys_1 / q

exp_term_0 = xp.exp(-(xs_0 ** 2) * (1.0 - q2) - ys_0 ** 2 * (1.0 / q2 - 1.0))
exp_term_1 = xp.exp(-(xs_1 ** 2) * (1.0 - q2) - ys_1 ** 2 * (1.0 / q2 - 1.0))
exp_term_0 = xp.exp(-(xs_0**2) * (1.0 - q2) - ys_0**2 * (1.0 / q2 - 1.0))
exp_term_1 = xp.exp(-(xs_1**2) * (1.0 - q2) - ys_1**2 * (1.0 / q2 - 1.0))

if xp == np:
from scipy.special import wofz

output_grid[ind_pos_y] = -1j * (wofz(z1_0) - exp_term_0 * wofz(z2_0))
output_grid[~ind_pos_y] = xp.conj(-1j * (wofz(z1_1) - exp_term_1 * wofz(z2_1)))
output_grid[~ind_pos_y] = xp.conj(
-1j * (wofz(z1_1) - exp_term_1 * wofz(z2_1))
)

else:
output_grid[ind_pos_y] = -1j * (self.wofz(z1_0, xp=xp) - exp_term_0 * self.wofz(z2_0, xp=xp))
output_grid[~ind_pos_y] = xp.conj(-1j * (self.wofz(z1_1, xp=xp) - exp_term_1 * self.wofz(z2_1, xp=xp)))
output_grid[ind_pos_y] = -1j * (
self.wofz(z1_0, xp=xp) - exp_term_0 * self.wofz(z2_0, xp=xp)
)
output_grid[~ind_pos_y] = xp.conj(
-1j * (self.wofz(z1_1, xp=xp) - exp_term_1 * self.wofz(z2_1, xp=xp))
)

return output_grid

Expand Down
2 changes: 1 addition & 1 deletion test_autogalaxy/profiles/mass/stellar/test_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def test__image_2d_via_radii_from__correct_value():

assert intensity == pytest.approx(0.32465, 1e-2)


def test__wofz():
from scipy.special import wofz

Expand All @@ -263,4 +264,3 @@ def test__wofz():
assert wofz_approx_reg_1 == pytest.approx(wofz(7.0 + 1j * 0.1), 1e-4)
assert wofz_approx_reg_2 == pytest.approx(wofz(7.0 + 1j * 1e-11), 1e-4)
assert wofz_approx_reg_3 == pytest.approx(wofz(2.0 + 1j * 1.0), 1e-4)

Loading