Home > atmlab > arts > scenegen > asg_dimadd.m

asg_dimadd

PURPOSE ^

ASG_DIMADD Extrapolates ASG data to match Q.ATMOSPHERE_DIM

SYNOPSIS ^

function G = asg_dimadd( G, Q )

DESCRIPTION ^

 ASG_DIMADD   Extrapolates ASG data to match Q.ATMOSPHERE_DIM

    The function ensures that atmospheric fields are defined for 
    dimensions 1:Q.ATMOSPHERE_DIM and surface for 2:Q.ATMOSPHERE_DIM.
    Nothing is done if the DATA field is empty. 

    The data are extended following settings in G.DIMADD. The extrapolation
    method is selected by the field METHOD. The following options exist:

    FORMAT = 'expand'
    -----------------
    The data are simply expanded to fill missing higher dimensions. For 
    example, a 1D pressure profile is expanded to 2D by inserting the
    profile at each Q.LAT_GRID position.
   
    FORMAT = 'expand_weighting'
    reguires the fields
    G.DIMADD.weight    which is a weighting vector with the same length
    as the corresponding missing data in Q.(P,LAT,LON)_GRID
    -----------------        
    
    FORMAT = 'iaaft'
    the data are expanded in longitude dimension  by an Iterative
    Amplitude Adapted Fourier Transform algorithm   

    The data are expanded to fill missing higher dimensions. For
    example 2D pressure and latitude dependent data are
    expanded to longitudinal dependency by applying the weights
    in G.DIMADD.weight. So G.DATA(p1,lat1,lon1)=  
    G.DATA(p1,lat1)*G.DIMADD.weight(1) 

 FORMAT   G = asg_regrid( G, Q )
        
 OUT   G   Extrapolated ASG data.
 IN   
       G   gformat data data.
       Q   Qarts setting structure.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

asg_dimadd.m

SOURCE CODE ^

0001 % ASG_DIMADD   Extrapolates ASG data to match Q.ATMOSPHERE_DIM
0002 %
0003 %    The function ensures that atmospheric fields are defined for
0004 %    dimensions 1:Q.ATMOSPHERE_DIM and surface for 2:Q.ATMOSPHERE_DIM.
0005 %    Nothing is done if the DATA field is empty.
0006 %
0007 %    The data are extended following settings in G.DIMADD. The extrapolation
0008 %    method is selected by the field METHOD. The following options exist:
0009 %
0010 %    FORMAT = 'expand'
0011 %    -----------------
0012 %    The data are simply expanded to fill missing higher dimensions. For
0013 %    example, a 1D pressure profile is expanded to 2D by inserting the
0014 %    profile at each Q.LAT_GRID position.
0015 %
0016 %    FORMAT = 'expand_weighting'
0017 %    reguires the fields
0018 %    G.DIMADD.weight    which is a weighting vector with the same length
0019 %    as the corresponding missing data in Q.(P,LAT,LON)_GRID
0020 %    -----------------
0021 %
0022 %    FORMAT = 'iaaft'
0023 %    the data are expanded in longitude dimension  by an Iterative
0024 %    Amplitude Adapted Fourier Transform algorithm
0025 %
0026 %    The data are expanded to fill missing higher dimensions. For
0027 %    example 2D pressure and latitude dependent data are
0028 %    expanded to longitudinal dependency by applying the weights
0029 %    in G.DIMADD.weight. So G.DATA(p1,lat1,lon1)=
0030 %    G.DATA(p1,lat1)*G.DIMADD.weight(1)
0031 %
0032 % FORMAT   G = asg_regrid( G, Q )
0033 %
0034 % OUT   G   Extrapolated ASG data.
0035 % IN
0036 %       G   gformat data data.
0037 %       Q   Qarts setting structure.
0038 
0039 % 2007-10-19   Created by Patrick Eriksson
0040 
0041 function G = asg_dimadd( G, Q )
0042   
0043 
0044 %- Basic checks of input
0045 %
0046 %qcheck( @asgD, D );
0047 %qcheck( @asgG, G );
0048 %qcheck( @qarts, Q );
0049 %
0050 rqre_in_range( Q.ATMOSPHERE_DIM, 1, 3, 'Q.ATMOSPHERE_DIM' );
0051 
0052 
0053 
0054 %- New grids for p, lat and lon . To be used with 'expand' option.
0055 %
0056 expandg = { [1.1e5 1e-9], [-90 90], [-180 180] };
0057 
0058 
0059 for ig = 1 : length(G)
0060 
0061   %- Do nothing if DATA field is empty.
0062   %
0063   if isempty( G(ig).DATA )
0064     continue;
0065   end
0066   
0067   %- Determine new dimensions
0068   %
0069   %maxdim  = max( G(ig).DIMS( find(G(ig).DIMS <= Q.ATMOSPHERE_DIM) ) );
0070   maxdim=G(ig).DIM;
0071   %
0072   if isempty(maxdim)
0073     if G(ig).SURFACE
0074       maxdim = 1;
0075     else
0076       maxdim = 0;
0077     end
0078   end
0079   %
0080   newdims = maxdim+1 : Q.ATMOSPHERE_DIM;
0081 
0082   %- Already at Q.ATMOSPHERE_DIM?
0083   %
0084   if isempty( newdims )
0085     continue;
0086   end
0087   
0088   if ~isfield( G(ig).DIMADD, 'METHOD' )
0089     error( sprintf('No field ''METHOD in G(%d).DIMADD.', ig ) );
0090   end
0091 
0092   switch lower( G(ig).DIMADD.METHOD )
0093   
0094    %--- Simple expansion ---------------------------------------------------
0095    case 'expand'
0096     %
0097    
0098     G(ig) = gf_increase_dim( asgD, G(ig), newdims, {expandg{newdims}} );
0099 
0100    case 'expand_weighting'
0101     %
0102     if length(newdims)==1 
0103        if newdims~=3 
0104           error('only longitudinal dependency can be added with this option')
0105        end
0106     else
0107       error('only longitudinal dependency can be added with this option')
0108     end
0109     if length(Q.LON_GRID)~=length(G(ig).DIMADD.weights)
0110       error('mismatch in size between Q.LON_GRID and G.DIMADD.weights')
0111     end
0112     G(ig) = gf_increase_dim( D, G(ig), newdims, {Q.LON_GRID} );
0113     data=G(ig).DATA;
0114     if isvector(data)
0115        for jg=1:length(Q.LON_GRID)
0116            data(:,jg)=data(:,jg)*G(ig).DIMADD.weights(jg);
0117        end       
0118     else
0119        for jg=1:length(Q.LON_GRID)
0120            data(:,:,jg)=data(:,:,jg)*G(ig).DIMADD.weights(jg);
0121        end
0122     end 
0123     G(ig).DATA=data;
0124     
0125    case 'iaaft' 
0126     if length(newdims)==1 
0127       if newdims~=3 
0128           error('only longitudinal dependency can be added with this option')
0129       end
0130     else
0131       error('only longitudinal dependency can be added with this option')
0132     end  
0133     G(ig) = asg_2d23d( G(ig), Q );   
0134 
0135    otherwise
0136      error( sprintf( 'No recognised choice for G(%d).DIMADD.METHOD.', ig ) );
0137   end
0138 end
0139 
0140   
0141 % GF_INCREASE_DIM   Increase dimension of gformat data
0142 %
0143 %    Existing data are repeated to fill added dimensions.
0144 %
0145 %    To e.g. expand 1D data to 2D, covering the range [-90 90], do
0146 %       G = gf_increase_dim( D, G, 2, {[-90 90]} );
0147 %
0148 % FORMAT   G = gf_increase_dim( D, G, newdims, grids )
0149 %
0150 % OUT   G         Expanded data.
0151 % IN    D         Gformat definition structure
0152 %       G         Original gformat data.
0153 %       newdims   Data dimensions to be added, as a vector of integers.
0154 %       grids     Grids for new dimensions. An array of vectors, with same
0155 %                 length as *newdims*.
0156 
0157 % 2007-10-17   Created by Patrick Eriksson.
0158 
0159 
0160 function G = gf_increase_dim( D, G, newdims, grids )
0161 
0162 
0163 %- Check input
0164 %
0165 %rqre_datatype( 'struct', D );
0166 %rqre_datatype( 'struct', G );
0167 %rqre_field( D, 'DIM', 0 );
0168 %rqre_field( G, 'DIMS', 0 );
0169 %rqre_datatype( 'vector', newdims );
0170 %rqre_datatype( 'cell', grids );
0171 %
0172 newdims = vec2row( newdims );
0173 %
0174 if max(newdims) > D.DIM
0175   error( 'You have selected a dimension (in *newdims*) above D.DIM.' );
0176 end
0177 %
0178 if any( diff(newdims) < 1 )
0179   error( ['Input argument *newdims* must be sorted in ascending order, ',...
0180           'with no dimensions repeated.'] );
0181 end
0182 %
0183 if length(newdims) ~= length(grids)
0184   error( 'Difference in length between *newdims* and *grids*.' );
0185 end
0186 
0187 
0188 for ig = 1 : length(G)
0189 
0190   %if isempty(G(ig).DIMS)
0191   %  maxdim = 0;
0192   %else
0193   %  maxdim = G(ig).DIMS(end);
0194   %end
0195   maxdim=G(ig).DIM;
0196 
0197   if maxdim >= newdims(1)
0198     continue;
0199   end
0200   
0201   %- Create mapdata and include grids
0202   %
0203   mapdata = ones( 1, max([ 2 newdims(end) ]) ); 
0204   %
0205   for id = 1 : length(newdims)
0206     mapdata(newdims(id))                  = length( grids{id} );
0207     G(ig).(sprintf('GRID%d',newdims(id))) = grids{id};
0208   end
0209   
0210   %G(ig).DIMS = [ vec2row(G(ig).DIMS), newdims ];
0211   G(ig).DIM=max(newdims);
0212   G(ig).DATA = repmat( G(ig).DATA, mapdata );
0213 
0214 end
0215 
0216 return

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