Skip to content

Commit

Permalink
Added json data format loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubenknex committed Aug 29, 2018
1 parent 4798f26 commit e9ff6de
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
56 changes: 54 additions & 2 deletions qtplot/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from scipy.spatial import qhull
from pandas.io.api import read_table
import pandas as pd
import json, codecs

from .util import FixedOrderFormatter, eng_format

Expand All @@ -26,6 +27,43 @@ def __init__(self, filename):
self.shape = ()
self.ndim = 0

_, ext = os.path.splitext(filename)

if ext == '.dat':
self.load_qtlab_data(self.filename)
elif ext == '.json':
content = codecs.open(filename, 'r', 'utf-8').read()
datafile = json.loads(content)

data = []

for key in datafile['data'].keys():
if key == 'Datetime':
continue

self.ids.append(key)
self.labels.append(key)

for coord in datafile['attr']['_coordinates']:
name, size = coord['name'], coord['size']

if key == name:
self.shape = self.shape + (size,)

if size > 1:
self.sizes[name] = size

# Count the number of non-length-1 coordinates
self.ndim += 1

data.append(datafile['data'][key])

self.data = np.array(data).T
else:
logger.error('Unknown file format: %s' % filename)


def load_qtlab_data(self, filename):
with open(filename, 'r') as f:
first_line = f.readline().rstrip('\n\t\r')

Expand Down Expand Up @@ -73,8 +111,6 @@ def __init__(self, filename):
self.data = read_table(filename, comment='#', sep='\t',
header=None).values

self.load_qtlab_settings(filename)

def load_qtlab_settings(self, filename):
self.qtlab_settings = OrderedDict()

Expand Down Expand Up @@ -113,6 +149,22 @@ def load_qtlab_settings(self, filename):
else:
logger.warning('Could not find settings file %s' % settings_file_name)

def load_qcodes_data(self, filename):
with open(filename, 'r') as f:
first_line = f.readline().rstrip('\n\t\r')

logger.info('Loading QCoDeS file %s' % filename)

self.ids = first_line.split()[1:]

column_labels = f.readline().strip()[2:]
self.labels = [s[1:-1] for s in column_labels.split('\t')]

column_sizes = f.readline().strip()[2:]
self.shape = tuple(map(int, column_sizes.split('\t')))

self.ndim = len(self.shape)

def get_column(self, name):
if name in self.ids:
return self.data[:, self.ids.index(name)]
Expand Down
2 changes: 1 addition & 1 deletion qtplot/qtplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def get_axis_names(self):
def on_load_dat(self, event):
open_directory = self.profile_settings['open_directory']
filename = str(QtGui.QFileDialog.getOpenFileName(directory=open_directory,
filter='*.dat'))
filter='*.dat *.json'))

if filename != "":
self.load_dat_file(filename)
Expand Down
2 changes: 2 additions & 0 deletions qtplot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def populate_ui(self):
self.le_save_directory.setText(self.main.profile_settings['save_directory'])

def fill_tree(self):
"""
if self.main.dat_file is not None:
settings = self.main.dat_file.qtlab_settings
widgets = []
Expand All @@ -154,6 +155,7 @@ def fill_tree(self):
widgets.append(parent)
self.tree.insertTopLevelItems(0, widgets)
"""

def on_open_browse(self, event):
directory = str(QtGui.QFileDialog.getExistingDirectory(self, "Select Directory"))
Expand Down

0 comments on commit e9ff6de

Please sign in to comment.