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
7 changes: 3 additions & 4 deletions autoarray/dataset/plot/imaging_plots.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import Optional

import matplotlib.pyplot as plt

from autoarray.plot.utils import subplot_save, conf_subplot_figsize, tight_layout
from autoarray.plot.utils import subplots, subplot_save, conf_subplot_figsize, tight_layout


def subplot_imaging_dataset(
Expand Down Expand Up @@ -51,7 +50,7 @@ def subplot_imaging_dataset(

from autoarray.plot.array import plot_array

fig, axes = plt.subplots(3, 3, figsize=conf_subplot_figsize(3, 3))
fig, axes = subplots(3, 3, figsize=conf_subplot_figsize(3, 3))
axes = axes.flatten()

plot_array(
Expand Down Expand Up @@ -172,7 +171,7 @@ def subplot_imaging_dataset_list(
from autoarray.plot.array import plot_array

n = len(dataset_list)
fig, axes = plt.subplots(n, 3, figsize=conf_subplot_figsize(n, 3))
fig, axes = subplots(n, 3, figsize=conf_subplot_figsize(n, 3))
if n == 1:
axes = [axes]
for i, dataset in enumerate(dataset_list):
Expand Down
7 changes: 3 additions & 4 deletions autoarray/dataset/plot/interferometer_plots.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import numpy as np
from typing import Optional

import matplotlib.pyplot as plt

from autoarray.plot.array import plot_array
from autoarray.plot.grid import plot_grid
from autoarray.plot.yx import plot_yx
from autoarray.plot.utils import subplot_save, hide_unused_axes, conf_subplot_figsize, tight_layout
from autoarray.plot.utils import subplots, subplot_save, hide_unused_axes, conf_subplot_figsize, tight_layout
from autoarray.structures.grids.irregular_2d import Grid2DIrregular


Expand Down Expand Up @@ -39,7 +38,7 @@ def subplot_interferometer_dataset(
use_log10
Apply log10 normalisation to image panels.
"""
fig, axes = plt.subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
axes = axes.flatten()

plot_grid(dataset.data.in_grid, ax=axes[0], title="Visibilities", xlabel="", ylabel="")
Expand Down Expand Up @@ -117,7 +116,7 @@ def subplot_interferometer_dirty_images(
use_log10
Apply log10 normalisation.
"""
fig, axes = plt.subplots(1, 3, figsize=conf_subplot_figsize(1, 3))
fig, axes = subplots(1, 3, figsize=conf_subplot_figsize(1, 3))

plot_array(
dataset.dirty_image,
Expand Down
5 changes: 2 additions & 3 deletions autoarray/fit/plot/fit_imaging_plots.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional

import matplotlib.pyplot as plt

from autoarray.plot.array import plot_array
from autoarray.plot.utils import subplot_save, symmetric_vmin_vmax, hide_unused_axes, conf_subplot_figsize, tight_layout
from autoarray.plot.utils import subplots, subplot_save, symmetric_vmin_vmax, hide_unused_axes, conf_subplot_figsize, tight_layout


def subplot_fit_imaging(
Expand Down Expand Up @@ -43,7 +42,7 @@ def subplot_fit_imaging(
grid, positions, lines
Optional overlays forwarded to every panel.
"""
fig, axes = plt.subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
axes = axes.flatten()

plot_array(
Expand Down
7 changes: 3 additions & 4 deletions autoarray/fit/plot/fit_interferometer_plots.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import numpy as np
from typing import Optional

import matplotlib.pyplot as plt

from autoarray.plot.array import plot_array
from autoarray.plot.yx import plot_yx
from autoarray.plot.utils import subplot_save, symmetric_vmin_vmax, hide_unused_axes, conf_subplot_figsize, tight_layout
from autoarray.plot.utils import subplots, subplot_save, symmetric_vmin_vmax, hide_unused_axes, conf_subplot_figsize, tight_layout


def subplot_fit_interferometer(
Expand Down Expand Up @@ -40,7 +39,7 @@ def subplot_fit_interferometer(
Not used here (UV-plane residuals are scatter plots); kept for API
consistency.
"""
fig, axes = plt.subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
axes = axes.flatten()

uv = fit.dataset.uv_distances / 10**3.0
Expand Down Expand Up @@ -135,7 +134,7 @@ def subplot_fit_interferometer_dirty_images(
residuals_symmetric_cmap
Centre residual colour scale symmetrically around zero.
"""
fig, axes = plt.subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3))
axes = axes.flatten()

plot_array(
Expand Down
3 changes: 2 additions & 1 deletion autoarray/inversion/inversion/inversion_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from autoarray.settings import Settings

from autoarray import exc
from autoarray.util.fnnls import fnnls_cholesky


def curvature_matrix_diag_via_psf_weighted_noise_from(
Expand Down Expand Up @@ -281,6 +280,8 @@ def reconstruction_positive_only_from(

try:

from autoarray.util.fnnls import fnnls_cholesky

return fnnls_cholesky(
curvature_reg_matrix,
(data_vector).T,
Expand Down
6 changes: 4 additions & 2 deletions autoarray/inversion/mesh/interpolator/delaunay.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import numpy as np
import scipy.spatial
from scipy.spatial import cKDTree, Delaunay, Voronoi

from autoconf import cached_property

Expand All @@ -12,6 +10,7 @@

def scipy_delaunay(points_np, query_points_np, areas_factor):
"""Compute Delaunay simplices (simplices_padded) and Voronoi areas in one call."""
from scipy.spatial import Delaunay

max_simplices = 2 * points_np.shape[0]

Expand Down Expand Up @@ -182,6 +181,8 @@ def pix_indexes_for_sub_slim_index_delaunay_from(
# Case 2: Outside → KDTree NN
# ---------------------------
if outside_mask.any():
from scipy.spatial import cKDTree

tree = cKDTree(delaunay_points)
_, idx = tree.query(data_grid[outside_mask], k=1)
out[outside_mask, 0] = idx.astype(np.int32)
Expand All @@ -202,6 +203,7 @@ def scipy_delaunay_matern(points_np, query_points_np):
typically of shape (Q, 3), where each row gives the indices of the
Delaunay mesh vertices ("pixels") associated with that query point.
"""
from scipy.spatial import Delaunay

max_simplices = 2 * points_np.shape[0]

Expand Down
7 changes: 3 additions & 4 deletions autoarray/inversion/plot/inversion_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
from pathlib import Path
from typing import Optional, Union

import matplotlib.pyplot as plt
from autoconf import conf

from autoarray.inversion.mappers.abstract import Mapper
from autoarray.plot.array import plot_array
from autoarray.plot.utils import numpy_grid, numpy_lines, numpy_positions, subplot_save, hide_unused_axes, conf_subplot_figsize, tight_layout
from autoarray.plot.utils import subplots, numpy_grid, numpy_lines, numpy_positions, subplot_save, hide_unused_axes, conf_subplot_figsize, tight_layout
from autoarray.inversion.plot.mapper_plots import plot_mapper
from autoarray.structures.arrays.uniform_2d import Array2D

Expand Down Expand Up @@ -53,7 +52,7 @@ def subplot_of_mapper(
"""
mapper = inversion.cls_list_from(cls=Mapper)[mapper_index]

fig, axes = plt.subplots(3, 4, figsize=conf_subplot_figsize(3, 4))
fig, axes = subplots(3, 4, figsize=conf_subplot_figsize(3, 4))
axes = axes.flatten()

# panel 0: data subtracted
Expand Down Expand Up @@ -279,7 +278,7 @@ def subplot_mappings(
)
mapper.slim_indexes_for_pix_indexes(pix_indexes=pix_indexes)

fig, axes = plt.subplots(2, 2, figsize=conf_subplot_figsize(2, 2))
fig, axes = subplots(2, 2, figsize=conf_subplot_figsize(2, 2))
axes = axes.flatten()

# panel 0: data subtracted
Expand Down
5 changes: 2 additions & 3 deletions autoarray/inversion/plot/mapper_plots.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
from typing import Optional

import matplotlib.pyplot as plt

from autoarray.plot.array import plot_array
from autoarray.plot.inversion import plot_inversion_reconstruction
from autoarray.plot.utils import numpy_grid, numpy_lines, subplot_save, conf_subplot_figsize, tight_layout
from autoarray.plot.utils import subplots, numpy_grid, numpy_lines, subplot_save, conf_subplot_figsize, tight_layout

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -114,7 +113,7 @@ def subplot_image_and_mapper(
lines
Lines to overlay on both panels.
"""
fig, axes = plt.subplots(1, 2, figsize=conf_subplot_figsize(1, 2))
fig, axes = subplots(1, 2, figsize=conf_subplot_figsize(1, 2))

plot_array(
image,
Expand Down
4 changes: 2 additions & 2 deletions autoarray/mask/mask_2d_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import warnings
from scipy.ndimage import binary_dilation
from typing import Tuple

from autoarray import exc
Expand Down Expand Up @@ -465,7 +464,6 @@ def min_false_distance_to_edge(mask: np.ndarray) -> Tuple[int, int]:
from typing import Tuple

import numpy as np
from scipy.ndimage import binary_dilation


def required_shape_for_kernel(
Expand Down Expand Up @@ -608,6 +606,8 @@ def blurring_mask_2d_from(
)

# Pixels within kernel footprint of any unmasked pixel
from scipy.ndimage import binary_dilation

near_unmasked_padded = binary_dilation(unmasked_padded, structure=structure)
near_unmasked = near_unmasked_padded[
pad_y : pad_y + mask_2d.shape[0],
Expand Down
3 changes: 2 additions & 1 deletion autoarray/operators/convolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import numpy as np
from pathlib import Path
import scipy
from typing import Optional, Tuple, Union
import warnings

Expand Down Expand Up @@ -116,6 +115,8 @@ class determines how masked real-space data are embedded into a padded array,
full_shape = tuple(
s1 + s2 - 1 for s1, s2 in zip(mask_shape, self.kernel.shape_native)
)
import scipy.fft

fft_shape = tuple(scipy.fft.next_fast_len(s, real=True) for s in full_shape)

self.fft_shape = fft_shape
Expand Down
10 changes: 5 additions & 5 deletions autoarray/plot/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import os
from typing import List, Optional, Tuple

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm, Normalize

from autoarray.plot.utils import (
subplots,
apply_extent,
apply_labels,
conf_figsize,
Expand All @@ -29,7 +27,7 @@

def plot_array(
array,
ax: Optional[plt.Axes] = None,
ax=None,
# --- spatial metadata -------------------------------------------------------
extent: Optional[Tuple[float, float, float, float]] = None,
# --- overlays ---------------------------------------------------------------
Expand Down Expand Up @@ -158,7 +156,7 @@ def plot_array(
owns_figure = ax is None
if owns_figure:
figsize = figsize or conf_figsize("figures")
fig, ax = plt.subplots(1, 1, figsize=figsize)
fig, ax = subplots(1, 1, figsize=figsize)
else:
fig = ax.get_figure()

Expand All @@ -181,8 +179,10 @@ def plot_array(
vmax_log = np.nanmax(clipped)
if not np.isfinite(vmax_log) or vmax_log <= vmin_log:
vmax_log = vmin_log * 10.0
from matplotlib.colors import LogNorm
norm = LogNorm(vmin=vmin_log, vmax=vmax_log)
elif vmin is not None or vmax is not None:
from matplotlib.colors import Normalize
norm = Normalize(vmin=vmin, vmax=vmax)
else:
norm = None
Expand Down
9 changes: 5 additions & 4 deletions autoarray/plot/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

from typing import Iterable, List, Optional, Tuple

import matplotlib.pyplot as plt
import numpy as np

from autoarray.plot.utils import (
subplots,
get_cmap,
apply_extent,
apply_labels,
conf_figsize,
Expand All @@ -20,7 +21,7 @@

def plot_grid(
grid,
ax: Optional[plt.Axes] = None,
ax=None,
# --- errors -----------------------------------------------------------------
y_errors: Optional[np.ndarray] = None,
x_errors: Optional[np.ndarray] = None,
Expand Down Expand Up @@ -108,13 +109,13 @@ def plot_grid(
owns_figure = ax is None
if owns_figure:
figsize = figsize or conf_figsize("figures")
fig, ax = plt.subplots(1, 1, figsize=figsize)
fig, ax = subplots(1, 1, figsize=figsize)
else:
fig = ax.get_figure()

# --- scatter / errorbar ----------------------------------------------------
if color_array is not None:
cmap = plt.get_cmap(colormap)
cmap = get_cmap(colormap)
colors = cmap((color_array - color_array.min()) / (np.ptp(color_array) or 1))

if y_errors is None and x_errors is None:
Expand Down
7 changes: 3 additions & 4 deletions autoarray/plot/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

from typing import List, Optional, Tuple

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm, Normalize

from autoarray.plot.utils import apply_extent, apply_labels, conf_figsize, save_figure, _conf_imshow_origin
from autoarray.plot.utils import subplots, apply_extent, apply_labels, conf_figsize, save_figure, _conf_imshow_origin


def plot_inversion_reconstruction(
pixel_values: np.ndarray,
mapper,
ax: Optional[plt.Axes] = None,
ax=None,
# --- cosmetics --------------------------------------------------------------
title: str = "Reconstruction",
xlabel: str = 'x (")',
Expand Down Expand Up @@ -84,7 +83,7 @@ def plot_inversion_reconstruction(
owns_figure = ax is None
if owns_figure:
figsize = figsize or conf_figsize("figures")
fig, ax = plt.subplots(1, 1, figsize=figsize)
fig, ax = subplots(1, 1, figsize=figsize)
else:
fig = ax.get_figure()

Expand Down
Loading
Loading