Create node to store an array. Parameters ---------- node_path : str PyTable node path; e.g. '/path/to/node'. array_or_shape : array or shape tuple Array or shape tuple for an array. If given a shape tuple, the `dtype` parameter mu
(
self,
node_path,
array_or_shape,
dtype=None,
chunked=False,
extendable=False,
**kwargs
)
| 156 | yield node_path, _wrap_node(node) |
| 157 | |
| 158 | def create_array( |
| 159 | self, |
| 160 | node_path, |
| 161 | array_or_shape, |
| 162 | dtype=None, |
| 163 | chunked=False, |
| 164 | extendable=False, |
| 165 | **kwargs |
| 166 | ): |
| 167 | """Create node to store an array. |
| 168 | |
| 169 | Parameters |
| 170 | ---------- |
| 171 | node_path : str |
| 172 | PyTable node path; e.g. '/path/to/node'. |
| 173 | array_or_shape : array or shape tuple |
| 174 | Array or shape tuple for an array. If given a shape tuple, the |
| 175 | `dtype` parameter must also specified. |
| 176 | dtype : str or numpy.dtype |
| 177 | Data type of array. Only necessary if `array_or_shape` is a shape. |
| 178 | chunked : bool |
| 179 | Controls whether the array is chunked. |
| 180 | extendable : {None | bool} |
| 181 | Controls whether the array is extendable. |
| 182 | kwargs : key/value pairs |
| 183 | Keyword args passed to PyTables `File.create_(c|e)array`. |
| 184 | """ |
| 185 | self._check_node(node_path) |
| 186 | self._assert_valid_path(node_path) |
| 187 | |
| 188 | h5 = self._h5 |
| 189 | |
| 190 | if isinstance(array_or_shape, tuple): |
| 191 | if dtype is None: |
| 192 | msg = "`dtype` must be specified if only given array shape." |
| 193 | raise ValueError(msg) |
| 194 | array = None |
| 195 | dtype = dtype |
| 196 | shape = array_or_shape |
| 197 | else: |
| 198 | array = array_or_shape |
| 199 | dtype = array.dtype.name |
| 200 | shape = array.shape |
| 201 | |
| 202 | path, name = self.split_path(node_path) |
| 203 | if extendable: |
| 204 | shape = (0,) + shape[1:] |
| 205 | atom = get_atom(dtype) |
| 206 | node = h5.create_earray( |
| 207 | path, name, atom, shape, filters=self.h5filters, **kwargs |
| 208 | ) |
| 209 | if array is not None: |
| 210 | node.append(array) |
| 211 | elif chunked: |
| 212 | atom = get_atom(dtype) |
| 213 | node = h5.create_carray( |
| 214 | path, name, atom, shape, filters=self.h5filters, **kwargs |
| 215 | ) |