[AstroPy] unit equivalency testing

John K. Parejko parejkoj at uw.edu
Thu Feb 23 16:48:36 EST 2017


Ah, perfect! I don’t know how I missed that. Thank you!

Making a convenience method on Quantity would be helpful. Heck, here’s a hastily-written PR that implements it:

https://github.com/astropy/astropy/pull/5836

John

> On 23Feb 2017, at 12:57, Adrian Price-Whelan <adrianmpw at gmail.com> wrote:
> 
> I think what you want is "is_equivalent()":
> 
>>>> import astropy.units as u
>>>> a = 15*u.kpc
>>>> a.unit.is_equivalent(u.km)
> True
>>>> a = 15*u.Hz
>>>> a.unit.is_equivalent(u.Angstrom, equivalencies=u.spectral())
> True
> 
> Right now, it's just a method on UnitBase objects, but it might make
> sense to add a convenience method on Quantity as well...
> 
> On Thu, Feb 23, 2017 at 2:44 PM, John K. Parejko <parejkoj at uw.edu> wrote:
>> Hello astropy,
>> 
>> I’m looking for a way to check whether astropy units are “convertible” to each other. For now, asking if the two units have the same physical type is a good start for me (which might be a handy utility method on a quantity: `quantity1.convertible_to(quantity2)`):
>> 
>> u.get_physical_type(quantity.unit) == u.get_physical_type(self.unit)
>> 
>> but I see that there’s a rich unit equivalency system available. What I’d like is something like `quantity1.equivalent_to(quantity2)`, that returns True/False whether those units are equivalent, based on the defined equivalencies of that unit. Is there such a feature available?
>> 
>> Thank you,
>> John
>> 
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> https://mail.scipy.org/mailman/listinfo/astropy
> 
> 
> 
> -- 
> Adrian M. Price-Whelan
> Lyman Spitzer, Jr. Postdoctoral Fellow
> Princeton University
> http://adrian.pw
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy




More information about the AstroPy mailing list