Home > atmlab > datasets > MaskInvalidGeoTimedataWithNaN.m

MaskInvalidGeoTimedataWithNaN

PURPOSE ^

MaskInvalidGeoTimedataWithNaN Mask invalid geodata and time data with NaN

SYNOPSIS ^

function S = MaskInvalidGeoTimedataWithNaN(S)

DESCRIPTION ^

 MaskInvalidGeoTimedataWithNaN Mask invalid geodata and time data with NaN
 Purpose: To remove invalid data that can't be used by the collocation
 codes anyway.

 NOTE: This is an interal function to many of the satreaders.<dataset>.m
       This means that the input data is assumed to follow the
       conventions set up in the collocatio toolbox (fields must be called
       'lat','lon','time'), i.e. -180<=lon<=180,  -90<=lat<=90,
       0<=time.


 IN
     S         struct                  output structure from
                                       satreaders.<datasets>

 OUT
     S         struct                  Same structure, but filtered

 USAGE: S = removeInvalidGeoTimedata(S)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

MaskInvalidGeoTimedataWithNaN.m

SOURCE CODE ^

0001 function S = MaskInvalidGeoTimedataWithNaN(S)
0002 % MaskInvalidGeoTimedataWithNaN Mask invalid geodata and time data with NaN
0003 % Purpose: To remove invalid data that can't be used by the collocation
0004 % codes anyway.
0005 %
0006 % NOTE: This is an interal function to many of the satreaders.<dataset>.m
0007 %       This means that the input data is assumed to follow the
0008 %       conventions set up in the collocatio toolbox (fields must be called
0009 %       'lat','lon','time'), i.e. -180<=lon<=180,  -90<=lat<=90,
0010 %       0<=time.
0011 %
0012 %
0013 % IN
0014 %     S         struct                  output structure from
0015 %                                       satreaders.<datasets>
0016 %
0017 % OUT
0018 %     S         struct                  Same structure, but filtered
0019 %
0020 % USAGE: S = removeInvalidGeoTimedata(S)
0021 
0022 % $Id: MaskInvalidGeoTimedataWithNaN.m 8541 2013-07-18 22:11:52Z gerrit $
0023 % Salomon Eliasson
0024 
0025 errId = ['atmlab:' mfilename ':badInput'];
0026 if isempty(S.lat)
0027     warning(errId,'Data struct is empty')
0028     return
0029 end
0030 assert(isequal(size(S.lat),size(S.lon)),errId,'S.lat, and S.lon must be the same size')
0031 assert(isequal([size(S.lat,1),1],size(S.time)),errId,...
0032     'S.time must be a vector of the same length as the geodata')
0033 
0034 ltindex = S.lat >= -90 & S.lat <= 90;
0035 lnindex = S.lon >= -180 & S.lon <= 180;
0036 tindex  = S.time >= 0;
0037 
0038 index = ltindex & lnindex;
0039 
0040 if any(~(index(:))) || any(~tindex)
0041     if logical(sum(~index(:)))
0042         logtext(atmlab('OUT'),...
0043             'Flagging %d data values (%.2f%%) due to invalid (lat, lon, or time) \n',...
0044             sum(~index(:)),100*sum(~index(:))/length(index(:)))
0045     end
0046     %for F = fieldnames(S)'
0047     for F = {'time','lat','lon'} % I can't be garanteed that the data is atleast single (to fit NaN)
0048         if strcmp(F{1},'time')
0049             S.time(~tindex)     = NaN;
0050             continue
0051         end
0052         if isequal(size(S.(F{1}),1),size(index,1))
0053             S.(F{1})(~index)    = NaN;
0054             S.(F{1})(~tindex,:) = NaN;
0055         end
0056     end
0057     
0058 end
0059 
0060 end

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