sbpy icon indicating copy to clipboard operation
sbpy copied to clipboard

Problem when model parameters is a `astropy.units.Magnitude`

Open jianyangli opened this issue 2 years ago • 0 comments

High-level problem description

When any model parameter is an astropy.units.Magnitude type, model evaluation fails.

What did you do?

import astropy.units as u
import sbpy.units as sbu
from sbpy.photometry import HG

sbu.enable() # enable sbpy units

hg = HG(3.4 * sbu.VEGAmag, 0.12)
print(hg(30 * u.deg))

What did you expect?

Print out the value of HG phase function at 30 deg phase angle:

4.75 VEGAmag

What did really happen?

The above code snippet will throw a UnitTypeError, stating that 'Quantity instances require normal units, not <class 'astropy.units.function.logarithmic.MagUnit'> instance.'

The fundamental reason is because astropy.modleing.Model evaluates model value by assembling the parameter value and unit into an astropy.units.Quantity. But a MagUnit type cannot make a Quantity, but a Magnitude type.

This issue is reported by https://github.com/astropy/astropy/issues/13133, and is current being addressed with PR https://github.com/astropy/astropy/pull/13158. Once this issue is fixed in astropy, sbpy should be updated accordingly or checked to make sure this issue is also resolved.

Provide information on your environment:

operating system and version: MacOSX 10.15.7 sbpy version: '0.2.3.dev223+g9eb0523' astropy version: '5.0.4' numpy version: '1.22.3'

jianyangli avatar May 03 '22 18:05 jianyangli