add support for python 3
This commit is contained in:
+19
-4
@@ -89,22 +89,37 @@ class Comparator(Aggregator, HDF5Container):
|
||||
return missing_nums
|
||||
|
||||
def _get_units(self, unit, data=None):
|
||||
"Get real units from info files"
|
||||
"""
|
||||
Get real units from info files
|
||||
unit is either:
|
||||
1. An instance of cst.Unit (pymses unit class)
|
||||
2. A string beginning by "unit_", referring to a code unit,
|
||||
available in self.info
|
||||
3. A dict {unit1 : exp1, unit2: exp2, ...} with unitX as 2.
|
||||
and expX a float, referring to the compound unit
|
||||
unit1**exp1 * unit2**exp2
|
||||
4. A dict {key: unit, ...} where key is a field name (eg. 'time', or 'mass')
|
||||
and unit the corresponding unit (on one on the above format)
|
||||
|
||||
Returns:
|
||||
1-3. : a cst.Unit instance
|
||||
4. : a dict {key: unit, ...} with same key as input and unit being cst.Unit instances
|
||||
"""
|
||||
if isinstance(unit, cst.Unit):
|
||||
return unit
|
||||
if isinstance(unit, str):
|
||||
if isinstance(unit, str) and unit[:5] == "unit_":
|
||||
res = self.info[unit]
|
||||
if unit == "unit_length":
|
||||
res = res / self.info["boxlen"]
|
||||
return res
|
||||
if unit.keys()[0] in self.info:
|
||||
if list(unit)[0][:5] == "unit_":
|
||||
new_unit = cst.none
|
||||
for base_unit_str in unit:
|
||||
expo = unit[base_unit_str]
|
||||
base_unit = self._get_units(base_unit_str)
|
||||
new_unit = new_unit * base_unit ** expo
|
||||
return new_unit
|
||||
if (not data is None) and isinstance(data, dict) and unit.keys()[0] in data:
|
||||
if (not data is None) and isinstance(data, dict) and list(unit)[0] in data:
|
||||
for key in unit:
|
||||
unit[key] = self._get_units(unit[key])
|
||||
return unit
|
||||
|
||||
Reference in New Issue
Block a user