Home > atmlab > deprecated > collocation_read_dual.m

collocation_read_dual

PURPOSE ^

collocation_read_dual Read collocations from two linked sources

SYNOPSIS ^

function [M, c] = collocation_read_dual(sat1, sensor1, sat2, sensor2,startdate, enddate, varargin)

DESCRIPTION ^

 collocation_read_dual Read collocations from two linked sources

 Read collocation from two sources, where the first dataset links to the
 second dataset. For example, the collocated dataset
 collocation_cpr_mhs/avhrr consists of collocations where the primary is
 collocation_cpr_mhs and the secondary is avhrr. Thus, the collocated
 dataset contains row numbers referring to the (averaged)
 CPR/MHS-collocations. This function reads the 'primary' collocations',
 gets the row-numbers, and then reads the associated information from the
 secondary, linked-to collocated dataset. Hence, whereas <a href="matlab:help collocation_read">collocation_read</a>
 needs one cols, limits and filter argument, this function needs two of
 each: one applying to the primary, one applying to the secondary.

 At the time of writing (13 October 2010) the only valid primary
 collocated dataset is collocation_collocation_cpr_mhs_avhrr, so dataset1
 MUST be 'collocation_cpr_mhs' and dataset2 MUST be 'avhrr', or it won't
 work. However, this may change in the future. As the collocations are
 with the averaged dataset (one-per-mhs rather than one-per-cpr), one also
 MUST request at least one mean-datafield.

 FORMAT

 [M, c] = collocation_read_dual(...
   sat1, dataset1, sat2, dataset2, ...
   startdate, enddate[, ...
   cols1[, cols2[, limits1[, limits2[, ...
   filters1[, filters2]]]]]])

 IN

       sat1        string      primary satellite
       dataset1    string      primary dataset, such as
                               'collocation_cpr_mhs'
       sat2        string      secondary satellite
       dataset2    string      secondary dataset, such as 'avhrr'
       startdate   3x1 array   datevec for first date
       enddate     3x1 array   datevec for last date (inclusive)
       cols1       cell array  Column names from sat1/dataset1
       cols2       cell array  Column names for sat2/dataset2; must
                               include a mean-datafield.
       limits1     structure   Limits to values for sat1/dataset1
       limits2     structure   Limits to values for sat2/dataset2
       filter1     cell array  Filters as for <a href="matlab:help collocation_read">collocation_read</a>
       filter2     cell array  Filters as for <a href="matlab:help collocation_read">collocation_read</a>

 OUT

       M           Nxp matrix  Matrix containing N collocations with p
                               columns
       c           structure   c1: column names for sat1/dataset1
                               c2: column names for sat2/dataset2

 EXAMPLE

 >> [M, c] = collocation_read_dual(...
               'noaa18', 'collocation_cpr_mhs', 'noaa18', 'avhrr', ...
               [2006 7 1], [2006 7 5], ...
               {'AVHRR_LAT', 'AVHRR_LONG', 'AVHRR', 3:5}, ...
               {'B_LAT', 'B_LONG', 'MEAN'});

 See also <a href="matlab:help collocation_read">collocation_read</a>.

 $Id: collocation_read_dual.m 7553 2012-04-27 19:08:16Z gerrit $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

collocation_read_dual.m

SOURCE CODE ^

0001 function [M, c] = collocation_read_dual(...
0002     sat1, sensor1, sat2, sensor2, ...
0003     startdate, enddate, varargin)
0004 
0005 
0006 % collocation_read_dual Read collocations from two linked sources
0007 %
0008 % Read collocation from two sources, where the first dataset links to the
0009 % second dataset. For example, the collocated dataset
0010 % collocation_cpr_mhs/avhrr consists of collocations where the primary is
0011 % collocation_cpr_mhs and the secondary is avhrr. Thus, the collocated
0012 % dataset contains row numbers referring to the (averaged)
0013 % CPR/MHS-collocations. This function reads the 'primary' collocations',
0014 % gets the row-numbers, and then reads the associated information from the
0015 % secondary, linked-to collocated dataset. Hence, whereas <a href="matlab:help collocation_read">collocation_read</a>
0016 % needs one cols, limits and filter argument, this function needs two of
0017 % each: one applying to the primary, one applying to the secondary.
0018 %
0019 % At the time of writing (13 October 2010) the only valid primary
0020 % collocated dataset is collocation_collocation_cpr_mhs_avhrr, so dataset1
0021 % MUST be 'collocation_cpr_mhs' and dataset2 MUST be 'avhrr', or it won't
0022 % work. However, this may change in the future. As the collocations are
0023 % with the averaged dataset (one-per-mhs rather than one-per-cpr), one also
0024 % MUST request at least one mean-datafield.
0025 %
0026 % FORMAT
0027 %
0028 % [M, c] = collocation_read_dual(...
0029 %   sat1, dataset1, sat2, dataset2, ...
0030 %   startdate, enddate[, ...
0031 %   cols1[, cols2[, limits1[, limits2[, ...
0032 %   filters1[, filters2]]]]]])
0033 %
0034 % IN
0035 %
0036 %       sat1        string      primary satellite
0037 %       dataset1    string      primary dataset, such as
0038 %                               'collocation_cpr_mhs'
0039 %       sat2        string      secondary satellite
0040 %       dataset2    string      secondary dataset, such as 'avhrr'
0041 %       startdate   3x1 array   datevec for first date
0042 %       enddate     3x1 array   datevec for last date (inclusive)
0043 %       cols1       cell array  Column names from sat1/dataset1
0044 %       cols2       cell array  Column names for sat2/dataset2; must
0045 %                               include a mean-datafield.
0046 %       limits1     structure   Limits to values for sat1/dataset1
0047 %       limits2     structure   Limits to values for sat2/dataset2
0048 %       filter1     cell array  Filters as for <a href="matlab:help collocation_read">collocation_read</a>
0049 %       filter2     cell array  Filters as for <a href="matlab:help collocation_read">collocation_read</a>
0050 %
0051 % OUT
0052 %
0053 %       M           Nxp matrix  Matrix containing N collocations with p
0054 %                               columns
0055 %       c           structure   c1: column names for sat1/dataset1
0056 %                               c2: column names for sat2/dataset2
0057 %
0058 % EXAMPLE
0059 %
0060 % >> [M, c] = collocation_read_dual(...
0061 %               'noaa18', 'collocation_cpr_mhs', 'noaa18', 'avhrr', ...
0062 %               [2006 7 1], [2006 7 5], ...
0063 %               {'AVHRR_LAT', 'AVHRR_LONG', 'AVHRR', 3:5}, ...
0064 %               {'B_LAT', 'B_LONG', 'MEAN'});
0065 %
0066 % See also <a href="matlab:help collocation_read">collocation_read</a>.
0067 %
0068 % $Id: collocation_read_dual.m 7553 2012-04-27 19:08:16Z gerrit $
0069 
0070 cols1 = colloc_constants(['cols_' sensor1 '_' sensor2]);
0071 cols2 = colloc_constants(['cols_' cols1.links.sensor1 '_' cols1.links.sensor2]);
0072 
0073 [cols_in1, cols_in2, limits1, limits2, filter1, filter2] = ...
0074     optargs(varargin, ...
0075     {{cols1.links.start, cols1.links.lineno}, {}, ...
0076     struct, struct, {}, {}});
0077 
0078 % make sure cols1.links.start and cols1.links.lineno are asked for
0079 for f = {cols1.links.start, cols1.links.lineno}
0080     if ~any(strcmp(f{1}, cols_in1))
0081         cols_in1 = [cols_in1 f{1}]; %#ok<AGROW>
0082     end
0083 end
0084 
0085 % verify at least some mean-data-fields in M2 are asked for
0086 if isempty(intersect(...
0087         fieldnames(cols2.meandata), ...
0088         cols_in2(cellfun(@isstr, cols_in2))))
0089     error('atmlab:collocation_read_dual', ...
0090         'When reading dual collocations, you MUST request meandata for the secondary!');
0091 end
0092 
0093 [M1, c1] = collocation_read(sat1, sensor1, sat2, sensor2, ...
0094     startdate, enddate, cols_in1, limits1, filter1);
0095 
0096 % convert limits-structure to limits-matrix for M2
0097 name_struct = cols_cell_to_cols_struct(cols2, cols_in2);
0098 limmat = limstruct2limmat(limits2, name_struct);
0099 
0100 % when filtering the secondary, we want to filter out the corresponding
0101 % rows in M1 as well; keep track of the rows we want to keep
0102 M1_rows = true(size(M1, 1), 1);
0103 
0104 N = 0;
0105 [starttimes, firsts] = unique(M1(:, c1.(cols1.links.start)), 'first');
0106 [~, lasts] = unique(M1(:, c1.(cols1.links.start)), 'last');
0107 for i = 1:length(starttimes) % loop through secondary granules with any data
0108     starttime = starttimes(i);
0109     first = firsts(i);
0110     last = lasts(i);
0111     rows = M1(first:last, c1.(cols1.links.lineno));
0112     [year month day] = unixsecs2date(starttime);
0113     [M2, c2, ~, f2] = collocation_read(...
0114         cols1.links.sat1, cols1.links.sensor1, ...
0115         sat1, cols1.links.sensor2, ...
0116         [year month day], [year month day], ...
0117         cols_in2, nan, filter2);                    % don't filter anything;
0118                                                     % just 'calculate' f2
0119     M2 = M2(rows, :);                               % make it same size as M1-part
0120     lim = collocation_restrain(M2, limmat, f2);     % NOW filter
0121     M1_rows(first:last) = lim;                      % in both M1
0122     M2 = M2(lim, :);                                % and M2
0123     
0124     % pre-allocate only here, so that we know the width
0125     if i==1
0126         M2_all = nan*zeros(size(M1, 1), size(M2, 2));
0127     end
0128     M2_all(N+1:N+size(M2, 1), :) = M2;
0129     N = N + size(M2, 1);
0130 end
0131 M2_all(isnan(M2_all(:, 1)), :) = []; % get rid of superfluous rows
0132 M2 = M2_all;
0133 
0134 % correct column-numbers for subsequent concatenation
0135 c2 = structfun(@(v) v+size(M1, 2), c2, 'UniformOutput', false);
0136 c.c1 = c1;
0137 c.c2 = c2;
0138 M = [M1(M1_rows, :) M2];

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005