[yt-svn] commit/yt: xarthisius: Merged in nmearl/yt (pull request #1668)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Sep 14 20:54:56 PDT 2015
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/4979406431c6/
Changeset: 4979406431c6
Branch: yt
User: xarthisius
Date: 2015-09-15 03:54:46+00:00
Summary: Merged in nmearl/yt (pull request #1668)
Fixing Tipsy frontend
Affected #: 2 files
diff -r 43e11e9fc943815fd62611e5a0626a27982e24db -r 4979406431c662b038db914287ae227092199b78 doc/source/examining/loading_data.rst
--- a/doc/source/examining/loading_data.rst
+++ b/doc/source/examining/loading_data.rst
@@ -1257,8 +1257,8 @@
.. _specifying-cosmology-tipsy:
-Specifying Tipsy Cosmological Parameters
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Specifying Tipsy Cosmological Parameters and Setting Default Units
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Cosmological parameters can be specified to Tipsy to enable computation of
default units. The parameters recognized are of this form:
@@ -1270,5 +1270,27 @@
'omega_matter': 0.272,
'hubble_constant': 0.702}
-These will be used set the units, if they are specified.
+If you wish to set the default units directly, you can do so by using the
+``unit_base`` keyword in the load statement.
+ .. code-block:: python
+
+ import yt
+ ds = yt.load(filename, unit_base={'length', (1.0, 'Mpc')})
+
+
+Loading Cosmological Simulations
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+If you are not using a parameter file (i.e. non-Gasoline users), then you must
+use keyword ``cosmology_parameters`` when loading your data set to indicate to
+yt that it is a cosmological data set. If you do not wish to set any
+non-default cosmological parameters, you may pass an empty dictionary.
+
+ .. code-block:: python
+
+ import yt
+ ds = yt.load(filename, cosmology_parameters={})
+
+
+
diff -r 43e11e9fc943815fd62611e5a0626a27982e24db -r 4979406431c662b038db914287ae227092199b78 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -32,6 +32,7 @@
from yt.utilities.physical_constants import \
G, \
cm_per_kpc
+from yt import YTQuantity
from .fields import \
TipsyFieldInfo
@@ -167,9 +168,9 @@
self.domain_dimensions = np.ones(3, "int32") * nz
periodic = self.parameters.get('bPeriodic', True)
period = self.parameters.get('dPeriod', None)
- comoving = self.parameters.get('bComove', False)
self.periodicity = (periodic, periodic, periodic)
- if comoving and period is None:
+ self.comoving = self.parameters.get('bComove', False)
+ if self.comoving and period is None:
period = 1.0
if self.bounding_box is None:
if periodic and period is not None:
@@ -186,7 +187,9 @@
self.domain_left_edge = bbox[:,0]
self.domain_right_edge = bbox[:,1]
- if comoving:
+ # If the cosmology parameters dictionary got set when data is
+ # loaded, we can assume it's a cosmological data set
+ if self.comoving or self._cosmology_parameters is not None:
cosm = self._cosmology_parameters or {}
self.scale_factor = hvals["time"]#In comoving simulations, time stores the scale factor a
self.cosmological_simulation = 1
@@ -224,8 +227,15 @@
self.length_unit = self.quan(lu, 'kpc')*self.scale_factor
self.mass_unit = self.quan(mu, 'Msun')
density_unit = self.mass_unit/ (self.length_unit/self.scale_factor)**3
- # Gasoline's hubble constant, dHubble0, is stored units of proper code time.
- self.hubble_constant *= np.sqrt(G.in_units('kpc**3*Msun**-1*s**-2')*density_unit).value/(3.2407793e-18)
+
+ # If self.comoving is set, we know this is a gasoline data set,
+ # and we do the conversion on the hubble constant.
+ if self.comoving:
+ # Gasoline's hubble constant, dHubble0, is stored units of
+ # proper code time.
+ self.hubble_constant *= np.sqrt(G.in_units(
+ 'kpc**3*Msun**-1*s**-2') * density_unit).value / (
+ 3.2407793e-18)
cosmo = Cosmology(self.hubble_constant,
self.omega_matter, self.omega_lambda)
self.current_time = cosmo.hubble_time(self.current_redshift)
@@ -237,6 +247,24 @@
density_unit = self.mass_unit / self.length_unit**3
self.time_unit = 1.0 / np.sqrt(G * density_unit)
+ # If unit base is defined by the user, override all relevant units
+ if self._unit_base is not None:
+ length = self._unit_base.get('length', self.length_unit)
+ length = self.quan(*length) if isinstance(length, tuple) else self.quan(length)
+ self.length_unit = length
+
+ mass = self._unit_base.get('mass', self.mass_unit)
+ mass = self.quan(*mass) if isinstance(mass, tuple) else self.quan(mass)
+ self.mass_unit = mass
+
+ density_unit = self.mass_unit / self.length_unit**3
+ self.time_unit = 1.0 / np.sqrt(G * density_unit)
+
+ time = self._unit_base.get('time', self.time_unit)
+ time = self.quan(*time) if isinstance(time, tuple) else self.quan(time)
+ self.time_unit = time
+
+
@staticmethod
def _validate_header(filename):
'''
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list