[yt-svn] commit/yt: 9 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Oct 22 02:34:46 PDT 2015
9 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/706d1fadc247/
Changeset: 706d1fadc247
Branch: yt
User: ngoldbaum
Date: 2015-10-06 04:04:54+00:00
Summary: Fix various issues with tipsy cosmological units
Affected #: 2 files
diff -r 6de676ee8923b1bf55cb5990452646f2b09addb8 -r 706d1fadc247ebc31b20777ed52d003675643af3 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -169,12 +169,14 @@
periodic = self.parameters.get('bPeriodic', True)
period = self.parameters.get('dPeriod', None)
self.periodicity = (periodic, periodic, periodic)
- self.comoving = self.parameters.get('bComove', False)
+ self.comoving = self.parameters.get(
+ 'bComove', self._cosmology_parameters is not None)
if self.comoving and period is None:
period = 1.0
if self.bounding_box is None:
if periodic and period is not None:
- # If we are periodic, that sets our domain width to either 1 or dPeriod.
+ # If we are periodic, that sets our domain width to
+ # either 1 or dPeriod.
self.domain_left_edge = np.zeros(3, "float64") - 0.5*period
self.domain_right_edge = np.zeros(3, "float64") + 0.5*period
else:
@@ -189,14 +191,19 @@
# 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:
+ if self.comoving is True:
cosm = self._cosmology_parameters or {}
- self.scale_factor = hvals["time"]#In comoving simulations, time stores the scale factor a
+ # In comoving simulations, time stores the scale factor a
+ self.scale_factor = hvals["time"]
self.cosmological_simulation = 1
- dcosm = dict(current_redshift=(1.0/self.scale_factor)-1.0,
- omega_lambda=self.parameters.get('dLambda', cosm.get('omega_lambda',0.0)),
- omega_matter=self.parameters.get('dOmega0', cosm.get('omega_matter',0.0)),
- hubble_constant=self.parameters.get('dHubble0', cosm.get('hubble_constant',1.0)))
+ dcosm = dict(
+ current_redshift=(1.0/self.scale_factor)-1.0,
+ omega_lambda=self.parameters.get(
+ 'dLambda', cosm.get('omega_lambda',0.0)),
+ omega_matter=self.parameters.get(
+ 'dOmega0', cosm.get('omega_matter',0.0)),
+ hubble_constant=self.parameters.get(
+ 'dHubble0', cosm.get('hubble_constant',1.0)))
for param in dcosm.keys():
pval = dcosm[param]
setattr(self, param, pval)
@@ -226,16 +233,8 @@
# In cosmological runs, lengths are stored as length*scale_factor
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
+ density_unit = self.mass_unit/(self.length_unit/self.scale_factor)**3
- # 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)
diff -r 6de676ee8923b1bf55cb5990452646f2b09addb8 -r 706d1fadc247ebc31b20777ed52d003675643af3 yt/frontends/tipsy/tests/test_outputs.py
--- a/yt/frontends/tipsy/tests/test_outputs.py
+++ b/yt/frontends/tipsy/tests/test_outputs.py
@@ -42,7 +42,7 @@
hubble_constant = 0.702)
kwargs = dict(field_dtypes = {"Coordinates": "d"},
cosmology_parameters = cosmology_parameters,
- unit_base = {'length': (1.0/60.0, "Mpccm/h")},
+ unit_base = {'length': (60.0, "Mpccm/h")},
n_ref = 64)
ds = data_dir_load(pkdgrav, TipsyDataset, (), kwargs)
yield assert_equal, str(ds), "halo1e11_run1.00400"
@@ -73,7 +73,7 @@
omega_matter = 0.272,
hubble_constant = 0.702)
kwargs = dict(cosmology_parameters = cosmology_parameters,
- unit_base = {'length': (1.0/60.0, "Mpccm/h")},
+ unit_base = {'length': (60.0, "Mpccm/h")},
n_ref = 64)
ds = data_dir_load(gasoline_dmonly, TipsyDataset, (), kwargs)
yield assert_equal, str(ds), "agora_1e11.00400"
https://bitbucket.org/yt_analysis/yt/commits/797fbe61a57f/
Changeset: 797fbe61a57f
Branch: yt
User: ngoldbaum
Date: 2015-10-06 04:27:43+00:00
Summary: If hubble constant comes from dHubble0, convert to units of 100 km/s/Mpc
Affected #: 1 file
diff -r 706d1fadc247ebc31b20777ed52d003675643af3 -r 797fbe61a57f212068668087388f6a9a0c804208 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -234,8 +234,13 @@
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
-
- cosmo = Cosmology(self.hubble_constant,
+ if 'dHubble0' in self.parameters:
+ # Gasoline's internal hubble constant, dHubble0, is stored in
+ # units of proper code time
+ self.hubble_constant *= np.sqrt(G * density_unit)
+ # Finally, we convert the hubble constant from Hz to 100 km/s/Mpc
+ self.hubble_constant /= self.quan(100, 'km/s/Mpc')
+ self.cosmo = Cosmology(self.hubble_constant,
self.omega_matter, self.omega_lambda)
self.current_time = cosmo.hubble_time(self.current_redshift)
else:
https://bitbucket.org/yt_analysis/yt/commits/314b56dd755f/
Changeset: 314b56dd755f
Branch: yt
User: ngoldbaum
Date: 2015-10-06 05:53:44+00:00
Summary: Remove incorrect assignment of cosmo to self
Affected #: 1 file
diff -r 797fbe61a57f212068668087388f6a9a0c804208 -r 314b56dd755f11fad3586adc1ce7cd76b2bcac3d yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -240,7 +240,7 @@
self.hubble_constant *= np.sqrt(G * density_unit)
# Finally, we convert the hubble constant from Hz to 100 km/s/Mpc
self.hubble_constant /= self.quan(100, 'km/s/Mpc')
- self.cosmo = Cosmology(self.hubble_constant,
+ cosmo = Cosmology(self.hubble_constant,
self.omega_matter, self.omega_lambda)
self.current_time = cosmo.hubble_time(self.current_redshift)
else:
https://bitbucket.org/yt_analysis/yt/commits/a962b8bc8d9c/
Changeset: a962b8bc8d9c
Branch: yt
User: ngoldbaum
Date: 2015-10-06 06:01:14+00:00
Summary: Clarifying a comment
Affected #: 1 file
diff -r 314b56dd755f11fad3586adc1ce7cd76b2bcac3d -r a962b8bc8d9c0859ce0e2018a5500aabbde5fd80 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -238,7 +238,7 @@
# Gasoline's internal hubble constant, dHubble0, is stored in
# units of proper code time
self.hubble_constant *= np.sqrt(G * density_unit)
- # Finally, we convert the hubble constant from Hz to 100 km/s/Mpc
+ # Finally, we scale the hubble constant by 100 km/s/Mpc
self.hubble_constant /= self.quan(100, 'km/s/Mpc')
cosmo = Cosmology(self.hubble_constant,
self.omega_matter, self.omega_lambda)
https://bitbucket.org/yt_analysis/yt/commits/e3229e6431e8/
Changeset: e3229e6431e8
Branch: yt
User: brittonsmith
Date: 2015-10-16 12:29:56+00:00
Summary: Fixing mass units for cosmological tipsy datasets.
Affected #: 1 file
diff -r a962b8bc8d9c0859ce0e2018a5500aabbde5fd80 -r e3229e6431e8dce7fdf807f9c4ffc2e1bfa4bfc3 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -208,7 +208,7 @@
pval = dcosm[param]
setattr(self, param, pval)
else:
- self.cosmological_simulation = 0.0
+ self.cosmological_simulation = 0
kpc_unit = self.parameters.get('dKpcUnit', 1.0)
self._unit_base['cm'] = 1.0 / (kpc_unit * cm_per_kpc)
@@ -227,48 +227,52 @@
super(TipsyDataset, self)._set_derived_attrs()
def _set_code_unit_attributes(self):
+ # First try to set units based on parameter file
if self.cosmological_simulation:
mu = self.parameters.get('dMsolUnit', 1.)
+ self.mass_unit = self.quan(mu, 'Msun')
lu = self.parameters.get('dKpcUnit', 1000.)
# In cosmological runs, lengths are stored as length*scale_factor
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
+ density_unit = self.mass_unit / (self.length_unit / self.scale_factor)**3
if 'dHubble0' in self.parameters:
# Gasoline's internal hubble constant, dHubble0, is stored in
# units of proper code time
self.hubble_constant *= np.sqrt(G * density_unit)
# Finally, we scale the hubble constant by 100 km/s/Mpc
self.hubble_constant /= self.quan(100, 'km/s/Mpc')
- cosmo = Cosmology(self.hubble_constant,
- self.omega_matter, self.omega_lambda)
- self.current_time = cosmo.hubble_time(self.current_redshift)
else:
mu = self.parameters.get('dMsolUnit', 1.0)
self.mass_unit = self.quan(mu, 'Msun')
lu = self.parameters.get('dKpcUnit', 1.0)
self.length_unit = self.quan(lu, 'kpc')
- 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
+ for my_unit in ["length", "mass", "time"]:
+ if my_unit in self._unit_base:
+ my_val = self._unit_base[my_unit]
+ my_val = \
+ self.quan(*my_val) if isinstance(my_val, tuple) \
+ else self.quan(my_val)
+ setattr(self, "%s_unit" % my_unit, my_val)
- 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
+ # Finally, set the dependent units
+ if self.cosmological_simulation:
+ cosmo = Cosmology(self.hubble_constant,
+ self.omega_matter, self.omega_lambda)
+ self.current_time = cosmo.hubble_time(self.current_redshift)
+ # mass units are rho_crit(z=0) * domain volume
+ mu = cosmo.critical_density(0.0) * \
+ (1 + self.current_redshift)**3 * self.length_unit**3
+ self.mass_unit = self.quan(mu.in_units("Msun"), "Msun")
+ density_unit = self.mass_unit / (self.length_unit / self.scale_factor)**3
+ else:
+ density_unit = self.mass_unit / self.length_unit**3
- density_unit = self.mass_unit / self.length_unit**3
+ if not hasattr(self, "time_unit"):
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):
'''
https://bitbucket.org/yt_analysis/yt/commits/11ade422936b/
Changeset: 11ade422936b
Branch: yt
User: brittonsmith
Date: 2015-10-16 12:40:24+00:00
Summary: Making hubble constant not a YTQuantity so it doesn't get units added back on.
Affected #: 1 file
diff -r e3229e6431e8dce7fdf807f9c4ffc2e1bfa4bfc3 -r 11ade422936b34192ab8bb2a344c2a33b0f8c8a1 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -241,6 +241,9 @@
self.hubble_constant *= np.sqrt(G * density_unit)
# Finally, we scale the hubble constant by 100 km/s/Mpc
self.hubble_constant /= self.quan(100, 'km/s/Mpc')
+ # If we leave it as a YTQuantity, the cosmology object
+ # used below will add units back on.
+ self.hubble_constant = self.hubble_constant.in_units("").d
else:
mu = self.parameters.get('dMsolUnit', 1.0)
self.mass_unit = self.quan(mu, 'Msun')
https://bitbucket.org/yt_analysis/yt/commits/525e7a051959/
Changeset: 525e7a051959
Branch: yt
User: brittonsmith
Date: 2015-10-16 12:53:01+00:00
Summary: Make sure to modify hubble constant in unit registry since it gets changed by tipsy frontend.
Affected #: 1 file
diff -r 11ade422936b34192ab8bb2a344c2a33b0f8c8a1 -r 525e7a0519598da6ffffd2db50ee95aec26e037d yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -270,6 +270,8 @@
(1 + self.current_redshift)**3 * self.length_unit**3
self.mass_unit = self.quan(mu.in_units("Msun"), "Msun")
density_unit = self.mass_unit / (self.length_unit / self.scale_factor)**3
+ # need to do this again because we've modified the hubble constant
+ self.unit_registry.modify("h", self.hubble_constant)
else:
density_unit = self.mass_unit / self.length_unit**3
https://bitbucket.org/yt_analysis/yt/commits/85d2a0080323/
Changeset: 85d2a0080323
Branch: yt
User: ngoldbaum
Date: 2015-10-22 05:35:09+00:00
Summary: Making comoving a deprecated propery in the tipsy frontend.
Affected #: 2 files
diff -r 525e7a0519598da6ffffd2db50ee95aec26e037d -r 85d2a0080323dc8d85200e9a23ebd6a8d8f27d2a yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -23,6 +23,7 @@
from yt.frontends.sph.data_structures import \
ParticleDataset
+from yt.funcs import deprecate
from yt.geometry.particle_geometry_handler import \
ParticleIndex
from yt.data_objects.static_output import \
@@ -32,7 +33,6 @@
from yt.utilities.physical_constants import \
G, \
cm_per_kpc
-from yt import YTQuantity
from .fields import \
TipsyFieldInfo
@@ -169,9 +169,9 @@
periodic = self.parameters.get('bPeriodic', True)
period = self.parameters.get('dPeriod', None)
self.periodicity = (periodic, periodic, periodic)
- self.comoving = self.parameters.get(
- 'bComove', self._cosmology_parameters is not None)
- if self.comoving and period is None:
+ self.cosmological_simulation = float(self.parameters.get(
+ 'bComove', self._cosmology_parameters is not None))
+ if self.cosmological_simulation and period is None:
period = 1.0
if self.bounding_box is None:
if periodic and period is not None:
@@ -191,11 +191,10 @@
# If the cosmology parameters dictionary got set when data is
# loaded, we can assume it's a cosmological data set
- if self.comoving is True:
+ if self.cosmological_simulation == 1.0:
cosm = self._cosmology_parameters or {}
# In comoving simulations, time stores the scale factor a
self.scale_factor = hvals["time"]
- self.cosmological_simulation = 1
dcosm = dict(
current_redshift=(1.0/self.scale_factor)-1.0,
omega_lambda=self.parameters.get(
@@ -208,7 +207,6 @@
pval = dcosm[param]
setattr(self, param, pval)
else:
- self.cosmological_simulation = 0
kpc_unit = self.parameters.get('dKpcUnit', 1.0)
self._unit_base['cm'] = 1.0 / (kpc_unit * cm_per_kpc)
@@ -319,3 +317,8 @@
@classmethod
def _is_valid(self, *args, **kwargs):
return TipsyDataset._validate_header(args[0])[0]
+
+ @property
+ @deprecate(replacement='cosmological_simulation')
+ def comoving(self):
+ return self.cosmological_simulation == 1.0
diff -r 525e7a0519598da6ffffd2db50ee95aec26e037d -r 85d2a0080323dc8d85200e9a23ebd6a8d8f27d2a yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -221,24 +221,29 @@
if ytcfg.getint("yt", "__topcomm_parallel_rank") > 0: return
mylog.info(*args)
-def deprecate(func):
- """
- This decorator issues a deprecation warning.
+def deprecate(replacement):
+ def real_deprecate(func):
+ """
+ This decorator issues a deprecation warning.
- This can be used like so:
+ This can be used like so:
- .. code-block:: python
+ .. code-block:: python
- @deprecate
- def some_really_old_function(...):
+ @deprecate("new_function")
+ def some_really_old_function(...):
- """
- @wraps(func)
- def run_func(*args, **kwargs):
- warnings.warn("%s has been deprecated and may be removed without notice!" \
- % func.__name__, DeprecationWarning, stacklevel=2)
- func(*args, **kwargs)
- return run_func
+ """
+ @wraps(func)
+ def run_func(*args, **kwargs):
+ message = "%s has been deprecated and may be removed without notice!"
+ if replacement is not None:
+ message += " Use %s instead." % replacement
+ warnings.warn(message % func.__name__, DeprecationWarning,
+ stacklevel=2)
+ func(*args, **kwargs)
+ return run_func
+ return real_deprecate
def pdb_run(func):
"""
https://bitbucket.org/yt_analysis/yt/commits/a5d76f647fbb/
Changeset: a5d76f647fbb
Branch: yt
User: brittonsmith
Date: 2015-10-22 09:34:37+00:00
Summary: Merged in ngoldbaum/yt (pull request #1787)
Tipsy cosmology unit fixes
Affected #: 3 files
diff -r d77e881944f88d7d4fce3c90b4fec115cf0180ce -r a5d76f647fbb9a740e21cf5d8269660aea6736cc yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -23,6 +23,7 @@
from yt.frontends.sph.data_structures import \
ParticleDataset
+from yt.funcs import deprecate
from yt.geometry.particle_geometry_handler import \
ParticleIndex
from yt.data_objects.static_output import \
@@ -167,12 +168,14 @@
periodic = self.parameters.get('bPeriodic', True)
period = self.parameters.get('dPeriod', None)
self.periodicity = (periodic, periodic, periodic)
- self.comoving = self.parameters.get('bComove', False)
- if self.comoving and period is None:
+ self.cosmological_simulation = float(self.parameters.get(
+ 'bComove', self._cosmology_parameters is not None))
+ if self.cosmological_simulation and period is None:
period = 1.0
if self.bounding_box is None:
if periodic and period is not None:
- # If we are periodic, that sets our domain width to either 1 or dPeriod.
+ # If we are periodic, that sets our domain width to
+ # either 1 or dPeriod.
self.domain_left_edge = np.zeros(3, "float64") - 0.5*period
self.domain_right_edge = np.zeros(3, "float64") + 0.5*period
else:
@@ -187,19 +190,22 @@
# 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:
+ if self.cosmological_simulation == 1.0:
cosm = self._cosmology_parameters or {}
- self.scale_factor = hvals["time"]#In comoving simulations, time stores the scale factor a
- self.cosmological_simulation = 1
- dcosm = dict(current_redshift=(1.0/self.scale_factor)-1.0,
- omega_lambda=self.parameters.get('dLambda', cosm.get('omega_lambda',0.0)),
- omega_matter=self.parameters.get('dOmega0', cosm.get('omega_matter',0.0)),
- hubble_constant=self.parameters.get('dHubble0', cosm.get('hubble_constant',1.0)))
+ # In comoving simulations, time stores the scale factor a
+ self.scale_factor = hvals["time"]
+ dcosm = dict(
+ current_redshift=(1.0/self.scale_factor)-1.0,
+ omega_lambda=self.parameters.get(
+ 'dLambda', cosm.get('omega_lambda',0.0)),
+ omega_matter=self.parameters.get(
+ 'dOmega0', cosm.get('omega_matter',0.0)),
+ hubble_constant=self.parameters.get(
+ 'dHubble0', cosm.get('hubble_constant',1.0)))
for param in dcosm.keys():
pval = dcosm[param]
setattr(self, param, pval)
else:
- self.cosmological_simulation = 0.0
kpc_unit = self.parameters.get('dKpcUnit', 1.0)
self._unit_base['cm'] = 1.0 / (kpc_unit * cm_per_kpc)
@@ -218,51 +224,57 @@
super(TipsyDataset, self)._set_derived_attrs()
def _set_code_unit_attributes(self):
+ # First try to set units based on parameter file
if self.cosmological_simulation:
mu = self.parameters.get('dMsolUnit', 1.)
+ self.mass_unit = self.quan(mu, 'Msun')
lu = self.parameters.get('dKpcUnit', 1000.)
# In cosmological runs, lengths are stored as length*scale_factor
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
-
- # 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)
+ density_unit = self.mass_unit / (self.length_unit / self.scale_factor)**3
+ if 'dHubble0' in self.parameters:
+ # Gasoline's internal hubble constant, dHubble0, is stored in
+ # units of proper code time
+ self.hubble_constant *= np.sqrt(G * density_unit)
+ # Finally, we scale the hubble constant by 100 km/s/Mpc
+ self.hubble_constant /= self.quan(100, 'km/s/Mpc')
+ # If we leave it as a YTQuantity, the cosmology object
+ # used below will add units back on.
+ self.hubble_constant = self.hubble_constant.in_units("").d
else:
mu = self.parameters.get('dMsolUnit', 1.0)
self.mass_unit = self.quan(mu, 'Msun')
lu = self.parameters.get('dKpcUnit', 1.0)
self.length_unit = self.quan(lu, 'kpc')
- 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
+ for my_unit in ["length", "mass", "time"]:
+ if my_unit in self._unit_base:
+ my_val = self._unit_base[my_unit]
+ my_val = \
+ self.quan(*my_val) if isinstance(my_val, tuple) \
+ else self.quan(my_val)
+ setattr(self, "%s_unit" % my_unit, my_val)
- 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
+ # Finally, set the dependent units
+ if self.cosmological_simulation:
+ cosmo = Cosmology(self.hubble_constant,
+ self.omega_matter, self.omega_lambda)
+ self.current_time = cosmo.hubble_time(self.current_redshift)
+ # mass units are rho_crit(z=0) * domain volume
+ mu = cosmo.critical_density(0.0) * \
+ (1 + self.current_redshift)**3 * self.length_unit**3
+ self.mass_unit = self.quan(mu.in_units("Msun"), "Msun")
+ density_unit = self.mass_unit / (self.length_unit / self.scale_factor)**3
+ # need to do this again because we've modified the hubble constant
+ self.unit_registry.modify("h", self.hubble_constant)
+ else:
+ density_unit = self.mass_unit / self.length_unit**3
- density_unit = self.mass_unit / self.length_unit**3
+ if not hasattr(self, "time_unit"):
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):
'''
@@ -304,3 +316,8 @@
@classmethod
def _is_valid(self, *args, **kwargs):
return TipsyDataset._validate_header(args[0])[0]
+
+ @property
+ @deprecate(replacement='cosmological_simulation')
+ def comoving(self):
+ return self.cosmological_simulation == 1.0
diff -r d77e881944f88d7d4fce3c90b4fec115cf0180ce -r a5d76f647fbb9a740e21cf5d8269660aea6736cc yt/frontends/tipsy/tests/test_outputs.py
--- a/yt/frontends/tipsy/tests/test_outputs.py
+++ b/yt/frontends/tipsy/tests/test_outputs.py
@@ -42,7 +42,7 @@
hubble_constant = 0.702)
kwargs = dict(field_dtypes = {"Coordinates": "d"},
cosmology_parameters = cosmology_parameters,
- unit_base = {'length': (1.0/60.0, "Mpccm/h")},
+ unit_base = {'length': (60.0, "Mpccm/h")},
n_ref = 64)
ds = data_dir_load(pkdgrav, TipsyDataset, (), kwargs)
yield assert_equal, str(ds), "halo1e11_run1.00400"
@@ -73,7 +73,7 @@
omega_matter = 0.272,
hubble_constant = 0.702)
kwargs = dict(cosmology_parameters = cosmology_parameters,
- unit_base = {'length': (1.0/60.0, "Mpccm/h")},
+ unit_base = {'length': (60.0, "Mpccm/h")},
n_ref = 64)
ds = data_dir_load(gasoline_dmonly, TipsyDataset, (), kwargs)
yield assert_equal, str(ds), "agora_1e11.00400"
diff -r d77e881944f88d7d4fce3c90b4fec115cf0180ce -r a5d76f647fbb9a740e21cf5d8269660aea6736cc yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -221,24 +221,29 @@
if ytcfg.getint("yt", "__topcomm_parallel_rank") > 0: return
mylog.info(*args)
-def deprecate(func):
- """
- This decorator issues a deprecation warning.
+def deprecate(replacement):
+ def real_deprecate(func):
+ """
+ This decorator issues a deprecation warning.
- This can be used like so:
+ This can be used like so:
- .. code-block:: python
+ .. code-block:: python
- @deprecate
- def some_really_old_function(...):
+ @deprecate("new_function")
+ def some_really_old_function(...):
- """
- @wraps(func)
- def run_func(*args, **kwargs):
- warnings.warn("%s has been deprecated and may be removed without notice!" \
- % func.__name__, DeprecationWarning, stacklevel=2)
- func(*args, **kwargs)
- return run_func
+ """
+ @wraps(func)
+ def run_func(*args, **kwargs):
+ message = "%s has been deprecated and may be removed without notice!"
+ if replacement is not None:
+ message += " Use %s instead." % replacement
+ warnings.warn(message % func.__name__, DeprecationWarning,
+ stacklevel=2)
+ func(*args, **kwargs)
+ return run_func
+ return real_deprecate
def pdb_run(func):
"""
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