Home > atmlab > deprecated > overlap_granule.m

overlap_granule

PURPOSE ^

overlap_granule Find overlapping granules

SYNOPSIS ^

function [granules, names] = overlap_granule(sat1, sensor1, date1, sat2, sensor2)

DESCRIPTION ^

 overlap_granule Find overlapping granules

 For granule sat1/sensor1 at date2, find all granules for
 sat2/sensor2 that have a time overlap, +/- the maximum collocation time.
 Also returns the names of the satellites.

 Assumes granules contain data for at most one day.

 If sat2==poes, returns for all the poes satellites (except sat2==sat1).

 FORMAT

   [granules, names] = ...
       overlap_granule(sat1, sensor1, date1, sat2, sensor2)

 IN

   sat1    string  primary satellit
   sensor1 string  sensor on sat1 to consider
   date1   vector  starting date/time for sat1
   sat2    string  secondary satellite (special case 'poes')
   sensor2 string  sensor on sat2 to consider

 OUT

   granules Nx5 mat    [year month day hour minute] for each granule.
   names    string     for each granule, name of satellite

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

overlap_granule.m

SOURCE CODE ^

0001 function [granules, names] = overlap_granule(sat1, sensor1, date1, sat2, sensor2)
0002 
0003 % overlap_granule Find overlapping granules
0004 %
0005 % For granule sat1/sensor1 at date2, find all granules for
0006 % sat2/sensor2 that have a time overlap, +/- the maximum collocation time.
0007 % Also returns the names of the satellites.
0008 %
0009 % Assumes granules contain data for at most one day.
0010 %
0011 % If sat2==poes, returns for all the poes satellites (except sat2==sat1).
0012 %
0013 % FORMAT
0014 %
0015 %   [granules, names] = ...
0016 %       overlap_granule(sat1, sensor1, date1, sat2, sensor2)
0017 %
0018 % IN
0019 %
0020 %   sat1    string  primary satellit
0021 %   sensor1 string  sensor on sat1 to consider
0022 %   date1   vector  starting date/time for sat1
0023 %   sat2    string  secondary satellite (special case 'poes')
0024 %   sensor2 string  sensor on sat2 to consider
0025 %
0026 % OUT
0027 %
0028 %   granules Nx5 mat    [year month day hour minute] for each granule.
0029 %   names    string     for each granule, name of satellite
0030 %
0031 % $Id: overlap_granule.m 7553 2012-04-27 19:08:16Z gerrit $
0032 
0033 warning(['atmlab:' mfilename], 'old style function, being phased out, use OO way');
0034 
0035 %% special case sat1==poes: do all POES sats
0036 
0037 if strcmp(sat2, 'poes')
0038     allsatnames = datasets_constants('POES_satellite_names');
0039     allsatnos = datasets_constants('POES_satellite_numbers');
0040     nsats = length(allsatnames);
0041     granules = zeros(3*nsats, 5); % pre-allocate
0042     
0043     names = cell(3*nsats, 1);
0044     n = 0;
0045     for i = 1:nsats
0046         satname = allsatnames{i};
0047         if strcmp(sat1, satname) % don't collocate with myself
0048             continue
0049         end
0050         [granules_i, names_i] = overlap_granule(sat1, sensor1, date1, ...
0051             satname, amsub_or_mhs(satname));
0052         granules(n+1:n+size(granules_i, 1), 1:5) = granules_i;
0053         names(n+1:n+size(granules_i, 1)) = names_i;
0054         n = n + size(granules_i, 1);
0055     end
0056     % correct for over-preallocation
0057     granules(n+1:end, :) = [];
0058     names(n+1:end) = [];
0059     return
0060 end
0061 
0062 %% get duration of a granule of sensor1
0063 
0064 duration = datasets_constants(['granule_duration_' sensor1]);
0065 
0066 %% find starting time in unixsecs
0067 
0068 granule_start = date2unixsecs(date1(1), date1(2), date1(3), date1(4), date1(5));
0069 granule_end = granule_start + duration;
0070 
0071 %% find all granules yesterday/today/tomorrow
0072 
0073 today_num = datenum(date1(1), date1(2), date1(3));
0074 yesterday = datevec(today_num - 1);
0075 tomorrow = datevec(today_num + 1);
0076 
0077 threedays = [...
0078     find_granules_by_date(yesterday(1), yesterday(2), yesterday(3), sat2, sensor2, false); ...
0079     find_granules_by_date(date1(1), date1(2), date1(3), sat2, sensor2, false); ...
0080     find_granules_by_date(tomorrow(1), tomorrow(2), tomorrow(3), sat2, sensor2, false)];
0081 threedays = sortrows(threedays);
0082 granules_unixsecs = date2unixsecs(...
0083     threedays(:, 1), threedays(:, 2), threedays(:, 3), threedays(:, 4), threedays(:, 5));
0084 
0085 % last granule starting after the reference granule
0086 
0087 b = find(granule_start - colloc_config('interval') > granules_unixsecs, 1, 'last');
0088 
0089 % first granule ending before the reference granule
0090 
0091 e = find(granule_end + colloc_config('interval') < granules_unixsecs, 1, 'first');
0092 
0093 granules = threedays(b:e, :);
0094 names = repmat({sat2}, [size(granules, 1) 1]);

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