question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't instantiate Quantity with logarithmic units.

See original GitHub issue

I’m trying to create a Quantity that represents units of wavelength in log_10(Angstrom), so I figured dex(Angstrom) would work fine. It only sort of does.

>>> foo = np.linspace(3., 5., 10) * u.Unit("dex(Angstrom)")
>>> foo
<Dex [ 3.        , 3.22222222, 3.44444444, 3.66666667, 3.88888889,
       4.11111111, 4.33333333, 4.55555556, 4.77777778, 5.        ] dex(Angstrom)>
>>> foo.physical
<Quantity [   1000.        ,   1668.1005372 ,   2782.55940221,
              4641.58883361,   7742.63682681,  12915.49665015,
             21544.34690032,  35938.13663805,  59948.42503189, 100000.        ] Angstrom>
>>> bar = Quantity(np.linspace(3., 5., 10), unit=u.Unit("dex(Angstrom)"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/weaver/Documents/local/products/anaconda/envs/py3/lib/python3.5/site-packages/astropy/units/quantity.py", line 332, in __new__
    value._set_unit(value_unit)
  File "/Users/weaver/Documents/local/products/anaconda/envs/py3/lib/python3.5/site-packages/astropy/units/quantity.py", line 722, in _set_unit
    .format(type(self).__name__, UnitBase, type(unit)))
astropy.units.core.UnitTypeError: Quantity instances require <class 'astropy.units.core.UnitBase'> units, not <class 'astropy.units.function.logarithmic.DexUnit'> instances.

So why can’t DexUnit instances inherit from UnitBase? This is a pretty serious problem for me because I use dex(Angstrom) units all the time. For example, basically every SDSS spectrum file uses these units.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
mhvkcommented, Mar 2, 2017

Another thought: in context of the zen of python – There should be one-- and preferably only one --obvious way to do it – yet another suggestion is simply to state that multiplication with a unit is the right way to instantiate a Quantity (with perhaps still that long-promised context manager that allows one to avoid copies).

2reactions
pllimcommented, Mar 2, 2017

I feel like this is the same issue I brought up some time ago, which incidentally interrupted Marten’s vacation… https://github.com/astropy/astropy/issues/5178#issuecomment-232984105 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Units of a log of a physical quantity - Math Stack Exchange
Overall, the argument x of ln(x) must be unitless, and a log transformed quantity must be unitless. If x=0.5 is measured in some...
Read more >
How could logarithm be applied to a quantity with unit? - Quora
The answer is clearly log(2). But at what point, and by what justification, do the units disappear? Subtracting quantities does not normally make...
Read more >
Adding a New Unit · angularsen/UnitsNet Wiki - GitHub
So you want to add a quantity or unit that is not yet part of Units.NET? ... To create a logarithmic unit, follow...
Read more >
1.3 The Language of Physics: Physical Quantities and Units
In physics, there are seven fundamental physical quantities that are measured in base or physical fundamental units: length, mass, time, electric current ...
Read more >
Log-log scale plot - MATLAB loglog - MathWorks
If Y contains complex numbers, loglog plots the imaginary part of Y versus the ... Create a set of x- and y-coordinates and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found