Skip to content

Commit

Permalink
KMeans raises error for pixels > masked data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Dec 30, 2023
1 parent 0afad71 commit da2eb30
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions autoarray/inversion/pixelization/image_mesh/kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from sklearn.cluster import KMeans as ScipyKMeans
from typing import TYPE_CHECKING, Optional
import sys
import warnings

if TYPE_CHECKING:
Expand Down Expand Up @@ -70,13 +71,30 @@ def image_plane_mesh_grid_from(
"""

if self.pixels > grid.shape[0]:

print(
"""
The number of pixels passed to the KMeans object exceeds the number of image-pixels in the mask of
the data being fitted. This is not allowed by the KMenas algorithm and will cause an error.
To fix this, you should reduce the number of pixels in the KMeans object to be less than the number
of image-pixels in the mask of the data being fitted.
If you are performing model-fitting, you should update the priors to have an upper limit which does
not exceed the number of image-pixels in the mask of the data being fitted.
For adaptive fitting, the KMeans object has been superseeded by the Hilbert object, which does not
have this limitation and performs better in general. You should therefore consider using the Hilbert
object instead.
""")

sys.exit()

warnings.filterwarnings("ignore")

weight_map = self.weight_map_from(adapt_data=adapt_data)

if self.pixels > grid.shape[0]:
raise exc.GridException

kmeans = ScipyKMeans(
n_clusters=int(self.pixels),
random_state=1,
Expand Down

0 comments on commit da2eb30

Please sign in to comment.