Comments (6)
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.
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.
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.
I looked into this a little, and my conclusions so far:
x::Level == 3u"dBm"
can simply be plotted logarithmically usinglinear(x)
.x::Gain == 3u"dB"
can slightly less simply be plotted logarithmically usinguconvertp(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, as0.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 theQuantity
object theGain
and theUnit
is stored separately. There's aUnitful.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.
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.
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)
- Compatibility when using two user recipes together HOT 8
- Recipe for parametric with units? HOT 14
- TagBot trigger issue HOT 16
- unitful yerr seems to break HOT 6
- Vector{Any} doesn't plot HOT 4
- Shape() fails on conversion HOT 4
- `vline` and `hline` not supporting both `xunit` and `yunit` HOT 3
- Support Unitful xticks and yticks? HOT 1
- Units in colorbar clim
- No units on colorbar for 1-argument version of heatmap HOT 1
- axis labels for `plot!`
- Recipe request for Plots with ribbon keyword HOT 1
- Units from 3rd axis applied to 4th plot HOT 8
- Tuple vs Vector behavior HOT 1
- Is it neccessary that UnitfulStrings outlive the recipe? HOT 4
- The `aspect_ratio` controls the digit spacing, ignoring the units HOT 6
- New Recipes to support StatsPlots.jl HOT 5
- Crash on annotate HOT 1
- Error with `plot!(xticks)` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unitfulrecipes.jl.