-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbatch_mask.m
131 lines (95 loc) · 3.4 KB
/
batch_mask.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
% batch_mask: batch script for priducing edgemask and datamask files
% from DEM scene pairs.
% Ian Howat, [email protected], Ohio State University
%% ArcticDEM input directory settings
updir='/data2/ArcticDEM'; %location of region directory
regionnum='30'; % ArcticDEM region #
res='2'; % DEM resolution
%% load file names
demdir=dir([updir,'/region_',regionnum,'*']);
demdir=[updir,'/',demdir(1).name,'/tif_results/',res,'m'];
fprintf('working: %s\n',demdir);
f = dir([demdir,'/*_matchtag.tif']);
fdate=[f.datenum];
f={f.name};
%% Update Mode - will only reprocess masks older than the matchtag file
fedge = dir([demdir,'/*_edgemask.tif']);
if ~isempty(fedge)
fedgeDate=[fedge.datenum];
fedge={fedge.name};
[~,IA,IB] = intersect(f,strrep(fedge,'edgemask.tif','matchtag.tif'));
n= fedgeDate(IB) - fdate(IA) >= -6.9444e-04;
f(IA(n))=[];
clear fdate fedge fedgeDate
end
i=1;
for i=1:1:length(f)
matchFile = [demdir,'/',f{i}];
fprintf('processing %d of %d: %s \n',i,length(f),matchFile)
OutEdgeMaskName= strrep(matchFile,'matchtag.tif','edgemask.tif');
OutDataMaskName= strrep(matchFile,'matchtag.tif','datamask.tif');
m=readGeotiff(matchFile);
fprintf('making %s \n',OutEdgeMaskName)
%find SETSM version
metaFileName=strrep(matchFile,'matchtag.tif','meta.txt');
if ~exist(metaFileName,'file');
disp('no meta file, assumimg SETSM version > 2.0');
setsmVersion=3;
else
c=textread(metaFileName,'%s','delimiter','\n');
r=find(~cellfun(@isempty,strfind(c,'SETSM Version=')));
if ~isempty(r)
setsmVersion=deblank(strrep(c{r(1)},'SETSM Version=',''));
else; setsmVersion='2.03082016'; end
fprintf('Using settings for SETSM Version = %s\n',setsmVersion)
setsmVersion=str2num(setsmVersion);
end
if setsmVersion < 2.01292016
n= floor(21*2/m.info.map_info.dx);
Pmin=0.8;
Amin=2000/m.info.map_info.dx;
crop=n;
else
n= floor(101*2/m.info.map_info.dx);
Pmin=0.99;
Amin=2000/m.info.map_info.dx;
crop=n;
end
% shadeFileName=strrep(matchFile,'matchtag.tif','shade.tif');
% s=readGeotiff(shadeFileName);
m1.z=edgeMask(m.z,'n',n,'Pmin',Pmin,'Amin',Amin,'crop',crop);
if isfield(m.Tinfo,'GeoDoubleParamsTag')
if m.Tinfo.GeoDoubleParamsTag(1) > 0
projstr='polar stereo north';
else
projstr='polar stereo south';
end
else
projstr=m.Tinfo.GeoAsciiParamsTag;
a=findstr( projstr, 'Zone');
b=findstr( projstr, ',');
c = findstr( projstr,'Northern Hemisphere');
if ~isempty(c)
projstr=[projstr(a+4:b-1),' North'];
else
projstr=[projstr(a+4:b-1),' South'];
end
end
writeGeotiff(OutEdgeMaskName,m.x,m.y,m1.z,1,0,projstr)
m.z(~m1.z)=uint8(0);
clear m1
fprintf('making %s \n',OutDataMaskName)
if setsmVersion <= 2.0
n= floor(21*2/m.info.map_info.dx);
Pmin=0.3;
Amin=1000;
Amax=10000;
else
n= floor(101*2/m.info.map_info.dx);
Pmin=0.90;
Amin=1000;
Amax=1000;
end
m.z=DataDensityMask(m.z,'n',n,'Pmin',Pmin,'Amin',Amin,'Amax',Amax);
writeGeotiff(OutDataMaskName,m.x,m.y,m.z,1,0,projstr)
end