-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathannotate_ts_event.m
executable file
·71 lines (67 loc) · 2.1 KB
/
annotate_ts_event.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
function [lh,ax] = annotate_ts_event(varargin)
%function [lh,ax] = annotate_ts_event([ax,][filterfun,][ts[,minV[,drawV[,plotstyle[,ARGS]]]]])
%
% Place markers of PLOTSTYLE (v. PLOT, DEFAULT: 'k^') at each date in time
% series TS where TS.data<=MINV (DEFAULT: PRCTILE(TS.data,3)), at value DRAWV
% (DEFAULT: MINV). If first arg is a HANDLE, make that the default AXES. If
% ISINF(DRAWV) is True, draw markers at y=MIN(YLIM(AX)) (bottom of AXES).
%
% If first or second arg. is a FUNCTION_HANDLE, only plots indices that are
% also returned by FILTERFUN(TS) (DEFAULT: filterfun=TS_BOREAL_WARM, v.).
% Thus by default, only "northern summer events" are annotated. This is,
% e.g., useful for marking UPWELLING events (where TS is a near-bottom sea
% temperature time series), but has application for many numeric criteria.
%
% Optional additional ARGS are passed through to PLOT (v.)
%
% Last Saved Time-stamp: <Mon 2018-03-26 12:53:03 Eastern Daylight Time gramer>
varargout = {};
args = varargin;
if ( ~isempty(args) && ishandle(args{1}) )
ax = args{1};
args(1) = [];
else
ax = gca;
end;
if ( ~isempty(args) && isa(args{1},'function_handle') )
filterfun = args{1};
args(1) = [];
else
%filterfun = @ts_isfinite;
filterfun = @ts_boreal_warm;
end;
if ( ~isempty(args) && is_ts(args{1}) )
ts = args{1};
args(1) = [];
else
error('No valid Time Series specified!');
end;
if ( ~isempty(args) && isnumeric(args{1}) )
minV = args{1};
args(1) = [];
else
minV = prctile(ts.data,3);
end;
if ( ~isempty(args) && isnumeric(args{1}) )
drawV = args{1};
args(1) = [];
if ( isinf(drawV) )
if ( drawV > 0 )
drawV = max(ylim(ax));
else
drawV = min(ylim(ax));
end;
end;
else
drawV = minV;
end;
if ( ~isempty(args) && ischar(args{1}) )
plotstyle = args{1};
args(1) = [];
else
plotstyle = 'k^';
end;
ix = intersect(filterfun(ts),find(ts.data<=minV));
hold on;
lh=plot(ts.date(ix),repmat(drawV,[1,numel(ix)]),plotstyle,args{:});
return;