From 2a6608ac9b9c5987690ca8292a5ce6c1aa4ab031 Mon Sep 17 00:00:00 2001 From: James Nightingale Date: Fri, 20 Oct 2023 18:10:03 +0100 Subject: [PATCH] more informatie error --- autoarray/config/general.yaml | 2 +- autoarray/exc.py | 10 ++++++ autoarray/plot/mat_plot/two_d.py | 18 +++++------ autoarray/structures/structure_decorators.py | 32 ++++++++++++++++++-- test_autoarray/config/general.yaml | 2 +- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/autoarray/config/general.yaml b/autoarray/config/general.yaml index 7915cf642..7beab815c 100644 --- a/autoarray/config/general.yaml +++ b/autoarray/config/general.yaml @@ -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: diff --git a/autoarray/exc.py b/autoarray/exc.py index 657ec8324..dd0b9a3b7 100644 --- a/autoarray/exc.py +++ b/autoarray/exc.py @@ -18,6 +18,16 @@ class ArrayException(Exception): pass + +class ConfigException(Exception): + """ + Raises exceptions associated with the `structures/array` modules and `Array` classes. + + For example if a 2D array's shape and its corresponding 2D mask shape do not match. + """ + + pass + class GridException(Exception): """ Raises exceptions associated with the `structures/grid` modules and `Grid` classes. diff --git a/autoarray/plot/mat_plot/two_d.py b/autoarray/plot/mat_plot/two_d.py index 888838957..dc9de56f1 100644 --- a/autoarray/plot/mat_plot/two_d.py +++ b/autoarray/plot/mat_plot/two_d.py @@ -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 @@ -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 diff --git a/autoarray/structures/structure_decorators.py b/autoarray/structures/structure_decorators.py index 864080601..f5a6d30aa 100644 --- a/autoarray/structures/structure_decorators.py +++ b/autoarray/structures/structure_decorators.py @@ -542,9 +542,35 @@ 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: + print( + fr""" + 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`). + """ + ) + + import sys + sys.exit(1) with np.errstate(all="ignore"): # Division by zero fixed via isnan grid_radii = cls.radial_grid_from(grid=grid) diff --git a/test_autoarray/config/general.yaml b/test_autoarray/config/general.yaml index 307b3f67f..8d0325a13 100644 --- a/test_autoarray/config/general.yaml +++ b/test_autoarray/config/general.yaml @@ -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