Skip to content

Commit 88bd414

Browse files
Jammy2211claude
authored andcommitted
docs: refactor docstrings for autoarray/structures package
- abstract_structure: add docstrings to all undocumented properties (geometry, derive_grid, derive_indexes, derive_mask, shape_slim, shape_native, pixel_scales, pixel_scale, header_dict, pixel_area, total_area, origin, unmasked_grid, total_pixels); expand trimmed_after_convolution_from (was bare NotImplementedError) - arrays/uniform_2d: add missing params (header, skip_mask, xp) to __init__; add docstrings to in_counts, in_counts_per_second, original_orientation, readout_offsets; fix "locaiton" typo; fix self-referential sentence in brightest_sub_pixel_coordinate; fix no_mask example (was aa.Array2D.manual + syntax error with period) - arrays/array_2d_util: fix "input array input a convert" description; add docstring to check_array_2d; fix "oigin"/"reszied" typos; fix wrong function name in example (index_flat_for_index_2d_from → index_slim_for_index_2d_from); remove duplicate array_2d_native param - arrays/irregular: add docstrings to values and native properties - arrays/uniform_1d: add full __init__ docstring; fix "Make Array2D" comment → "Make Array1D" - grids/grid_2d_util: fix "he " → "The" (×2); fix "silm" → "slim"; fix "flloat" → "float" (×2); fix mask_2d param name in grid_2d_slim_from; add docstrings to convert_grid, check_grid_slim, check_grid_2d, check_grid_2d_and_mask_2d - grids/grid_1d_util: rewrite convert_grid_1d docstring (was copy-pasted from Grid2D with wrong class/param names grid_2d/mask_2d); fix grid_1d_slim_via_mask_from ("2D mask" → "1D mask", wrong example) - grids/uniform_1d: fix __init__ params (was "(y,x)" for a 1D grid); fix no_mask params and example ("autogrid", "np.ndgrid", "Grid2D"); fix __native__ section referencing Grid2D instead of Grid1D - grids/irregular_2d: add docstrings to values, slim, native properties; fix "*Coordinate* instance" → "Grid2DIrregular instance" (×2) - visibilities: fix "visibilitiy" typo Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9c0044b commit 88bd414

10 files changed

Lines changed: 245 additions & 60 deletions

File tree

autoarray/structures/abstract_structure.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,62 +29,125 @@ def slim(self) -> "Structure":
2929

3030
@property
3131
def geometry(self):
32+
"""
33+
The geometry object of the mask associated with this structure, which defines coordinate conversions
34+
between pixel units and scaled units.
35+
"""
3236
return self.mask.geometry
3337

3438
@property
3539
def derive_grid(self) -> DeriveGrid2D:
40+
"""
41+
The ``DeriveGrid2D`` object of the mask, used to compute derived grids of (y,x) coordinates such as
42+
the edge grid, border grid, and full unmasked grid.
43+
"""
3644
return self.mask.derive_grid
3745

3846
@property
3947
def derive_indexes(self) -> DeriveIndexes2D:
48+
"""
49+
The ``DeriveIndexes2D`` object of the mask, used to compute index arrays that map data between the
50+
``slim`` (1D unmasked) and ``native`` (2D full-shape) representations.
51+
"""
4052
return self.mask.derive_indexes
4153

4254
@property
4355
def derive_mask(self) -> DeriveMask2D:
56+
"""
57+
The ``DeriveMask2D`` object of the mask, used to compute derived masks such as the edge mask,
58+
border mask, and blurring mask.
59+
"""
4460
return self.mask.derive_mask
4561

4662
@property
4763
def shape_slim(self) -> int:
64+
"""
65+
The 1D shape of the data structure in its ``slim`` representation, equal to the number of unmasked pixels.
66+
"""
4867
return self.mask.shape_slim
4968

5069
@property
5170
def shape_native(self) -> Tuple[int, ...]:
71+
"""
72+
The shape of the data structure in its ``native`` representation (e.g. ``(total_y_pixels, total_x_pixels)``
73+
for a 2D structure).
74+
"""
5275
return self.mask.shape
5376

5477
@property
5578
def pixel_scales(self) -> Tuple[float, ...]:
79+
"""
80+
The (y,x) scaled units to pixel units conversion factors of every pixel, as a tuple of floats.
81+
"""
5682
return self.mask.pixel_scales
5783

5884
@property
5985
def pixel_scale(self) -> float:
86+
"""
87+
The pixel scale as a single float value. Assumes all pixel scales are equal (e.g. square pixels).
88+
"""
6089
return self.mask.pixel_scale
6190

6291
@property
6392
def header_dict(self) -> Dict:
93+
"""
94+
The FITS header dictionary of the mask associated with this structure, containing pixel scale and origin entries.
95+
"""
6496
return self.mask.header_dict
6597

6698
@property
6799
def pixel_area(self):
100+
"""
101+
The area of a single pixel in scaled units squared (``pixel_scales[0] * pixel_scales[1]``).
102+
103+
Only valid for 2D structures; raises ``GridException`` for 1D structures.
104+
"""
68105
if len(self.pixel_scales) != 2:
69106
raise exc.GridException("Cannot compute area of structure which is not 2D.")
70107

71108
return self.pixel_scales[0] * self.pixel_scales[1]
72109

73110
@property
74111
def total_area(self):
112+
"""
113+
The total area of all unmasked pixels in scaled units squared (``total_pixels * pixel_area``).
114+
"""
75115
return self.total_pixels * self.pixel_area
76116

77117
@property
78118
def origin(self) -> Tuple[int, ...]:
119+
"""
120+
The (y,x) scaled units origin of the mask's coordinate system.
121+
"""
79122
return self.mask.origin
80123

81124
@property
82125
def unmasked_grid(self) -> Union[Grid1D, Grid2D]:
126+
"""
127+
A grid of (y,x) coordinates of every pixel in the full mask shape (including masked pixels), using
128+
the mask's geometry to compute each pixel's scaled coordinate.
129+
"""
83130
return self.mask.derive_grid.all_false
84131

85132
@property
86133
def total_pixels(self) -> int:
134+
"""
135+
The total number of unmasked pixels in the data structure (its ``slim`` length).
136+
"""
87137
return self.shape[0]
88138

89139
def trimmed_after_convolution_from(self, kernel_shape) -> "Structure":
140+
"""
141+
Trim the data structure back to its original shape after PSF convolution has been performed on a
142+
padded version of it.
143+
144+
This is the inverse of ``padded_before_convolution_from``: first the data structure is padded so
145+
that edge-pixel signal is not lost during convolution, and then this method trims the result back
146+
to the original shape.
147+
148+
Parameters
149+
----------
150+
kernel_shape
151+
The 2D shape of the convolution kernel used to pad and trim the data structure.
152+
"""
90153
raise NotImplementedError

autoarray/structures/arrays/array_2d_util.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def convert_array(array: Union[np.ndarray, List]) -> np.ndarray:
1414
"""
15-
If the input array input a convert is of type list, convert it to type NumPy array.
15+
Convert the input array to a NumPy ``ndarray`` if it is a list, or unwrap it if it is an autoarray object.
1616
1717
Parameters
1818
----------
@@ -32,6 +32,16 @@ def convert_array(array: Union[np.ndarray, List]) -> np.ndarray:
3232

3333

3434
def check_array_2d(array_2d: np.ndarray):
35+
"""
36+
Check that an array intended for use as an ``Array2D`` slim representation has exactly 1 dimension.
37+
38+
Raises ``ArrayException`` if the array is not 1D.
39+
40+
Parameters
41+
----------
42+
array_2d
43+
The array to check, which must have shape [total_unmasked_pixels].
44+
"""
3545
if len(array_2d.shape) != 1:
3646
raise exc.ArrayException(
3747
"An array input into the Array2D.__new__ method is not of shape 1."
@@ -281,9 +291,9 @@ def resized_array_2d_from(
281291
resized_shape
282292
The (y,x) new pixel dimension of the trimmed array.
283293
origin
284-
The oigin of the resized array, e.g. the central pixel around which the array is extracted.
294+
The origin of the resized array, e.g. the central pixel around which the array is extracted.
285295
pad_value
286-
If the reszied array is bigger in size than the input array, the value the padded edge values are filled in
296+
If the resized array is bigger in size than the input array, the value the padded edge values are filled in
287297
using.
288298
289299
Returns
@@ -405,7 +415,7 @@ def index_slim_for_index_2d_from(indexes_2d: np.ndarray, shape_native) -> np.nda
405415
Examples
406416
--------
407417
indexes_2d = np.array([[0,0], [1,0], [2,0], [2,2]])
408-
indexes_flat = index_flat_for_index_2d_from(indexes_2d=indexes_2d, shape=(3,3))
418+
indexes_slim = index_slim_for_index_2d_from(indexes_2d=indexes_2d, shape_native=(3,3))
409419
"""
410420
# Calculate 1D indexes as row_index * number_of_columns + col_index
411421
index_slim_for_index_native_2d = (
@@ -434,11 +444,9 @@ def array_2d_slim_from(
434444
Parameters
435445
----------
436446
array_2d_native
437-
A 2D array of values on the dimensions of the grid.
447+
A 2D array of values on the dimensions of the grid, with shape [total_y_pixels, total_x_pixels].
438448
mask_2d
439449
A 2D array of bools, where `False` values mean unmasked and are included in the mapping.
440-
array_2d_native
441-
The 2D array of values which are mapped to a 1D array.
442450
443451
Returns
444452
-------

autoarray/structures/arrays/irregular.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def __init__(self, values: Union[List, np.ndarray]):
4545

4646
@property
4747
def values(self):
48+
"""
49+
The raw underlying 1D ndarray of values, with shape [total_values].
50+
"""
4851
return self.array
4952

5053
@property
@@ -56,6 +59,10 @@ def slim(self) -> "ArrayIrregular":
5659

5760
@property
5861
def native(self) -> Structure:
62+
"""
63+
The ``ArrayIrregular`` in its ``native`` representation. For an irregular array there is no 2D native
64+
format, so this returns the array as-is.
65+
"""
5966
return self
6067

6168
@property

autoarray/structures/arrays/uniform_1d.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ def __init__(
2525
store_native: bool = False,
2626
xp=np,
2727
):
28+
"""
29+
A uniform 1D array of values, paired with a 1D mask of pixels.
30+
31+
Each entry of an ``Array1D`` corresponds to a value at the centre of a pixel in its corresponding ``Mask1D``.
32+
It is ordered such that pixels begin from the left of the corresponding mask and go right.
33+
34+
Like ``Array2D``, the ``Array1D`` supports ``slim`` (1D, unmasked only) and ``native`` (1D, full length)
35+
data representations.
36+
37+
Parameters
38+
----------
39+
values
40+
The values of the array, input in the ``slim`` or ``native`` format.
41+
mask
42+
The 1D mask associated with the array, defining which pixels each array value is paired with.
43+
header
44+
Optional metadata header associated with the array (e.g. from a FITS file).
45+
store_native
46+
If True, the ndarray is stored in its native format [total_pixels]. This avoids mapping large data
47+
arrays to and from the slim / native formats, which can be a computational bottleneck.
48+
xp
49+
The array module to use (default ``numpy``; pass ``jax.numpy`` for JAX support).
50+
"""
2851

2952
values = array_1d_util.convert_array_1d(
3053
array_1d=values, mask_1d=mask, store_native=store_native, xp=xp
@@ -66,7 +89,7 @@ def no_mask(
6689
6790
array_1d = aa.Array1D.no_mask(values=np.array([1.0, 2.0, 3.0, 4.0]), pixel_scales=1.0)
6891
69-
# Make Array2D from input list.
92+
# Make Array1D from input list.
7093
7194
array_1d = aa.Array1D.no_mask(values=[1.0, 2.0, 3.0, 4.0], pixel_scales=1.0)
7295

autoarray/structures/arrays/uniform_2d.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,15 @@ def __init__(
187187
mask
188188
The 2D mask associated with the array, defining the pixels each array value in its ``slim`` representation
189189
is paired with.
190+
header
191+
Optional metadata header (e.g. from a FITS file) associated with the array.
190192
store_native
191193
If True, the ndarray is stored in its native format [total_y_pixels, total_x_pixels]. This avoids
192194
mapping large data arrays to and from the slim / native formats, which can be a computational bottleneck.
195+
skip_mask
196+
If True, masking is skipped and values are stored as-is without zeroing masked entries.
197+
xp
198+
The array module to use (default ``numpy``; pass ``jax.numpy`` for JAX support).
193199
194200
Examples
195201
--------
@@ -334,22 +340,39 @@ def native_skip_mask(self) -> "Array2D":
334340

335341
@property
336342
def in_counts(self) -> "Array2D":
343+
"""
344+
The array converted from electrons-per-second (eps) to total counts, using the exposure time stored
345+
in the associated ``Header``.
346+
"""
337347
return self.header.array_eps_to_counts(array_eps=self)
338348

339349
@property
340350
def in_counts_per_second(self) -> "Array2D":
351+
"""
352+
The array converted from electrons-per-second (eps) to counts-per-second, via an intermediate
353+
conversion to total counts using the ``Header`` exposure time.
354+
"""
341355
return self.header.array_counts_to_counts_per_second(
342356
array_counts=self.in_counts
343357
)
344358

345359
@property
346360
def original_orientation(self) -> Union[np.ndarray, "Array2D"]:
361+
"""
362+
The array rotated back to its original CCD read-out orientation, using the read-out-electronics (ROE)
363+
corner stored in the associated ``Header``.
364+
"""
347365
return layout_util.rotate_array_via_roe_corner_from(
348366
array=self, roe_corner=self.header.original_roe_corner
349367
)
350368

351369
@property
352370
def readout_offsets(self) -> Tuple[int, int]:
371+
"""
372+
The (y,x) pixel offsets of the read-out electronics corner, taken from the associated ``Header``.
373+
374+
Returns ``(0, 0)`` if no header is present or no readout offsets are stored in the header.
375+
"""
353376
if self.header is not None:
354377
if self.header.readout_offsets is not None:
355378
return self.header.readout_offsets
@@ -438,10 +461,10 @@ def brightest_sub_pixel_coordinate_in_region_from(
438461
439462
For example, if the input region is `region=(-0.15, 0.25, 0.35, 0.55)` the code finds all pixels inside of
440463
this region in scaled units, finds the brightest pixel of those pixels, and then on a 3x3 grid surrounding
441-
this pixel determines the locaiton of the brightest sub pixel using a weighted centre calculation.
464+
this pixel determines the location of the brightest sub pixel using a weighted centre calculation.
442465
443-
The centre of the brightest pixel is returned, the function `brightest_sub_pixel_coordinate_in_region_from`
444-
performs a sub pixel calculation to return the brightest sub pixel coordinate.
466+
Unlike ``brightest_coordinate_in_region_from``, which returns the centre of the brightest pixel, this
467+
function performs a weighted-centroid sub-pixel calculation to return a more precise coordinate.
445468
446469
Parameters
447470
----------
@@ -621,9 +644,9 @@ def no_mask(
621644
# Make Array2D from input list, native format
622645
# (This array has shape_native=(2,2)).
623646
624-
array_2d = aa.Array2D.manual(
625-
array=np.array([[1.0, 2.0], [3.0, 4.0]]),
626-
pixel_scales=1.0.
647+
array_2d = aa.Array2D.no_mask(
648+
values=np.array([[1.0, 2.0], [3.0, 4.0]]),
649+
pixel_scales=1.0,
627650
)
628651
"""
629652

autoarray/structures/grids/grid_1d_util.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@ def convert_grid_1d(
1616
grid_1d: Union[np.ndarray, List], mask_1d: Mask1D, store_native: bool = False, xp=np
1717
) -> np.ndarray:
1818
"""
19-
The `manual` classmethods in the Grid2D object take as input a list or ndarray which is returned as a Grid2D.
19+
The ``manual`` classmethods in the ``Grid1D`` object take as input a list or ndarray which is returned as a ``Grid1D``.
2020
21-
This function performs the following and checks and conversions on the input:
21+
This function performs the following checks and conversions on the input:
2222
23-
1: If the input is a list, convert it to an ndarray.
24-
2: Check that the number of pixels in the array is identical to that of the mask.
25-
3) Map the input ndarray to its `slim` representation.
23+
1. If the input is a list, convert it to an ndarray.
24+
2. Check that the number of pixels in the array is identical to that of the mask.
25+
3. Map the input ndarray to its ``slim`` representation.
2626
27-
For a Grid2D, `slim` refers to a 2D NumPy array of shape [total_coordinates, 2] and `native` a 3D NumPy array of
28-
shape [total_y_coordinates, total_x_coordinates, 2]
27+
For a ``Grid1D``, ``slim`` refers to a 1D NumPy array of shape [total_unmasked_pixels] and ``native`` a 1D
28+
NumPy array of shape [total_pixels].
2929
3030
Parameters
3131
----------
32-
grid_2d
33-
The input (y,x) grid of coordinates which is converted to an ndarray if it is a list.
34-
mask_2d
35-
The mask of the output Array2D.
32+
grid_1d
33+
The input (x,) grid of coordinates which is converted to an ndarray if it is a list.
34+
mask_1d
35+
The mask of the output ``Grid1D``.
3636
store_native
37-
If True, the ndarray is stored in its native format [total_y_pixels, total_x_pixels, 2]. This avoids
38-
mapping large data arrays to and from the slim / native formats, which can be a computational bottleneck.
37+
If True, the ndarray is stored in its native format [total_pixels]. This avoids mapping large data arrays
38+
to and from the slim / native formats, which can be a computational bottleneck.
39+
xp
40+
The array module to use (default ``numpy``; pass ``jax.numpy`` for JAX support).
3941
"""
4042

4143
grid_1d = grid_2d_util.convert_grid(grid=grid_1d)
@@ -114,20 +116,20 @@ def grid_1d_slim_via_mask_from(
114116
A 1D array of bools, where `False` values are unmasked and therefore included as part of the calculated
115117
grid.
116118
pixel_scales
117-
The (x) scaled units to pixel units conversion factor of the 2D mask array.
119+
The (x,) scaled units to pixel units conversion factor of the 1D mask array.
118120
origin
119-
The (x) origin of the 2D array, which the grid is shifted around.
121+
The (x,) origin of the 1D array, which the grid is shifted around.
120122
121123
Returns
122124
-------
123125
ndarray
124-
A grid of (x) scaled coordinates at the centre of every pixel unmasked pixel on the 2D mask
126+
A grid of (x) scaled coordinates at the centre of every unmasked pixel in the 1D mask
125127
array. The grid array has dimensions (total_unmasked_pixels, ).
126128
127129
Examples
128130
--------
129131
mask = np.array([True, False, True, False, False, False])
130-
grid_slim = grid_1d_via_mask_from(mask_1d=mask_1d, pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))
132+
grid_slim = grid_1d_slim_via_mask_from(mask_1d=mask, pixel_scales=(0.5,), origin=(0.0,))
131133
"""
132134
centres_scaled = geometry_util.central_scaled_coordinate_1d_from(
133135
shape_slim=mask_1d.shape, pixel_scales=pixel_scales, origin=origin

0 commit comments

Comments
 (0)