Skip to content

Commit

Permalink
Merge pull request #469 from achilleas-k/feat/dimension-links
Browse files Browse the repository at this point in the history
Dimension links
  • Loading branch information
jgrewe authored Jul 20, 2020
2 parents 2e6491f + 0ab71e7 commit 5e9ab0b
Show file tree
Hide file tree
Showing 13 changed files with 589 additions and 395 deletions.
39 changes: 25 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ matrix:
env: pymajor=3 coverage=1
dist: xenial
sudo: true
- python: "3.7"
os: linux
env: pymajor=3 nocompat=1
dist: xenial
- language: generic
os: osx
env: pymajor=2
Expand Down Expand Up @@ -56,25 +60,28 @@ addons:
- libboost-all-dev

before_install:
- nixprefix="/usr/local"
- export NIX_INCDIR=${nixprefix}/include/nixio-1.0
- export NIX_LIBDIR=${nixprefix}/lib
- export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:${nixprefix}/lib/pkgconfig
# build nix for compat tests
- if [[ -z "${nocompat}" ]]; then
nixprefix="/usr/local";
export NIX_INCDIR=${nixprefix}/include/nixio-1.0;
export NIX_LIBDIR=${nixprefix}/lib;
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:${nixprefix}/lib/pkgconfig;
git clone --branch ${NIX_BRANCH} https://github.com/G-Node/nix /tmp/libnix;
pushd /tmp/libnix;
mkdir build;
pushd build;
cmake -DCMAKE_INSTALL_PREFIX=${nixprefix} ..;
make;
sudo make install;
popd;
popd;
fi
# For macOS python3
- export PATH="/usr/local/opt/python@3.8/bin:$PATH"
- alias pip2='pip'
- if [[ "${TRAVIS_OS_NAME}" != "osx" ]]; then pip${pymajor} install --upgrade numpy; fi
- pip${pymajor} install --upgrade h5py pytest pytest-xdist pytest-cov six;
- if [[ "${pymajor}" == 2 ]]; then pip${pymajor} install enum34; fi
- git clone --branch ${NIX_BRANCH} https://github.com/G-Node/nix /tmp/libnix
- pushd /tmp/libnix
- mkdir build
- pushd build
- cmake -DCMAKE_INSTALL_PREFIX=${nixprefix} ..
- make
- sudo make install
- popd
- popd
- which pip${pymajor}
- which python${pymajor}
- python${pymajor} --version
Expand All @@ -83,7 +90,11 @@ install:
- python${pymajor} setup.py build

script:
- pytest --cov=nixio --nix-compat -nauto;
- if [[ "${nocompat}" == 1 ]]; then
pytest --cov=nixio -nauto;
else
pytest --cov=nixio --nix-compat -nauto;
fi

after_success:
- if [[ "${coverage}" == 1 ]]; then
Expand Down
9 changes: 4 additions & 5 deletions nixio/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,10 @@ def create_data_frame(self, name="", type_="", col_dict=None,
else: # if col_names is None
if data is not None and type(data[0]) == np.void:
col_dtype = data[0].dtype
for i, dt in enumerate(col_dtype.fields.values()):
cn = list(col_dtype.fields.keys())
raw_dt = col_dtype.fields.values()
raw_dt = list(raw_dt)
raw_dt_list = [ele[0] for ele in raw_dt]
cn = list(col_dtype.fields.keys())
raw_dt = col_dtype.fields.values()
raw_dt = list(raw_dt)
raw_dt_list = [ele[0] for ele in raw_dt]
col_dict = OrderedDict(zip(cn, raw_dt_list))
if len(col_dtype.fields.values()) != len(col_dict):
raise exceptions.DuplicateColumnName
Expand Down
71 changes: 3 additions & 68 deletions nixio/data_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
from .source_link_container import SourceLinkContainer
from .datatype import DataType
from .dimensions import (Dimension, SampledDimension, RangeDimension,
SetDimension, DataFrameDimension,
DimensionType, DimensionContainer)
SetDimension, DimensionType, DimensionContainer)
from . import util
from .compression import Compression

from .exceptions import InvalidUnit, IncompatibleDimensions
from .exceptions import IncompatibleDimensions
from .section import Section


Expand Down Expand Up @@ -118,7 +117,7 @@ def append_sampled_dimension(self, sampling_interval, label=None,
self.force_updated_at()
return smpldim

def append_range_dimension(self, ticks, label=None, unit=None):
def append_range_dimension(self, ticks=None, label=None, unit=None):
"""
Append a new RangeDimension to the list of existing dimension
descriptors.
Expand All @@ -138,61 +137,6 @@ def append_range_dimension(self, ticks, label=None, unit=None):
self.force_updated_at()
return rdim

def append_data_frame_dimension(self, data_frame, column_idx=None):
"""
Append a new DataFrameDimension to the list of existing dimension
descriptors.
:param data_frame: The referenced DataFrame
:type data_frame: nix.DataFrame
:param column_idx: Index of the referenced column of the DataFrame.
The default column determines the default label,
ticks, and unit of this Dimension.
:type column_idx: int or None
:returns: Thew newly created DataFrameDimension.
:rtype: DataFrameDimension
"""
index = len(self.dimensions) + 1
dfdim = DataFrameDimension.create_new(self, index,
data_frame, column_idx)
if self.file.auto_update_timestamps:
self.force_updated_at()
return dfdim

def append_alias_range_dimension(self):
"""
Append a new RangeDimension that uses the data stored in this
DataArray as ticks. This works only(!) if the DataArray is 1-D and
the stored data is numeric. A ValueError will be raised otherwise.
:returns: The created dimension descriptor.
:rtype: RangeDimension
"""
if (len(self.data_extent) > 1 or
not DataType.is_numeric_dtype(self.dtype)):
raise ValueError("AliasRangeDimensions only allowed for 1D "
"numeric DataArrays.")
if self._dimension_count() > 0:
raise ValueError("Cannot append additional alias dimension. "
"There must only be one!")
# check if existing unit is SI
if self.unit:
u = self.unit
if not (util.units.is_si(u) or util.units.is_compound(u)):
raise InvalidUnit(
"AliasRangeDimensions are only allowed when SI or "
"composites of SI units are used. "
"Current SI unit is {}".format(u),
"DataArray.append_alias_range_dimension"
)
aliasdim = RangeDimension.create_new_alias(self, 1)
if self.file.auto_update_timestamps:
self.force_updated_at()
return aliasdim

def delete_dimensions(self):
"""
Delete all the dimension descriptors for this DataArray.
Expand Down Expand Up @@ -311,15 +255,6 @@ def unit(self, u):
if u == "":
u = None
util.check_attr_type(u, str)
if (self._dimension_count() == 1 and
self.dimensions[0].dimension_type == DimensionType.Range and
self.dimensions[0].is_alias and u is not None):
if not (util.units.is_si(u) or util.units.is_compound(u)):
raise InvalidUnit(
"[{}]: Non-SI units are not allowed if the DataArray "
"has an AliasRangeDimension.".format(u),
"DataArray.unit"
)
self._h5group.set_attr("unit", u)
if self.file.auto_update_timestamps:
self.force_updated_at()
Expand Down
2 changes: 1 addition & 1 deletion nixio/data_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def write_rows(self, rows, index):
self._write_data(rows, sl=index)
else:
cr_list = []
for i, cr in enumerate(rows):
for cr in rows:
cr_list.append(tuple(cr))
self._write_data(cr_list, sl=index)

Expand Down
Loading

0 comments on commit 5e9ab0b

Please sign in to comment.