Changeset 883

Show
Ignore:
Timestamp:
01/04/12 15:50:09 (18 months ago)
Author:
jjr8
Message:

MATLAB code for #513: Tools that load currents into connectivity simulations should have an option to interpolate missing values.

Files:
1 moved

Legend:

Unmodified
Added
Removed
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/Matlab/Functions.matlab/InpaintNaNs.m

    r872 r883  
    1 function B = inpaint_nans2(A, method, maxHoleSize, xEdgesWrap) 
     1function [B] = InpaintNaNs(A, method, maxHoleSize, edgesWrap) 
     2% InpaintNaNs: inpaint_nans with some additional options. 
     3 
     4% If the caller indicated that the left and right edges wrap, buffer those 
     5% edges by 10 cells. Hopefully this will be enough for maxHoleSize to still 
     6% work properly. 
     7 
     8if edgesWrap ~= 0 
     9    buffer = min(10, size(A,2)); 
     10    A2 = zeros(size(A,1), size(A,2) + buffer*2, class(A)); 
     11    A2(:, 1:buffer) = A(:, (size(A,2)-buffer+1):size(A,2)); 
     12    A2(:, (buffer+1):(buffer+size(A,2))) = A; 
     13    A2(:, (buffer+size(A,2)+1):size(A2,2)) = A(:, 1:buffer); 
     14else 
     15    A2 = A; 
     16end 
     17 
     18% Call inpaint_nans. If maxHoleSize was provided, only fill holes up to 
     19% that size with what inpaint_nans returns (leave the others as NaN). 
     20 
    221if maxHoleSize >= 1 
    3   L = bwlabel(isnan(A), 4); 
     22  C = inpaint_nans(A2, method); 
     23  L = bwlabel(isnan(A2), 4); 
    424  STATS = regionprops(L, 'Area'); 
    5   B = A; 
    6   B(ismember(L, find(arrayfun(@(x) x.Area >= maxHoleSize, STATS)))) = inpaint_nans(A, method); 
     25  H = ismember(L, find(arrayfun(@(x) x.Area <= maxHoleSize, STATS))); 
     26  B2 = A2; 
     27  B2(H) = C(H); 
    728else 
    8   B = inpaint_nans(A, method); 
     29  B2 = inpaint_nans(A2, method); 
     30end 
     31 
     32% If the caller indicated that the left and right edges wrap, extract the 
     33% output array from within the buffer. 
     34 
     35if edgesWrap ~= 0 
     36    B = B2(:, (buffer+1):(size(B2,2)-buffer)); 
     37else 
     38    B = B2; 
     39end 
     40 
    941end 
    1042 
     
    460492% A was when we came in. 
    461493B=reshape(B,n,m); 
    462  
     494end 
    463495 
    464496% ==================================================== 
     
    526558  neighbors_list=[]; 
    527559end 
    528  
    529  
    530  
    531  
    532  
    533  
    534  
    535  
    536  
    537  
    538  
    539  
    540  
    541  
    542  
    543  
     560end