This commit is contained in:
bartels-rausch committed 2023-10-31 10:06:36 +01:00
commit 0337ecc260
3 files changed
+57 -42

No files matched your search

+10 -6
View File
@@ -14,23 +14,27 @@ if ~iscellstr(exclude_var_set)
end
INFO = h5info(filename);
num_rows = length(INFO.Groups);
num_attr1 = length(INFO.Groups(1).Datasets);
num_attr2 = length(INFO.Groups(1).Attributes);
num_cols = num_attr1 + num_attr2;
sz = [num_rows,num_cols];
% Extract group level attributes, they align for all
% groups/measurements/rows of the table in filename .h5
% groups (here denoting measurements/or rows) of the table in filename .h5
group_columns = {INFO.Groups(1).Attributes.Name};
dataset_columns = {};
for j = 1 : num_attr1
dataset_columns{j} = INFO.Groups(1).Datasets(j).Attributes.Value;
if num_attr1 == 1 && isempty(INFO.Groups(1).Datasets(num_attr1).Attributes)
dataset_columns = {};
num_attr1 = 0;
num_cols = num_cols - 1;
else
for j = 1 : num_attr1
dataset_columns{j} = INFO.Groups(1).Datasets(j).Attributes.Value;
end
end
%TODO: Implement feature to exclude varibales/columns as well as rows at
%reading time. This requires propagating modifications
% % % Select group and dataset columns to be loaded from hdf5 file, which are
+47 -36
View File
@@ -10,6 +10,11 @@ function success = save_table_as_hdf5(input_table, filename)
% Email: juan.florez-ospina@psi.ch
if istable(input_table)
string_columns = input_table(:,vartype("string")).Properties.VariableNames;
input_table = convertvars(input_table,string_columns,'cellstr');
% split multicolumn variables
input_table = splitvars(input_table);
column_names = input_table.Properties.VariableNames;
else
success = 0;
@@ -58,44 +63,50 @@ cell_table = input_table(:,rest_columns);
[rows, cols] = size(input_table);
for i = 1 : rows
group_name = strcat("/MEAS",string(i),"/");
for j = 1 : length(rest_columns)
dataset_name = strcat("DS",string(rest_columns_idx(j)));
% Some table entries do not provide direct access to the object
% of interest, but may contain either {object} or {{object}}.
% The following loop solves that problem. TODO: is this generic enough?
data = cell_table{i,column_names{rest_columns_idx(j)}}{1}; % <=> data = cell_table{i,rest_columns{j}}{1};
while iscell(data)
data = data{1};
group_name = strcat("/MEAS_",string(i),"/");
if ~isempty(rest_columns)
for j = 1 : length(rest_columns)
dataset_name = strcat("DS",string(rest_columns_idx(j)));
% Some table entries do not provide direct access to the object
% of interest, but may contain either {object} or {{object}}.
% The following loop solves that problem. TODO: is this generic enough?
data = cell_table{i,column_names{rest_columns_idx(j)}}{1}; % <=> data = cell_table{i,rest_columns{j}}{1};
while iscell(data)
data = data{1};
end
% when there is no data, we still need to provide a valid size
if ~isempty(data)
sz = size(data);
else
sz = [1,1];
end
%%%%
% Group's dataset: Create dataset of size sz in a certain group
h5create(filename, strcat(group_name,dataset_name),sz);
% Dataset's attribute: Add attribute with dataset_name equal to column_name
attr = "column_name";
attr_value = column_names{rest_columns_idx(j)}; % <=> rest_columns{j};
h5writeatt(filename,strcat(group_name,dataset_name),attr,attr_value)
%attr = "column_name_idx";
%attr_value = rest_columns_idx(j); % <=> rest_columns{j};
%h5writeatt(filename,strcat(group_name,dataset_name),attr,attr_value)
% Assign 'data' to the dataset. 'data' has to be of admissible type.
try
h5write(filename,strcat(group_name,dataset_name),data)
catch exception
disp(exception)
%h5write(filename,strcat(group_name,dataset_name),cell_table{i,rest_columns{j}})
end
end
% when there is no data, we still need to provide a valid size
if ~isempty(data)
sz = size(data);
else
sz = [1,1];
end
%%%%
% Group's dataset: Create dataset of size sz in a certain group
else
dataset_name = "DS_EMPTY";
sz = [1,1];
h5create(filename, strcat(group_name,dataset_name),sz);
% Dataset's attribute: Add attribute with dataset_name equal to column_name
attr = "column_name";
attr_value = column_names{rest_columns_idx(j)}; % <=> rest_columns{j};
h5writeatt(filename,strcat(group_name,dataset_name),attr,attr_value)
%attr = "column_name_idx";
%attr_value = rest_columns_idx(j); % <=> rest_columns{j};
%h5writeatt(filename,strcat(group_name,dataset_name),attr,attr_value)
% Assign 'data' to the dataset. 'data' has to be of admissible type.
try
h5write(filename,strcat(group_name,dataset_name),data)
catch exception
disp(exception)
%h5write(filename,strcat(group_name,dataset_name),cell_table{i,rest_columns{j}})
end
end
% Group's attribute: Assign group attributes
View File
Whitespace-only changes.