Skip to content

Commit

Permalink
Merge pull request #27 from kouwenhovenlab/master
Browse files Browse the repository at this point in the history
sync from lab repo
  • Loading branch information
wpfff committed Jan 31, 2019
2 parents 3ccd121 + ab8ec25 commit 252a5fd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
12 changes: 11 additions & 1 deletion plottr/data/datadict.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,8 @@ def guess_shape_from_datadict(data: DataDict) -> \

def datadict_to_meshgrid(data: DataDict,
target_shape: Union[Tuple[int, ...], None] = None,
inner_axis_order: Union[None, List[str]] = None) \
inner_axis_order: Union[None, List[str]] = None,
use_existing_shape: bool = False) \
-> MeshgridDataDict:
"""
Try to make a meshgrid from a dataset.
Expand All @@ -951,6 +952,10 @@ def datadict_to_meshgrid(data: DataDict,
specified axes in all but order.
The data is then transposed to conform to the
specified order.
:param use_existing_shape: if ``True``, simply use the shape that the data
already has. For numpy-array data, this might
already be present.
if ``False``, flatten and reshape.
:return: the generated ``MeshgridDataDict``.
"""

Expand All @@ -961,6 +966,11 @@ def datadict_to_meshgrid(data: DataDict,
if not data.axes_are_compatible():
raise ValueError('Non-compatible axes, cannot grid that.')

if not use_existing_shape and data.is_expandable():
data = data.expand()
elif use_existing_shape:
target_shape = data.dependents()[0].shape

# guess what the shape likely is.
if target_shape is None:
shp_specs = guess_shape_from_datadict(data)
Expand Down
71 changes: 36 additions & 35 deletions plottr/data/qcodes_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_data_from_ds(ds: DataSet, start: Optional[int] = None,
with `start` and `end` only a subset of rows in the DB can be specified.
"""
names = [n for n, v in ds.paramspecs.items()]
return {n : ds.get_data(n, start=start, end=end) for n in names}
return {n : np.squeeze(ds.get_data(n, start=start, end=end)) for n in names}


def get_all_data_from_ds(ds: DataSet) -> Dict[str, List[List]]:
Expand All @@ -171,39 +171,39 @@ def get_all_data_from_ds(ds: DataSet) -> Dict[str, List[List]]:
return get_data_from_ds(ds)


def expand(data: Dict[str, List[List]],
copy=True) -> Dict[str, np.ndarray]:
"""
Expands data to get us everying expanded into columns of the same length.
To achieve the same length, data will be repeated along the most inner
axis if necessary.
Arguments:
data: dictionary in the form {'name' : [[row1], [row2], ...], ...}.
the values are thus exactly what dataset.get_data('name') will return.
"""
if copy:
data = deepcopy(data)

inner_len = 1
for k, v in data.items():
if len(v) == 0:
return data

if type(v[0][0]) not in [list, np.ndarray]:
continue
else:
inner_len = len(v[0][0])
break

for k, v in data.items():
v = np.array(v)
if inner_len > 1 and v.shape[-1] == 1:
v = np.repeat(v, inner_len, axis=-1)
v = v.reshape(-1)
data[k] = v

return data
# def expand(data: Dict[str, List[List]],
# copy=True) -> Dict[str, np.ndarray]:
# """
# Expands data to get us everying expanded into columns of the same length.
# To achieve the same length, data will be repeated along the most inner
# axis if necessary.
#
# Arguments:
# data: dictionary in the form {'name' : [[row1], [row2], ...], ...}.
# the values are thus exactly what dataset.get_data('name') will return.
# """
# if copy:
# data = deepcopy(data)
#
# inner_len = 1
# for k, v in data.items():
# if len(v) == 0:
# return data
#
# if type(v[0][0]) not in [list, np.ndarray]:
# continue
# else:
# inner_len = len(v[0][0])
# break
#
# for k, v in data.items():
# v = np.array(v)
# if inner_len > 1 and v.shape[-1] == 1:
# v = np.repeat(v, inner_len, axis=-1)
# v = v.reshape(-1)
# data[k] = v
#
# return data


def ds_to_datadict(ds: DataDict, start: Optional[int] = None,
Expand All @@ -212,7 +212,8 @@ def ds_to_datadict(ds: DataDict, start: Optional[int] = None,
Make a datadict from a qcodes dataset.
`start` and `end` allow selection of only a subset of rows.
"""
data = expand(get_data_from_ds(ds, start=start, end=end))
# data = expand(get_data_from_ds(ds, start=start, end=end))
data = get_data_from_ds(ds, start=start, end=end)
struct = get_ds_structure(ds)
datadict = DataDict(**struct)
for k, v in data.items():
Expand Down
2 changes: 1 addition & 1 deletion plottr/node/dim_reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def validateOptions(self, data):
self.logger().debug(f'x-Axis is None. this will result in empty output data.')
return False
elif self._xyAxes[0] not in availableAxes:
self.logger().warning(f'x-Axis {self._xyAxis[0]} not present in data')
self.logger().warning(f'x-Axis {self._xyAxes[0]} not present in data')
return False

if self._xyAxes[1] is None:
Expand Down

0 comments on commit 252a5fd

Please sign in to comment.