-
Notifications
You must be signed in to change notification settings - Fork 2
/
load_coarse_topo.m
64 lines (58 loc) · 1.92 KB
/
load_coarse_topo.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
function coarse_topo=load_coarse_topo(...
topofile,topo_names,fine_topo)
%loads coarse topography
%inputs:
%topofile - h5 or matfile with coarse topograpy
%topo_names - names of coarse topography vars
%fine_topo - fine topo struct
%output
%coarse_topo - reprojected coarse topo w/ Zdiff
%ReferencingMatrix - coarse Referencing Matrix
%load topofile
geolocated=false;
[~,~,ext]=fileparts(topofile);
switch ext
case '.mat'
m=load(topofile);
if isempty(m)
error('could not read ldas file %s',topofile);
end
if isfield(m,'lat')
lat=m.lat;
lon=m.lon;
geolocated=true;
else
ReferencingMatrix=m.ReferencingMatrix;
end
for i=1:length(topo_names)
coarse_topo.(topo_names{i})=m.(topo_names{i});
end
case '.h5'
for i=1:length(topo_names)
loc=['/Grid/',topo_names{i}];
coarse_topo.(topo_names{i})=h5read(topofile,loc);
end
ReferencingMatrix=h5readatt(topofile,'/Grid',...
'ReferencingMatrix');
otherwise
error('topo file %s not .mat or .h5',topofile);
end
% reproject coarse elevation, slope, and aspect to fine scale
for i=1:length(topo_names)
if geolocated
coarse_topo.(topo_names{i})=reprojectRaster(coarse_topo.(topo_names{i}),...
[],[],fine_topo.hdr.ProjectionStructure,'lat',lat,'lon',lon,...
'rasterref',fine_topo.hdr.RasterReference);
else
coarse_topo.(topo_names{i})=reprojectRaster(coarse_topo.(topo_names{i}),...
ReferencingMatrix,[],fine_topo.hdr.ProjectionStructure,...
'rasterref',fine_topo.hdr.RasterReference);
end
end
% Difference between fine and reprojected DEM
coarse_topo.Zdiff=fine_topo.dem-coarse_topo.Z;
% coarse_topo=rmfield(coarse_topo,'Z');
if ~geolocated
coarse_topo.CoarseRefMatrix=ReferencingMatrix;
end
end