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
71 changes: 2 additions & 69 deletions autoarray/geometry/geometry_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import numpy as np
from typing import Tuple, Union


from autoarray import numba_util
from autoarray import type as ty


Expand Down Expand Up @@ -178,70 +176,6 @@ def convert_pixel_scales_2d(pixel_scales: ty.PixelScales) -> Tuple[float, float]
return pixel_scales


@numba_util.jit()
def central_pixel_coordinates_2d_numba_from(
shape_native: Tuple[int, int],
) -> Tuple[float, float]:
"""
Returns the central pixel coordinates of a 2D geometry (and therefore a 2D data structure like an ``Array2D``)
from the shape of that data structure.

Examples of the central pixels are as follows:

- For a 3x3 image, the central pixel is pixel [1, 1].
- For a 4x4 image, the central pixel is [1.5, 1.5].

Parameters
----------
shape_native
The dimensions of the data structure, which can be in 1D, 2D or higher dimensions.

Returns
-------
The central pixel coordinates of the data structure.
"""
return (float(shape_native[0] - 1) / 2, float(shape_native[1] - 1) / 2)


@numba_util.jit()
def central_scaled_coordinate_2d_numba_from(
shape_native: Tuple[int, int],
pixel_scales: ty.PixelScales,
origin: Tuple[float, float] = (0.0, 0.0),
) -> Tuple[float, float]:
"""
Returns the central scaled coordinates of a 2D geometry (and therefore a 2D data structure like an ``Array2D``)
from the shape of that data structure.

This is computed by using the data structure's shape and converting it to scaled units using an input
pixel-coordinates to scaled-coordinate conversion factor `pixel_scales`.

The origin of the scaled grid can also be input and moved from (0.0, 0.0).

Parameters
----------
shape_native
The 2D shape of the data structure whose central scaled coordinates are computed.
pixel_scales
The (y,x) scaled units to pixel units conversion factor of the 2D data structure.
origin
The (y,x) scaled units origin of the coordinate system the central scaled coordinate is computed on.

Returns
-------
The central coordinates of the 2D data structure in scaled units.
"""

central_pixel_coordinates = central_pixel_coordinates_2d_numba_from(
shape_native=shape_native
)

y_pixel = central_pixel_coordinates[0] + (origin[0] / pixel_scales[0])
x_pixel = central_pixel_coordinates[1] - (origin[1] / pixel_scales[1])

return (y_pixel, x_pixel)


def central_pixel_coordinates_2d_from(
shape_native: Tuple[int, int],
) -> Tuple[float, float]:
Expand Down Expand Up @@ -294,7 +228,7 @@ def central_scaled_coordinate_2d_from(
The central coordinates of the 2D data structure in scaled units.
"""

central_pixel_coordinates = central_pixel_coordinates_2d_numba_from(
central_pixel_coordinates = central_pixel_coordinates_2d_from(
shape_native=shape_native
)

Expand Down Expand Up @@ -367,7 +301,6 @@ def pixel_coordinates_2d_from(
return (y_pixel, x_pixel)


@numba_util.jit()
def scaled_coordinates_2d_from(
pixel_coordinates_2d: Tuple[float, float],
shape_native: Tuple[int, int],
Expand Down Expand Up @@ -411,7 +344,7 @@ def scaled_coordinates_2d_from(
origin=(0.0, 0.0)
)
"""
central_scaled_coordinates = central_scaled_coordinate_2d_numba_from(
central_scaled_coordinates = central_scaled_coordinate_2d_from(
shape_native=shape_native, pixel_scales=pixel_scales, origin=origins
)

Expand Down
12 changes: 12 additions & 0 deletions autoarray/inversion/inversion/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ def __init__(
A dictionary which contains timing of certain functions calls which is used for profiling.
"""

try:
import numba
except ModuleNotFoundError:
raise exc.InversionException(
"Inversion functionality (linear light profiles, pixelized reconstructions) is "
"disabled if numba is not installed.\n\n"
"This is because the run-times without numba are too slow.\n\n"
"Please install numba, which is described at the following web page:\n\n"
"https://pyautolens.readthedocs.io/en/latest/installation/overview.html"
)


self.dataset = dataset

self.linear_obj_list = linear_obj_list
Expand Down
Loading
Loading