Default keywords for spectral flux units and its type

Hi! I have been updating my library to use astropy units on the spectra declaration and I wonder if anyone could please help me to use the proper declaration and identification for these variables. This question has two parts:

There are issues on the github which discuss the spectral flux declaration. And they seem to be included on the astropy.units.spectral() function. However, I cannot find the keywords for the FLAM, FNU, wavenumber etc:

> import astropy
> from astropy import units as au
> from astropy.units.core import CompositeUnit, IrreducibleUnit, PrefixUnit, Unit
> 
> flux_keyword_lists = ['F_lam', 'f_la', 'flam', 'Flam', 'f_lam', 'FLAM', 'F_LAM']
> for keyword in flux_keyword_lists:
>     try:
>         unit_variable = au.Unit(keyword)
>         print(f'{keyword} is a VALID unit')
>     except ValueError:
>         print(f'{keyword} is NOT a valid unit')

F_lam is NOT a valid unit
f_la is NOT a valid unit
flam is NOT a valid unit
Flam is NOT a valid unit
f_lam is NOT a valid unit
FLAM is NOT a valid unit
F_LAM is NOT a valid unit

Are they actually included in the units database?

So far I have been adding them as aliases:

au.add_enabled_aliases({'F_lam': au.erg/au.s/au.cm**2/au.AA, 'F_nu': au.erg/au.s/au.cm**2/au.Hz,
                        'f_E': au.photon/au.s/au.cm**2/au.keV, 'f_lam': au.photon/au.s/au.cm**2/au.AA,
                        'WN': 1/au.cm})

I would also like to give the user the option to include their own astropy units in the spectra declaration. However, to confirm if the user input is an astropy unit I have found upto 4 different types:

isinstance(input_variable, (CompositeUnit, IrreducibleUnit, PrefixUnit, Unit))

Is there a unique identifier for astropy unit classes?

Thanks for any advice.

FLAM , F_lam or any of their variations are not included in the standard units because they are not physical units in any sense, although it is a common alias for flux density in cgs units found in many spectrum headers and also used extensively in synphot, I think.
I don’t know if would make sense in your case to import the definitions from synphot; otherwise declaring them as custom units as you did is probably the way to go.
The pull request you referred to should ensure that the composite unit u.Unit('erg / (s * cm**2 * Angstrom)') will be recognised as spectral flux density per wavelength, whether defined under its own alias or not.

The common base class for all units is UnitBase.

Thank you very much @dhomeier for the reply!

I will use synphot style and create the units with the def_unit method and and then add them to the unit list via the add_enabled_units method. I am also going to use their double naming convection with “flam” and “FLAM”

1 Like