def main(): scpm.init_logger() sampler = Sampler() try: sampler.open() sampler.start() try: calibration = scpm.load_calibration_file() except: calibration = None adc_data = sampler.adc_data_queue.get() except KeyboardInterrupt: sampler.terminate() else: sampler.terminate() adc_data = scpm.join_frames_and_widen(adc_data) split_adc_data = scpm.split_channels(adc_data) adc_rms = scpm.calculate_adc_rms(split_adc_data) if calibration is not None: calcd_data = scpm.calculate_calibrated_power( split_adc_data, adc_rms, calibration) print("") scpm.print_power(calcd_data) voltage, current = scpm.convert_adc_to_numpy_float(split_adc_data) voltage, current = scpm.shift_phase(voltage, current, calibration) scpm.plot(voltage, current, calibration) logging.shutdown()
def main(): scpm.init_logger() sampler = Sampler() try: sampler.open() sampler.start() try: calibration = scpm.load_calibration_file() except: calibration = None adc_data = sampler.adc_data_queue.get() except KeyboardInterrupt: sampler.terminate() else: sampler.terminate() adc_data = scpm.join_frames_and_widen(adc_data) split_adc_data = scpm.split_channels(adc_data) adc_rms = scpm.calculate_adc_rms(split_adc_data) if calibration is not None: calcd_data = scpm.calculate_calibrated_power(split_adc_data, adc_rms, calibration) print("") scpm.print_power(calcd_data) voltage, current = scpm.convert_adc_to_numpy_float(split_adc_data) voltage, current = scpm.shift_phase(voltage, current, calibration) scpm.plot(voltage, current, calibration) logging.shutdown()
def main(): args = setup_argparser() if not os.path.exists(args.input): raise Exception("Input '{}' does not exist".format(args.input)) scpm.init_logger() log.setLevel(logging.ERROR) # Process args.input if os.path.isdir(args.input): filenames = get_flac_filenames(args.input) filenames.sort() print(filenames) else: filenames = [args.input] # Delete output fname if it exists if not args.do_not_delete_output and os.path.exists(args.output): log.info("Deleting '{}'".format(args.output)) os.remove(args.output) for fname in filenames: convert_flac_file(fname, args.output, args.calibration_file, args.correct_phase)
def main(): scpm.init_logger() recorder = Recorder() try: recorder.start() except KeyboardInterrupt: recorder.terminate() except: log.exception('') recorder.terminate() raise
def main(): scpm.init_logger() sampler = Sampler() wu = WattsUp() try: sampler.open() sampler.start() wu.open() calibration = scpm.load_calibration_file() log.info("Comparing SCPM data with WattsUp data..." " press CTRL+C to stop.") while True: wu_data = wu.get() # blocking if wu_data is None: log.warn("wu_data is none!") continue time.sleep(config.RECORD_SECONDS) # Now get ADC data recorded at wu_data.time adc_data = scpm.find_time(sampler.adc_data_queue, wu_data.time) if adc_data: print("") adc_data = scpm.join_frames_and_widen(adc_data) split_adc_data = scpm.split_channels(adc_data) adc_rms = scpm.calculate_adc_rms(split_adc_data) calcd_data = scpm.calculate_calibrated_power(split_adc_data, adc_rms, calibration) scpm.print_power(calcd_data, wu_data) else: log.warn("Could not find ADC data for time {}" .format(wu_data.time)) except KeyboardInterrupt: pass except Exception: log.exception("") wu.terminate() sampler.terminate() raise wu.terminate() sampler.terminate()
def main(): scpm.init_logger() sampler = Sampler() wu = WattsUp() try: sampler.open() sampler.start() wu.open() calibration = scpm.load_calibration_file() log.info("Comparing SCPM data with WattsUp data..." " press CTRL+C to stop.") while True: wu_data = wu.get() # blocking if wu_data is None: log.warn("wu_data is none!") continue time.sleep(config.RECORD_SECONDS) # Now get ADC data recorded at wu_data.time adc_data = scpm.find_time(sampler.adc_data_queue, wu_data.time) if adc_data: print("") adc_data = scpm.join_frames_and_widen(adc_data) split_adc_data = scpm.split_channels(adc_data) adc_rms = scpm.calculate_adc_rms(split_adc_data) calcd_data = scpm.calculate_calibrated_power( split_adc_data, adc_rms, calibration) scpm.print_power(calcd_data, wu_data) else: log.warn("Could not find ADC data for time {}".format( wu_data.time)) except KeyboardInterrupt: pass except Exception: log.exception("") wu.terminate() sampler.terminate() raise wu.terminate() sampler.terminate()
def main(): scpm.init_logger() sampler = Sampler() wu = WattsUp() try: sampler.open() sampler.start() wu.open() scpm.calibrate(sampler.adc_data_queue, wu) except KeyboardInterrupt: pass except Exception: log.exception("") wu.terminate() sampler.terminate() raise wu.terminate() sampler.terminate()
def main(): args = setup_argparser() scpm.init_logger() wavfile = uncompress_and_load(args.input_file) samples_per_degree = (wavfile.getframerate() / config.MAINS_HZ) / 360 calibration = scpm.load_calibration_file( filename=args.calibration_file, samples_per_degree=samples_per_degree) adc_data = get_adc_data(wavfile) adc_data.sample_width = wavfile.getsampwidth() adc_data = scpm.join_frames_and_widen(adc_data) split_adc_data = scpm.split_channels(adc_data) adc_rms = scpm.calculate_adc_rms(split_adc_data) voltage, current = scpm.convert_adc_to_numpy_float(split_adc_data) print(len(voltage), len(current)) if calibration is None: print("No calibration data loaded.") else: calcd_data = scpm.calculate_calibrated_power(split_adc_data, adc_rms, calibration) print("") scpm.print_power(calcd_data) if args.correct_phase: print("Correcting phase by {} degrees = {} samples.".format( calibration.phase_diff, calibration.phase_diff_n_samples)) voltage, current = scpm.shift_phase(voltage, current, calibration) else: print("Not correcting phase difference" " (use --correct-phase to correct phase)") scpm.plot(voltage, current, calibration) wavfile.close()
def main(): args = setup_argparser() scpm.init_logger() wavfile = uncompress_and_load(args.input_file) samples_per_degree = (wavfile.getframerate() / config.MAINS_HZ) / 360 calibration = scpm.load_calibration_file(filename=args.calibration_file, samples_per_degree=samples_per_degree) adc_data = get_adc_data(wavfile) adc_data.sample_width = wavfile.getsampwidth() adc_data = scpm.join_frames_and_widen(adc_data) split_adc_data = scpm.split_channels(adc_data) adc_rms = scpm.calculate_adc_rms(split_adc_data) voltage, current = scpm.convert_adc_to_numpy_float(split_adc_data) print(len(voltage), len(current)) if calibration is None: print("No calibration data loaded.") else: calcd_data = scpm.calculate_calibrated_power(split_adc_data, adc_rms, calibration) print("") scpm.print_power(calcd_data) if args.correct_phase: print("Correcting phase by {} degrees = {} samples." .format(calibration.phase_diff, calibration.phase_diff_n_samples)) voltage, current = scpm.shift_phase(voltage, current, calibration) else: print("Not correcting phase difference" " (use --correct-phase to correct phase)") scpm.plot(voltage, current, calibration) wavfile.close()