Optional manually defined power scale
This commit is contained in:
4
Makefile
4
Makefile
@@ -40,6 +40,6 @@ lint:
|
|||||||
golint .
|
golint .
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f build
|
- rm -r build
|
||||||
rm -rf internal/resources
|
- rm -rf internal/resources
|
||||||
|
|
||||||
|
|||||||
12
gopow.go
12
gopow.go
@@ -14,7 +14,7 @@ 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"
|
||||||
app.Version = "0.0.2"
|
app.Version = "0.0.3"
|
||||||
app.Author = "github.com/dhogborg"
|
app.Author = "github.com/dhogborg"
|
||||||
app.Email = "d@hogborg.se"
|
app.Email = "d@hogborg.se"
|
||||||
|
|
||||||
@@ -68,6 +68,16 @@ func main() {
|
|||||||
Value: "png",
|
Value: "png",
|
||||||
Usage: "Output file format, default png [png,jpeg]",
|
Usage: "Output file format, default png [png,jpeg]",
|
||||||
},
|
},
|
||||||
|
cli.Float64Flag{
|
||||||
|
Name: "max-power",
|
||||||
|
Value: 0,
|
||||||
|
Usage: "Define a manual maximum power (format nn.n)",
|
||||||
|
},
|
||||||
|
cli.Float64Flag{
|
||||||
|
Name: "min-power",
|
||||||
|
Value: 0,
|
||||||
|
Usage: "Define a manual minimum power (format nn.n)",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "verbose",
|
Name: "verbose",
|
||||||
Usage: "Enable more verbose output",
|
Usage: "Enable more verbose output",
|
||||||
|
|||||||
@@ -13,11 +13,17 @@ import (
|
|||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PowerConfigAuto = -9813
|
||||||
|
)
|
||||||
|
|
||||||
type RunConfig struct {
|
type RunConfig struct {
|
||||||
InputFile string
|
InputFile string
|
||||||
OutputFile string
|
OutputFile string
|
||||||
Format string
|
Format string
|
||||||
Annotations bool
|
Annotations bool
|
||||||
|
MaxPower float64
|
||||||
|
MinPower float64
|
||||||
}
|
}
|
||||||
|
|
||||||
type GoPow struct {
|
type GoPow struct {
|
||||||
@@ -33,6 +39,15 @@ func NewGoPow(c *cli.Context) (*GoPow, error) {
|
|||||||
OutputFile: c.String("output"),
|
OutputFile: c.String("output"),
|
||||||
Format: c.String("format"),
|
Format: c.String("format"),
|
||||||
Annotations: !c.Bool("no-annotations"),
|
Annotations: !c.Bool("no-annotations"),
|
||||||
|
MaxPower: c.Float64("max-power"),
|
||||||
|
MinPower: c.Float64("min-power"),
|
||||||
|
}
|
||||||
|
|
||||||
|
if !c.IsSet("max-power") {
|
||||||
|
config.MaxPower = PowerConfigAuto
|
||||||
|
}
|
||||||
|
if !c.IsSet("min-power") {
|
||||||
|
config.MinPower = PowerConfigAuto
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.InputFile == "" {
|
if config.InputFile == "" {
|
||||||
@@ -66,10 +81,20 @@ func NewGoPow(c *cli.Context) (*GoPow, error) {
|
|||||||
|
|
||||||
func (g *GoPow) Render() error {
|
func (g *GoPow) Render() error {
|
||||||
|
|
||||||
|
conf := &RenderConfig{}
|
||||||
|
|
||||||
|
if g.config.MaxPower != PowerConfigAuto {
|
||||||
|
conf.MaxPower = &g.config.MaxPower
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.config.MinPower != PowerConfigAuto {
|
||||||
|
conf.MinPower = &g.config.MinPower
|
||||||
|
}
|
||||||
|
|
||||||
log.Debug("staring render")
|
log.Debug("staring render")
|
||||||
g.timestamp = time.Now()
|
g.timestamp = time.Now()
|
||||||
|
|
||||||
table, err := NewTable(g.config.InputFile)
|
table, err := NewTable(g.config.InputFile, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -77,7 +102,7 @@ func (g *GoPow) Render() error {
|
|||||||
g.image = table.Image()
|
g.image = table.Image()
|
||||||
|
|
||||||
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, table.ColorAt(x, y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TableComplex struct {
|
type TableComplex struct {
|
||||||
File string // our input file
|
File string // our input file
|
||||||
|
Config *RenderConfig
|
||||||
|
|
||||||
Rows []*LineComplex
|
Rows []*LineComplex
|
||||||
|
|
||||||
Min float64 // minimum power value, used for color rendering
|
|
||||||
Max float64 // maximum dito
|
|
||||||
|
|
||||||
Bins int // horizontal slots, columns, bandwidth
|
Bins int // horizontal slots, columns, bandwidth
|
||||||
Integrations int // vertical slots, rows
|
Integrations int // vertical slots, rows
|
||||||
|
|
||||||
@@ -33,11 +31,19 @@ type TableComplex struct {
|
|||||||
TimeEnd *time.Time
|
TimeEnd *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTable(file string) (*TableComplex, error) {
|
// RenderConfig overrides automaticly calculated defaults
|
||||||
|
type RenderConfig struct {
|
||||||
|
MinPower *float64 // minimum power value, used for color rendering
|
||||||
|
MaxPower *float64 // maximum dito
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTable(file string, conf *RenderConfig) (*TableComplex, error) {
|
||||||
|
|
||||||
log.Debug("creating table")
|
log.Debug("creating table")
|
||||||
|
|
||||||
t := &TableComplex{}
|
t := &TableComplex{
|
||||||
|
Config: conf,
|
||||||
|
}
|
||||||
|
|
||||||
err := t.Load(file)
|
err := t.Load(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -70,8 +76,8 @@ func (t *TableComplex) Load(file string) error {
|
|||||||
|
|
||||||
func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
||||||
|
|
||||||
t.Max = float64(math.MaxFloat64 * -1)
|
var max = float64(math.MaxFloat64 * -1)
|
||||||
t.Min = float64(math.MaxFloat64)
|
var min = float64(math.MaxFloat64)
|
||||||
|
|
||||||
lines := bytes.Split(filebuffer, []byte("\n"))
|
lines := bytes.Split(filebuffer, []byte("\n"))
|
||||||
|
|
||||||
@@ -100,11 +106,11 @@ func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
|||||||
|
|
||||||
rows = append(rows, row)
|
rows = append(rows, row)
|
||||||
|
|
||||||
if t.Min > row.LowSample() {
|
if min > row.LowSample() {
|
||||||
t.Min = row.LowSample()
|
min = row.LowSample()
|
||||||
}
|
}
|
||||||
if t.Max < row.HighSample() {
|
if max < row.HighSample() {
|
||||||
t.Max = row.HighSample()
|
max = row.HighSample()
|
||||||
}
|
}
|
||||||
|
|
||||||
t.HzLow = row.HzLow
|
t.HzLow = row.HzLow
|
||||||
@@ -134,9 +140,17 @@ func (t *TableComplex) parseBuffer(filebuffer []byte) []*LineComplex {
|
|||||||
|
|
||||||
sort.Sort(LineSort(rows))
|
sort.Sort(LineSort(rows))
|
||||||
|
|
||||||
|
if t.Config.MaxPower == nil {
|
||||||
|
t.Config.MaxPower = &max
|
||||||
|
}
|
||||||
|
|
||||||
|
if t.Config.MinPower == nil {
|
||||||
|
t.Config.MinPower = &min
|
||||||
|
}
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"pMax": t.Max,
|
"pMax": *t.Config.MaxPower,
|
||||||
"pMin": t.Min,
|
"pMin": *t.Config.MinPower,
|
||||||
}).Debug("integrated lines")
|
}).Debug("integrated lines")
|
||||||
|
|
||||||
t.Integrations = len(rows)
|
t.Integrations = len(rows)
|
||||||
@@ -185,14 +199,21 @@ func (t *TableComplex) ColorAt(x, y int) color.Color {
|
|||||||
|
|
||||||
cell := t.Rows[y].Sample(x)
|
cell := t.Rows[y].Sample(x)
|
||||||
|
|
||||||
hue_start := 236.0
|
hueStart := 236.0
|
||||||
hue_end := 0.0
|
hueEnd := 0.0
|
||||||
|
|
||||||
span := (t.Min - t.Max) * -1
|
span := (*t.Config.MinPower - *t.Config.MaxPower) * -1
|
||||||
h_per_deg := (hue_start - hue_end) / span
|
hPerDeg := (hueStart - hueEnd) / span
|
||||||
pow_normalized := cell - t.Min
|
powNormalized := cell - *t.Config.MinPower
|
||||||
pow_degrees := pow_normalized * h_per_deg
|
powDegrees := powNormalized * hPerDeg
|
||||||
hue := hue_start - pow_degrees
|
hue := hueStart - powDegrees
|
||||||
|
|
||||||
|
if hue > hueStart {
|
||||||
|
hue = hueStart
|
||||||
|
}
|
||||||
|
if hue < hueEnd {
|
||||||
|
hue = hueEnd
|
||||||
|
}
|
||||||
|
|
||||||
return colorful.Hsv(hue, 1, 0.90)
|
return colorful.Hsv(hue, 1, 0.90)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user