[yt-users] Setting Units

Britton Smith brittonsmith at gmail.com
Fri Sep 26 04:35:42 PDT 2014


Hi John,

I think you should be able to wipe out the units being used in the function
and add your own by doing:

return data.ds.arr(krate.d, "cm**3/s")

krate.d gives you just the data array without units.

Britton

On Fri, Sep 26, 2014 at 7:05 AM, John Regan <johnanthonyregan at gmail.com>
wrote:

> 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
>
>
>
>
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20140926/6c438679/attachment.html>


More information about the yt-users mailing list