Skip to content

Commit 0d28624

Browse files
author
Martin D. Weinberg
committed
A few more minor changes for readability
1 parent 8584d4c commit 0d28624

File tree

2 files changed

+61
-26
lines changed

2 files changed

+61
-26
lines changed

intro/overview.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ Here's the code for computing coefficients::
9696
#
9797
coef = basis.createFromArray(data[:,0], data[:,1:4], time=3.0)
9898

99+
# Add your simulation units (we assume a unit-free simulation here)
100+
#
101+
coef.setUnits([('mass', 'none', 1.0), ('length', 'none', 1.0),
102+
('time', 'none', 1.0), ('G', 'none', 1.0)])
103+
99104
# Make an HDF5 file
100105
#
101106
coefs = pyEXP.coefs.Coefs.makecoefs(coef)
@@ -144,6 +149,11 @@ More detailed information on YAML and config parameters is available
144149
in the :ref:`What is YAML?<yamlconfig>` and :ref:`How to visualize the
145150
BFE bases used to make your coefficients<visualizing-bases>` pages.
146151

152+
The unit system in EXP is described in more detail in :ref:`Units in
153+
EXP and pyEXP<units>`. For this example, we assume a unit-free
154+
simulation but it's easy to add any unit system that is convenient for
155+
you.
156+
147157
pyEXP is then ready to make the coefficients from your phase-space
148158
data. This example assumes that the mass and positions of your
149159
particles are in columns 1, 2, 3, 4 of the file and that the positions

topics/units.rst

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. role:: python(code)
2+
:language: python
3+
:class: highlight
4+
15
.. _units:
26

37
Units in EXP and pyEXP
@@ -6,23 +10,26 @@ Units in EXP and pyEXP
610
Overview
711
--------
812

9-
The EXP N-body code assumes the gravitational constant is unity,
10-
``G=1``, and that mass, position and velocity units can have any
11-
value defined by the user. In other words, EXP does not enforce any
12-
particular unit set.
13+
The EXP N-body code assumes the gravitational constant is unity and
14+
that mass, position and velocity units can have any value defined by
15+
the user. In other words, the EXP N-body code does not enforce any
16+
particular unit set consistent with ``G=1``.
1317

1418
pyEXP will also accept mass, position, time, and velocity with any
1519
unit set defined by the imported simulation as well as an arbitrary
1620
value of the gravitational constant. Explicit units types and the
1721
gravitational constant ``G`` may be set at construction time as we
1822
will describe below in :ref:`unit-schema`. pyEXP **requires** the
1923
user to set units explicitly when coefficient sets are
20-
constructed. See :ref:`intro-pyEXP-tutorial`. There is no default.
24+
constructed. There is no default. See :ref:`intro-pyEXP-tutorial` for
25+
an end-to-end example of coefficient computation.
2126

2227
All unit information is written into the EXP coefficient files as HDF5
23-
attributes. Also see :ref:`hdf5-unit-attributes` for details.
28+
attributes. Also see :ref:`hdf5-unit-attributes` for details. You
29+
may add units to previously computed coefficient files using the
30+
script described in :ref:`units_old`.
2431

25-
.. _unit-scheme:
32+
.. _unit-schema:
2633

2734
The EXP unit schema
2835
-------------------
@@ -34,7 +41,12 @@ EXP requires one of the following two sequences of 4 unit types:
3441
2. Mass, Length, Velocity, gravitational constant (G)
3542

3643

37-
Each unit is a ``tuple`` which takes the form::
44+
Other combinations are possible in principle, such as Mass, Length,
45+
Velocity and Time. However, this would require an automatic deduction
46+
of the gravitational constant. EXP does not current know about
47+
physical unit conversion. This feature may be added in the future.
48+
49+
Each separate unit is defined as a ``tuple`` which takes the form::
3850

3951
('unit type', 'unit name', <float value>)
4052

@@ -57,8 +69,8 @@ The type and name strings are checked against the allowed values as follows:
5769
The value can be any valid floating-point number.
5870

5971
The allowed types and names may be queried interactively in pyEXP
60-
using the ``getAllowedUnitTypes()`` and
61-
``getAllowedUnitNames(type)``, see :ref:`units-interface`. For
72+
using the :python:`getAllowedUnitTypes()` and
73+
:python:`getAllowedUnitNames(type)`, see :ref:`units-interface`. For
6274
development reference, these allowed strings are defined in
6375
``expui/UnitValidator.cc`` in the EXP source tree.
6476

@@ -67,13 +79,14 @@ As an example, a Gadget user might define mass units as::
6779
('mass', 'Msun', 1.0e10)
6880

6981
The full units specification is a list of tuples that includes one of
70-
the four sequences. In C++, the list is a ``std::vector`` of tuples.
82+
the four sequences. In C++, the list is a :cpp:any:`std::vector<>` of
83+
tuples.
7184

7285
As an example, all native EXP simulations have the following unit
73-
lists::
86+
lists:
7487

75-
[('mass', 'none', 1.0f), ('length', 'none', 1.0f), ('time', 'none',
76-
1.0f), ('G', 'none', 1.0f)]
88+
.. code-block:: python
89+
[('mass', 'none', 1.0f), ('length', 'none', 1.0f), ('time', 'none', 1.0f), ('G', 'none', 1.0f)]
7790
7891
7992
Units in pyEXP
@@ -119,24 +132,28 @@ is called ``coefs``. The following command will register the unit set:
119132
('velocity', 'km/s', 1.0), ('G', 'mixed', 43007.1) ])
120133
121134
These units will be in the HDF5 that you create using
122-
``coefs.WriteH5Coefs('filename')``. You can query, for example, the
123-
allowed 'mass' units with the call
124-
``coefs.getAllowedUnitNames('mass')`` which returns:
135+
:python:`coefs.WriteH5Coefs('filename')`. You can query, for example,
136+
the allowed 'mass' units with the call
137+
:python:`coefs.getAllowedUnitNames('mass')` which returns:
125138

126139
.. code-block:: python
127140
128141
['gram', 'earth_mass', 'solar_mass', 'kilograms', 'kg', 'g', 'Mearth', 'Msun', 'None', 'none']
129142
130-
A quick note: 'mixed' is an allowed alias when dealing with
131-
gravitational constants that have physical units. You can see all
132-
unit types with ``getAllowedUnitTypes()``; this returns ``['mass',
133-
'length', 'time', 'velocity', 'G']``. You can see the recognized
134-
aliases for each type using ``getAllowedTypeAliases(type)``. For
135-
example, the recognized aliases for 'G' are:
143+
The allowed mass units for 'G' are:
136144

137145
.. code-block:: python
138146
139-
['G', 'Grav', 'Grav_constant', 'Gravitational_constant', 'grav', 'grav_constant', 'gravitational_constant']
147+
['gram', 'earth_mass', 'solar_mass', 'kilograms', 'kg', 'g', 'Mearth', 'Msun', 'None', 'none']
148+
149+
150+
A quick note: 'mixed' is an allowed alias when dealing with
151+
gravitational constants that have physical units. You can see all
152+
unit types with :python:`getAllowedUnitTypes()`; this returns
153+
:python:`['mass', 'length', 'time', 'velocity', 'G']`. You can see
154+
the recognized aliases for each type using
155+
:python:`getAllowedTypeAliases(type)`. The gravitational constant is
156+
a special case. The recognized unit names for 'G' are: :python:`['','mixed', 'none', 'unitless']``.
140157

141158
The C++ UI echos the functions above and adds functions to retrieve
142159
units
@@ -167,8 +184,8 @@ developers creating new coefficient classes.
167184
The HDF5 specification
168185
----------------------
169186

170-
.. note:: This section assumes basic familiarity with HDF5 and `h5py`
171-
in particular.
187+
.. note:: This and the following sections assumes basic familiarity
188+
with HDF5 and `h5py` in particular.
172189

173190
EXP HDF5 coefficient files contain a full set of metadata describing
174191
their basis type, basis parameters, geometry, and units as attributes
@@ -226,6 +243,11 @@ group with the following hierarchy::
226243
}
227244
228245

246+
.. _units_old:
247+
248+
Backward compatibility
249+
----------------------
250+
229251
A units attribute list could be easily added to existing HDF5 files
230252
using `h5py` using the schema described above. For example, assuming
231253
that you already have an open HDF5 coefficient file named `f`, the
@@ -264,3 +286,6 @@ following code:
264286
265287
# File is automatically closed on leaving the 'with' block, flush and
266288
# update saved data on disk
289+
290+
You can update the :python:`data` array in the example above to match your
291+
unit set.

0 commit comments

Comments
 (0)