autolens.Array2D#
- class Array2D[source]#
Bases:
AbstractArray2D
A uniform 2D array of values, which are paired with a 2D mask of pixels which may be split into sub-pixels.
The
Array2D`, like all data structures (e.g. ``Grid2D
,VectorYX2D
) has in-built functionality which:Applies a 2D mask (a
Mask2D
object) to the da_ta structure’s values.Maps the data structure between two data representations: slim` (all unmasked values in a 1D
ndarray
) andnative
(all unmasked values in a 2Dndarray
).Associates Cartesian
Grid2D
objects of (y,x) coordinates with the data structure (e.g. a (y,x) grid of all unmasked pixels).Associates sub-grids with the data structure, which perform calculations higher resolutions which are then binned up.
Each entry of an
Array2D
corresponds to a value at the centre of a sub-pixel in its correspondingMask2D
. It is ordered such that pixels begin from the top-row of the corresponding mask and go right and down. The positive y-axis is upwards and positive x-axis to the right.A detailed description of the data structure API is provided below.
SLIM DATA REPRESENTATION (sub-size=1)
Below is a visual illustration of an
Array2D
’s 2D mask, where a total of 10 pixels are unmasked and are included in the array.x x x x x x x x x x x x x x x x x x x x This is an example ``Mask2D``, where: x x x x x x x x x x x x x x O O x x x x x = `True` (Pixel is masked and excluded from the array) x x x O O O O x x x O = `False` (Pixel is not masked and included in the array) x x x O O O O x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
The mask pixel index’s are as follows (the positive / negative direction of the
Grid2D
objects associated with the array are also shown on the y and x axes).<--- -ve x +ve --> x x x x x x x x x x ^ array_2d[0] = 10 x x x x x x x x x x I array_2d[1] = 20 x x x x x x x x x x I array_2d[2] = 30 x x x x 0 1 x x x x +ve array_2d[3] = 40 x x x 2 3 4 5 x x x y array_2d[4] = 50 x x x 6 7 8 9 x x x -ve array_2d[5] = 60 x x x x x x x x x x I array_2d[6] = 70 x x x x x x x x x x I array_2d[7] = 80 x x x x x x x x x x \/ array_2d[8] = 90 x x x x x x x x x x array_2d[9] = 100
The
Array2D
in itsslim
data representation is anndarray
of shape [total_unmasked_pixels].For the
Mask2D
above theslim
representation therefore contains 10 entries and two examples of these entries are:array[3] = the 4th unmasked pixel's value, given by value 40 above. array[6] = the 7th unmasked pixel's value, given by value 80 above.
A Cartesian grid of (y,x) coordinates, corresponding to all
slim
values (e.g. unmasked pixels) is given byarray_2d.derive_grid.masked.slim
.NATIVE DATA REPRESENTATION (sub_size=1)
The
Array2D
above, but represented as an anndarray
of shape [total_y_values, total_x_values], where all masked entries have values of 0.0.For the following mask:
x x x x x x x x x x x x x x x x x x x x This is an example ``Mask2D``, where: x x x x x x x x x x x x x x O O x x x x x = `True` (Pixel is masked and excluded from the array) x x x O O O O x x x O = `False` (Pixel is not masked and included in the array) x x x O O O O x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Where the array has the following indexes (left figure) and values (right):
<--- -ve x +ve --> x x x x x x x x x x ^ array_2d[0] = 10 x x x x x x x x x x I array_2d[1] = 20 x x x x x x x x x x I array_2d[2] = 30 x x x x 0 1 x x x x +ve array_2d[3] = 40 x x x 2 3 4 5 x x x y array_2d[4] = 50 x x x 6 7 8 9 x x x -ve array_2d[5] = 60 x x x x x x x x x x I array_2d[6] = 70 x x x x x x x x x x I array_2d[7] = 80 x x x x x x x x x x \/ array_2d[8] = 90 x x x x x x x x x x array_2d[9] = 100
In the above array:
- array[0,0] = 0.0 (it is masked, thus zero) - array[0,0] = 0.0 (it is masked, thus zero) - array[3,3] = 0.0 (it is masked, thus zero) - array[3,3] = 0.0 (it is masked, thus zero) - array[3,4] = 10 - array[3,5] = 20 - array[4,5] = 50
SLIM TO NATIVE MAPPING
The
Array2D
has functionality which maps data between theslim
andnative
data representations.For the example mask above, the 1D
ndarray
given bymask.derive_indexes.slim_to_native
is:slim_to_native[0] = [3,4] slim_to_native[1] = [3,5] slim_to_native[2] = [4,3] slim_to_native[3] = [4,4] slim_to_native[4] = [4,5] slim_to_native[5] = [4,6] slim_to_native[6] = [5,3] slim_to_native[7] = [5,4] slim_to_native[8] = [5,5] slim_to_native[9] = [5,6]
SUB GRIDDING
If the
Mask2D
sub_size
is > 1, the array has entries corresponding to the values at the centre of every sub-pixel of each unmasked pixel.The sub-array indexes are ordered such that pixels begin from the first (top-left) sub-pixel in the first unmasked pixel. Indexes then go over the sub-pixels in each unmasked pixel, for every unmasked pixel.
Therefore, the shapes of the sub-array are as follows:
slim
representation: anndarray
of shape [total_unmasked_pixels*sub_size**2].native
representation: anndarray
of shape [total_y_values*sub_size, total_x_values*sub_size].
Below is a visual illustration of a sub array. Indexing of each sub-pixel goes from the top-left corner. In contrast to the array above, our illustration below restricts the mask to just 2 pixels, to keep the illustration brief.
x x x x x x x x x x x x x x x x x x x x This is an example ``Mask2D``, where: x x x x x x x x x x x x x x x x x x x x x = `True` (Pixel is masked and excluded from lens) x 0 0 x x x x x x x O = `False` (Pixel is not masked and included in lens) x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
If
sub_size=2
, each unmasked pixel has 4 (2x2) sub-pixel values. For the example above, pixels 0 and 1 each have 4 values which map to thearray_2d
’sslim
representation as follows:Pixel 0 - (2x2): array_2d.slim[0] = value of first sub-pixel in pixel 0. 0 1 array_2d.slim[1] = value of first sub-pixel in pixel 1. 2 3 array_2d.slim[2] = value of first sub-pixel in pixel 2. array_2d.slim[3] = value of first sub-pixel in pixel 3. Pixel 1 - (2x2): array_2d.slim[4] = value of first sub-pixel in pixel 0. 4 5 array_2d.slim[5] = value of first sub-pixel in pixel 1. 6 7 array_2d.slim[6] = value of first sub-pixel in pixel 2. array_2d.slim[7] = value of first sub-pixel in pixel 3.
For the
native
data representation we get the following mappings:Pixel 0 - (2x2): array_2d.native[8, 2] = value of first sub-pixel in pixel 0. 0 1 array_2d.native[8, 3] = value of first sub-pixel in pixel 1. 2 3 array_2d.native[9, 2] = value of first sub-pixel in pixel 2. array_2d.native[9, 3] = value of first sub-pixel in pixel 3. Pixel 1 - (2x2): array_2d.native[10, 4] = value of first sub-pixel in pixel 0. 4 5 array_2d.native[10, 5] = value of first sub-pixel in pixel 1. 6 7 array_2d.native[11, 4] = value of first sub-pixel in pixel 2. array_2d.native[11, 5] = value of first sub-pixel in pixel 3. Other entries (all masked sub-pixels are zero): array_2d.native[0, 0] = 0.0 (it is masked, thus zero) array_2d.native[15, 12] = 0.0 (it is masked, thus zero)
If we used a sub_size of 3, for pixel 0 we we would create a 3x3 sub-array:
array_2d.slim[0] = value of first sub-pixel in pixel 0. array_2d.slim[1] = value of first sub-pixel in pixel 1. array_2d.slim[2] = value of first sub-pixel in pixel 2. 0 1 2 array_2d.slim[3] = value of first sub-pixel in pixel 3. 3 4 5 array_2d.slim[4] = value of first sub-pixel in pixel 4. 6 7 8 array_2d.slim[5] = value of first sub-pixel in pixel 5. array_2d.slim[6] = value of first sub-pixel in pixel 6. array_2d.slim[7] = value of first sub-pixel in pixel 7. array_2d.slim[8] = value of first sub-pixel in pixel 8.
- Parameters
values – The values of the array, which can be input in the
slim
ornative
format.mask – The 2D mask associated with the array, defining the pixels each array value in its
slim
representation is paired with.store_native – If True, the ndarray is stored in its native format [total_y_pixels, total_x_pixels]. This avoids mapping large data arrays to and from the slim / native formats, which can be a computational bottleneck.
Examples
This example uses the
Array2D.no_mask
method to create theArray2D
.Different methods using different inputs are available and documented throughout this webpage.
import autoarray as aa # Make Array2D from input np.ndarray with sub_size 1. array_2d = aa.Array2D.no_mask( values=np.array([1.0, 2.0, 3.0, 4.0]), shape_native=(2, 2), pixel_scales=1.0, sub_size=1 ) # Make Array2D from input list with different shape_native and sub_size 1. array_2d = aa.Array2D.no_mask( values=[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape_native=(2, 3), pixel_scales=1.0, sub_size=1 )
import autoarray as aa # Make Array2D with sub_size 2. array_2d = aa.Array2D.no_mask( values=[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], shape_native=(2, 1), pixel_scales=1.0, sub_size=2, ) # Apply 2D mask to Array2D with sub_size 2, where the # True value masks entries (5.0, 6.0, 7.0, 8.0). mask = aa.Mask2D( mask=[[False], [True]], pixel_scales=2.0, sub_size=2 ) array_2d = array_2d.apply_mask(mask=mask) # Print certain array attributes. print(array_2d.slim) # masked 1D data representation on sub-grid. print(array_2d.native) # masked 2D data representation on sub-grid. print(array_2d.slim.binned) # masked 1D data representation binned up from sub-grid. print(array_2d.native.binned) # masked 2D data representation binned up from sub-grid. # Output array to .fits file. array_2d.output_to_fits(file_path="/path/for/output")
Methods
all
Returns True if all elements evaluate to True.
any
Returns True if any of the elements of a evaluate to True.
apply_mask
- rtype
argmax
Return indices of the maximum values along the given axis.
argmin
Return indices of the minimum values along the given axis.
argpartition
Returns the indices that would partition this array.
argsort
Returns the indices that would sort this array.
astype
Copy of the array, cast to a specified type.
byteswap
Swap the bytes of the array elements
choose
Use an index array to construct a new array from a set of choices.
clip
Return an array whose values are limited to
[min, max]
.compress
Return selected slices of this array along given axis.
conj
Complex-conjugate all elements.
conjugate
Return the complex conjugate, element-wise.
copy
Return a copy of the array.
cumprod
Return the cumulative product of the elements along the given axis.
cumsum
Return the cumulative sum of the elements along the given axis.
diagonal
Return specified diagonals.
dot
dump
Dump a pickle of the array to the specified file.
dumps
Returns the pickle of the array as a string.
extent_of_zoomed_array
For an extracted zoomed array computed from the method zoomed_around_mask compute its extent in scaled coordinates.
fill
Fill the array with a scalar value.
flatten
Return a copy of the array collapsed into one dimension.
flip_hdu_for_ds9
Returns an
Array2D
by loading the array values from a .fits file.Returns an
Array2D
by from a PrimaryHDU object which has been loaded via astropy.fitsReturns an
Array2D
by by inputting the y and x pixel values where the array is filled and the values that fill it.Returns an
Array2D
where all values are filled with an input fill value, analogous tonp.full()
.getfield
Returns a field of the given array as a certain type.
item
Copy an element of an array to a standard Python scalar and return it.
itemset
Insert scalar into an array (scalar is cast to array's dtype, if possible)
max
Return the maximum along a given axis.
mean
Returns the average of the array elements along given axis.
min
Return the minimum along a given axis.
newbyteorder
Return the array with the same data viewed with a different byte order.
Returns an
Array2D
from an array via inputs in its slim or native data representation.nonzero
Return the indices of the elements that are non-zero.
Returns an
Array2D
where all values are filled with ones, analogous tonp.ones()
.output_to_fits
Output the array to a .fits file.
padded_before_convolution_from
When the edge pixels of a mask are unmasked and a convolution is to occur, the signal of edge pixels will be 'missing' if the grid is used to evaluate the signal via an analytic function.
partition
Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array.
prod
Return the product of the array elements over the given axis
ptp
Peak to peak (maximum - minimum) value along a given axis.
put
Set
a.flat[n] = values[n]
for all n in indices.ravel
Return a flattened array.
repeat
Repeat elements of an array.
reshape
Returns an array containing the same data with a new shape.
resize
Change shape and size of array in-place.
resized_from
Resize the array around its centre to a new input shape.
round
Return a with each element rounded to the given number of decimals.
searchsorted
Find indices where elements of v should be inserted in a to maintain order.
setfield
Put a value into a specified place in a field defined by a data-type.
setflags
Set array flags WRITEABLE, ALIGNED, WRITEBACKIFCOPY, respectively.
sort
Sort an array in-place.
squeeze
Remove axes of length one from a.
std
Returns the standard deviation of the array elements along given axis.
structure_2d_from
- rtype
Structure
structure_2d_list_from
- rtype
List
[Structure
]
sum
Return the sum of the array elements over the given axis.
swapaxes
Return a view of the array with axis1 and axis2 interchanged.
take
Return an array formed from the elements of a at the given indices.
tobytes
Construct Python bytes containing the raw data bytes in the array.
tofile
Write array to a file as text or binary (default).
tolist
Return the array as an
a.ndim
-levels deep nested list of Python scalars.tostring
A compatibility alias for tobytes, with exactly the same behavior.
trace
Return the sum along diagonals of the array.
transpose
Returns a view of the array with axes transposed.
trimmed_after_convolution_from
When the edge pixels of a mask are unmasked and a convolution is to occur, the signal of edge pixels will be 'missing' if the grid is used to evaluate the signal via an analytic function.
var
Returns the variance of the array elements, along given axis.
view
New view of array with the same data.
Returns an
Array2D
where all values are filled with zeros, analogous tonp.zeros()
.zoomed_around_mask
Extract the 2D region of an array corresponding to the rectangle encompassing all unmasked values.
Attributes
T
The transposed array.
base
Base object if memory is from some other object.
binned
Convenience method to access the binned-up array in its 1D representation, which is a Grid2D stored as an
ndarray
of shape [total_unmasked_pixels, 2].binned_across_columns
- rtype
binned_across_rows
- rtype
ctypes
An object to simplify the interaction of the array with the ctypes module.
data
Python buffer object pointing to the start of the array's data.
derive_grid
- rtype
DeriveGrid2D
derive_indexes
- rtype
DeriveIndexes2D
derive_mask
- rtype
DeriveMask2D
dtype
Data-type of the array's elements.
flags
Information about the memory layout of the array.
flat
A 1-D iterator over the array.
geometry
hdu_for_output
The array as an HDU object, which can be output to a .fits file.
imag
The imaginary part of the array.
in_counts
- rtype
in_counts_per_second
- rtype
itemsize
Length of one array element in bytes.
native
Return a Array2D where the data is stored in its native representation, which is an
ndarray
of shape [sub_size*total_y_pixels, sub_size*total_x_pixels].native_skip_mask
Return a Array2D where the data is stored in its native representation, which is an
ndarray
of shape [sub_size*total_y_pixels, sub_size*total_x_pixels].nbytes
Total bytes consumed by the elements of the array.
ndim
Number of array dimensions.
origin
original_orientation
pixel_area
pixel_scale
- rtype
pixel_scale_header
- rtype
pixel_scales
readout_offsets
real
The real part of the array.
shape
Tuple of array dimensions.
shape_native
shape_slim
- rtype
size
Number of elements in the array.
slim
Return an Array2D where the data is stored its slim representation, which is an
ndarray
of shape [total_unmasked_pixels * sub_size**2].store_native
strides
Tuple of bytes to step in each dimension when traversing an array.
sub_shape_native
sub_shape_slim
- rtype
sub_size
- rtype
total_area
total_pixels
- rtype
unmasked_grid
- classmethod no_mask(values, pixel_scales, shape_native=None, sub_size=1, origin=(0.0, 0.0), header=None)[source]#
Returns an
Array2D
from an array via inputs in its slim or native data representation.From a
slim
1D input the method cannot determine the 2D shape of the array and its mask. Theshape_native
must therefore also be input into this method. The mask is setup as a unmasked Mask2D ofshape_native
.For a full description of
Array2D
objects, including a description of theslim
andnative
attribute used by the API, see theArray2D class API documentation
.- Parameters
values (
Union
[ndarray
,List
]) – The values of the array input with shape [total_unmasked_pixels*(sub_size**2)] or shape [total_y_pixels*sub_size, total_x_pixel*sub_size].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, float) structure.shape_native (
Optional
[Tuple
[int
,int
]]) – The 2D shape of the array in itsnative
format, and its 2D mask (only required if input shape is inslim
format).sub_size (
int
) – The size (sub_size x sub_size) of each unmasked pixels sub-array.origin (
Tuple
[float
,float
]) – The (y,x) scaled units origin of the mask’s coordinate system.
Examples
import autoarray as aa # Make Array2D from input list, native format with sub_size 1 # (This array has shape_native=(2,2)). array_2d = aa.Array2D.manual( array=np.array([[1.0, 2.0], [3.0, 4.0]]), pixel_scales=1.0. sub_size=1 )
import autoarray as aa # Make Array2D from input list, slim format with sub_size 2. array_2d = aa.Array2D.no_mask( values=[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], shape_native=(2, 1), pixel_scales=1.0, sub_size=2, )
- Return type
- classmethod full(fill_value, shape_native, pixel_scales, sub_size=1, origin=(0.0, 0.0), header=None)[source]#
Returns an
Array2D
where all values are filled with an input fill value, analogous tonp.full()
.For a full description of
Array2D
objects, including a description of theslim
andnative
attribute used by the API, see theArray2D class API documentation
.From this input the method cannot determine the 2D shape of the array and its mask. The
shape_native
must therefore also be input into this method. The mask is setup as a unmasked Mask2D ofshape_native
.- Parameters
fill_value (
float
) – The value all array elements are filled with.shape_native (
Tuple
[int
,int
]) – The 2D shape of the array in itsnative
format, and its 2D mask.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, float) structure.sub_size (
int
) – The size (sub_size x sub_size) of each unmasked pixels sub-array.origin (
Tuple
[float
,float
]) – The (y,x) scaled units origin of the mask’s coordinate system.
Examples
import autoarray as aa # Make Array2D with sub_size 1. array_2d = aa.Array2D.full( fill_value=2.0, shape_native=(2, 2), pixel_scales=1.0, sub_size=1 )
import autoarray as aa # Make Array2D with sub_size 2. array_2d = aa.Array2D.full( fill_value=2.0, shape_native=(2, 2), pixel_scales=1.0, sub_size=2 )
- Return type
- classmethod ones(shape_native, pixel_scales, sub_size=1, origin=(0.0, 0.0), header=None)[source]#
Returns an
Array2D
where all values are filled with ones, analogous tonp.ones()
.For a full description of
Array2D
objects, including a description of theslim
andnative
attribute used by the API, see theArray2D class API documentation
.From this input the method cannot determine the 2D shape of the array and its mask. The
shape_native
must therefore also be input into this method. The mask is setup as a unmasked Mask2D ofshape_native
.- Parameters
shape_native (
Tuple
[int
,int
]) – The 2D shape of the array in itsnative
format, and its 2D mask.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, float) structure.sub_size (
int
) – The size (sub_size x sub_size) of each unmasked pixels sub-array.origin (
Tuple
[float
,float
]) – The (y,x) scaled units origin of the mask’s coordinate system.
Examples
import autoarray as aa # Make Array2D with sub_size 1. array_2d = aa.Array2D.ones( shape_native=(2, 2), pixel_scales=1.0, sub_size=1 )
import autoarray as aa # Make Array2D with sub_size 2. array_2d = aa.Array2D.ones( shape_native=(2, 2), pixel_scales=1.0, sub_size=2 )
- Return type
- classmethod zeros(shape_native, pixel_scales, sub_size=1, origin=(0.0, 0.0), header=None)[source]#
Returns an
Array2D
where all values are filled with zeros, analogous tonp.zeros()
.For a full description of
Array2D
objects, including a description of theslim
andnative
attribute used by the API, see theArray2D class API documentation
.From this input the method cannot determine the 2D shape of the array and its mask. The
shape_native
must therefore also be input into this method. The mask is setup as a unmasked Mask2D ofshape_native
.- Parameters
shape_native (
Tuple
[int
,int
]) – The 2D shape of the array in itsnative
format, and its 2D mask.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, float) structure.sub_size (
int
) – The size (sub_size x sub_size) of each unmasked pixels sub-array.origin (
Tuple
[float
,float
]) – The (y,x) scaled units origin of the mask’s coordinate system.
Examples
import autoarray as aa # Make Array2D with sub_size 1. array_2d = aa.Array2D.zeros( shape_native=(2, 2), pixel_scales=1.0, sub_size=1 )
import autoarray as aa # Make Array2D with sub_size 2. array_2d = aa.Array2D.zeros( shape_native=(2, 2), pixel_scales=1.0, sub_size=2 )
- Return type
- classmethod from_fits(file_path, pixel_scales, hdu=0, sub_size=1, origin=(0.0, 0.0))[source]#
Returns an
Array2D
by loading the array values from a .fits file.For a full description of
Array2D
objects, including a description of theslim
andnative
attribute used by the API, see theArray2D class API documentation
.- 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’pixel_scales (
Union
[Tuple
[float
],Tuple
[float
,float
],float
,None
]) – 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, float) structure.hdu (
int
) – The Header-Data Unit of the .fits file the array data is loaded from.sub_size (
int
) – The size (sub_size x sub_size) of each unmasked pixels sub-array.origin (
Tuple
[float
,float
]) – The (y,x) scaled units origin of the coordinate system.
Examples
import autoarray as aa # Make Array2D with sub_size 1. array_2d = aa.Array2D.from_fits( file_path="path/to/file.fits", hdu=0, pixel_scales=1.0, sub_size=1 )
import autoarray as aa # Make Array2D with sub_size 2. # (It is uncommon that a sub-gridded array would be loaded from # a .fits, but the API support its). array_2d = aa.Array2D.from_fits( file_path="path/to/file.fits", hdu=0, pixel_scales=1.0, sub_size=2 )
- Return type
- classmethod from_primary_hdu(primary_hdu, sub_size=1, origin=(0.0, 0.0))[source]#
Returns an
Array2D
by from a PrimaryHDU object which has been loaded via astropy.fitsThis assumes that the header of the PrimaryHDU contains an entry named PIXSCALE which gives the pixel-scale of the array.
For a full description of
Array2D
objects, including a description of theslim
andnative
attribute used by the API, see theArray2D class API documentation
.- Parameters
primary_hdu (
PrimaryHDU
) – The PrimaryHDU object which has already been loaded from a .fits file via astropy.fits and contains the array data and the pixel-scale in the header with an entry named PIXSCALE.sub_size (
int
) – The size (sub_size x sub_size) of each unmasked pixels sub-array.origin (
Tuple
[float
,float
]) – The (y,x) scaled units origin of the coordinate system.
Examples
from astropy.io import fits import autoarray as aa # Make Array2D with sub_size 1. primary_hdu = fits.open("path/to/file.fits") array_2d = aa.Array2D.from_primary_hdu( primary_hdu=primary_hdu, sub_size=1 )
import autoarray as aa # Make Array2D with sub_size 2. # (It is uncommon that a sub-gridded array would be loaded from # a .fits, but the API support its). primary_hdu = fits.open("path/to/file.fits") array_2d = aa.Array2D.from_primary_hdu( primary_hdu=primary_hdu, sub_size=2 )
- Return type
- classmethod from_yx_and_values(y, x, values, shape_native, pixel_scales, sub_size=1, header=None)[source]#
Returns an
Array2D
by by inputting the y and x pixel values where the array is filled and the values that fill it.For a full description of
Array2D
objects, including a description of theslim
andnative
attribute used by the API, see theArray2D class API documentation
.- Parameters
y (
Union
[ndarray
,List
]) – The y pixel indexes where value are input, with shape [total_unmasked_pixels*sub_size].x (
Union
[ndarray
,List
]) – The x pixel indexes where value are input, with shape [total_unmasked_pixels*sub_size].list (values or) – The values which are used to fill in the array, with shape [total_unmasked_pixels*sub_size].
shape_native (
Tuple
[int
,int
]) – The 2D shape of the array in itsnative
format, and its 2D mask.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, float) structure.sub_size (
int
) – The size (sub_size x sub_size) of each unmasked pixels sub-grid.origin – The origin of the grid’s mask.
Examples
import autoarray as aa # Make Array2D with sub_size 1. array_2d = aa.Array2D.from_yx_and_values( y=np.array([0.5, 0.5, -0.5, -0.5]), x=np.array([-0.5, 0.5, -0.5, 0.5]), values=np.array([1.0, 2.0, 3.0, 4.0]), shape_native=(2, 2), pixel_scales=1.0, sub_size=1, )
import autoarray as aa # Make Array2D with sub_size 2. array_2d = aa.Array2D.from_yx_and_values( y=np.array([1.0, 1.0. 0.5, 0.5, -0.5, -0.5, -1.0, -1.0]), x=np.array([-0.5, 0.5, -0.5, 0.5, -0.5, 0.5, -0.5, 0.5]), values=np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), shape_native=(2, 1), pixel_scales=1.0, sub_size=2, )
- Return type