diff --git a/autoarray/fit/fit_util.py b/autoarray/fit/fit_util.py index c2e58e64c..2ac734497 100644 --- a/autoarray/fit/fit_util.py +++ b/autoarray/fit/fit_util.py @@ -302,17 +302,18 @@ def chi_squared_with_mask_fast_from( mask The mask applied to the chi-squared-map, where `False` entries are included in the calculation. """ - - return np.sum( - np.square( - np.divide( - np.subtract( - data, - model_data, - ), - noise_map, + return float( + np.sum( + np.square( + np.divide( + np.subtract( + data, + model_data, + )[np.asarray(mask) == 0], + noise_map[np.asarray(mask) == 0], + ) ) - )[np.asarray(mask) == 0] + ) ) diff --git a/autoarray/inversion/pixelization/mappers/mapper_util.py b/autoarray/inversion/pixelization/mappers/mapper_util.py index d2a0cfd37..354558bfd 100644 --- a/autoarray/inversion/pixelization/mappers/mapper_util.py +++ b/autoarray/inversion/pixelization/mappers/mapper_util.py @@ -1,4 +1,5 @@ import numpy as np +from scipy.spatial import cKDTree from typing import Tuple from autoconf import conf @@ -172,6 +173,20 @@ def pix_indexes_for_sub_slim_index_delaunay_from( return pix_indexes_for_sub_slim_index, pix_indexes_for_sub_slim_index_sizes +def nearest_pixelization_index_for_slim_index_from_kdtree(grid, mesh_grid): + + kdtree = cKDTree(mesh_grid) + + sparse_index_for_slim_index = [] + + for i in range(grid.shape[0]): + + input_point = [grid[i, [0]], grid[i, 1]] + index = kdtree.query(input_point)[1] + sparse_index_for_slim_index.append(index) + + return sparse_index_for_slim_index + @numba_util.jit() def nearest_pixelization_index_for_slim_index_from(grid, mesh_grid): """ diff --git a/autoarray/inversion/pixelization/mesh/mesh_util.py b/autoarray/inversion/pixelization/mesh/mesh_util.py index 49b21c7b5..308cb66bb 100644 --- a/autoarray/inversion/pixelization/mesh/mesh_util.py +++ b/autoarray/inversion/pixelization/mesh/mesh_util.py @@ -469,22 +469,6 @@ def voronoi_neighbors_from( ------- The arrays containing the 1D index of every pixel's neighbors and the number of neighbors that each pixel has. """ - """ - Returns the neighbors and total number of neighbors of every cell on a Voronoi mesh. - - Neighbors are returned as an ndarray of shape [total_pixels, max_neighbors_in_a_given_voronoi pixel], where - entries have values of -1 if the pixel has no neighbor. - - The number of neighbors of every pixel is also returned as an ndarray of shape [total_pixels], where the values - are integers between 0 and the total neighbors in a given Voronoi pixel. - - Parameters - ---------- - pixels - The number of pixels on the Voronoi mesh - ridge_points - Contains the information on every Voronoi pixel and its neighbors. - """ neighbors_sizes = np.zeros(shape=(pixels)) for ridge_index in range(ridge_points.shape[0]): diff --git a/autoarray/plot/mat_plot/one_d.py b/autoarray/plot/mat_plot/one_d.py index 2ced7adeb..bda51202b 100644 --- a/autoarray/plot/mat_plot/one_d.py +++ b/autoarray/plot/mat_plot/one_d.py @@ -165,7 +165,7 @@ def plot_yx( text_manual_dict_y=None, bypass: bool = False, ): - if (y is None) or np.count_nonzero(y) == 0: + if (y is None) or np.count_nonzero(y) == 0 or np.isnan(y).all(): return ax = None