-
Notifications
You must be signed in to change notification settings - Fork 1
/
model_prism_monthly.m
52 lines (39 loc) · 1.2 KB
/
model_prism_monthly.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
function [ basin ] = model_prism_monthly(lat,lon,date,basinid)
old_dir = cd
prism_dir = 'K:/GIS/MODEL/input/PRISM/precip/monthly/'
basin_dir = 'K:/GIS/MODEL/input/basins/'
dates = date + calmonths(0:11)';
[yrs, mos, ~] = datevec(dates);
date_strings = cellstr(num2str(yrs*100 + mos));
for i = 1:numel(date_strings)
cd(prism_dir)
wc = strcat('*',date_strings{i},'_asc.asc');
files = dir(wc);
name = extractfield(files, 'name')';
assert(numel(name)==1)
[p,r]=arcgridread(char(name));
cd(basin_dir)
basins = shaperead('Aug6')
idx = find(strcmpi(num2str(basinid),{basins.BasinID}));
basin = basins(idx);
bbox = basin.BoundingBox;
if sum(abs(bbox(:)) < 180) == 4
x = lon;
y = lat;
else
[x, y] = deg2utm(lat, lon);
end
bx = basin.X;
by = basin.Y;
clipL = min(bbox(:,1)) - 0.1;
clipR = max(bbox(:,1)) + 0.1;
clipU = min(bbox(:,2)) - 0.1;
clipD = max(bbox(:,2)) + 0.1;
[clipU, clipL] = map2pix(r,clipL,clipU)
[clipD, clipR] = map2pix(r,clipR,clipD)
p(round(clipU):round(clipD), round(clipL):round(clipR))
imagesc(p(clipU:clipD, clipL:clipR))
break
end
cd(old_dir)
end