New issue 1259: magnetic field units for athena frontend https://bitbucket.org/yt_analysis/yt/issues/1259/magnetic-field-units-for-at... Chang-Goo Kim: I set unit conversion factors with 'unit_override' keyword. These are the units I'm using
print ya.unit_base
{'length_unit': (1.0, 'pc'), 'mass_unit': (2.38858753789e-24, 'g/cm**3*pc**3'), 'time_unit': (1.0, 's*pc/km')} This should set the magnetic field unit as follows:
mu=yt.YTQuantity(ya.unit_base['mass_unit'][0],ya.unit_base['mass_unit'][1]) lu=yt.YTQuantity(ya.unit_base['length_unit'][0],ya.unit_base['length_unit'][1]) tu=yt.YTQuantity(ya.unit_base['time_unit'][0],ya.unit_base['time_unit'][1]) mag_unit=(np.sqrt(4*np.pi*mu/lu)/tu) print mag_unit.convert_to_units('gauss')
5.4786746797e-07 gauss But, what I found in the unit_registry is a bit strange number.
print ds.unit_registry['code_magnetic']
(3.5449077018110318, sqrt((mass))/(sqrt((length))*(time)), 0.0, '\\rm{code\\ magnetic}') It seems that "magnetic_unit" was set correctly in yt/frontends/athena/data_structures.py: self.magnetic_unit = np.sqrt(4*np.pi * self.mass_unit / (self.time_unit**2 * self.length_unit)) self.magnetic_unit.convert_to_units("gauss")