[yt-users] Setting Units

John Regan johnanthonyregan at gmail.com
Fri Sep 26 04:05:26 PDT 2014


Hi All,

I'm having a little trouble with Units in YT-3.0.

I want to calculate the rates for some collisional dissociations as used in
Enzo. The rates are fits so the dimensions are not going to be as required
and YT doesn't like that!

An example script showing the problem is shown below:

#####################################################
import yt
from yt.utilities.physical_constants import kboltz
import numpy as np

def _k7(field, data): #H + e -> HM + gamma
    Tergs = data["Temperature"]*kboltz
    TeV = Tergs.convert_to_units('eV')
    krate = 6.77e-15*np.power(TeV, 0.8779)
    return krate #cm^3 s^-1

yt.add_field(("gas", "k7rate"), units="cm**3/s", function=_k7)

Filename = "....../RD0000/RD0000"

ds = yt.load(Filename)
sp = ds.sphere('max', (100, 'kpc'))
print sp["k7rate"]
#######################################################

The script fails with the error:
yt.utilities.exceptions.YTUnitConversionError: Unit dimensionalities do not
match. Tried to convert between eV**(8779/10000) (dim
(length)**(8779/5000)*(mass)**(8779/10000)/(time)**(8779/5000)) and cm**3/s
(dim (length)**3/(time)).

which makes sense because the _k7() function is just a fit based on
temperature. Is there a way to "set" the units of k7 to be cm^3 s^-1?

Cheers,
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20140926/01c7014b/attachment.htm>


More information about the yt-users mailing list