-
Notifications
You must be signed in to change notification settings - Fork 0
/
combineData.m
107 lines (85 loc) · 4.1 KB
/
combineData.m
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
105
106
107
function [data, rowLabels, rowConfidence, imgLabels, metadata] = combineData(dates, folderPrefix, folderTimestamps, rawDataDir)
% combineData combine data from individual folders into one mat file.
%
% Data are organized in the following folder hiearchy:
% ├── yyyy-mm-dd
% │ ├── prefix-hhmmss
% │ ├── prefix-hhmmss
% │ └── prefix-hhmmss
% ├── yyyy-mm-dd
% │ ├── prefix-hhmmss
% │ ├── prefix-hhmmss
% │ └── prefix-hhmmss
%
% Where prefix is the folder prefix (e.g., description of the location
% or project). hhmmss is a 24-hour ISO-format timestamp indicating when the
% data collection run started. Each prefix-timestamp folder contains the
% data files: individual mat files for each image, and an adjusted_data file
% that contains all the individual images, metdata, etc. after some
% preprocessing. The adjusted_data file is what gets used in this function.
%
% [data,rowLabels,rowConfidence,imgLabels,metadata] = ...
% combineData(dates,folderPrefix,folderTimestamps,rawDataDir)
%
% Inputs:
% - dates (string): Vector of dates corresponding to the folder names that
% will be combined.
% - folderPrefix (string): Prefix of the folders.
% - folderTimestamps (string): Vector of timestamps corresponding to the
% folder names that will be combined.
% - rawDataDir (string): Name of the top-level folder that contains the data.
%
% Outputs:
% - data: Cell array containing all of the data. Each cell contains an image.
% - rowLabels: Cell array containing the row labels. Each cell corresponds to
% one image.
% - rowConfidence: Cell array containing the confidence raings. Each cell
% corresponds to one image.
% - imgLabels: Array of ground truth image labels: 1 indicates that the image
% contains one or more insects.
% - metadata: Struct containing metadata for each image. Metadata includes
% the day, folder name, pan angle, tilt angle, range bins (in meters),
% and the timestamps for each pulse in the image.
% SPDX-License-Identifier: BSD-3-Clause
% TODO: argument validation
% TODO make these (optional) arguments
DATA_FILENAME = "adjusted_data_junecal_volts.mat";
LABELS_FILENAME = "labels.mat";
%% Create initial data structures
metadata = struct('Day', string(), 'FolderName', string(), 'FileName', string(), 'Pan', {}, ...
'Tilt', {}, 'Range', {}, 'Timestamps', {});
data = {};
rowLabels = {};
rowConfidence = {};
imgLabels = false;
%% Folder Setup
globalImageNum = 0;
for index = 1:length(dates)
date = dates(index);
scanNums = folderTimestamps{index};
for scanNum = 1:length(scanNums)
filePath = rawDataDir + filesep + date + filesep + folderPrefix + scanNums(scanNum);
% load data
load(filePath + filesep + DATA_FILENAME);
% load labels
labels = load(filePath + filesep + LABELS_FILENAME);
numImages = numel(adjusted_data_junecal);
for scanImageNum = 1:numImages
globalImageNum = globalImageNum + 1;
data{globalImageNum} = adjusted_data_junecal(scanImageNum).data;
rowLabels(globalImageNum) = labels.rowLabels(scanImageNum);
rowConfidence(globalImageNum) = labels.rowConfidence(scanImageNum);
imgLabels(globalImageNum) = labels.imageLabels(scanImageNum);
metadata(globalImageNum).Day = date;
metadata(globalImageNum).FolderName = folderPrefix + scanNums(scanNum);
metadata(globalImageNum).Pan = adjusted_data_junecal(scanImageNum).pan;
metadata(globalImageNum).Tilt = adjusted_data_junecal(scanImageNum).tilt;
metadata(globalImageNum).Range = adjusted_data_junecal(scanImageNum).range;
metadata(globalImageNum).Timestamps = adjusted_data_junecal(scanImageNum).time;
% the filename field is really <foldername>/<filename>, so we get rid of the
% the foldername here since we already have that information
tmp = split(adjusted_data_junecal(scanImageNum).filename, '/');
metadata(globalImageNum).FileName = string(tmp{2});
end
end
end