8
gopow.go
8
gopow.go
@@ -10,7 +10,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "RTL GoPow"
|
app.Name = "RTL GoPow"
|
||||||
app.Usage = "Render a rtl_power CSV output as waterfall image"
|
app.Usage = "Render a rtl_power CSV output as waterfall image"
|
||||||
@@ -19,7 +18,6 @@ func main() {
|
|||||||
app.Email = "d@hogborg.se"
|
app.Email = "d@hogborg.se"
|
||||||
|
|
||||||
app.Action = func(c *cli.Context) {
|
app.Action = func(c *cli.Context) {
|
||||||
|
|
||||||
if c.Bool("verbose") == true {
|
if c.Bool("verbose") == true {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
} else {
|
} else {
|
||||||
@@ -49,7 +47,6 @@ func main() {
|
|||||||
}).Fatal("write failed")
|
}).Fatal("write failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
@@ -86,6 +83,11 @@ func main() {
|
|||||||
Name: "no-annotations",
|
Name: "no-annotations",
|
||||||
Usage: "Disabled annotations such as time and frequency scales",
|
Usage: "Disabled annotations such as time and frequency scales",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "palette",
|
||||||
|
Usage: "Select the palette for output image. [spectrum,yellow]",
|
||||||
|
Value: "spectrum",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type RunConfig struct {
|
|||||||
Annotations bool
|
Annotations bool
|
||||||
MaxPower float64
|
MaxPower float64
|
||||||
MinPower float64
|
MinPower float64
|
||||||
|
Palette string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GoPow struct {
|
type GoPow struct {
|
||||||
@@ -33,7 +34,6 @@ type GoPow struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewGoPow(c *cli.Context) (*GoPow, error) {
|
func NewGoPow(c *cli.Context) (*GoPow, error) {
|
||||||
|
|
||||||
config := &RunConfig{
|
config := &RunConfig{
|
||||||
InputFile: c.String("input"),
|
InputFile: c.String("input"),
|
||||||
OutputFile: c.String("output"),
|
OutputFile: c.String("output"),
|
||||||
@@ -41,6 +41,7 @@ func NewGoPow(c *cli.Context) (*GoPow, error) {
|
|||||||
Annotations: !c.Bool("no-annotations"),
|
Annotations: !c.Bool("no-annotations"),
|
||||||
MaxPower: c.Float64("max-power"),
|
MaxPower: c.Float64("max-power"),
|
||||||
MinPower: c.Float64("min-power"),
|
MinPower: c.Float64("min-power"),
|
||||||
|
Palette: c.String("palette"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.IsSet("max-power") {
|
if !c.IsSet("max-power") {
|
||||||
@@ -80,7 +81,6 @@ func NewGoPow(c *cli.Context) (*GoPow, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GoPow) Render() error {
|
func (g *GoPow) Render() error {
|
||||||
|
|
||||||
conf := &RenderConfig{}
|
conf := &RenderConfig{}
|
||||||
|
|
||||||
if g.config.MaxPower != PowerConfigAuto {
|
if g.config.MaxPower != PowerConfigAuto {
|
||||||
@@ -91,6 +91,14 @@ func (g *GoPow) Render() error {
|
|||||||
conf.MinPower = &g.config.MinPower
|
conf.MinPower = &g.config.MinPower
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var palette Palette
|
||||||
|
switch g.config.Palette {
|
||||||
|
case "yellow":
|
||||||
|
palette = &YellowPalette{}
|
||||||
|
default:
|
||||||
|
palette = &SpectrumPalette{}
|
||||||
|
}
|
||||||
|
|
||||||
log.Debug("staring render")
|
log.Debug("staring render")
|
||||||
g.timestamp = time.Now()
|
g.timestamp = time.Now()
|
||||||
|
|
||||||
@@ -103,12 +111,11 @@ func (g *GoPow) Render() error {
|
|||||||
|
|
||||||
for y, row := range table.Rows {
|
for y, row := range table.Rows {
|
||||||
for x := range row.Samples {
|
for x := range row.Samples {
|
||||||
g.image.Set(x, y, table.ColorAt(x, y))
|
g.image.Set(x, y, palette.ColorAt(table, x, y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.config.Annotations {
|
if g.config.Annotations {
|
||||||
|
|
||||||
annotator, err := NewAnnotator(g.image, table)
|
annotator, err := NewAnnotator(g.image, table)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -124,7 +131,6 @@ func (g *GoPow) Render() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GoPow) Write() error {
|
func (g *GoPow) Write() error {
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"file": g.config.OutputFile,
|
"file": g.config.OutputFile,
|
||||||
}).Debug("staring output write")
|
}).Debug("staring output write")
|
||||||
|
|||||||
61
internal/gopow/palette.go
Normal file
61
internal/gopow/palette.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package gopow
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image/color"
|
||||||
|
|
||||||
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Palette interface {
|
||||||
|
ColorAt(table *TableComplex, x, y int) color.Color
|
||||||
|
}
|
||||||
|
|
||||||
|
type YellowPalette struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *YellowPalette) ColorAt(table *TableComplex, x, y int) color.Color {
|
||||||
|
cell := table.Rows[y].Sample(x)
|
||||||
|
|
||||||
|
hueStart := 0.0
|
||||||
|
hueEnd := 1.0
|
||||||
|
|
||||||
|
span := (*table.Config.MinPower - *table.Config.MaxPower) * -1
|
||||||
|
hPerDeg := (hueStart - hueEnd) / span
|
||||||
|
powNormalized := cell - *table.Config.MinPower
|
||||||
|
powDegrees := powNormalized * hPerDeg
|
||||||
|
hue := hueStart - powDegrees
|
||||||
|
|
||||||
|
if hue < hueStart {
|
||||||
|
hue = hueStart
|
||||||
|
}
|
||||||
|
if hue > hueEnd {
|
||||||
|
hue = hueEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
return colorful.Color{hue, hue, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
type SpectrumPalette struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SpectrumPalette) ColorAt(table *TableComplex, x, y int) color.Color {
|
||||||
|
cell := table.Rows[y].Sample(x)
|
||||||
|
|
||||||
|
hueStart := 236.0
|
||||||
|
hueEnd := 0.0
|
||||||
|
|
||||||
|
span := (*table.Config.MinPower - *table.Config.MaxPower) * -1
|
||||||
|
hPerDeg := (hueStart - hueEnd) / span
|
||||||
|
powNormalized := cell - *table.Config.MinPower
|
||||||
|
powDegrees := powNormalized * hPerDeg
|
||||||
|
hue := hueStart - powDegrees
|
||||||
|
|
||||||
|
if hue > hueStart {
|
||||||
|
hue = hueStart
|
||||||
|
}
|
||||||
|
if hue < hueEnd {
|
||||||
|
hue = hueEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
return colorful.Hsv(hue, 1, 0.90)
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package gopow
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -11,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/lucasb-eyer/go-colorful"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,7 +36,6 @@ type RenderConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewTable(file string, conf *RenderConfig) (*TableComplex, error) {
|
func NewTable(file string, conf *RenderConfig) (*TableComplex, error) {
|
||||||
|
|
||||||
log.Debug("creating table")
|
log.Debug("creating table")
|
||||||
|
|
||||||
t := &TableComplex{
|
t := &TableComplex{
|
||||||
@@ -54,7 +51,6 @@ func NewTable(file string, conf *RenderConfig) (*TableComplex, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TableComplex) Load(file string) error {
|
func (t *TableComplex) Load(file string) error {
|
||||||
|
|
||||||
log.Debug("loading table")
|
log.Debug("loading table")
|
||||||
|
|
||||||
t.File = file
|
t.File = file
|
||||||
@@ -75,7 +71,6 @@ func (t *TableComplex) Load(file string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
||||||
|
|
||||||
var max = float64(math.MaxFloat64 * -1)
|
var max = float64(math.MaxFloat64 * -1)
|
||||||
var min = float64(math.MaxFloat64)
|
var min = float64(math.MaxFloat64)
|
||||||
|
|
||||||
@@ -84,7 +79,6 @@ func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
|||||||
table := map[string][]*LineComplex{}
|
table := map[string][]*LineComplex{}
|
||||||
|
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
|
|
||||||
cells := strings.Split(string(l), ",")
|
cells := strings.Split(string(l), ",")
|
||||||
line := NewLineComplex(cells)
|
line := NewLineComplex(cells)
|
||||||
|
|
||||||
@@ -99,11 +93,8 @@ func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
|||||||
|
|
||||||
// loop over hash keys with lines
|
// loop over hash keys with lines
|
||||||
for _, lines := range table {
|
for _, lines := range table {
|
||||||
|
|
||||||
row := t.IntegrateLines(lines)
|
row := t.IntegrateLines(lines)
|
||||||
|
|
||||||
if row != nil {
|
if row != nil {
|
||||||
|
|
||||||
rows = append(rows, row)
|
rows = append(rows, row)
|
||||||
|
|
||||||
if min > row.LowSample() {
|
if min > row.LowSample() {
|
||||||
@@ -117,7 +108,6 @@ func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
|||||||
t.HzHigh = row.HzHigh
|
t.HzHigh = row.HzHigh
|
||||||
|
|
||||||
if row.Time != nil {
|
if row.Time != nil {
|
||||||
|
|
||||||
if t.TimeStart == nil {
|
if t.TimeStart == nil {
|
||||||
t.TimeStart = row.Time
|
t.TimeStart = row.Time
|
||||||
}
|
}
|
||||||
@@ -134,7 +124,6 @@ func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
|||||||
t.TimeEnd = row.Time
|
t.TimeEnd = row.Time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +159,6 @@ func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TableComplex) Image() *image.RGBA {
|
func (t *TableComplex) Image() *image.RGBA {
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"width": t.Bins,
|
"width": t.Bins,
|
||||||
"height": t.Integrations,
|
"height": t.Integrations,
|
||||||
@@ -180,7 +168,6 @@ func (t *TableComplex) Image() *image.RGBA {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TableComplex) IntegrateLines(lines []*LineComplex) *LineComplex {
|
func (t *TableComplex) IntegrateLines(lines []*LineComplex) *LineComplex {
|
||||||
|
|
||||||
if len(lines) == 0 {
|
if len(lines) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -194,27 +181,3 @@ func (t *TableComplex) IntegrateLines(lines []*LineComplex) *LineComplex {
|
|||||||
|
|
||||||
return masterline
|
return masterline
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TableComplex) ColorAt(x, y int) color.Color {
|
|
||||||
|
|
||||||
cell := t.Rows[y].Sample(x)
|
|
||||||
|
|
||||||
hueStart := 236.0
|
|
||||||
hueEnd := 0.0
|
|
||||||
|
|
||||||
span := (*t.Config.MinPower - *t.Config.MaxPower) * -1
|
|
||||||
hPerDeg := (hueStart - hueEnd) / span
|
|
||||||
powNormalized := cell - *t.Config.MinPower
|
|
||||||
powDegrees := powNormalized * hPerDeg
|
|
||||||
hue := hueStart - powDegrees
|
|
||||||
|
|
||||||
if hue > hueStart {
|
|
||||||
hue = hueStart
|
|
||||||
}
|
|
||||||
if hue < hueEnd {
|
|
||||||
hue = hueEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
return colorful.Hsv(hue, 1, 0.90)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user