autogalaxy.Array1D#
- class Array1D[source]#
Bases:
StructureA uniform 1D array of values, paired with a 1D mask of pixels.
Each entry of an
Array1Dcorresponds to a value at the centre of a pixel in its correspondingMask1D. It is ordered such that pixels begin from the left of the corresponding mask and go right.Like
Array2D, theArray1Dsupportsslim(1D, unmasked only) andnative(1D, full length) data representations.- Parameters:
values (
Union[ndarray,List]) – The values of the array, input in theslimornativeformat.mask (
Mask1D) – The 1D mask associated with the array, defining which pixels each array value is paired with.header (
Optional[Header]) – Optional metadata header associated with the array (e.g. from a FITS file).store_native (
bool) – If True, the ndarray is stored in its native format [total_pixels]. This avoids mapping large data arrays to and from the slim / native formats, which can be a computational bottleneck.xp – The array module to use (default
numpy; passjax.numpyfor JAX support).
Methods
allastypecopyCreate an Array1D (see Array1D.__new__) by loading the array values from a .fits file.
Create an Array1D (see Array1D.__new__) where all values are filled with an input fill value, analogous to the method np.full().
instance_flattenFlatten an instance of an autoarray class into a tuple of its attributes (i.e.. a pytree).
instance_unflattenUnflatten a tuple of attributes (i.e. a pytree) into an instance of an autoarray class.
invertmaxminCreate a Array1D (see Array1D.__new__) by inputting the array values in 1D
Create an Array1D (see Array1D.__new__) where all values are filled with ones, analogous to the method np.ones().
reshapesqrtsumtrimmed_after_convolution_fromTrim the data structure back to its original shape after PSF convolution has been performed on a padded version of it.
with_new_arrayCopy this object but give it a new array.
Create an Array1D (see Array1D.__new__) where all values are filled with zeros, analogous to the method np.zeros().
Attributes
arrayderive_gridThe
DeriveGrid2Dobject of the mask, used to compute derived grids of (y,x) coordinates such as the edge grid, border grid, and full unmasked grid.derive_indexesThe
DeriveIndexes2Dobject of the mask, used to compute index arrays that map data between theslim(1D unmasked) andnative(2D full-shape) representations.derive_maskThe
DeriveMask2Dobject of the mask, used to compute derived masks such as the edge mask, border mask, and blurring mask.dtypegeometryThe geometry object of the mask associated with this structure, which defines coordinate conversions between pixel units and scaled units.
header_dictThe FITS header dictionary of the mask associated with this structure, containing pixel scale and origin entries.
imagis_transformedReturn an Array1D where the data is stored in its native representation, which is an ndarray of shape [total_pixels].
ndimoriginThe (y,x) scaled units origin of the mask's coordinate system.
pixel_areaThe area of a single pixel in scaled units squared (
pixel_scales[0] * pixel_scales[1]).pixel_scaleThe pixel scale as a single float value.
pixel_scalesThe (y,x) scaled units to pixel units conversion factors of every pixel, as a tuple of floats.
realshapeshape_nativeThe shape of the data structure in its
nativerepresentation (e.g.(total_y_pixels, total_x_pixels)for a 2D structure).shape_slimThe 1D shape of the data structure in its
slimrepresentation, equal to the number of unmasked pixels.sizeReturn an Array1D where the data is stored its slim representation, which is an ndarray of shape [total_unmasked_pixels].
total_areaThe total area of all unmasked pixels in scaled units squared (
total_pixels * pixel_area).total_pixelsThe total number of unmasked pixels in the data structure (its
slimlength).unmasked_gridA grid of (y,x) coordinates of every pixel in the full mask shape (including masked pixels), using the mask's geometry to compute each pixel's scaled coordinate.
- classmethod no_mask(values, pixel_scales, origin=(0.0,), header=None)[source]#
Create a Array1D (see Array1D.__new__) by inputting the array values in 1D
- Parameters:
values (
Union[ndarray,Tuple[float],List[float]]) – The values of the array input as an ndarray of shape [total_unmasked_pixels] or a list.pixel_scales (
Union[Tuple[float],Tuple[float,float],float]) – The scaled units to pixel units conversion factor of the array data coordinates (e.g. the x-axis).
Examples
import autoarray as aa # Make Array1D from input np.ndarray. array_1d = aa.Array1D.no_mask(values=np.array([1.0, 2.0, 3.0, 4.0]), pixel_scales=1.0) # Make Array1D from input list. array_1d = aa.Array1D.no_mask(values=[1.0, 2.0, 3.0, 4.0], pixel_scales=1.0) # Print array's slim (masked 1D data representation) and # native (masked 1D data representation) print(array_1d.slim) print(array_1d.native)
- classmethod full(fill_value, shape_native, pixel_scales, origin=(0.0,), header=None)[source]#
Create an Array1D (see Array1D.__new__) where all values are filled with an input fill value, analogous to the method np.full().
From 1D input the method cannot determine the 1D shape of the array and its mask, thus the shape_native must be input into this method. The mask is setup as a unmasked Mask1D of size shape_native.
- Parameters:
fill_value (
float) – The value all array elements are filled with.shape_native (Tuple[int]) – The 1D shape of the mask the array is paired with.
pixel_scales (
Union[Tuple[float],Tuple[float,float],float]) – The (y,x) scaled units to pixel units conversion factors of every pixel. If this is input as a float, it is converted to a (float,) structure.origin ((float,)) – The (x) scaled units origin of the mask’s coordinate system.
- classmethod zeros(shape_native, pixel_scales, origin=(0.0,), header=None)[source]#
Create an Array1D (see Array1D.__new__) where all values are filled with zeros, analogous to the method np.zeros().
From 1D input the method cannot determine the 1D shape of the array and its mask, thus the shape_native must be input into this method. The mask is setup as a unmasked Mask1D of size shape_native.
- Parameters:
shape_native (Tuple[int]) – The 1D shape of the mask the array is paired with.
pixel_scales (
Union[Tuple[float],Tuple[float,float],float]) – The (y,x) scaled units to pixel units conversion factors of every pixel. If this is input as a float, it is converted to a (float,) structure.origin ((float,)) – The (x) scaled units origin of the mask’s coordinate system.
- classmethod ones(shape_native, pixel_scales, origin=(0.0,), header=None)[source]#
Create an Array1D (see Array1D.__new__) where all values are filled with ones, analogous to the method np.ones().
From 1D input the method cannot determine the 1D shape of the array and its mask, thus the shape_native must be input into this method. The mask is setup as a unmasked Mask1D of size shape_native.
- Parameters:
shape_native (Tuple[int]) – The 1D shape of the mask the array is paired with.
pixel_scales (
Union[Tuple[float],Tuple[float,float],float]) – The (y,x) scaled units to pixel units conversion factors of every pixel. If this is input as a float, it is converted to a (float,) structure.origin ((float,)) – The (x) scaled units origin of the mask’s coordinate system.
- classmethod from_fits(file_path, pixel_scales, hdu=0, origin=(0.0, 0.0))[source]#
Create an Array1D (see Array1D.__new__) by loading the array values from a .fits file.
- Parameters:
file_path (
Union[Path,str]) – The path the file is loaded from, including the filename and the .fits extension, e.g. ‘/path/to/filename.fits’hdu (
int) – The Header-Data Unit of the .fits file the array data is loaded from.pixel_scales (
Union[Tuple[float],Tuple[float,float],float]) – The (x,) scaled units to pixel units conversion factors of every pixel. If this is input as a float, it is converted to a (float,) structure.origin (
Tuple[float]) – The (x,) scaled units origin of the coordinate system.
- property slim: Array1D#
Return an Array1D where the data is stored its slim representation, which is an ndarray of shape [total_unmasked_pixels].
If it is already stored in its slim representation it is returned as it is. If not, it is mapped from native to slim and returned as a new Array1D.