Home > atmlab > datasets > +satreaders > patmosx.m

patmosx

PURPOSE ^

SATREADERS.PATMOSX reads patmosx data

SYNOPSIS ^

function [S,attr] = patmosx(file, varargin)

DESCRIPTION ^

 SATREADERS.PATMOSX reads patmosx data

 Read PATMOS-x data and output the data in the format common to all
 satreaders.<dataset>.m readers in atmlab. Geodata and time data are
 always retrieved from the data file.

 NOTE: This reader actually reads 2 files, one ascending, one descending

 For info on the common format, see <a href="matlab:help SatDataset/reader">SatDataset/reader</a>.

 IN

   file    string      Path to gzipped file
   extra   cell array (optional) extra fields.

 OUT

   data    struct  With fields:
                   time    time in seconds since 00:00 UT
                   lat     latitude in degrees, one column per viewing angle
                   lon     longitude in [-180, 180] degrees, colums as for lat

 FORMAT

   S = satreaders.patmosx(file, varargin)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

patmosx.m

SOURCE CODE ^

0001 function [S,attr] = patmosx(file, varargin)
0002 
0003 % SATREADERS.PATMOSX reads patmosx data
0004 %
0005 % Read PATMOS-x data and output the data in the format common to all
0006 % satreaders.<dataset>.m readers in atmlab. Geodata and time data are
0007 % always retrieved from the data file.
0008 %
0009 % NOTE: This reader actually reads 2 files, one ascending, one descending
0010 %
0011 % For info on the common format, see <a href="matlab:help SatDataset/reader">SatDataset/reader</a>.
0012 %
0013 % IN
0014 %
0015 %   file    string      Path to gzipped file
0016 %   extra   cell array (optional) extra fields.
0017 %
0018 % OUT
0019 %
0020 %   data    struct  With fields:
0021 %                   time    time in seconds since 00:00 UT
0022 %                   lat     latitude in degrees, one column per viewing angle
0023 %                   lon     longitude in [-180, 180] degrees, colums as for lat
0024 %
0025 % FORMAT
0026 %
0027 %   S = satreaders.patmosx(file, varargin)
0028 
0029 % $Id: patmosx.m 8720 2013-10-21 20:41:39Z gerrit $
0030 % Salomon Eliasson
0031 
0032 core_fields = {'latitude','longitude','scan_line_time'};
0033 extra_fields = optargs(varargin, {{}});
0034 all_fields = [core_fields(:); extra_fields(:)];
0035 
0036 % read both ascending and descending files. Get the attributes incase
0037 % wanted
0038 tmpdir = create_tmpfolder();
0039 cleanupObject = onCleanup(@() delete_tmpfolder(tmpdir));
0040 filename = uncompress(file,tmpdir);
0041 % read the data. This also scales the data automatically!
0042 S1  = read_clavrx_hdf(filename,all_fields);
0043 S1.latitude = repmat(S1.latitude',[1,length(S1.longitude)]);
0044 S1.longitude = repmat(S1.longitude,[size(S1.latitude,1),1]);
0045 
0046 if regexp(file,'_asc_')
0047     file2 = strrep(file,'asc','des');
0048 else
0049     file2 = strrep(file,'des','asc');
0050 end
0051 
0052 if exist(file2,'file')
0053     tmpdir2 = create_tmpfolder();
0054     cleanupObject2 = onCleanup(@() delete_tmpfolder(tmpdir2));
0055     filename = uncompress(file2,tmpdir2);
0056     S2  = read_clavrx_hdf(filename,all_fields);
0057     S2.latitude = repmat(S2.latitude',[1,length(S2.longitude)]);
0058     S2.longitude = repmat(S2.longitude,[size(S2.latitude,1),1]);
0059 else
0060     S2 = [];
0061 end
0062 
0063 S = concatenateDatafields(S1,S2);
0064 
0065 % rename some fields
0066 S.lon = double(S.longitude(:));
0067 S.lat = double(S.latitude(:));
0068 
0069 % construct time axis with same dimensions
0070 S.time = S.scan_line_time*3600; % is in hours
0071 D = datasets;
0072 info = D.patmosx.find_info_from_granule(file);
0073 date = dayofyear_inverse(str2double(info.year), str2double(info.doy));
0074 S.epoch = round(date2unixsecs(date.year, date.month, date.day));
0075 S.version = info.version;
0076 S.path = file;
0077 
0078 S = rmfield(S,core_fields);
0079 
0080 S = MaskInvalidGeoTimedataWithNaN(S);
0081 
0082 end
0083 %%%%%%%%%%%%%
0084 % SUBFUNCTION
0085 
0086 function S = concatenateDatafields(Sasc,Sdec)
0087 %% concatinateDatafields
0088 %
0089 %
0090 % For each field make sure they are concatinated and then sorted by time (if applicable)
0091 %
0092 
0093 if ~isempty(Sdec)
0094     % FLATTEN the data
0095     sz = size(Sasc.scan_line_time);
0096     for F = fieldnames(Sasc)'
0097         if isequal(size(Sasc.(F{1})),sz)
0098             S.(F{1}) = [Sasc.(F{1})(:);Sdec.(F{1})(:)];
0099         end
0100     end
0101 else
0102     % FLATTEN the data
0103     sz = size(Sasc.scan_line_time);
0104     for F = fieldnames(Sasc)'
0105         if isequal(size(Sasc.(F{1})),sz)
0106             S.(F{1}) = Sasc.(F{1})(:);
0107         end
0108     end
0109     
0110 end
0111 % SORT the data in ascending time
0112 [S.scan_line_time,index] = sort(S.scan_line_time);
0113 sz = size(S.scan_line_time);
0114 for F = fieldnames(S)'
0115     if isequal(size(S.(F{1})),sz) && ~strcmp(F{1},'scan_line_time')
0116         S.(F{1}) = S.(F{1})(index);
0117     end
0118 end
0119 
0120 end

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