get_runs.html 7.26 KB
 Geoffrey Cowles committed Jul 10, 2013 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 131 132 133 134 `````` Description of get_runs
Home > utilities > get_runs.m

get_runs

PURPOSE

GET_RUNS Finds runs of continuous change in some value beyond some length

SYNOPSIS

function totalVolume = get_runs(plotOPTS,data,cellVolume,lengthThreshold,changeThreshold)

DESCRIPTION

GET_RUNS Finds runs of continuous change in some value beyond some length  and magnitude thresholds.    We're just doing lots of time series analyses here, so provide only a  time series as DATA.

CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:
• do_volume_change DO_VOLUME_CHANGE Calculate volume of water which experiences a change in

SOURCE CODE

0001 function totalVolume = get_runs(plotOPTS,data,cellVolume,lengthThreshold,changeThreshold) 0002 % GET_RUNS Finds runs of continuous change in some value beyond some length 0003 % and magnitude thresholds. 0004 % 0005 % We're just doing lots of time series analyses here, so provide only a 0006 % time series as DATA. 0007  0008 % Make sure we have a totalVolume value to output even if this time step 0009 % doesn't match the threshold conditions specified. 0010 totalVolume=0; 0011  0012 % Make an array of the time indices. 0013 timeIdx=1:length(data); 0014 % Calculate the differences ... 0015 dataChange=diff(data); 0016 % and find where they're negative. 0017 negIdx=dataChange<0; 0018  0019 % Use the diff of the negative indices to find the start and end of each 0020 % run. 0021 dn=diff(negIdx); 0022 dnIdxStart=timeIdx(dn>0)+1; % add one to move start along to correct index 0023 dnIdxEnd=timeIdx(dn<0); 0024  0025 % Check if the start and end are identical (i.e. we have a spike). 0026 if (numel(dnIdxStart)==1 || numel(dnIdxEnd)==1) 0027     if dnIdxStart==dnIdxEnd 0028 %         warning('Single spike in time series, so carry on.') 0029         longOnesIdx(:,1:2)=nan(1,2); 0030         return 0031     end 0032 end 0033 % Check for no values 0034 if sum(dnIdxStart)==0 || sum(dnIdxEnd)==0 0035 %     warning('No appropriate values here, so carry on.') 0036     longOnesIdx(:,1:2)=nan(1,2); 0037     return 0038 end 0039 % Check the first index in dnIdxEnd is larger than the dnIdxStart. 0040 if dnIdxEnd(1)<dnIdxStart(1) 0041     % Strip it out and adjust the dnIdxStart index accordingly. 0042     dnIdxEnd=dnIdxEnd(2:end); 0043     dnIdxStart=dnIdxStart(1:end-1); 0044 end 0045  0046 % If arrays are different lengths, lop off the last one from the longer 0047 % array. 0048 if length(dnIdxEnd)>length(dnIdxStart) 0049     timeIndices=(dnIdxEnd(1:end-1)-dnIdxStart)>=lengthThreshold; 0050 elseif length(dnIdxEnd)<length(dnIdxStart) 0051     timeIndices=(dnIdxEnd-dnIdxStart(1:end-1))>=lengthThreshold; 0052 elseif length(dnIdxEnd)==length(dnIdxStart) 0053     if dnIdxStart(1)==1 0054         timeIndices=(dnIdxEnd(1:end-1)-dnIdxStart(2:end))>=lengthThreshold; 0055     elseif dnIdxEnd(1)==1 0056         timeIndices=(dnIdxEnd(2:end)-dnIdxStart(1:end-1))>=lengthThreshold; 0057     else 0058         timeIndices=(dnIdxEnd-dnIdxStart)>=lengthThreshold; 0059     end 0060 else 0061     return 0062 end 0063  0064 if sum(timeIndices~=0) 0065     longOnesIdx(:,1)=dnIdxStart(timeIndices); 0066     longOnesIdx(:,2)=dnIdxEnd(timeIndices); 0067 else 0068     return 0069 end     0070  0071 totalVolume=0; 0072 for jj=1:size(longOnesIdx,1) 0073     % Average change 0074 %     changeMetric=mean(data(longOnesIdx(jj,1):longOnesIdx(jj,2))); 0075     % Maximum change (i.e. closest to zero in our case) 0076     changeMetric=max(data(longOnesIdx(jj,1):longOnesIdx(jj,2))); 0077     if changeMetric<changeThreshold 0078         totalVolume=totalVolume+sum(cellVolume(longOnesIdx(jj,1):longOnesIdx(jj,2))); 0079     end 0080 end 0081  0082 end 0083

Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005
``````