You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/explaining_ndcube/arithmetic.rst
+44-27Lines changed: 44 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,14 @@ Arithmetic Operations
5
5
*********************
6
6
7
7
Arithmetic operations are a crucial tool in n-dimensional data analysis.
8
-
Applications include subtracting a background from a 1-D timeseries or spectrum, scaling an image by a vignetting function, any many others.
8
+
Applications include subtracting a background from a 1-D timeseries or spectrum, scaling an image by a vignetting function, and many others.
9
9
To aid with such workflows, `~ndcube.NDCube` supports addition, subtraction, multiplication, and division with numbers, arrays, `~astropy.units.Quantity`.
10
10
Raising an `~ndcube.NDCube` to a power is also supported.
11
-
These operations return a new `~ndcube.NDCube` with the data array (and where appropriate, the uncertainties) altered in accordance with the arithmetic operation.
11
+
These operations return a new `~ndcube.NDCube` with the data array (and, where appropriate, the uncertainties) altered in accordance with the arithmetic operation.
12
12
Other attributes of the `~ndcube.NDCube` remain unchanged.
13
13
14
-
In addition, combining `~ndcube.NDCube` with coordinate-less `~astropy.nddata.NDData` subclasses via these operations is important.
15
-
Such operations can be more complicated. Hence see the :ref:`arithmetic_nddata` section below for a discussion separate, more detailed discussion.
14
+
In addition, combining `~ndcube.NDCube` with coordinate-less `~astropy.nddata.NDData` subclasses via these operations is also supported.
15
+
Such operations can be more complicated. See the section below on :ref:`arithmetic_nddata` for a discussion separate, more detailed discussion.
16
16
17
17
.. _arithmetic_standard:
18
18
@@ -22,12 +22,12 @@ Standard Arithmetic Operations
22
22
Addition and Subtraction with Numbers, Arrays and Quantities
@@ -133,8 +141,10 @@ Multiplying and Dividing with Numbers, Arrays and Quantities
133
141
134
142
An `~ndcube.NDCube` can be multiplied and divided by numbers, arrays, and `~astropy.units.Quantity` via the ``*`` and ``-`` operators.
135
143
These work similarly to addition and subtraction with a few minor differences:
144
+
136
145
- The uncertainties of the resulting `~ndcube.NDCube` are scaled by the same factor as the data.
137
146
- Classes with different units can be combined.
147
+
138
148
* e.g. an `~ndcube.NDCube` with a unit of counts divided by an `~astropy.units.Quantity` with a unit is seconds will result in an `~ndcube.NDCube` with a unit of counts per second.
139
149
* This also holds for cases were unitful and unitless classes can be combined. In such cases, the unit of the resulting `~ndcube.NDCube` will be the same as that of the unitful object.
Sometimes more advanced arithmetic operations are required.
192
209
For example, we may want to create a sequence of running difference images which highlight changes between frames, and propagate the uncertainties associated with each image.
193
210
Alternatively, we may want to subtract one image from another, but exclude a certain region of the image with a mask.
194
211
In such cases, numbers, arrays and `~astropy.units.Quantity` are insufficient, and we would like to subtract two `~ndcube.NDCube` objects.
195
212
This is not directly supported, but can still be achieved in practice, as we shall see below.
196
213
197
-
Why Arithmetic Operations with Coordinate-aware NDData Instances Are Not Directly Supported, and How the Same Result Can Be Achieved
Arithmetic operations between two `~ndcube.NDCube` instances (or equivalently, an `~ndcube.NDCube` and another coordinate-aware object) are not supported because of the possibility of supporting non-sensical operations.
201
218
For example, what does it mean to multiply a spectrum and an image in a coordinate-aware way?
@@ -211,8 +228,8 @@ In many cases, a simple solution would be to extract the data (an optionally the
211
228
.. expanding-code-block:: python
212
229
:summary: Expand to see definition of cube1 and cube2.
0 commit comments