Skip to content

Commit 161b3b7

Browse files
committed
Move to_nddata specific docs to to_nddata docstring
1 parent ad88129 commit 161b3b7

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

docs/explaining_ndcube/arithmetic.rst

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,7 @@ Raising NDCube to a Power
217217
>>> cube_with_unit.data
218218
array([[10, 11, 12],
219219
[13, 14, 15]])
220-
221-
>>> import warnings
222-
>>> with warnings.catch_warnings():
223-
... warnings.simplefilter("ignore") # Catching warnings not needed but keeps docs cleaner.
224-
...
225-
... new_cube = cube_with_unit**2
226-
220+
>>> new_cube = cube_with_unit**2
227221
>>> new_cube.data
228222
array([[100, 121, 144],
229223
[169, 196, 225]])
@@ -303,29 +297,9 @@ Therefore, arithmetic operations between `~ndcube.NDCube` instances via:
303297
304298
where addition, subtraction, multiplication and division are all enabled by the ``+``, ``-``, ``*``, and ``/`` operators, respectively.
305299

306-
Note that `~ndcube.NDCube` attributes not supported by the constructor of the output type employed by `ndcube.NDCube.to_nddata` are dropped by the conversion.
307-
Therefore, since `ndcube.NDCube.to_nddata` converts to `~astropy.nddata.NDData` by default, there was no need in the above example to explicitly set `~ndcube.NDCube.extra_coords` and `~ndcube.NDCube.global_coords` to ``None``.
308-
Note that the output type of `ndcube.NDCube.to_nddata` can be controlled via the ``nddata_type`` kwarg.
309-
For example:
310-
311-
>>> from astropy.nddata import NDDataRef
312-
>>> nddataref2 = cube2.to_nddata(wcs=None, nddata_type=NDDataRef)
313-
>>> print(type(nddataref2) is NDDataRef)
314-
True
315-
316300
Requiring users to explicitly remove coordinate-awareness makes it clear that coordinates are not combined as part of arithmetic operations.
317301
It also makes it unambiguous which operand's coordinates are maintained through the operation.
318302

319-
`ndcube.NDCube.to_nddata` is not limited to changing/removing the WCS.
320-
The value of any input supported by the ``nddata_type``'s constructor can be altered by setting a kwarg for that input, e.g.:
321-
322-
.. code-block:: python
323-
324-
>>> nddata_ones = cube2.to_nddata(data=np.ones(cube2.data.shape))
325-
>>> nddata_ones.data
326-
array([[1., 1., 1.],
327-
[1., 1., 1.]])
328-
329303
Handling of Data, Units and Meta
330304
""""""""""""""""""""""""""""""""
331305
The treatment of the ``data`` and ``unit`` attributes in operations between `~ndcube.NDCube` and coordinate-less `~astropy.nddata.NDData` subclasses are the same as for arrays and `~astropy.units.Quantity`.

ndcube/ndcube.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,21 @@ def to_nddata(self,
15591559
an `~ndcube.NDCube` (called ``cube``) without an uncertainty,
15601560
but with ``global_coords`` and ``extra_coords`` do::
15611561
1562-
>>> nddata_without_coords = cube.to_nddata(uncertainty=None, global_coords=True, extra_coords=True) # doctest: +SKIP
1562+
>>> nddata_without_coords = cube.to_nddata(uncertainty=None, global_coords="copy", extra_coords="copy") # doctest: +SKIP
1563+
1564+
To create a different type of ``NDData`` object do::
1565+
1566+
>>> from astropy.nddata import NDDataRef
1567+
>>> nddataref2 = cube2.to_nddata(wcs=None, nddata_type=NDDataRef)
1568+
1569+
The value of any input supported by the ``nddata_type``'s
1570+
constructor can be altered by setting a kwarg for that input,
1571+
e.g.::
1572+
1573+
>>> nddata_ones = cube2.to_nddata(data=np.ones(cube2.data.shape))
1574+
>>> nddata_ones.data
1575+
array([[1., 1., 1.],
1576+
[1., 1., 1.]])
15631577
"""
15641578
# Put all NDData kwargs in a dict
15651579
user_kwargs = {"data": data,

0 commit comments

Comments
 (0)