Skip to content

Commit

Permalink
Some docs bugfixes relating to NDMeta.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRyanIrish committed Jul 21, 2024
1 parent a58c705 commit 944b0df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
14 changes: 7 additions & 7 deletions docs/explaining_ndcube/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ We can now access each piece of metadata by indexing ``meta`` as if it were a `d
.. code-block:: python
>>> meta["name"]
"world"
'world'
In this example we have provided a very simple set of metadata.
In fact, it is so simple that there is no practical difference between ``meta`` and a simple `dict`.
Expand All @@ -108,7 +108,7 @@ We can now access the comments by indexing the `~ndcube.NDMeta.key_comments` pro
.. code-block:: python
>>> meta.key_comments["name"]
"Each planet in the solar system has a name."
'Each planet in the solar system has a name.'
Now let's discuss how to initialize how to `~ndcube.NDMeta` with axis-aware metadata.
(Here, we will specifically consider grid-aligned metadata. Axis-aligned metadata is assigned in the same way. But see the :ref:`assigning_axis_aligned_metadata` section for more details.)
Expand All @@ -132,9 +132,9 @@ It is easy to see which axes a piece of metadata corresponds to by indexing the
.. code-block:: python
>>> meta.axes["exposure time"]
(0,)
array([0])
>>> meta.axes["pixel response"]
(0, 2)
array([0, 2])
Finally, it is possible to attach the shape of the associated data to the `~ndcube.NDMeta` instance via the ``data_shape`` kwarg:

Expand Down Expand Up @@ -186,17 +186,17 @@ Unwanted metadata can be removing by employing the `del` operator.
>>> del meta["voltage"]
>>> meta.get("voltage", "deleted")
"deleted"
'deleted'
Note that the `del` operator also removes associated comments and axes.

.. code-block:: python
>>> del meta["voltage"]
>>> meta.key_comments.get("voltage", "deleted")
"deleted"
'deleted'
>>> meta.axes.get("voltage", "deleted")
"deleted"
'deleted'
Data Shape
----------
Expand Down
16 changes: 8 additions & 8 deletions docs/explaining_ndcube/slicing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ Therefore, slicing is achieved by applying Python's slicing API to `~ndcube.NDMe
>>> from ndcube import NDMeta
>>> raw_meta = {"salutation": "hello", "name": "world",
... "exposure time": u.Quantity([2] * 4, unit=u.s),
... "pixel response", np.ones((4, 5))}
... "pixel response": np.ones((4, 5))}
>>> axes = {"exposure time": 0, "pixel response": (1, 2)}
>>> meta = NDMeta(raw_meta, axes=axes, data_shape=(4, 4, 5))
Expand Down Expand Up @@ -466,16 +466,16 @@ Moreover, because the first axis has been sliced away, ``"exposure time"`` is no
.. code-block:: python
>>> list(sliced_meta.axes.keys())
["pixel response"]
['pixel response']
Finally, note that axis-agnostic metadata is unaltered by the slicing process.

.. code-block:: python
>>> sliced_meta["salultation"]
"hello"
>>> sliced_meta["salutation"]
'hello'
>>> sliced_meta["name"]
"world"
'world'
Automatically Slicing NDMeta Attached to Other ND Objects
Expand Down Expand Up @@ -518,8 +518,8 @@ In fact, ``sliced_cube.meta`` is equivalent to ``sliced_meta`` from the previous
>>> sliced_cube.meta["exposure time"]
<Quantity 2. s>
>>> list(sliced_cube.meta.axes.keys())
["pixel response"]
['pixel response']
>>> sliced_cube.meta["salultation"]
"hello"
'hello'
>>> sliced_cube.meta["name"]
"world"
'world'
2 changes: 1 addition & 1 deletion ndcube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
from .ndcube_sequence import NDCubeSequence, NDCubeSequenceBase
from .version import version as __version__

__all__ = ['NDCube', 'NDCubeSequence', "Meta", "NDCollection", "ExtraCoords", "GlobalCoords", "ExtraCoordsABC", "GlobalCoordsABC", "NDCubeBase", "NDCubeSequenceBase", "__version__"]
__all__ = ['NDCube', 'NDCubeSequence', "NDCollection", "NDMeta", "ExtraCoords", "GlobalCoords", "ExtraCoordsABC", "GlobalCoordsABC", "NDCubeBase", "NDCubeSequenceBase", "__version__"]

0 comments on commit 944b0df

Please sign in to comment.