Removing matplotlib dependency

Change-Id: I6aa93b00c888e4d80b88952df8c202cb0c66f2a2
This commit is contained in:
t2 2017-11-09 09:41:17 +01:00
parent 1731188222
commit 8d4680ccc5
4 changed files with 12 additions and 56 deletions

View File

@ -1,4 +1,3 @@
import matplotlib.pyplot as plt
import csv import csv
import numpy as np import numpy as np
from numpy import linalg from numpy import linalg
@ -19,38 +18,12 @@ class OpusData(object):
self.interpolated_data = interp self.interpolated_data = interp
self.meta = meta self.meta = meta
def plot_raw(self):
plt.plot(self.raw_data[0], self.raw_data[1], 'o', markeredgewidth=1,
markeredgecolor='r', markerfacecolor='None')
plt.show()
def plot_interpolated(self):
if self.interpolated_data:
plt.plot(self.interpolated_data[0], self.interpolated_data[1], 'o')
plt.show()
else:
raise NoInterpolatedDataException()
def plot_data(self):
plt.plot(self.raw_data[0], self.raw_data[1], 'bo')
if self.interpolated_data:
plt.plot(self.interpolated_data[0],
self.interpolated_data[1],
'ro')
plt.show()
def compare_with(self, file_path): def compare_with(self, file_path):
with open(file_path, 'rb') as csv_file: with open(file_path, 'rb') as csv_file:
csv_reader = csv.reader(csv_file) csv_reader = csv.reader(csv_file)
x_r = np.array(map(lambda x: float(x[1:]), next(csv_reader)[2:]))
y_r = np.array(map(lambda x: float(x), next(csv_reader)[2:])) y_r = np.array(map(lambda x: float(x), next(csv_reader)[2:]))
dist = linalg.norm(y_r - self.interpolated_data[1], ord=1) dist = linalg.norm(y_r - self.raw_data[1], ord=1)
print("L1 distance between rbart and python versions:", dist) print("L1 distance between series:", dist)
plt.plot(x_r, y_r, 'bo')
plt.plot(self.interpolated_data[0],
self.interpolated_data[1],
'ro')
plt.show()
def gen_interp_waves(self, conf): def gen_interp_waves(self, conf):
wunit = (conf.wave_start - conf.wave_end) / (float(conf.iwsize - 1)) wunit = (conf.wave_start - conf.wave_end) / (float(conf.iwsize - 1))

View File

@ -1,26 +1,18 @@
from brukeropusreader.opus_reader import opus_reader from brukeropusreader.opus_reader import opus_reader
from os import walk
import os
import sys import sys
import argparse
def filter_fun(nm): def main(path_to_file):
return (nm[0] != '.') and (nm[-2:] in ('.0', '.1', '.2', '.3')) od = opus_reader(path_to_file)
print(od.raw_data[1])
def main(path_to_opus_files):
i = 0
all_files = 0
for path, subdirs, files in walk(path_to_opus_files):
for name in filter(filter_fun, files):
all_files += 1
try:
od = opus_reader(os.path.join(path, name))
od.plot_raw()
except Exception as e:
i += 1
print(i, ":", name, str(e))
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("opus_path",
help="Path to opus file",
action="store")
args = parser.parse_args()
main(sys.argv[1]) main(sys.argv[1])

View File

@ -1,3 +1,2 @@
numpy numpy
scipy scipy
matplotlib

View File

@ -4,13 +4,5 @@
# #
# pip-compile --output-file requirements.txt requirements.in # pip-compile --output-file requirements.txt requirements.in
# #
backports.functools-lru-cache==1.4 # via matplotlib
cycler==0.10.0 # via matplotlib
matplotlib==2.1.0
numpy==1.13.3 numpy==1.13.3
pyparsing==2.2.0 # via matplotlib
python-dateutil==2.6.1 # via matplotlib
pytz==2017.2 # via matplotlib
scipy==0.19.1 scipy==0.19.1
six==1.11.0 # via cycler, matplotlib, python-dateutil
subprocess32==3.2.7 # via matplotlib