Skip to content

Star

Star

A star object holding stellar parameters.

Parameters:

Name Type Description Default
prot float

Stellar rotation period [days]. If differential rotation is on, this is the rotation period at the equator.

25
incl float

Inclination of the rotational axis [degrees].

90
diffrotB float

Coefficient for latitudinal differential rotation (sin^2 term).

0
diffrotC float

Coefficient for latitudinal differential rotation (sin^4 term).

0
cb1 float

Absolute value of the convective blueshift (m/s).

0
coeffs array - like

Coefficient(s) of the limb-darkening law.

[0.29, 0.34]
law int

Limb-darkening law type. Can be 0 for linear, 1 for quadratic, 2 for square root, 3 for logarithmic, 4 for exponential, 5 for Claret's non-linear law.

1
radius float

Stellar radius [R_sun].

1
mass float

Stellar mass [M_sun].

1
teff float

Effective temperature of the star [K].

5778
start_psi float

Starting phase [in units of rotation period].

0
Properties

vrot (astropy.Quantity): Rotation velocity of the star at the equator, calculated from prot and radius.

Methods:

Name Description
set_vrot_units

Set the units for the vrot property.

set

Set attributes of the star, taking care of units and validating limb-darkening coefficients if law or coeffs are changed.

Raises:

Type Description
ValueError

If the number of limb-darkening coefficients does not match the selected law.

Source code in SOAP/classes.py
class Star:
    """
    A star object holding stellar parameters.

    Args:
        prot (float):
            Stellar rotation period [days]. If differential rotation is on, this is
            the rotation period at the equator.
        incl (float):
            Inclination of the rotational axis [degrees].
        diffrotB (float, optional):
            Coefficient for latitudinal differential rotation (sin^2 term).
        diffrotC (float, optional):
            Coefficient for latitudinal differential rotation (sin^4 term).
        cb1 (float, optional):
            Absolute value of the convective blueshift (m/s).
        coeffs (array-like, optional):
            Coefficient(s) of the limb-darkening law.
        law (int, optional):
            Limb-darkening law type. Can be 0 for linear, 1 for quadratic, 2 for square root, 3 for logarithmic, 4 for exponential, 5 for Claret's non-linear law.
        radius (float, optional):
            Stellar radius [R_sun].
        mass (float, optional):
            Stellar mass [M_sun].
        teff (float, optional):
            Effective temperature of the star [K].
        start_psi (float, optional):
            Starting phase [in units of rotation period].

    Properties:
        vrot (astropy.Quantity):
            Rotation velocity of the star at the equator, calculated from prot and radius.

    Methods:
        set_vrot_units(units):
            Set the units for the vrot property.
        set(**kwargs):
            Set attributes of the star, taking care of units and validating limb-darkening coefficients if law or coeffs are changed.

    Raises:
        ValueError: If the number of limb-darkening coefficients does not match the selected law.
    """

    @maybe_quantity_input(
        prot=U.day, incl=U.deg, teff=U.K, radius=U.R_sun, mass=U.M_sun
    )
    def __init__(
        self,
        prot=25,
        incl=90,
        diffrotB=0,
        diffrotC=0,
        cb1=0,
        coeffs=[0.29, 0.34],
        law=1,
        radius=1,
        mass=1,
        teff=5778,
        start_psi=0,
    ):

        self.prot = prot
        self.incl = incl
        self.diffrotB, self.diffrotC = diffrotB, diffrotC
        self.cb1 = cb1
        self.coeffs = coeffs
        self.law = law
        self.start_psi = start_psi
        self.radius = radius
        self.mass = mass
        self.teff = teff
        # default units for vrot
        self._vrot_units = kms

        self._validate_ld()  # ← validate at construction time

    def _validate_ld(self):
        """Check that coeffs length matches the selected limb-darkening law."""
        if self.law not in _LD_LAW_NCOEFFS:
            raise ValueError(
                f"Unknown limb-darkening law: {self.law}. "
                f"Valid laws are: {list(_LD_LAW_NCOEFFS.keys())}"
            )
        required = _LD_LAW_NCOEFFS[self.law]
        given = len(self.coeffs)
        if given != required:
            raise ValueError(
                f"Law {self.law} ({_LD_LAW_NAMES[self.law]}) requires "
                f"{required} coefficient(s), but {given} were given: {self.coeffs}"
            )

    def __setattr__(self, name, value):
        try:
            old = getattr(self, name)
            if has_unit(old):
                super().__setattr__(name, value << old.unit)
            else:
                super().__setattr__(name, value)
        except AttributeError:
            super().__setattr__(name, value)
        # Re-validate whenever law or coeffs changes after construction
        if name in ("law", "coeffs"):
            try:
                self._validate_ld()
            except AttributeError:
                pass  # coeffs or law not yet set during __init__
        # try to update self.vrot
        try:
            _ = self.vrot
        except AttributeError:
            pass

    def set_vrot_units(self, units):
        self._vrot_units = units

    def __setattr__(self, name, value):
        try:
            old = getattr(self, name)
            if has_unit(old):
                super().__setattr__(name, value << old.unit)
            else:
                super().__setattr__(name, value)
        except AttributeError:
            super().__setattr__(name, value)
        # try to update self.vrot
        try:
            _ = self.vrot
        except AttributeError:
            pass

    @property
    def vrot(self):
        """Rotation velocity of the star at the equator"""
        vrot = (2 * np.pi * self.radius) / (self.prot)
        vrot <<= self._vrot_units
        try:  # update CCFs vrot
            self._ccf.vrot = vrot
            self._ccf_active_region.vrot = vrot
        except AttributeError:
            pass
        return vrot

    def __repr__(self):
        pars = (
            f"prot={self.prot}; incl={self.incl}; radius={self.radius}; "
            f"mass={self.mass}; teff={self.teff:.0f}; diffrotB={self.diffrotB}; "
            f"diffrotC={self.diffrotC}; cb1={self.cb1}; law={self.law, _LD_LAW_NAMES[self.law]}; "
            f"coeffs={self.coeffs}; start_psi={self.start_psi}"
        )
        return "SOAP.Star(%s)" % pars


    def set(self, **kwargs):
        set_object_attributes(self, kwargs)
        self._validate_ld()  # ← validate when setting attributes

vrot property

Rotation velocity of the star at the equator