Skip to content

Instantly share code, notes, and snippets.

@emakryo
Created February 7, 2017 08:22
Show Gist options
  • Save emakryo/3272f53f9d028186303ddeabb3ad7253 to your computer and use it in GitHub Desktop.
Save emakryo/3272f53f9d028186303ddeabb3ad7253 to your computer and use it in GitHub Desktop.
#!/usr/bin/env pythonw
import os
import sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog
if __name__ == '__main__':
app = QApplication(sys.argv)
w = QWidget()
# w.show()
home_dir = os.path.expanduser('~')
file_dialog = QFileDialog(w)
file_dialog.setFileMode(QFileDialog.ExistingFile)
read_file = file_dialog.getOpenFileName(w, 'Open file', home_dir)[0]
print(read_file)
data = [[]]
try:
with open(read_file) as f:
for line in f:
fields = line.split()
start = int(int(fields[5], 16)//0x8000)
value = int(int(fields[6], 16)//4)
if start > 0:
data .append([])
data[-1].append(value)
except IndexError:
QMessageBox.critical("Parse Error", "Invalid file format: " + raed_file)
sys.exit(1)
length = max([len(x) for x in data])
data = list(filter(lambda x: len(x) > 0, data))
for x in data:
if len(x) < length:
x.extend([np.nan]*(length-len(x)))
file_dialog = QFileDialog(w)
if len(os.path.dirname(read_file)) > 0:
default_write_dir = os.path.dirname(read_file)
else:
default_write_dir = '~'
write_dir = QFileDialog.getExistingDirectory(w, 'Save folder', default_write_dir)
print(write_dir)
for i, x in enumerate(data):
plt.xlim((0,length))
plt.xlabel('Delta')
plt.ylabel('Intensity')
plt.plot(x)
plt.savefig(os.path.join(write_dir, 'plot%d.png'%i))
plt.clf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment