def _set_code_unit_attributes(self):
    if ((self._unit_base is None) and (self.cosmological_simulation == 1)):
        only_on_root(mylog.info, 'Assuming length units are in Mpc/h (comoving)')
        self._unit_base = dict(length=(1.0, 'Mpccm/h'))
    unit_base = (self._unit_base or {})
    if ('length' in unit_base):
        length_unit = unit_base['length']
    elif ('UnitLength_in_cm' in unit_base):
        if (self.cosmological_simulation == 0):
            length_unit = (unit_base['UnitLength_in_cm'], 'cm')
        else:
            length_unit = (unit_base['UnitLength_in_cm'], 'cmcm/h')
    else:
        raise RuntimeError
    length_unit = _fix_unit_ordering(length_unit)
    setdefaultattr(self, 'length_unit', self.quan(length_unit[0], length_unit[1]))
    if ('velocity' in unit_base):
        velocity_unit = unit_base['velocity']
    elif ('UnitVelocity_in_cm_per_s' in unit_base):
        velocity_unit = (unit_base['UnitVelocity_in_cm_per_s'], 'cm/s')
    else:
        velocity_unit = (100000.0, 'cm/s  * sqrt(a)')
    velocity_unit = _fix_unit_ordering(velocity_unit)
    setdefaultattr(self, 'velocity_unit', self.quan(velocity_unit[0], velocity_unit[1]))
    if ('mass' in unit_base):
        mass_unit = unit_base['mass']
    elif ('UnitMass_in_g' in unit_base):
        if (self.cosmological_simulation == 0):
            mass_unit = (unit_base['UnitMass_in_g'], 'g')
        else:
            mass_unit = (unit_base['UnitMass_in_g'], 'g/h')
    else:
        mass_unit = (1.0, '1e10*Msun/h')
    mass_unit = _fix_unit_ordering(mass_unit)
    setdefaultattr(self, 'mass_unit', self.quan(mass_unit[0], mass_unit[1]))
    if ('time' in unit_base):
        time_unit = unit_base['time']
    elif ('UnitTime_in_s' in unit_base):
        time_unit = (unit_base['UnitTime_in_s'], 's')
    else:
        tu = (self.length_unit / self.velocity_unit).to('yr/h')
        time_unit = (tu.d, tu.units)
    setdefaultattr(self, 'time_unit', self.quan(time_unit[0], time_unit[1]))
def _set_code_unit_attributes(self):
    if ((self._unit_base is None) and (self.cosmological_simulation == 1)):
        only_on_root(mylog.info, 'Assuming length units are in Mpc/h (comoving)')
        self._unit_base = dict(length=(1.0, 'Mpccm/h'))
    unit_base = (self._unit_base or {})
    if ('length' in unit_base):
        length_unit = unit_base['length']
    elif ('UnitLength_in_cm' in unit_base):
        if (self.cosmological_simulation == 0):
            length_unit = (unit_base['UnitLength_in_cm'], 'cm')
        else:
            length_unit = (unit_base['UnitLength_in_cm'], 'cmcm/h')
    else:
        raise RuntimeError
    length_unit = _fix_unit_ordering(length_unit)
    setdefaultattr(self, 'length_unit', self.quan(length_unit[0], length_unit[1]))
    if ('velocity' in unit_base):
        velocity_unit = unit_base['velocity']
    elif ('UnitVelocity_in_cm_per_s' in unit_base):
        velocity_unit = (unit_base['UnitVelocity_in_cm_per_s'], 'cm/s')
    else:
        velocity_unit = (100000.0, 'cm/s  * sqrt(a)')
    velocity_unit = _fix_unit_ordering(velocity_unit)
    setdefaultattr(self, 'velocity_unit', self.quan(velocity_unit[0], velocity_unit[1]))
    if ('mass' in unit_base):
        mass_unit = unit_base['mass']
    elif ('UnitMass_in_g' in unit_base):
        if (self.cosmological_simulation == 0):
            mass_unit = (unit_base['UnitMass_in_g'], 'g')
        else:
            mass_unit = (unit_base['UnitMass_in_g'], 'g/h')
    else:
        mass_unit = (1.0, '1e10*Msun/h')
    mass_unit = _fix_unit_ordering(mass_unit)
    setdefaultattr(self, 'mass_unit', self.quan(mass_unit[0], mass_unit[1]))
    if ('time' in unit_base):
        time_unit = unit_base['time']
    elif ('UnitTime_in_s' in unit_base):
        time_unit = (unit_base['UnitTime_in_s'], 's')
    else:
        tu = (self.length_unit / self.velocity_unit).to('yr/h')
        time_unit = (tu.d, tu.units)
    setdefaultattr(self, 'time_unit', self.quan(time_unit[0], time_unit[1]))