|
| 1 | +% nix.DataArray class that can store arbitrary n-dimensional data |
| 2 | +% along with further information. |
| 3 | +% |
| 4 | +% The DataArray is the core entity of the NIX data model, its purpose is to store |
| 5 | +% arbitrary n-dimensional data. In addition to the common fields id, name, type, |
| 6 | +% and definition the DataArray stores sufficient information to understand the |
| 7 | +% physical nature of the stored data. |
| 8 | +% |
| 9 | +% A guiding principle of the data model is to provide enough information to create a |
| 10 | +% plot of the stored data. In order to do so, the DataArray defines a property dataType |
| 11 | +% which provides the physical type of the stored data (for example 16 bit integer or |
| 12 | +% double precision IEEE floatingpoint number). The property unit specifies the SI unit |
| 13 | +% of the values stored in the DataArray whereas the label defines what is given in this |
| 14 | +% units. Together, both specify what corresponds to the the y-axis of a plot. |
| 15 | +% |
| 16 | +% In some cases it is much more efficient or convenient to store data not as floating |
| 17 | +% point numbers but rather as (16 bit) integer values as, for example, read from a data |
| 18 | +% acquisition board. In order to convert such data to the correct values, we follow the |
| 19 | +% approach taken by the comedi data-acquisition library (http://www.comedi.org) and |
| 20 | +% provide polynomCoefficients and an expansionOrigin. |
| 21 | +% |
| 22 | +% A DataArray can only be created from a Block entity. Do not use the |
| 23 | +% DataArray constructor. |
| 24 | +% |
| 25 | +% DataArray supports only the storage of numeric and logical data. |
| 26 | +% |
| 27 | +% nix.DataArray dynamic properties: |
| 28 | +% id (char): read-only, automatically created id of the entity. |
| 29 | +% name (char): read-only, name of the entity. |
| 30 | +% type (char): read-write, type can be used to give semantic meaning to an |
| 31 | +% entity and expose it to search methods in a broader context. |
| 32 | +% definition (char): read-write, optional description of the entity. |
| 33 | +% label (char): read-write, optional label of the raw data for plotting. |
| 34 | +% unit (char): read-write, optional unit of the raw data. |
| 35 | +% Supports only SI units. |
| 36 | +% expansionOrigin (double): read-write, the expansion origin of the |
| 37 | +% calibration polynom. 0.0 by default. |
| 38 | +% polynomCoefficients (double): read-write, The polynom coefficients for the |
| 39 | +% calibration. By default this is set to a |
| 40 | +% {0.0, 1.0} for a linear calibration with zero offset. |
| 41 | +% dataExtent ([double]): read-write, the size of the raw data. |
| 42 | +% The size of a DataArray can be changed with this |
| 43 | +% property, but only within the original dimensionality, |
| 44 | +% e.g. a 2D array must always remain a 2D array, but |
| 45 | +% can be modified in either of the two dimensions. |
| 46 | +% |
| 47 | +% info (struct): Entity property summary. The values in this structure are detached |
| 48 | +% from the entity, changes will not be persisted to the file. |
| 49 | +% |
| 50 | +% nix.DataArray dynamic child entity properties: |
| 51 | +% dimensions access to all dimensions associated with a DataArray. |
| 52 | +% sources access to all first level nix.Source child entities. |
| 53 | +% |
| 54 | +% See also nix.Source, nix.Section. |
| 55 | +% |
| 56 | +% |
1 | 57 | % Copyright (c) 2016, German Neuroinformatics Node (G-Node)
|
2 | 58 | %
|
3 | 59 | % All rights reserved.
|
|
7 | 63 | % LICENSE file in the root of the Project.
|
8 | 64 |
|
9 | 65 | classdef DataArray < nix.NamedEntity & nix.MetadataMixIn & nix.SourcesMixIn
|
10 |
| - %DataArray nix DataArray object |
11 | 66 |
|
12 | 67 | properties (Hidden)
|
13 |
| - % namespace reference for nix-mx functions |
14 |
| - alias = 'DataArray' |
| 68 | + alias = 'DataArray' % namespace for DataArray nix backend function access. |
15 | 69 | end
|
16 | 70 |
|
17 | 71 | properties (Dependent)
|
18 |
| - dimensions % should not be dynamic due to complex set operation |
| 72 | + dimensions % should not be dynamic due to complex set operation. |
19 | 73 | end
|
20 | 74 |
|
21 | 75 | methods
|
|
37 | 91 | % -----------------
|
38 | 92 |
|
39 | 93 | function dimensions = get.dimensions(obj)
|
| 94 | + % Get all Dimensions associated with this DataArray. |
| 95 | + % |
| 96 | + % Returns: ([nix.Dimension]) A list of all associated Dimensions. |
| 97 | + % |
| 98 | + % Example: dims = currDataArray.dimensions; |
| 99 | + % |
| 100 | + % See also nix.RangeDimension, nix.SampledDimension, nix.SetDimension. |
| 101 | + |
40 | 102 | dimensions = {};
|
41 | 103 | fname = strcat(obj.alias, '::dimensions');
|
42 | 104 | currList = nix_mx(fname, obj.nixhandle);
|
|
58 | 120 | end
|
59 | 121 |
|
60 | 122 | function r = appendSetDimension(obj)
|
| 123 | + % Append a new SetDimension as last entry to the list of existing |
| 124 | + % dimension descriptors of the invoking DataArray. |
| 125 | + % |
| 126 | + % Used to provide labels for dimensionless data e.g. when stacking |
| 127 | + % different signals. In the example the first dimension would |
| 128 | + % describe the measured unit, the second dimension the time, |
| 129 | + % the third dimension would provide labels for three different |
| 130 | + % signals measured within the same experiment and packed into |
| 131 | + % the same 3D DataArray. |
| 132 | + % |
| 133 | + % Returns: (nix.SetDimension) The newly created SetDimension. |
| 134 | + % |
| 135 | + % Example: dim = currDataArray.appendSetDimension(); |
| 136 | + % |
| 137 | + % See also nix.SetDimension. |
| 138 | + |
61 | 139 | fname = strcat(obj.alias, '::appendSetDimension');
|
62 | 140 | h = nix_mx(fname, obj.nixhandle);
|
63 | 141 | r = nix.Utils.createEntity(h, @nix.SetDimension);
|
64 | 142 | end
|
65 | 143 |
|
66 | 144 | function r = appendSampledDimension(obj, interval)
|
| 145 | + % Append a new SampledDimension as last entry to the list of |
| 146 | + % existing dimension descriptors of the invoking DataArray. |
| 147 | + % |
| 148 | + % Used to describe the regularly sampled dimension of data. |
| 149 | + % |
| 150 | + % interval (double): The sampling interval of the Dimension to create. |
| 151 | + % |
| 152 | + % Returns: (nix.SampledDimension) The newly created SampledDimension. |
| 153 | + % |
| 154 | + % Example: stepSize = 5; |
| 155 | + % dim = currDataArray.appendSampledDimension(stepSize); |
| 156 | + % |
| 157 | + % See also nix.SampledDimension. |
| 158 | + |
67 | 159 | fname = strcat(obj.alias, '::appendSampledDimension');
|
68 | 160 | h = nix_mx(fname, obj.nixhandle, interval);
|
69 | 161 | r = nix.Utils.createEntity(h, @nix.SampledDimension);
|
70 | 162 | end
|
71 | 163 |
|
72 | 164 | function r = appendRangeDimension(obj, ticks)
|
| 165 | + % Append a new SampledDimension as last entry to the list of |
| 166 | + % existing dimension descriptors of the invoking DataArray. |
| 167 | + % |
| 168 | + % Used to describe the irregularly sampled dimension of data. |
| 169 | + % |
| 170 | + % ticks ([double]): The ticks of the RangeDimension. |
| 171 | + % |
| 172 | + % Returns: (nix.RangeDimension) The newly created RangeDimension. |
| 173 | + % |
| 174 | + % Example: dim = currDataArray.appendRangeDimension([1 10 21 15]); |
| 175 | + % |
| 176 | + % See also nix.SampledDimension. |
| 177 | + |
73 | 178 | fname = strcat(obj.alias, '::appendRangeDimension');
|
74 | 179 | h = nix_mx(fname, obj.nixhandle, ticks);
|
75 | 180 | r = nix.Utils.createEntity(h, @nix.RangeDimension);
|
76 | 181 | end
|
77 | 182 |
|
78 | 183 | function r = appendAliasRangeDimension(obj)
|
| 184 | + % Append a new RangeDimension that uses the data stored in the invoking |
| 185 | + % DataArray as ticks. |
| 186 | + % This works only(!) if the DataArray is 1D and the stored data is numeric. |
| 187 | + % |
| 188 | + % Returns: (nix.RangeDimension) The newly created RangeDimension. |
| 189 | + % |
| 190 | + % Example: dim = currDataArray.appendAliasRangeDimension(); |
| 191 | + % |
| 192 | + % See also nix.RangeDimension. |
| 193 | + |
79 | 194 | fname = strcat(obj.alias, '::appendAliasRangeDimension');
|
80 | 195 | h = nix_mx(fname, obj.nixhandle);
|
81 | 196 | r = nix.Utils.createEntity(h, @nix.RangeDimension);
|
82 | 197 | end
|
83 | 198 |
|
84 | 199 | function r = openDimensionIdx(obj, idx)
|
85 |
| - % Getting the dimension by index starts with 1 |
86 |
| - % instead of 0 compared to all other index functions. |
| 200 | + % Returns the Dimension entity for the specified dimension of the data. |
| 201 | + % |
| 202 | + % idx (double): The index of the respective Dimension. |
| 203 | + % |
| 204 | + % Returns: (nix.Dimension) The corresonding Dimension. |
| 205 | + % |
| 206 | + % Example: dim = currDataArray.openDimensionIdx(2); |
| 207 | + % |
| 208 | + % See also nix.RangeDimension, nix.SampledDimension, nix.SetDimension. |
| 209 | + |
87 | 210 | fname = strcat(obj.alias, '::openDimensionIdx');
|
88 | 211 | dim = nix_mx(fname, obj.nixhandle, idx);
|
89 | 212 | switch (dim.dimensionType)
|
|
97 | 220 | end
|
98 | 221 |
|
99 | 222 | function r = deleteDimensions(obj)
|
| 223 | + % Remove all Dimensions from the invoking DataArray. |
| 224 | + % |
| 225 | + % Returns: (logical) True if the Dimensions were removed, |
| 226 | + % False otherwise. |
| 227 | + % |
| 228 | + % Example: check = currDataArray.deleteDimensions(); |
| 229 | + |
100 | 230 | fname = strcat(obj.alias, '::deleteDimensions');
|
101 | 231 | r = nix_mx(fname, obj.nixhandle);
|
102 | 232 | end
|
103 | 233 |
|
104 | 234 | function r = dimensionCount(obj)
|
| 235 | + % Get the number of nix.Dimensions associated with the invoking DataArray. |
| 236 | + % |
| 237 | + % Returns: (uint) The number of Dimensions. |
| 238 | + % |
| 239 | + % Example: dc = currDataArray.dimensionCount(); |
| 240 | + |
105 | 241 | r = nix.Utils.fetchEntityCount(obj, 'dimensionCount');
|
106 | 242 | end
|
107 | 243 |
|
|
110 | 246 | % -----------------
|
111 | 247 |
|
112 | 248 | function r = readAllData(obj)
|
| 249 | + % Returns an array with the complete raw data stored in the |
| 250 | + % DataArray. |
| 251 | + % |
| 252 | + % The returned data is read-only, changes will not be written to file. |
| 253 | + % |
| 254 | + % Returns: (var) The complete raw data. |
| 255 | + % |
| 256 | + % Example: data = currDataArray.readAllData(); |
| 257 | + |
113 | 258 | fname = strcat(obj.alias, '::readAll');
|
114 | 259 | data = nix_mx(fname, obj.nixhandle);
|
115 | 260 | r = nix.Utils.transposeArray(data);
|
|
119 | 264 | %-- If a DataArray has been created as boolean or numeric,
|
120 | 265 | %-- provide that only values of the proper DataType can be written.
|
121 | 266 | function [] = writeAllData(obj, data)
|
| 267 | + % Writes raw data to the invoking DataArray. |
| 268 | + % |
| 269 | + % DataType and extent of the written data has to |
| 270 | + % match the invoking DataArray. |
| 271 | + % |
| 272 | + % Example: dataSet = ones(15, 15, 15); |
| 273 | + % currDataArray.writeAllData(dataSet); |
| 274 | + |
122 | 275 | if (isinteger(obj.readAllData) && isfloat(data))
|
123 | 276 | disp('Warning: Writing Float data to an Integer DataArray');
|
124 | 277 | end
|
|
147 | 300 | end
|
148 | 301 |
|
149 | 302 | function r = datatype(obj)
|
| 303 | + % Returns the datatype of the data stored by the invoking DataArray. |
| 304 | + % |
| 305 | + % Example: dt = currDataArray.datatype; |
| 306 | + |
150 | 307 | fname = strcat(obj.alias, '::dataType');
|
151 | 308 | r = nix_mx(fname, obj.nixhandle);
|
152 | 309 | end
|
153 | 310 |
|
154 |
| - % Set data extent enables to increase the original size |
155 |
| - % of a data array within the same dimensions. |
156 |
| - % e.g. increase the size of a 2D array [5 10] to another |
157 |
| - % 2D array [5 11]. Changing the dimensions is not possible |
158 |
| - % e.g. changing from a 2D array to a 3D array. |
159 |
| - % Furthermore if the extent shrinks the size of an array |
160 |
| - % or remodels the size of an array to a completely different |
161 |
| - % shape, existing data that does not fit into the new shape |
162 |
| - % will be lost! |
163 | 311 | function [] = setDataExtent(obj, extent)
|
| 312 | + % Change the shape of the invoking DataArray. |
| 313 | + % |
| 314 | + % Set data extent enables to increase the original size |
| 315 | + % of a DataArray within the same dimensions. |
| 316 | + % e.g. increase the size of a 2D array [5 10] to another |
| 317 | + % 2D array [5 11]. Changing the dimensions is not possible |
| 318 | + % e.g. changing from a 2D array to a 3D array. |
| 319 | + % Furthermore if the extent shrinks the size of an array |
| 320 | + % or remodels the size of an array to a completely different |
| 321 | + % shape, existing data that does not fit into the new shape |
| 322 | + % will be lost! |
| 323 | + % |
| 324 | + % extent ([double]): shape of the DataArray. |
| 325 | + % |
| 326 | + % Example: currDataArray.setDataExtent([12 15]); |
| 327 | + |
164 | 328 | fname = strcat(obj.alias, '::setDataExtent');
|
165 | 329 | nix_mx(fname, obj.nixhandle, extent);
|
166 | 330 | end
|
|
0 commit comments