# Default keywords for spectral flux units and its type

**URL:** <https://community.openastronomy.org/t/default-keywords-for-spectral-flux-units-and-its-type/909>\
**Category:** Astropy\
**Tags:** astropy, question\
**Created:** [February 15, 2024, 8:12pm UTC](https://community.openastronomy.org/t/default-keywords-for-spectral-flux-units-and-its-type/909 "2024-02-15T20:12:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vital-Fernandez](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/vital-fernandez/32/245_2.png) [@Vital-Fernandez](https://community.openastronomy.org/u/Vital-Fernandez)\
**Post date:** [February 15, 2024, 8:12pm UTC](https://community.openastronomy.org/t/default-keywords-for-spectral-flux-units-and-its-type/909/1 "2024-02-15T20:12:38Z")

</div>

Hi! I have been updating my [library](https://lime-stable.readthedocs.io/en/latest/) 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:

- 
  1. 

There are [issues](https://github.com/astropy/astropy/pull/1410) 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:

```auto
> 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?

- 
  1. 

So far I have been adding them as aliases:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dhomeier](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/dhomeier/32/65_2.png) [@dhomeier](https://community.openastronomy.org/u/dhomeier)\
**Post date:** [February 21, 2024, 11:02pm UTC](https://community.openastronomy.org/t/default-keywords-for-spectral-flux-units-and-its-type/909/2 "2024-02-21T23:02:09Z")

</div>

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](https://github.com/astropy/astropy/pull/1410) 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.

> [@Vital-Fernandez](#):
>
> 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?

The common base class for all units is `UnitBase`.

---

<div class="post-metadata">

**Author:** ![Vital-Fernandez](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/vital-fernandez/32/245_2.png) [@Vital-Fernandez](https://community.openastronomy.org/u/Vital-Fernandez)\
**Post date:** [March 29, 2024, 2:36pm UTC](https://community.openastronomy.org/t/default-keywords-for-spectral-flux-units-and-its-type/909/3 "2024-03-29T14:36:13Z")

</div>

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”
