Skip to content

Add input validation to OpacityCalculator.__init__ in tardis/analysis/opacity.py #3465

@vinitjain2005

Description

@vinitjain2005

Currently, the OpacityCalculator.init method does not validate some of its input parameters. For example:

  • lam_min can be greater than or equal to lam_max
  • nbins can be zero or negative
  • mdl can be None

If such values are passed, errors may occur later during frequency grid construction or opacity calculations. These errors may not clearly indicate that the issue originates from invalid input arguments.

Describe the solution you'd like

I would like to add explicit input validation in the init method of OpacityCalculator, such as:

  • Raising a ValueError if lam_min >= lam_max
  • Raising a ValueError if nbins <= 0
  • Raising a ValueError if mdl is None

This would improve robustness and provide clearer, earlier error messages without changing any scientific functionality.

Describe alternatives you've considered
An alternative approach would be to rely on downstream errors when invalid inputs are used. However, this can lead to less clear error messages and make debugging more difficult. Adding explicit validation at initialization makes the class safer and easier to use.

Additional context
This change would only improve input validation and error clarity. It would not modify any numerical calculations or physics-related logic.

Vinit Jain
GitHub: @vinitjain2005

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