forked from klostest/PhenoCamAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPicsInTime.m
executable file
·103 lines (88 loc) · 3.57 KB
/
getPicsInTime.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
function [picName, picTimesPruned] = getPicsInTime(site)
% Instructions: place this file in the directory containing Phenocam site
% directories. It takes one argument: the string 'site'. It will create
% directories for each year in the site directory and fill them with near
% noon images, one per day.
%
% example arguments
% site = 'upperbuffalo';
% year = 2008;
% site = 'uillinoisenergyfarm';
% year = 'all';
% picDir = [site filesep num2str(year)];
% outDir = [site filesep num2str(year) 'NearNoon'];
% mkdir(outDir);
listing = dir(site);
for i = 1:length({listing.name})
if strmatch(listing(i).name(1), '.'), continue; end
if listing(i).isdir
if ~isempty(str2num(listing(i).name)) &&...
(str2num(listing(i).name) > 1980) &&...
(str2num(listing(i).name) < 2020) ;
% outDir = ['NearNoon' site filesep listing(i).name];
% mkdir(outDir);
yearListing = dir([site filesep listing(i).name]);
counter = 1;
for j = 1:length({yearListing.name})
if strmatch(yearListing(j).name(1), '.'), continue; end
if ( yearListing(j).isdir &&...
(str2num(yearListing(j).name) >= 01) &&...
(str2num(yearListing(j).name) <= 12) );
jpegListing = dir([site filesep listing(i).name...
filesep yearListing(j).name filesep '*.jpg']);
%get rid of IR photos
isIR = strfind({jpegListing.name}, 'IR');
count2 = 1;
irCount = 0;
for k = 1:length(isIR)
if isempty(isIR{k})
nonIRListing{count2} = jpegListing(k).name;
count2 = count2 + 1;
irCount = irCount + 1;
end
end
%only do if there were IR photos
if irCount==0, nonIRListing = cell(0,0); end
for k = 1:length(nonIRListing)
jpeg_files{counter} = [site filesep listing(i).name...
filesep yearListing(j).name filesep...
nonIRListing{k}];
counter = counter + 1;
end
end
end
outDir = [site filesep 'NearNoon' listing(i).name];
mkdir(outDir);
%parse the jpeg file names
for j=1:length(jpeg_files)
% split strings by the underscore
parts = regexp(jpeg_files{j},'_','split');
year(j) = str2double(char(parts(2)));
month(j) = str2double(char(parts(3)));
day(j) = str2double(char(parts(4)));
time = char(parts(5));
if length(time) < 10
time;
end
hour(j) = str2double(time(1:2));
minutes(j) = str2double(time(3:4));
DOY(j) = date2jd(year(j), month(j), day(j),...
hour(j), minutes(j));
end
%get unique DOYs
roundedDOY = floor(DOY);
unDOY = unique(roundedDOY);
%find closest pics to noon
counter = 1;
for j = 1:length(unDOY)
distanceFromNoon = abs( DOY - (unDOY(j) + 0.5) );
[C,I] = min(distanceFromNoon);
copyfile(jpeg_files{I}, outDir);
counter = counter + 1;
end
end
end
clear yearListing jpegListing jpeg_files parts year month day time...
hour minutes DOY roundedDOY unDOY distanceFromNoon nonIRListing...
isIR
end