Open petigura opened 12 years ago
I'm guessing you did something like import dimensionful as dm
. In this case dm.yr
is a Unit object, not a Quantity. Here's what I tried...
from dimensionful import Quantity, G, c
mdot = Quantity(1.0, "Msun") * G / c**3 / Quantity(1.0, "yr")
mdot.convert_to_cgs()
print mdot
1.56195933878e-13 (dimensionless)
In your script, it tries to divide the data of Mdot
by yr
. Do you have any suggestions for what it should do when that happens? I wasn't sure what to do.
Hey, Casey.
I'm guessing you did something like
import dimensionful as dm
. In this casedm.yr
is a Unit object, not a Quantity. Here's what I tried...from dimensionful import Quantity, G, c mdot = Quantity(1.0, "Msun") * G / c**3 / Quantity(1.0, "yr") mdot.convert_to_cgs() print mdot
1.56195933878e-13 (dimensionless)
I see what I did. I was confusing year, the unit, with 1 year a dimensionful quantity.
In your script, it tries to divide the data of
Mdot
byyr
. Do you have any suggestions for what it should do when that happens? I wasn't sure what to do.
I wouldn't try to guess what the user means. But an important choice is to decide whether we think of 1 year as a unit or just as a shorthand for 3.14e7 seconds.
Erik
How about this?
Why is this not simplifying in CGS
import dimensionful reload(dimensionful) m = 4_pi_dm.Quantity(1.0,"Msun")/dm.Quantity(20.0,"day")_dm.Quantity(1.0,"Rsun")__2 /dm.c print m print m.convert_to_cgs() 2.09584502195e-11 Msun_Rsun_2_s/(cmday) None
Quantity.convert_to_cgs() always returns None.
m.convert_to_cgs()
print m
would do it.
There are several *_to_cgs methods of Quantity. Quantity.get_in_cgs() creates and returns a new Quantity, Quantity.convert_to_cgs() overwrites the attributes and has no return value, and Quantity.get_data_in_cgs() gets the conversion factor and returns the data multiplied to cgs only. Looking back at the docstrings, this is not totally obvious. I will make them more explicit.
Hey, Casey.
Should the time units be simplified?
4.92579497077314e-6/yr s
Erik