Home > custom > grid_tools > qt_disaggregate.m

qt_disaggregate

PURPOSE ^

PUPROSE: Disaggregate a quadtree sparse matrix created using

SYNOPSIS ^

function M = qt_disaggregate(D,S,ds) % include cellsize cs later!

DESCRIPTION ^

 PUPROSE:  Disaggregate a quadtree sparse matrix created using
           qt_aggregate to a full matrix of equal size
 -------------------------------------------------------------------
 USAGE: M = qt_disaggregate(D,S)
 where: D is the input sparse matrix created using qt_aggregate 
        S is the sparse matrix containing the quadtree structure returned
          by qtdecomp/gt_aggregate
        ds is a flag to downsample the output matrix if minimum block size
          is larger than 1 (optional, 0=false,1=true. default=0 )
        M is the output full matrix of size(D)

 EXAMPLE:
       [D,S] = qt_aggregate(peaks(512),'crit',0.05,'minq',4,'maxq',16);
       M = qt_disaggregate(D,S,1);
       - uses quadtree decomposition on a 512x512 example peaks surface,
         creating blocks betweeen 1 and 16 cell sizes.
       - Quadtree structure is disaggregated assigning values of quadtree
         blocks to underlying full matrix
       - downsamples the matrix to 128x128 as minq = 4

 See also: QTDECOMP, QT_AGGREGATE

 Note: Input matrices need to be of same size and have the same quadtree
       structure. This function is a complement of qt_aggregate

 Felix Hebeler, Dept. of Geography, University Zurich, June 2008.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function M = qt_disaggregate(D,S,ds)  % include cellsize cs later!
0002 % PUPROSE:  Disaggregate a quadtree sparse matrix created using
0003 %           qt_aggregate to a full matrix of equal size
0004 % -------------------------------------------------------------------
0005 % USAGE: M = qt_disaggregate(D,S)
0006 % where: D is the input sparse matrix created using qt_aggregate
0007 %        S is the sparse matrix containing the quadtree structure returned
0008 %          by qtdecomp/gt_aggregate
0009 %        ds is a flag to downsample the output matrix if minimum block size
0010 %          is larger than 1 (optional, 0=false,1=true. default=0 )
0011 %        M is the output full matrix of size(D)
0012 %
0013 % EXAMPLE:
0014 %       [D,S] = qt_aggregate(peaks(512),'crit',0.05,'minq',4,'maxq',16);
0015 %       M = qt_disaggregate(D,S,1);
0016 %       - uses quadtree decomposition on a 512x512 example peaks surface,
0017 %         creating blocks betweeen 1 and 16 cell sizes.
0018 %       - Quadtree structure is disaggregated assigning values of quadtree
0019 %         blocks to underlying full matrix
0020 %       - downsamples the matrix to 128x128 as minq = 4
0021 %
0022 % See also: QTDECOMP, QT_AGGREGATE
0023 %
0024 % Note: Input matrices need to be of same size and have the same quadtree
0025 %       structure. This function is a complement of qt_aggregate
0026 %
0027 % Felix Hebeler, Dept. of Geography, University Zurich, June 2008.
0028 
0029 % allocate space for the full matrix
0030 M=nan(size(D,1),size(D,2));
0031 %check what the minimum and maximum blocksize is
0032 z_min=min(nonzeros(S)); 
0033 %z_max=max(nonzeros(S));
0034 
0035 if ~exist('ds','var')
0036     ds=0;
0037 end
0038 
0039 % find nonzero elements and loop over them
0040 [row,col,v] = find(D);
0041 for i=1:size(row,1)
0042     M(row(i):row(i)+S(row(i),col(i))-1,col(i):col(i)+S(row(i),col(i))-1)=v(i);
0043 end
0044 
0045 % downsample grid if flag is set and zmin is greater than 1
0046 if ds==1 && z_min>1
0047    M=blkproc(M,[z_min z_min],@mmean); 
0048 end
0049 
0050 function m=mmean(x)
0051 % does mean(X(:))
0052 m=nanmean(x(:));

Generated on Tue 24-Feb-2009 19:14:50 by m2html © 2003