def _dset2rawniml_complete(r): '''adds any missing information and ensures data is formatted properly''' # if data is a list of strings, join it and store it as a string # otherwise leave data untouched if types.numpy_data_isstring(r['data']): r['data'] = list(r['data']) while True: data = r['data'] tp = type(data) if types.numpy_data_isstring(r['data']): r['data'] = list(r['data']) elif tp is list: r['data'] = ";".join(data) else: break # we're done if issubclass(tp, basestring): r['ni_dimen'] = '1' r['ni_type'] = 'String' elif tp is np.ndarray: data = types.nimldataassupporteddtype(data) if len(data.shape) == 1: data = np.reshape(data, (data.shape[0], 1)) r['data'] = data # ensure we store a supported type nrows, ncols = data.shape r['ni_dimen'] = str(nrows) tpstr = types.numpy_type2name(data.dtype) r['ni_type'] = '%d*%s' % (ncols, tpstr) if nrows > 1 else tpstr else: raise TypeError('Illegal type %r in %r' % (tp, data)) if not 'name' in r: r['name'] = 'AFNI_atr' return r
def _dset2rawniml_complete(r): '''adds any missing information and ensures data is formatted properly''' # if data is a list of strings, join it and store it as a string # otherwise leave data untouched if types.numpy_data_isstring(r['data']): r['data'] = list(r['data']) while True: data = r['data'] tp = type(data) if types.numpy_data_isstring(r['data']): r['data'] = list(r['data']) elif tp is list: if all(isinstance(d, basestring) for d in data): r['data'] = ";".join(data) else: tp = 'mixed' break else: break # we're done if tp == 'mixed': #data = [types.nimldataassupporteddtype(d) for d in data] #r['data'] = data nrows, ncols = _dset_nrows_ncols(data) r['ni_dimen'] = str(nrows) tpstrs = [] for d in data: if isinstance(d, basestring) or \ (type(d) is list and all(isinstance(di, basestring) for di in d)): tpstr = 'String' elif isinstance(d, np.ndarray): tpstr = types.numpy_type2name(d.dtype) else: raise ValueError('unrecognized type %s' % type(d)) tpstrs.append(tpstr) r['ni_type'] = ','.join(tpstrs) elif issubclass(tp, basestring): r['ni_dimen'] = '1' r['ni_type'] = 'String' elif tp is np.ndarray: data = types.nimldataassupporteddtype(data) if len(data.shape) == 1: data = np.reshape(data, (data.shape[0], 1)) r['data'] = data # ensure we store a supported type nrows, ncols = data.shape r['ni_dimen'] = str(nrows) tpstr = types.numpy_type2name(data.dtype) r['ni_type'] = '%d*%s' % (ncols, tpstr) if nrows > 1 else tpstr elif not data is None: raise TypeError('Illegal type %r in %r' % (tp, data)) if not 'name' in r: r['name'] = 'AFNI_atr' return r
def _dset2rawniml_complete(r): """adds any missing information and ensures data is formatted properly""" # if data is a list of strings, join it and store it as a string # otherwise leave data untouched if types.numpy_data_isstring(r["data"]): r["data"] = list(r["data"]) while True: data = r["data"] tp = type(data) if types.numpy_data_isstring(r["data"]): r["data"] = list(r["data"]) elif tp is list: if all(isinstance(d, basestring) for d in data): r["data"] = ";".join(data) else: tp = "mixed" break else: break # we're done if tp == "mixed": # data = [types.nimldataassupporteddtype(d) for d in data] # r['data'] = data nrows, ncols = _dset_nrows_ncols(data) r["ni_dimen"] = str(nrows) tpstrs = [] for d in data: if isinstance(d, basestring) or (type(d) is list and all(isinstance(di, basestring) for di in d)): tpstr = "String" elif isinstance(d, np.ndarray): tpstr = types.numpy_type2name(d.dtype) else: raise ValueError("unrecognized type %s" % type(d)) tpstrs.append(tpstr) r["ni_type"] = ",".join(tpstrs) elif issubclass(tp, basestring): r["ni_dimen"] = "1" r["ni_type"] = "String" elif tp is np.ndarray: data = types.nimldataassupporteddtype(data) if len(data.shape) == 1: data = np.reshape(data, (data.shape[0], 1)) r["data"] = data # ensure we store a supported type nrows, ncols = data.shape r["ni_dimen"] = str(nrows) tpstr = types.numpy_type2name(data.dtype) r["ni_type"] = "%d*%s" % (ncols, tpstr) if nrows > 1 else tpstr elif data is not None: raise TypeError("Illegal type %r in %r" % (tp, data)) if not "name" in r: r["name"] = "AFNI_atr" return r