Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more informative error #76

Merged
merged 4 commits into from
Oct 23, 2023
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
2 changes: 1 addition & 1 deletion autoarray/config/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ numba:
nopython: true
parallel: false
pixelization:
voronoi_nn_max_interpolation_neighbors: 100
voronoi_nn_max_interpolation_neighbors: 300
structures:
native_binned_only: false # If True, data structures are only stored in their native and binned format. This is used to reduce memory usage in autocti.
test:
Expand Down
2 changes: 1 addition & 1 deletion autoarray/inversion/inversion/inversion_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def reconstruction_positive_only_from(
P_initial=P_initial,
)

except (RuntimeError, np.linalg.LinAlgError) as e:
except (RuntimeError, np.linalg.LinAlgError, ValueError) as e:
raise exc.InversionException() from e

else:
Expand Down
2 changes: 1 addition & 1 deletion autoarray/mask/mask_2d_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ def rescaled_mask_2d_from(mask_2d: np.ndarray, rescale_factor: float) -> np.ndar
scale=rescale_factor,
mode="edge",
anti_aliasing=False,
# multichannel=False,
# multichannel=False,
)

rescaled_mask_2d[0, :] = 1
Expand Down
18 changes: 9 additions & 9 deletions autoarray/plot/mat_plot/two_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def plot_array(
# so that if a mask is irregular and zooming in creates white edges, that instead it doesnt have the eddge.
# This could just be a matplotlib settings to change the edge color?

# array = array.resized_from(new_shape=(401, 401))
# array = array.resized_from(new_shape=(401, 401))

if array.mask.is_all_false:
buffer = 0
Expand Down Expand Up @@ -338,14 +338,14 @@ def plot_array(
)
self.colorbar_tickparams.set(cb=cb)

# levels = np.logspace(np.log10(0.3), np.log10(20.0), 10)
# plt.contour(
# # array.mask.derive_grid.unmasked_sub_1,
# array.native[::-1],
# levels=levels,
# colors="black",
# extent=extent,
# )
levels = np.logspace(np.log10(0.3), np.log10(20.0), 10)
plt.contour(
# array.mask.derive_grid.unmasked_sub_1,
array.native[::-1],
levels=levels,
colors="black",
extent=extent,
)

grid_indexes = None

Expand Down
10 changes: 7 additions & 3 deletions autoarray/plot/wrap/base/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(
manual_tick_values: Optional[List[float]] = None,
manual_alignment: Optional[str] = None,
manual_unit: Optional[str] = None,
manual_log10 : bool = False,
manual_log10: bool = False,
**kwargs,
):
"""
Expand Down Expand Up @@ -102,8 +102,12 @@ def manual_tick_labels_from(
]

if self.manual_log10:
manual_tick_labels = ["{:.0e}".format(label) for label in manual_tick_labels]
manual_tick_labels = [label.replace("1e", "$10^{") + "}$" for label in manual_tick_labels]
manual_tick_labels = [
"{:.0e}".format(label) for label in manual_tick_labels
]
manual_tick_labels = [
label.replace("1e", "$10^{") + "}$" for label in manual_tick_labels
]
manual_tick_labels = [
label.replace("{-0", "{-").replace("{+0", "{+").replace("+", "")
for label in manual_tick_labels
Expand Down
4 changes: 4 additions & 0 deletions autoarray/preloads.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import numpy as np
import os
from typing import List

from autoconf import conf
Expand Down Expand Up @@ -465,6 +466,9 @@ def check_via_fit(self, fit):
settings_inversion=settings_inversion,
)

if os.environ.get("PYAUTOFIT_TEST_MODE") == "1":
return

try:
if (
abs(
Expand Down
2 changes: 1 addition & 1 deletion autoarray/structures/arrays/kernel_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def rescaled_with_odd_dimensions_from(
rescale_factor,
anti_aliasing=False,
mode="constant",
# multichannel=False,
# multichannel=False,
)

if kernel_rescaled.shape[0] % 2 == 0 and kernel_rescaled.shape[1] % 2 == 0:
Expand Down
46 changes: 35 additions & 11 deletions autoarray/structures/structure_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List, Optional, Union

from autoconf import conf
from autoconf.exc import ConfigException
from autoarray.structures.arrays.uniform_1d import Array1D
from autoarray.structures.arrays.uniform_2d import Array2D
from autoarray.structures.grids.uniform_1d import Grid1D
Expand Down Expand Up @@ -39,7 +40,7 @@ def wrapper(
obj: object,
grid: Union[Grid1D, Grid2D, Grid2DIterate, Grid2DIrregular],
*args,
**kwargs
**kwargs,
) -> Union[Array1D, ArrayIrregular]:
"""
This decorator homogenizes the input of a "grid_like" 2D structure (`Grid2D`, `Grid2DIterate`,
Expand Down Expand Up @@ -128,7 +129,7 @@ def wrapper(
obj,
grid: Union[Grid1D, Grid2D, Grid2DIterate, Grid2DIrregular],
*args,
**kwargs
**kwargs,
) -> Union[Array1D, ArrayIrregular]:
"""
This decorator homogenizes the output of functions which compute a 1D result, by inspecting the output
Expand Down Expand Up @@ -184,7 +185,7 @@ def wrapper(
obj: object,
grid: Union[np.ndarray, Grid2D, Grid2DIterate, Grid2DIrregular, Grid1D],
*args,
**kwargs
**kwargs,
) -> Union[np.ndarray, Array2D, ArrayIrregular, Grid2D, Grid2DIrregular]:
"""
This decorator homogenizes the input of a "grid_like" 2D structure (`Grid2D`, `Grid2DIterate`,
Expand Down Expand Up @@ -261,7 +262,7 @@ def wrapper(
obj: object,
grid: Union[np.ndarray, Grid2D, Grid2DIterate, Grid2DIrregular, Grid1D],
*args,
**kwargs
**kwargs,
) -> List[Union[np.ndarray, Array2D, ArrayIrregular, Grid2D, Grid2DIrregular]]:
"""
This decorator serves the same purpose as the `grid_2d_to_structure` decorator, but it deals with functions
Expand Down Expand Up @@ -329,7 +330,7 @@ def wrapper(
obj: object,
grid: Union[np.ndarray, Grid2D, Grid2DIterate, Grid2DIrregular, Grid1D],
*args,
**kwargs
**kwargs,
) -> Union[np.ndarray, Array2D, ArrayIrregular, Grid2D, Grid2DIrregular]:
"""
This decorator homogenizes the input of a "grid_like" 2D vector_yx (`Grid2D`, `Grid2DIterate`,
Expand Down Expand Up @@ -399,7 +400,7 @@ def wrapper(
obj: object,
grid: Union[np.ndarray, Grid2D, Grid2DIterate, Grid2DIrregular, Grid1D],
*args,
**kwargs
**kwargs,
) -> List[Union[np.ndarray, Array2D, ArrayIrregular, Grid2D, Grid2DIrregular]]:
"""
This decorator serves the same purpose as the `grid_2d_to_vector_yx` decorator, but it deals with functions
Expand Down Expand Up @@ -463,7 +464,7 @@ def wrapper(
Grid2DIrregularTransformed,
],
*args,
**kwargs
**kwargs,
) -> Union[
np.ndarray,
Grid2D,
Expand Down Expand Up @@ -526,7 +527,7 @@ def wrapper(
cls,
grid: Union[np.ndarray, Grid2D, Grid2DIrregular, Grid2DIterate],
*args,
**kwargs
**kwargs,
) -> Union[np.ndarray, Grid2D, Grid2DIrregular, Grid2DIterate]:
"""

Expand All @@ -542,9 +543,32 @@ def wrapper(
The grid_like object whose coordinates are radially moved from (0.0, 0.0).
"""

grid_radial_minimum = conf.instance["grids"]["radial_minimum"][
"radial_minimum"
][cls.__class__.__name__]
try:
grid_radial_minimum = conf.instance["grids"]["radial_minimum"][
"radial_minimum"
][cls.__class__.__name__]
except KeyError as e:
raise ConfigException(
rf"""
The {cls.__class__.__name__} profile you are using does not have a corresponding
entry in the `config/grid.yaml` config file.

When a profile is evaluated at (0.0, 0.0), they commonly break due to numericalinstabilities (e.g.
division by zero). To prevent this, the code relocates the (y,x) coordinates of the grid to a
minimum radial value, specified in the `config/grids.yaml` config file.

For example, if the value in `grid.yaml` is `radial_minimum: 1e-6`, then any (y,x) coordinates
with a radial distance less than 1e-6 to (0.0, 0.0) are relocated to 1e-6.

For a profile to be used it must have an entry in the `config/grids.yaml` config file. Go to this
file now and add your profile to the `radial_minimum` section. Adopting a value of 1e-6 is a good
default choice.

If you are going to make a pull request to add your profile to the source code, you should also
add an entry to the `config/grids.yaml` config file of the source code itself
(e.g. `PyAutoGalaxy/autogalaxy/config/grids.yaml`).
"""
)

with np.errstate(all="ignore"): # Division by zero fixed via isnan
grid_radii = cls.radial_grid_from(grid=grid)
Expand Down
2 changes: 1 addition & 1 deletion test_autoarray/config/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ output:
model_results_every_update: 100
remove_files: false
pixelization:
voronoi_nn_max_interpolation_neighbors: 100
voronoi_nn_max_interpolation_neighbors: 300
profiling:
perform: false
repeats: 1
Expand Down