<div dir="ltr"><div><div><div><div><div><div><div>Hi All, <br><br></div>I'm having a little trouble with Units in YT-3.0.<br><br></div>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!<br><br></div>An example script showing the problem is shown below:<br><br>#####################################################<br>import yt<br>from yt.utilities.physical_constants import kboltz<br>import numpy as np<br><br>def _k7(field, data): #H + e -> HM + gamma<br>    Tergs = data["Temperature"]*kboltz<br>    TeV = Tergs.convert_to_units('eV')<br>    krate = 6.77e-15*np.power(TeV, 0.8779)<br>    return krate #cm^3 s^-1<br><br>yt.add_field(("gas", "k7rate"), units="cm**3/s", function=_k7)<br><br>Filename = "....../RD0000/RD0000"<br><br>ds = yt.load(Filename)<br>sp = ds.sphere('max', (100, 'kpc'))<br>print sp["k7rate"]<br>#######################################################<br><br></div>The script fails with the error:<br>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)).<br><br></div>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?<br><br></div>Cheers,<br></div>John<br><br><br><div><div><div><div><br><div><div><br></div></div></div></div></div></div></div>