PetroFit / petrofit

Python package for calculating Petrosian properties and fitting galaxy light profiles
https://petrofit.readthedocs.io
28 stars 7 forks source link

PSFModel param units bug #16

Closed robelgeda closed 3 years ago

robelgeda commented 3 years ago
---------------------------------------------------------------------------
UnitsError                                Traceback (most recent call last)
<ipython-input-212-cbe5b9548f04> in <module>
----> 1 psf_model.model

<ipython-input-199-8823ec4f77ac> in model(self)
    108         model = self._model.copy()
    109         for param in model.param_names:
--> 110             setattr(model, param, getattr(self, param))
    111 
    112         fixed = self.fixed

~/miniconda3/envs/lcbg/lib/python3.9/site-packages/astropy/modeling/core.py in __setattr__(self, attr, value)
    899             else:
    900                 if not isinstance(value, Quantity):
--> 901                     raise UnitsError(f"The '{param.name}' parameter should be given as a"
    902                                      " Quantity because it was originally "
    903                                      "initialized as a Quantity")

UnitsError: The 'ellip' parameter should be given as a Quantity because it was originally initialized as a Quantity
robelgeda commented 3 years ago

This is because the input model was init with quantities:

sersic_model = models.Sersic2D(
        amplitude=1,
        r_eff=25,
        n=3.7,
        x_0=mid,
        y_0=mid,
        ellip=get_source_ellip(row), 
        theta=get_source_theta(row),
        bounds = {
            'amplitude': (0., None),
            'r_eff': (0, None),
            'n': (0, 10),
            'ellip': (0, 1),
            'theta': (-2*np.pi, 2*np.pi),
            'x_0': (mid-d, mid+d),
            'y_0': (mid-d, mid+d),
        },
)

To fix change get_source_theta(row) -> get_source_theta(row).value