[Yt-svn] yt-commit r352 - trunk/yt/lagos
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Fri Jan 4 11:32:10 PST 2008
Author: mturk
Date: Fri Jan 4 11:32:01 2008
New Revision: 352
URL: http://yt.spacepope.org/changeset/352
Log:
Refactored unit-generation, made them more clear. Names will probably change at
some point to be clearer.
Also added some new radius fields for different units, and fixed a bug in the
_Fraction stuff.
Modified:
trunk/yt/lagos/DerivedFields.py
trunk/yt/lagos/OutputTypes.py
Modified: trunk/yt/lagos/DerivedFields.py
==============================================================================
--- trunk/yt/lagos/DerivedFields.py (original)
+++ trunk/yt/lagos/DerivedFields.py Fri Jan 4 11:32:01 2008
@@ -209,7 +209,7 @@
"H2I","H2II","HM",
"DI","DII","HDI"]
def _SpeciesFraction(field, data):
- sp = field.name.split("_")[0]
+ sp = field.name.split("_")[0] + "_Density"
return data[sp]/data["Density"]
for species in _speciesList:
add_field("%s_Fraction" % species,
@@ -438,10 +438,42 @@
(data["y"] - center[1])**2.0 +
(data["z"] - center[2])**2.0)
return radius
-def _ConvertRadius(data):
+def _ConvertRadiusCGS(data):
return data.convert("cm")
-add_field("Radius", validators=[ValidateParameter("center")],
- convert_function = _ConvertRadius, units=r"\rm{cm}")
+add_field("Radius", function=_Radius,
+ validators=[ValidateParameter("center")],
+ convert_function = _ConvertRadiusCGS, units=r"\rm{cm}")
+
+def _ConvertRadiusMpc(data):
+ return data.convert("mpc")
+add_field("RadiusMpc", function=_Radius,
+ validators=[ValidateParameter("center")],
+ convert_function = _ConvertRadiusMpc, units=r"\rm{Mpc}")
+
+def _ConvertRadiuskpc(data):
+ return data.convert("kpc")
+add_field("Radiuskpc", function=_Radius,
+ validators=[ValidateParameter("center")],
+ convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}")
+
+def _ConvertRadiuskpch(data):
+ return data.convert("kpch")
+add_field("Radiuskpch", function=_Radius,
+ validators=[ValidateParameter("center")],
+ convert_function = _ConvertRadiuskpc, units=r"\rm{kpc}/\rm{h}")
+
+def _ConvertRadiuspc(data):
+ return data.convert("pc")
+add_field("Radiuspc", function=_Radius,
+ validators=[ValidateParameter("center")],
+ convert_function = _ConvertRadiuspc, units=r"\rm{pc}")
+
+def _ConvertRadiusAU(data):
+ return data.convert("au")
+add_field("RadiusAU", function=_Radius,
+ validators=[ValidateParameter("center")],
+ convert_function = _ConvertRadiusAU, units=r"\rm{AU}")
+
add_field("RadiusCode", function=_Radius,
validators=[ValidateParameter("center")])
Modified: trunk/yt/lagos/OutputTypes.py
==============================================================================
--- trunk/yt/lagos/OutputTypes.py (original)
+++ trunk/yt/lagos/OutputTypes.py Fri Jan 4 11:32:01 2008
@@ -171,36 +171,52 @@
if len(self.parameters) == 0:
self.__parse_parameter_file()
if self["ComovingCoordinates"]:
- z = self["CosmologyCurrentRedshift"]
- boxh = self["CosmologyComovingBoxSize"]
- self.units['aye'] = (1.0 + self["CosmologyInitialRedshift"])/(z - 1.0)
- if not self.has_key("Time"):
- LengthUnit = 3.086e24 * boxh / self["CosmologyHubbleConstantNow"] \
- / (1+self["CosmologyInitialRedshift"])
- self.conversion_factors["Time"] = LengthUnit / self["x-velocity"]
+ self.__setup_comoving_units()
elif self.has_key("LengthUnits"):
- # We are given LengthUnits, which is number of cm per box length
- # So we convert that to box-size in Mpc
- z = 0
- boxh = 3.24077e-25 * self["LengthUnits"]
- self.units['aye'] = 1.0
+ self.__setup_getunits_units()
else:
- z = 0
- boxh = 1.0
- self.units['aye'] = 1.0
- if not self.has_key("TimeUnits"):
- mylog.warning("No time units. Setting 1.0 = 1 second.")
- self.conversion_factors["Time"] = 1.0
+ self.__setup_nounits_units()
+ self.time_units['1'] = 1
+ self.units['1'] = 1
seconds = self["Time"]
- box = boxh/(1+z)
- for unit in unitList.keys():
- self.units[unit] = unitList[unit] * box
- self.units[unit+'h'] = unitList[unit] * boxh
- self.time_units['1'] = 1
- self.units['1'] = 1
self.time_units['years'] = seconds / (365*3600*24.0)
self.time_units['days'] = seconds / (3600*24.0)
+ def __setup_comoving_units(self):
+ z = self["CosmologyCurrentRedshift"]
+ h = self["CosmologyHubbleConstantNow"]
+ boxcm_cal = self["CosmologyComovingBoxSize"]
+ boxcm_uncal = boxcm_cal / h
+ box_proper = boxcm_uncal/(1+z)
+ self.units['aye'] = (1.0 + self["CosmologyInitialRedshift"])/(z - 1.0)
+ if not self.has_key("Time"):
+ LengthUnit = 3.086e24 * box_proper
+ self.conversion_factors["Time"] = LengthUnit / self["x-velocity"]
+ for unit in unitList.keys():
+ self.units[unit] = unitList[unit] * box_proper
+ self.units[unit+'h'] = unitList[unit] * box_proper * h
+ self.units[unit+'hcm'] = unitList[unit] * boxcm_cal
+
+ def __setup_getunits_units(self):
+ # We are given LengthUnits, which is number of cm per box length
+ # So we convert that to box-size in Mpc
+ box_proper = 3.24077e-25 * self["LengthUnits"]
+ self.units['aye'] = 1.0
+ for unit in unitList.keys():
+ self.units[unit] = unitList[unit] * box_proper
+
+ def __setup_nounits_units(self):
+ z = 0
+ box_proper = 1.0
+ self.units['aye'] = 1.0
+ mylog.warning("No length units. Setting 1.0 = 1 proper Mpc.")
+ if not self.has_key("TimeUnits"):
+ mylog.warning("No time units. Setting 1.0 = 1 second.")
+ self.conversion_factors["Time"] = 1.0
+ for unit in unitList.keys():
+ self.units[unit] = unitList[unit] * box_proper
+ return box, boxh
+
def _get_hierarchy(self):
if self.__hierarchy == None:
self.__hierarchy = EnzoHierarchy(self, data_style=self.data_style)
More information about the yt-svn
mailing list