Browse Source

sinefit: allow user to override min/max frequency detection

tags/nilmtools-1.1.4
Jim Paris 8 years ago
parent
commit
57c23c3792
1 changed files with 19 additions and 4 deletions
  1. +19
    -4
      src/sinefit.py

+ 19
- 4
src/sinefit.py View File

@@ -18,6 +18,12 @@ def main(argv = None):
group.add_argument('-f', '--frequency', action='store', type=float,
default=60.0,
help='Approximate frequency (default: %(default)s)')
group.add_argument('-m', '--min-freq', action='store', type=float,
help='Minimum valid frequency '
'(default: approximate frequency / 2))')
group.add_argument('-M', '--max-freq', action='store', type=float,
help='Maximum valid frequency '
'(default: approximate frequency * 2))')

# Parse arguments
try:
@@ -34,13 +40,22 @@ def main(argv = None):
parser.error("need a column number >= 1")
if args.frequency < 0.1:
parser.error("frequency must be >= 0.1")
if args.min_freq is None:
args.min_freq = args.frequency / 2
if args.max_freq is None:
args.max_freq = args.frequency * 2
if (args.min_freq > args.max_freq or
args.min_freq > args.frequency or
args.max_freq < args.frequency):
parser.error("invalid min or max frequency")

f.check_dest_metadata({ "sinefit_source": f.src.path,
"sinefit_column": args.column })
f.process_numpy(process, args = (args.column, args.frequency))
f.process_numpy(process, args = (args.column, args.frequency,
args.min_freq, args.max_freq))

def process(data, interval, args, insert_function, final):
(column, f_expected) = args
(column, f_expected, f_min, f_max) = args
rows = data.shape[0]

# Estimate sampling frequency from timestamps
@@ -66,8 +81,8 @@ def process(data, interval, args, insert_function, final):
(A, f0, phi, C) = sfit4(this, fs)

# Check bounds. If frequency is too crazy, ignore this window
if f0 < (f_expected/2) or f0 > (f_expected*2):
print "frequency", f0, "too far from expected value", f_expected
if f0 < f_min or f0 > f_max:
print "frequency", f0, "outside valid range", f_min, "-", f_max
start += N
continue



Loading…
Cancel
Save