Skip to content

Commit fd0c44f

Browse files
nstarmaneerovaher
andcommitted
docs, changelog, and whatsnew
Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com> Co-authored-by: Eero Vaher <eero.vaher@gmail.com>
1 parent f514cf8 commit fd0c44f

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added argument ``rename`` to Cosmology's I/O, allowing for input and output symbols to
2+
be renamed.

‎docs/cosmology/io.rst‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,37 @@ Like for the other formats, the |Planck18| cosmology can be recovered with
203203
|Cosmology.from_format|.
204204

205205

206+
.. _cosmology_io_renaming_fields:
207+
208+
Renaming Fields
209+
===============
210+
211+
Many I/O methods in :mod:`~astropy.cosmology` support renaming fields of the
212+
|Cosmology| class when converting to a different format. This is done by
213+
passing a ``rename`` dictionary to the ``to_format`` method.
214+
Similarly, when converting from a different format, a ``rename`` dictionary
215+
can be passed to the ``from_format`` method, mapping the fields of the input
216+
to the fields of the |Cosmology| class.
217+
218+
For example, to rename the ``H0`` field to ``Hubble`` when converting to a table
219+
format::
220+
221+
>>> from astropy.cosmology import Planck18
222+
>>> renamed_table = Planck18.to_format("astropy.table", rename={"H0": "Hubble"})
223+
>>> renamed_table
224+
<QTable length=1>
225+
name Hubble Om0 Tcmb0 Neff m_nu Ob0
226+
km / (Mpc s) K eV
227+
str8 float64 float64 float64 float64 float64[3] float64
228+
-------- ------------ ------- ------- ------- ----------- -------
229+
Planck18 67.66 0.30966 2.7255 3.046 0.0 .. 0.06 0.04897
230+
231+
>>> cosmo = Cosmology.from_format(renamed_table, format="astropy.table",
232+
... rename={"Hubble": "H0"})
233+
>>> cosmo == Planck18
234+
True
235+
236+
206237
.. _custom_cosmology_converters:
207238

208239
Custom Cosmology To/From Formats

‎docs/whatsnew/6.0.rst‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ See :ref:`astropy-coordinates-create-geodetic` for more details.
5555
Updates to `~astropy.cosmology`
5656
===============================
5757

58+
Writing to LaTeX
59+
----------------
60+
5861
The :class:`~astropy.cosmology.Cosmology` class in :mod:`~astropy.cosmology` now
5962
supports the latex format in its :attr:`~astropy.cosmology.Cosmology.write()`
6063
method, allowing users to export a cosmology object to a LaTeX table.::
@@ -65,6 +68,37 @@ method, allowing users to export a cosmology object to a LaTeX table.::
6568
This will write the cosmology object to a file in LaTeX format,
6669
with appropriate formatting of units and table alignment.
6770

71+
Renaming fields in I/O
72+
----------------------
73+
74+
Most I/O methods in :mod:`~astropy.cosmology` (accessed by
75+
:meth:`~astropy.cosmology.Cosmology.read`,
76+
:meth:`~astropy.cosmology.Cosmology.write`,
77+
:meth:`~astropy.cosmology.Cosmology.from_format`,
78+
:meth:`~astropy.cosmology.Cosmology.to_format`) now support
79+
:ref:`renaming fields<cosmology_io_renaming_fields>`.
80+
81+
For example, to rename the ``H0`` field to ``Hubble`` when converting to a table
82+
format::
83+
84+
>>> from astropy.cosmology import Planck18
85+
>>> Planck18.to_format("astropy.table") # No renaming
86+
<QTable length=1>
87+
name H0 Om0 Tcmb0 Neff m_nu Ob0
88+
km / (Mpc s) K eV
89+
str8 float64 float64 float64 float64 float64[3] float64
90+
-------- ------------ ------- ------- ------- ----------- -------
91+
Planck18 67.66 0.30966 2.7255 3.046 0.0 .. 0.06 0.04897
92+
93+
>>> Planck18.to_format("astropy.table", rename={"H0": "Hubble"})
94+
<QTable length=1>
95+
name Hubble Om0 Tcmb0 Neff m_nu Ob0
96+
km / (Mpc s) K eV
97+
str8 float64 float64 float64 float64 float64[3] float64
98+
-------- ------------ ------- ------- ------- ----------- -------
99+
Planck18 67.66 0.30966 2.7255 3.046 0.0 .. 0.06 0.04897
100+
101+
68102
Full change log
69103
===============
70104

0 commit comments

Comments
 (0)