@@ -32,16 +32,27 @@ def convert_shape_native_1d(shape_native: Union[int, Tuple[int]]) -> Tuple[int]:
3232
3333def convert_pixel_scales_1d (pixel_scales : ty .PixelScales ) -> Tuple [float ]:
3434 """
35- Convert an input pixel scale of type `float` to a tuple `(float,)`. If the input is already a
36- `(float,)` tuple it is returned unchanged.
35+ Convert an input pixel scale given as a single real scalar to a tuple `(float,)`. If the
36+ input is already a `(float,)` tuple it is returned unchanged.
3737
38- This enables users to input the pixel scale as a single float and have the type automatically
39- normalised to `(float,)` which is used internally by 1D data structures.
38+ This enables users to input the pixel scale as a single number and have the type
39+ automatically normalised to `(float,)` which is used internally by 1D data structures.
40+
41+ Any concrete real scalar is widened — `int`, `float`, `np.integer` and `np.floating` — not
42+ just an exact `float`. An `int` is a natural thing to type by hand, and an `np.floating` is
43+ what indexing a numpy array or reading a FITS header returns, so both reach this function on
44+ paths a user would consider ordinary. The widened value is cast to a Python `float`, so the
45+ tuple this returns is always `(float,)` regardless of what went in.
46+
47+ A `bool` is deliberately *not* treated as a scalar here (see
48+ :func:`autoarray.validate.is_concrete_scalar`), and neither is a JAX tracer — a traced value
49+ passes through untouched so the function stays safe inside a `jax.jit`.
4050
4151 Parameters
4252 ----------
4353 pixel_scales
44- The pixel scale to convert, either as a plain `float` or a 1-element tuple `(float,)`.
54+ The pixel scale to convert, either as a plain real scalar or a 1-element tuple
55+ `(float,)`.
4556
4657 Returns
4758 -------
@@ -56,8 +67,8 @@ def convert_pixel_scales_1d(pixel_scales: ty.PixelScales) -> Tuple[float]:
5667
5768 validate .validate_pixel_scales (pixel_scales = pixel_scales )
5869
59- if type (pixel_scales ) is float :
60- pixel_scales = (pixel_scales ,)
70+ if validate . is_concrete_scalar (pixel_scales ):
71+ pixel_scales = (float ( pixel_scales ) ,)
6172
6273 return pixel_scales
6374
@@ -197,17 +208,28 @@ def scaled_coordinates_1d_from(
197208
198209def convert_pixel_scales_2d (pixel_scales : ty .PixelScales ) -> Tuple [float , float ]:
199210 """
200- Convert an input pixel scale of type `float` to a tuple `(float, float)`. If the input is
201- already type `(float, float)` it is returned unchanged.
211+ Convert an input pixel scale given as a single real scalar to a tuple `(float, float)`. If
212+ the input is already type `(float, float)` it is returned unchanged.
213+
214+ This enables users to input the pixel scale as a single number and have the type
215+ automatically normalised to `(float, float)` which is used internally for rectangular 2D
216+ grids (where both axes share the same pixel scale).
217+
218+ Any concrete real scalar is widened — `int`, `float`, `np.integer` and `np.floating` — not
219+ just an exact `float`. An `int` is a natural thing to type by hand, and an `np.floating` is
220+ what indexing a numpy array or reading a FITS header returns, so both reach this function on
221+ paths a user would consider ordinary. The widened value is cast to a Python `float`, so the
222+ tuple this returns is always `(float, float)` regardless of what went in.
202223
203- This enables users to input the pixel scale as a single float and have the type automatically
204- normalised to `(float, float)` which is used internally for rectangular 2D grids (where
205- both axes share the same pixel scale) .
224+ A `bool` is deliberately *not* treated as a scalar here (see
225+ :func:`autoarray.validate.is_concrete_scalar`), and neither is a JAX tracer — a traced value
226+ passes through untouched so the function stays safe inside a `jax.jit` .
206227
207228 Parameters
208229 ----------
209230 pixel_scales
210- The pixel scale to convert, either as a plain `float` or a 2-element tuple `(float, float)`.
231+ The pixel scale to convert, either as a plain real scalar or a 2-element tuple
232+ `(float, float)`.
211233
212234 Returns
213235 -------
@@ -228,8 +250,8 @@ def convert_pixel_scales_2d(pixel_scales: ty.PixelScales) -> Tuple[float, float]
228250
229251 validate .validate_pixel_scales (pixel_scales = pixel_scales )
230252
231- if type (pixel_scales ) is float :
232- pixel_scales = (pixel_scales , pixel_scales )
253+ if validate . is_concrete_scalar (pixel_scales ):
254+ pixel_scales = (float ( pixel_scales ), float ( pixel_scales ) )
233255
234256 return pixel_scales
235257
0 commit comments