Home > atmlab > geographical > geo_single_localtime.m

geo_single_localtime

PURPOSE ^

GEO_SINGLE_LOCALTIME Interpolates data to a specific local time

SYNOPSIS ^

function data = geo_single_localtime(utcvec,localtime,data,lon,lat,method)

DESCRIPTION ^

 GEO_SINGLE_LOCALTIME Interpolates data to a specific local time

 IN
     utcvec      [%f,...]              UTC values covering a day, e.g. 0:3:21
     localtime   %f                    scalar local time as a decimal number,
                                       e.g. 1.5 = 01:30AM
     data        data(lon,...,time)    data matrix with the dimensions
                                       data(lat,lon,...,time)
                                       or
                                       data(lon,lat,...,time)
     lon         [%f,...]              longitudes vector
     lat         [%f,...]              latitudes vector (needed for function
                                                         standardize_geodata)
     method      %s                    The method interp1 will use. It can be
                                       one of 'nearest', 'linear' (default),
                                       'spline' or 'cubic'
                                       

 OUT
     out =      data                   Interpolated data values at the
                                       specified localtime



 NOTE
     * Assumes input dimensions data(lon,lat,height,time) or data(lon,lat,time)
     * If your region data spans a square region (length(lat)=length(lon)) make
       sure

 USAGE: data = geo_single_localtime(utcvec,localtime,data,lon,lat,method)

 Created by Salomon Eliasson 
 Modified by Marston Johnston

 $Id: geo_single_localtime.m 7660 2012-06-18 07:24:53Z olemke $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

geo_single_localtime.m

SOURCE CODE ^

0001 function data = geo_single_localtime(utcvec,localtime,data,lon,lat,method)
0002 % GEO_SINGLE_LOCALTIME Interpolates data to a specific local time
0003 %
0004 % IN
0005 %     utcvec      [%f,...]              UTC values covering a day, e.g. 0:3:21
0006 %     localtime   %f                    scalar local time as a decimal number,
0007 %                                       e.g. 1.5 = 01:30AM
0008 %     data        data(lon,...,time)    data matrix with the dimensions
0009 %                                       data(lat,lon,...,time)
0010 %                                       or
0011 %                                       data(lon,lat,...,time)
0012 %     lon         [%f,...]              longitudes vector
0013 %     lat         [%f,...]              latitudes vector (needed for function
0014 %                                                         standardize_geodata)
0015 %     method      %s                    The method interp1 will use. It can be
0016 %                                       one of 'nearest', 'linear' (default),
0017 %                                       'spline' or 'cubic'
0018 %
0019 %
0020 % OUT
0021 %     out =      data                   Interpolated data values at the
0022 %                                       specified localtime
0023 %
0024 %
0025 %
0026 % NOTE
0027 %     * Assumes input dimensions data(lon,lat,height,time) or data(lon,lat,time)
0028 %     * If your region data spans a square region (length(lat)=length(lon)) make
0029 %       sure
0030 %
0031 % USAGE: data = geo_single_localtime(utcvec,localtime,data,lon,lat,method)
0032 %
0033 % Created by Salomon Eliasson
0034 % Modified by Marston Johnston
0035 %
0036 % $Id: geo_single_localtime.m 7660 2012-06-18 07:24:53Z olemke $
0037 
0038 if ~exist('method','var')
0039     method = 'linear';
0040 end
0041 
0042 N = ndims(data);
0043 
0044 assert( ( isequal(size(data,1),length(lon)) || isequal(size(data,2),length(lon))) && ...
0045     isequal(size(data,N),length(utcvec)),...
0046     ['atmlab:' mfilename ':badInput'],'See help')
0047 
0048 assert(ismember(method,{'nearest','linear','cubic','spline'}),...
0049 ['atmlab:' mfilename ':badInput'],'method: "%s" not valid',method)
0050 
0051 % INTERNALLY make lons -180:180 and adjust data accordingly
0052 [flags,lat,lon,data] = standardize_geodata(lat,lon,data); %#ok<ASGLU>
0053 
0054 % Get the SIZE of the original data
0055 sz = size(data);
0056 
0057 % PERMUTE so that the data(time,lon,lat...). % data(lat,lon,...) is ensured
0058 % via the standardize function
0059 data = permute(data,[N,2,1,3:N-1]);
0060 
0061 % COLLAPSE it to data(time,lon,lat*etc)
0062 data = data(:,:,:);
0063 
0064 % locally make utc CYCLIC (covering the whole day)
0065 switch method
0066     case {'nearest','linear'}, n=0;
0067     case 'cubic', n=1;
0068     case'spline', n=2;
0069 end
0070 
0071 assert(n < length(utcvec),['atmlab:' mfilename ':badInput'],...
0072     'method: "%s" requires utcvec to have at least %d values',method,n+1)
0073 if n ~= -1
0074     utcvec = [utcvec(end-n:end)-24, utcvec utcvec(1:n+1)+24];
0075     data = [data(end-n:end,:,:); data; data(1:n+1,:,:)];
0076 end
0077 
0078 % get the EQUIVALENT utc timefor each longitude for the local time
0079 utc0 = mod(localtime - 24/360 * lon, 24);
0080 
0081 % INTERPOLATE
0082 out = zeros([length(lon),size(data,3)],class(data));
0083 for i = 1:size(data,2) % longitude in the first dimension
0084     D = squeeze(data(:,i,:));
0085     out(i,:) = interp1(utcvec, D, utc0(i), method); %[lon,lat*etc]
0086 end
0087 
0088 % ----------------------------
0089 %  REARRANGE to original format
0090 
0091 % if the orig lons are in the 0:360 regime. Put them BACK
0092 if flags.lon360
0093     if flags.duplicate
0094         % remove -180 to avoid duplication
0095         lon = lon(2:end);
0096         out = out(2:end,:);
0097     end
0098     lon = lon +(lon < 0)*360;
0099     [lon,indexlon] = sort(lon); %#ok<ASGLU>
0100     out = out(indexlon,:);
0101     if flags.duplicate
0102         % reintroduce duplicates at 0 and 360
0103         out = [out; out(1,:)];
0104     end
0105 end
0106 
0107 % if the lons were DESCENDING
0108 if flags.lon_descend
0109     out = out(end:-1:1,:);
0110 end
0111 
0112 % RECONSTRUCT collapsed dimensions [lon,lat,...]
0113 data = reshape(out,[size(out,1),sz([1,3:N-1])]);
0114 
0115 % If the orig lats are DESCENDING. Put them BACK
0116 if flags.lat_descend
0117     % permute to put lat in first position in order to callapse
0118     data = permute(data,[2,1,3:N-1]); %[lat,lon,....]
0119     
0120     % locally flatten and reshape
0121     sz = size(data); 
0122     out = data(:,:);  %[lat,lon*etc]
0123     % adjust the lats
0124     out = out(end:-1:1,:);
0125     data = reshape(out,sz);  %[lat,lon,....]
0126     
0127     if flags.permute
0128         data = permute(data,[2,1,3:N-1]); % [lon,lat,...]
0129     end
0130 elseif ~flags.permute
0131     % If orig data was data(lon,lat,...), leave the data as is
0132     data = permute(data,[2,1,3:N-1]);
0133 end

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