Code Monkey home page Code Monkey logo

Comments (6)

gustaphe avatar gustaphe commented on May 23, 2024 3

Just a comment for this if you decide to go for it, a common construction is 1u"dB/m" which isa Quantity{Gain{Unitful.LogInfo{:Decibel, 10, 10}, :?, Int64}, 𝐋^-1, Unitful.FreeUnits{(m^-1), 𝐋^-1, nothing}}, so there is even more to think about.

from unitfulrecipes.jl.

jw3126 avatar jw3126 commented on May 23, 2024 1

Interesting, thanks for reporting! The issue is, that we dispatch on Unitful.Quantity, however stuff measured in log units, apparently is not Quantity:

julia> using Unitful

julia> supertypes(typeof(2u"dB"))
(Gain{Unitful.LogInfo{:Decibel, 10, 10}, :?, Int64}, Unitful.LogScaled{Unitful.LogInfo{:Decibel, 10, 10}}, Number, Any)

julia> supertypes(typeof(2u"m"))
(Quantity{Int64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, Unitful.AbstractQuantity{Int64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}, Number, Any)

This can probably be fixed by replacing Quantity by something like Union{AbstractQuantity, LogScaled} in this package. A PR would be welcome @anojo !

from unitfulrecipes.jl.

anojo avatar anojo commented on May 23, 2024 1

There's also that the function unit doesn't work (there's logunit instead), and that ustrip(u"dB", 2u"dB") doesn't seem to work either (but ustrip(2u"dB") does).

from unitfulrecipes.jl.

gustaphe avatar gustaphe commented on May 23, 2024 1

I looked into this a little, and my conclusions so far:

  • x::Level == 3u"dBm" can simply be plotted logarithmically using linear(x).
  • x::Gain == 3u"dB" can slightly less simply be plotted logarithmically using uconvertp(NoUnits, x) (assuming power logarithm rather than root power logarithm here, from my experience that's pretty uncontroversial, but should maybe be a keyword argument).
  • x::Quantity{<:Gain} == 3u"dB/m" is really tricky. It will rarely make sense to for instance convert this to a "linear" regime, as 0.01 /m ≠ -20 dB/m. So what we would want is to be able to save the "unit" dB/m on the axis, but we would then have to either feature request such a unit-like object from Unitful or roll our own, because in the Quantity object the Gain and the Unit is stored separately. There's a Unitful.MixedUnits type, but I haven't quite figured out how that enters into it.

https://github.com/gustaphe/UnitfulRecipes.jl/blob/logarithmic/src/logarithmic.jl

from unitfulrecipes.jl.

briochemc avatar briochemc commented on May 23, 2024

I'm actually surprised that there is no parent abstract type for those:

julia> typejoin(typeof(1u"m"), typeof(1u"dB"))
Number

And I'm not sure there's a reason for that. Maybe worth asking the Unitful.jl peeps?

Otherwise, I think @jw3126's suggestion is the best and quickest solution, unless I'm missing something. Maybe we could add it a constant

const QuantityOrLogScaled = Union{AbstractQuantity, LogScaled}

and then dispatch on that?

(and also maybe it's worth upstreaming that up into Unitful?)


Also, side note: I realize we use Quantity throughout and not AbstractQuantity. Maybe we should loosen that up for future compatibility?

from unitfulrecipes.jl.

briochemc avatar briochemc commented on May 23, 2024

OK so it looks like we need to think this through a bit more (and it will require a bit more work)!

from unitfulrecipes.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.