-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathnwbExport.m
More file actions
104 lines (99 loc) · 3.94 KB
/
nwbExport.m
File metadata and controls
104 lines (99 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function nwbExport(nwbFileObjects, filePaths, mode, options)
%NWBEXPORT - Writes an NWB file.
%
% Syntax:
% NWBEXPORT(nwb, filename) Writes the nwb object to a file at filename.
%
% NWBEXPORT(nwb, filename, Name, Value) Writes the nwb object using additional
% options provided as name-value pairs.
%
% Input Arguments:
% - nwb (NwbFile) - Nwb file object
% - filename (string) - Filepath pointing to an NWB file.
%
% Name-Value Arguments (options):
% Specify options using name-value arguments as Name1=Value1,...,NameN=ValueN,
% where Name is the argument name and Value is the corresponding value.
%
% - DatasetSettingsProfile (string) -
% Default: "none". Name of a predefined configuration profile for dataset
% chunking and compression. Available options: "default", "cloud" or
% "archive". If this argument is specified, all datasets in the file larger
% than a threshold specified in the profile will be configured for chunking
% and compression.
%
% - DatasetSettings (string | struct) -
% Default: empty struct. Provide the filename of a custom configuration
% profile or an in-memory structure representing a configuration profile.
%
% - OverrideDatasetSettings (logical) -
% Default: false. When true, existing DataPipe objects found in the file are reconfigured
% using the provided dataset settings.
%
% - StorageBackend (string) -
% Default: "hdf5". Storage backend used for export.
%
% Usage:
% Example 1 - Export an NWB file::
%
% % Create an NWB object with some properties:
% nwb = NwbFile;
% nwb.session_start_time = datetime('now');
% nwb.identifier = 'EMPTY';
% nwb.session_description = 'empty test file';
%
% % Write the nwb object to a file:
% nwbExport(nwb, 'empty.nwb');
%
% Example 2 - Export an NWB file using an older schema version::
%
% % Generate classes for an older version of NWB schemas:
% generateCore('2.5.0')
%
% % Create an NWB object with some properties:
% nwb = NwbFile;
% nwb.session_start_time = datetime('now');
% nwb.identifier = 'EMPTY';
% nwb.session_description = 'empty test file';
%
% % Write the nwb object to a file:
% nwbExport(nwb, 'empty.nwb');
%
% Example 3 - Export an NWB file using dataset settings tuned for cloud storage::
%
% nwbExport(nwb, 'empty.nwb', 'DatasetSettingsProfile', 'cloud');
%
% See also:
% generateCore, generateExtension, NwbFile, nwbRead
arguments
nwbFileObjects (1,:) NwbFile {mustBeNonempty}
filePaths (1,:) string {matnwb.common.compatibility.mustBeNonzeroLengthText}
mode (1,1) string {mustBeMember(mode, ["edit", "overwrite"])} = "edit"
options.DatasetSettingsProfile (1,1) io.config.enum.ConfigurationProfile = "none"
options.DatasetSettings = []
options.OverrideDatasetSettings (1,1) logical = false
options.StorageBackend (1,1) string = "hdf5"
end
assert(length(nwbFileObjects) == length(filePaths), ...
'NWB:Export:FilepathLengthMismatch', ...
'Lists of NWB objects to export and list of file paths must be the same length.')
shouldApplyDatasetSettings = ~isempty(options.DatasetSettings) || ...
~strcmp(string(options.DatasetSettingsProfile), "none");
if shouldApplyDatasetSettings
% Prepare dataset settings once and reuse across files.
if ~isempty(options.DatasetSettings)
datasetConfig = io.config.resolveDatasetConfiguration(options.DatasetSettings);
else
datasetConfig = io.config.readDatasetConfiguration(options.DatasetSettingsProfile);
end
for iFiles = 1:length(nwbFileObjects)
nwbFileObjects(iFiles).applyDatasetSettings(...
datasetConfig, 'OverrideExisting', options.OverrideDatasetSettings);
end
end
for iFiles = 1:length(nwbFileObjects)
filePath = char(filePaths(iFiles));
nwbFileObjects(iFiles).export(filePath, mode, ...
StorageBackend=options.StorageBackend);
end
end