Skip to content

Commit 5cf69f0

Browse files
Merge pull request #16 from VH-Lab/add-readfile-functions-13897329639786336155
Refactor pyraview MEX and implement readFile functions
2 parents a7fe899 + 548cabd commit 5cf69f0

5 files changed

Lines changed: 55 additions & 5 deletions

File tree

docs/API.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,28 @@ Returns:
9999
- `D`: A 3D matrix of size `(Samples x Channels x 2)`.
100100
- `D(:, :, 1)`: Minimum values.
101101
- `D(:, :, 2)`: Maximum values.
102+
103+
### `HEADER = pyraview.get_header(filename)`
104+
Reads the binary header from a Pyraview level file.
105+
106+
Arguments:
107+
- `filename`: String path to the file.
108+
109+
Returns:
110+
- `HEADER`: Struct containing metadata fields (`magic`, `version`, `dataType`, `channelCount`, `sampleRate`, `nativeRate`, `startTime`, `decimationFactor`).
111+
112+
### `obj = pyraview.Dataset(folderPath, [Name, Value...])`
113+
Class representing a dataset of multi-resolution files.
114+
115+
Arguments:
116+
- `folderPath`: (Optional) String path to the folder containing level files.
117+
- `NativeRate`: (Optional) Original sampling rate.
118+
- `NativeStartTime`: (Optional) Start time.
119+
- `Channels`: (Optional) Number of channels.
120+
- `DataType`: (Optional) Data type string (e.g., 'int16').
121+
- `decimationLevels`: (Optional) Vector of decimation factors.
122+
- `Files`: (Optional) Cell array of filenames.
123+
124+
Methods:
125+
- `[tVec, decimationLevel, sampleStart, sampleEnd] = obj.getLevelForReading(tStart, tEnd, pixels)`
126+
- `[tVec, dataOut] = obj.getData(tStart, tEnd, pixels)`

src/matlab/+pyraview/Dataset.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function scanFolder(obj)
9191
for i = 1:length(d)
9292
fullPath = fullfile(d(i).folder, d(i).name);
9393
try
94-
h = pyraview.pyraview_get_header_mex(fullPath);
94+
h = pyraview.get_header(fullPath);
9595

9696
if firstHeader
9797
obj.NativeRate = h.nativeRate;

src/matlab/+pyraview/get_header.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
%GET_HEADER Read the Pyraview binary header from a file.
2+
%
3+
% HEADER = pyraview.get_header(FILENAME) reads the standard 1024-byte header
4+
% from the specified Pyraview level file.
5+
%
6+
% Inputs:
7+
% FILENAME - String or character vector specifying the path to the
8+
% Pyraview level file.
9+
%
10+
% Outputs:
11+
% HEADER - Struct containing the following fields:
12+
% * magic (char): "PYRA" magic string.
13+
% * version (uint32): Format version.
14+
% * dataType (uint32): Enum value for data type (0-9).
15+
% * channelCount (uint32): Number of channels.
16+
% * sampleRate (double): Sample rate of this level.
17+
% * nativeRate (double): Original recording rate.
18+
% * startTime (double): Start time of the recording.
19+
% * decimationFactor (uint32): Cumulative decimation factor.
20+
%
21+
% Example:
22+
% h = pyraview.get_header('data_L1.bin');
23+
% fprintf('Channels: %d, Rate: %.2f Hz\n', h.channelCount, h.sampleRate);
24+
%
25+
% See also PYRAVIEW.READFILE, PYRAVIEW.DATASET

src/matlab/+pyraview/readFile.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
% Read header
4242
try
43-
h = pyraview.pyraview_get_header_mex(filename);
43+
h = pyraview.get_header(filename);
4444
catch e
4545
error('Pyraview:HeaderError', 'Failed to read header: %s', e.message);
4646
end

src/matlab/build_pyraview.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
mex('-v', '-outdir', out_dir, '-output', 'pyraview', include_path, src_path, mex_src);
2323
fprintf('Build pyraview successful.\n');
2424

25-
fprintf('Building pyraview_get_header_mex...\n');
26-
mex('-v', '-outdir', out_dir, '-output', 'pyraview_get_header_mex', include_path, src_path, header_src);
27-
fprintf('Build pyraview_get_header_mex successful.\n');
25+
fprintf('Building get_header...\n');
26+
mex('-v', '-outdir', out_dir, '-output', 'get_header', include_path, src_path, header_src);
27+
fprintf('Build get_header successful.\n');
2828
catch e
2929
fprintf('Build failed: %s\n', e.message);
3030
rethrow(e);

0 commit comments

Comments
 (0)