Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dmentipl committed Mar 11, 2020
1 parent 3989b69 commit 1e3763e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 53 deletions.
26 changes: 16 additions & 10 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Rotate a snapshot and plot column density.
>>> plonk.visualize.plot(
... snap=snap,
... quantity='density',
... extent=(-200, 200, -200, 200)
... extent=(-150, 150, -150, 150),
... cmap='gist_heat',
... )
>>> plt.show()
Expand All @@ -58,6 +59,7 @@ Plot cross section at z=0.
... interp='cross_section',
... z_slice=0.0,
... extent=(-150, 150, -150, 150),
... cmap='gist_heat',
... )
>>> plt.show()
Expand Down Expand Up @@ -85,14 +87,14 @@ Plot dust and gas side-by-side.
# Make plot
>>> fig, axes = plt.subplots(ncols=2, sharey=True, figsize=(12, 5))
>>> plonk.visualize.plot(
... gas,
... snap=gas,
... quantity='density',
... extent=extent,
... cmap='Blues_r',
... axis=axes[0],
... )
>>> plonk.visualize.plot(
... dust,
... snap=dust,
... quantity='density',
... extent=extent,
... cmap='Reds_r',
Expand All @@ -113,7 +115,6 @@ Plot mass accretion and accretion rate onto sink particles.
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> import plonk
>>> from astropy import constants
# Set Seaborn plot style
>>> plt.style.use('seaborn')
Expand All @@ -128,7 +129,8 @@ Plot mass accretion and accretion rate onto sink particles.
# Loop over sinks and plot
>>> for idx, sink in enumerate(sim.sink_quantities):
... time = sink.data['time'] / (2 * np.pi)
... macc = (constants.M_sun / constants.M_earth) * sink.data['macc']
... macc = sink.data['macc'].to_numpy()
... macc = (plonk.units('solar_mass') * macc).to('earth_mass').magnitude
... sink.data['mdot'] = np.gradient(macc, time)
... mdot = sink.data['mdot'].rolling(window=100).mean()
... ax[0].plot(time, macc, label=f'{sink_labels[idx]}')
Expand Down Expand Up @@ -166,12 +168,16 @@ Plot a density profile for multiple snapshots.
>>> times = list()
>>> profiles = list()
>>> for snap in sim.snaps[::7]:
... time = (snap.properties['time'] * snap.properties['utime']).to('year').magnitude
... snap.physical_units()
... time = (snap.properties['time'] * snap.units['time']).to('year').magnitude
... times.append(time)
... profile = plonk.Profile(snap, radius_min=10, radius_max=150, n_bins=200)
... profile['density'] = (
... profile['density'] * snap.properties['umass'] / snap.properties['udist'] ** 2
... ).magnitude
... profile = plonk.Profile(
... snap,
... radius_min=plonk.Quantity('10 au'),
... radius_max=plonk.units('150 au'),
... n_bins=200
... )
... _ = profile['density']
... profiles.append(profile)
# Plot profiles
Expand Down
99 changes: 57 additions & 42 deletions docs/source/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,24 @@ To see what arrays are loaded into memory you can use the
.. code-block:: pycon
>>> snap.loaded_arrays()
('position', 'type')
('position',)
Use :py:meth:`available_arrays` to see what arrays are available.

.. code-block:: pycon
>>> snap.available_arrays()
('density',
'divv',
'dt',
'dust_type',
'dustfrac',
'mass',
'position',
'smooth',
'tstop',
'type',
'velocity')
'divv',
'dt',
'dust_type',
'dustfrac',
'mass',
'position',
'smooth',
'tstop',
'type',
'velocity')
You can also define your own alias to access arrays. For example, if you prefer
to use the name `'coordinate'` rather than `'position',` use the
Expand Down Expand Up @@ -134,24 +134,29 @@ dictionary of metadata, i.e. non-array data, on the snapshot.
>>> list(snap.properties)
['time',
'udist',
'utime',
'umass',
'hfact',
'ieos',
'gamma',
'polyk',
'qfacdisc',
'grain size',
'grain density']
'hfact',
'ieos',
'gamma',
'polyk',
'qfacdisc',
'grain size',
'grain density']
Units are available vis the :py:attr:`units` attribute. We make use of the
Python units library Pint.

.. code-block:: pycon
>>> snap.units['length']
14960000000000.0 <Unit('centimeter')>
Sink particles are handled separately from the fluid, e.g. gas or dust,
particles. They are available as an attribute.

.. code-block:: pycon
>>> snap.sinks
<plonk.snap.Sinks>
<plonk.snap sinks>
>>> snap.sinks['spin']
array([[ 4.02648711e-10, -1.33037173e-09, 2.75977043e-06],
Expand Down Expand Up @@ -267,7 +272,7 @@ plot of column density, i.e. a projection plot.
>>> viz = plonk.visualize.plot(
... snap=snap,
... quantity='density',
... extent=(-150, 150, -150, 150)
... extent=(-150, 150, -150, 150),
... )
.. figure:: _static/density.png
Expand All @@ -283,21 +288,21 @@ limits of the colorbar.
>>> viz.objects['image'].set_clim(vmin=0.5e-8, vmax=1.5e-8)
Extra options can be passed in as keywords. For example, we can change the
colormap.
Alternatively, you can pass keyword arguments to the matplotlib functions. For
example, we set the colormap to 'gist_heat' and set the colorbar minimum and
maxiumum.

.. code-block:: pycon
>>> viz = plonk.visualize.plot(
... sim.snaps[-5],
... snap=snap,
... quantity='density',
... cmap='viridis',
... extent=(-150, 150, -150, 150),
... cmap='gist_heat',
... vmin=0.5e-8,
... vmax=1.5e-8,
... )
.. figure:: _static/polar.png

The column density in polar coordinates.

More fine-grained control can be achieved by using the full details of
:py:func:`visualize.plot`. See the API for more details.

Expand Down Expand Up @@ -346,7 +351,11 @@ Let's plot the gas and dust side-by-side.
>>> for subsnap, axis in zip(subsnaps, axes):
... plonk.visualize.plot(
... subsnap, quantity='density', extent=extent, axis=axis
... snap=subsnap,
... quantity='density',
... extent=extent,
... cmap='gist_heat',
... axis=axis,
... )
.. figure:: _static/dust-gas.png
Expand Down Expand Up @@ -406,19 +415,25 @@ To see what profiles are loaded and what are available use the
.. code-block:: pycon
>>> prof.loaded_keys()
('number', 'radius')
('number', 'radius', 'size')
>>> prof.available_keys()
('angmom_mag',
'angmom_phi',
'angmom_theta',
'density',
'eccentricity',
'mass',
'number',
'radius',
'scale_height',
'smooth')
'angmom_phi',
'angmom_theta',
'angmom_x',
'angmom_y',
'angmom_z',
'aspect_ratio',
'density',
'eccentricity',
'mass',
'number',
'radius',
'scale_height',
'size',
'smooth')
To load a profile, simply call it.

Expand Down
3 changes: 2 additions & 1 deletion docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ Produce a projection rendering of density.
>>> viz = plonk.visualize.plot(
... snap=snap,
... quantity='density',
... extent=(-150, 150, -150, 150)
... extent=(-150, 150, -150, 150),
... cmap='gist_heat',
... )
.. image:: _static/density.png
Expand Down
8 changes: 8 additions & 0 deletions plonk/snap/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def __init__(self, fn):
def __getitem__(self, inp):
return self.fn(inp, sinks=True)

def __repr__(self):
"""Dunder repr method."""
return self.__str__()

def __str__(self):
"""Dunder str method."""
return f'<plonk.snap sinks>'


class Snap:
"""Smoothed particle hydrodynamics Snap object.
Expand Down

0 comments on commit 1e3763e

Please sign in to comment.