-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCropAndConvert.m
More file actions
66 lines (51 loc) · 1.97 KB
/
Copy pathCropAndConvert.m
File metadata and controls
66 lines (51 loc) · 1.97 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
%% Reset MATLAB
close all
clear
clc
%% Enable dependencies
[githubDir,~,~] = fileparts(pwd);
d12packDir = fullfile(githubDir, 'd12pack');
circadianDir = fullfile(githubDir,'circadian');
addpath(d12packDir,circadianDir);
%% Map paths
timestamp = datestr(now,'yyyy-mm-dd_HHMM');
calPath = '\\root\projects\DaysimeterAndDimesimeterReferenceFiles\recalibration2016\calibration_log.csv';
prjDir = '\\root\programs\Outreach-Education\Light_and_Health_Inst\daysimeter_2016-10-18';
orgDir = fullfile(prjDir,'best_downloads');
logDir = fullfile(prjDir,'logs');
dbName = [timestamp,'.mat'];
dbPath = fullfile(prjDir,dbName);
tzPath = fullfile(prjDir,'time_zones.xlsx');
%% Read time zone table
tzTable = readtable(tzPath);
%% Crop and convert data
listingCDF = dir(fullfile(orgDir,'*.cdf'));
cdfPaths = fullfile(orgDir,{listingCDF.name});
loginfoPaths = regexprep(cdfPaths,'\.cdf','-LOG.txt');
datalogPaths = regexprep(cdfPaths,'\.cdf','-DATA.txt');
for iFile = numel(loginfoPaths):-1:1
cdfData = daysimeter12.readcdf(cdfPaths{iFile});
ID = cdfData.GlobalAttributes.subjectID;
thisObj = d12pack.HumanData;
thisObj.CalibrationPath = calPath;
thisObj.RatioMethod = 'newest';
thisObj.ID = ID;
thisObj.TimeZoneLaunch = 'America/New_York';
% Find matching time zone
tzIdx = tzTable.Subject == str2double(ID);
thisObj.TimeZoneDeploy = tzTable.TimeZone(tzIdx);
% Import the original data
thisObj.log_info = thisObj.readloginfo(loginfoPaths{iFile});
thisObj.data_log = thisObj.readdatalog(datalogPaths{iFile});
% Import bed log if one exists
bedlogPath = fullfile(logDir,['bedLog_subject ',ID,'.xlsx']);
if exist(bedlogPath,'file') == 2
thisObj.BedLog = d12pack.BedLogData;
thisObj.BedLog.import(bedlogPath,thisObj.TimeZoneDeploy);
end
% Crop the data
thisObj = crop(thisObj);
objArray(iFile,1) = thisObj;
end
%% Save converted data to file
save(dbPath,'objArray');