Skip to content

Commit

Permalink
Added spectral representation (#2)
Browse files Browse the repository at this point in the history
* Add files via upload

* Create fft1.json

Signed-off-by: Jerome Alperovitch <[email protected]>

* Add files via upload

* Update README.md

Signed-off-by: Jerome Alperovitch <[email protected]>

* Add files via upload

* Add files via upload

* Delete fft1.png

Signed-off-by: Jerome Alperovitch <[email protected]>

* Add files via upload

* Update README.md

Signed-off-by: Jerome Alperovitch <[email protected]>
  • Loading branch information
jalperov authored Aug 5, 2022
1 parent 8a243a1 commit 1086045
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 3 deletions.
6 changes: 3 additions & 3 deletions visualizations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ To configure a visualization:
# Gallery

| | | |
| --- | --- | --- |
| ![gauge1](gauge1.png) | | |
| [A simple gauge](./gauge1.json) | | |
| :---: | :---: | :---: |
| ![gauge1](gauge1.png) | ![fft1](fft1.png) | |
| [Simple gauge](./gauge1.json) | [Spectral representation](./fft1.json) | |


# Contributing
Expand Down
151 changes: 151 additions & 0 deletions visualizations/fft1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"url": {
"%context%": true,
"%timefield%": "ts_beg",
"index": "model_fft",
"body": {
"aggs": {
"f": {
"filter": {
"nested": {
"path": "fft_property",
"query": {
"exists": {
"field": "fft_property"
}
}
}
},
"aggs": {
"time_buckets": {
"top_hits": {
"sort": [
{"ts_beg": {"order": "desc"}}
],
"_source": {
"includes": [
"ts_beg",
"fft_property"
]
},
"size": 1
}
}
}
}
},
"size": 0
}
},
"format": {
"property": "aggregations.f.time_buckets.hits.hits"
}
},
"transform": [
{
"calculate": "datum._source.fft_property.spectrum",
"as": "hits"
},
{"flatten": ["hits"], "as": ["spectrum"]},
{
"calculate": "datum.spectrum.magnitude",
"as": "magnitude"
},
{
"calculate": "datum.spectrum.frequency",
"as": "frequency"
},
{
"window": [{"op": "rank", "as": "rank"}],
"sort": [
{"field": "frequency", "order": "ascending"}
]
},
{
"joinaggregate": [
{"op": "max", "field": "rank", "as": "maxrank"}
]
},
{
"calculate": "2*datum.spectrum.magnitude/(2*datum.maxrank-1)",
"as": "magnitude"
},
{"filter": "datum.frequency >0"}
],
"encoding": {
"x": {
"field": "frequency",
"title": "Frequency (Hz)",
"type": "quantitative",
"scale": {"domainMin": 0}
}
},
"layer": [
{
"mark": {
"type": "line",
"width": 3,
"color": "darkorange"
},
"encoding": {
"y": {
"field": "magnitude",
"title": "Amplitude",
"type": "quantitative",
"scale": {"type": "log"}
}
},
"params": [
{
"name": "grid",
"select": {
"type": "interval",
"encodings": ["x"]
},
"bind": "scales"
}
]
},
{
"mark": {"type": "rule"},
"encoding": {
"opacity": {
"condition": {
"value": 1,
"param": "hover",
"empty": false
},
"value": 0
},
"tooltip": [
{
"field": "frequency",
"type": "quantitative",
"format": ".5f",
"title": "Frequency (Hz)"
},
{
"field": "magnitude",
"type": "quantitative",
"format": ".4f",
"title": "Amplitude"
}
]
},
"params": [
{
"name": "hover",
"select": {
"type": "point",
"fields": ["frequency"],
"nearest": true,
"on": "mouseover",
"clear": "mouseout"
}
}
]
}
]
}
Binary file added visualizations/fft1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1086045

Please sign in to comment.