Document custom logarithmic units
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 75
Description
Another issue with `LogUnit`, but not specifically array-related like #10575 that came up on the mailing list a while ago:
On [defining custom **negative** log units](https://mail.python.org/pipermail/astropy/2020-June/004766.html) (in dex, not mag) – basically the OP already figured out a way to solve this by creating a custom unit type as
```
ndex = u.function.mixin.RegularFunctionUnit(['ndex'], -u.dex)
ndex._function_unit_class = u.function.logarithmic.DexUnit
zhPa = ndex(u.hPa)
```
but I still felt there might be a more direct solution, which I just realised would be
```
zhPa = u.LogUnit(u.hPa, '-1 dex')
```
This is described in the docstring of `u.DexUnit`, but that gets rather little exposure in https://docs.astropy.org/en/latest/units/logarithmic_units.html
Alternatively it seems the identical result (almost, except for the subclass inherited) can be obtained with
```
zhPa = u.DexUnit(u.hPa, '2.5 mag')
```
or even some chimera like
```
zhPa = u.MagUnit(u.hPa, '-10 dB')
```
- Is there still some other method to define such a unit using `u.dex` directly?
- If not, how is the canonical solution best documented?
Contributor guide
Research direction
Start with the DexUnit docstring and the logarithmic units documentation page linked in the issue. Check how negative custom log units are currently described and clarify whether u.dex offers another construction path. Done means the canonical solution and the direct-u.dex question are clearly documented with the relevant examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100