Skip to content

StokesPolarization can't be initialized floating point numbers #264

@israelmcmc

Description

@israelmcmc

While LinearPolarization can be initialized with floats, StokesPolarization forces you to use a function:

from astromodels import Constant, StokesPolarization, LinearPolarization

# This fails (TypeError: 0.5 is not of type Node)
# StokesPolarization(Q = .5, U = .5)

# This works
qpar = Constant()
qpar.k = .5

upar = Constant()
upar.k = .5

StokesPolarization(Q = qpar, U = upar)

# This works!
LinearPolarization(degree = .5, angle = 10)

# Also works
pd = Constant()
pd.k = .5

pa = Constant()
pa.k = 10

LinearPolarization(degree = pd, angle = pa)

For convenience, I think StokesPolarization should also have a condition to handle a single floating point number, like here:

if callable(degree):
self.degree = LinearParameter("degree", degree)
else:
self.degree = self._get_parameter_from_input(
degree,
0,
100,
"degree",
"Polarization degree",
"dimensionless_unscaled",
)
if callable(angle):
self.angle = LinearParameter("angle", angle)
else:
self.angle = self._get_parameter_from_input(
angle, 0, 180, "angle", "Polarization angle", "deg"
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions