Skip to content

Bugfix/filter sed conversion#80

Merged
PabloCorcho merged 4 commits into
mainfrom
bugfix/filter-sed-conversion
Oct 10, 2025
Merged

Bugfix/filter sed conversion#80
PabloCorcho merged 4 commits into
mainfrom
bugfix/filter-sed-conversion

Conversation

@PabloCorcho
Copy link
Copy Markdown
Collaborator

Filter now accepts flux density per wavelength and frequency unit. This avoids a lot of troubles for users that get confused with the units.

@PabloCorcho PabloCorcho requested a review from paranoya October 10, 2025 12:21
Comment thread src/pst/observables.py Outdated
@@ -292,10 +292,49 @@ def interpolate(self, wavelength=None):
return self.response

def _check_spectra(self, spectra, default_unit=u.Lsun / u.angstrom / u.cm**2):
Copy link
Copy Markdown
Owner

@paranoya paranoya Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps _ensure_f_lambda, _ensure_f_lambda_units, or ensure_spectra_units would be more descriptive... I think I lean towards the second (perhaps renaming spectra as f_lambda?)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And unit for the argument

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a private method. I don't know to what extent we need to be that careful given the docstrings... I don't understand the comment about the unit argument.

Comment thread src/pst/observables.py Outdated

Notes
-----
- Requires `self.wavelength` to be defined as an astropy Quantity with
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we should implement _ensure_wavelength_units

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, self.wavelength cannot be anything else but a quantity with length dimensions or None. I think what I am missing here is checking whether the attribute is None.

@PabloCorcho
Copy link
Copy Markdown
Collaborator Author

@paranoya lmk if you think there's something important missing, otherwise we can merge (the fix was for a student)

Comment thread src/pst/observables.py Outdated
spectra = u.Quantity(spectra, default_unit)
# Check flux density units
if spectra.unit.is_equivalent(u.W / (u.m**2 * u.m)):
return spectra
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, what about the following helper function?

def ensure_unit(x, unit, just_equivalent=True, equivalence=None):
    if not isinstance(x, u.Quantity):
        return x << unit
    if x.unit.is_equivalent(unit):
        if just_equivalent:
            return x
        else:
            return x.to(unit)
    else:
            return x.to(unit, equivalencies=equivalence)

and then

ensure_unit(wavelength, u.AA)
ensure_unit(spectra, u.Lsun/u.angstrom, equivalence=u.spectral_density(wavelength))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the check_unit method to also accept equivalencies, either taking arguments (spectral_density) or not ( spectral). The main difference is that the equivalency is used only when the input quantity is not equivalent to the target unit. This reduces the number of calls when using SSP data, which by default is in Flam.

@paranoya
Copy link
Copy Markdown
Owner

@paranoya lmk if you think there's something important missing, otherwise we can merge (the fix was for a student)

I see that CI testing is ongoing. Please go ahead once this is done @PabloCorcho.

@PabloCorcho PabloCorcho merged commit d11fecd into main Oct 10, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants