Home > atmlab > geoplots > atmplot_timeseries.m

atmplot_timeseries

PURPOSE ^

ATMPLOT_TIMESERIES Makes a time series plot of vertical profiles.

SYNOPSIS ^

function atmplot_timeseries(Ps,shadearg)

DESCRIPTION ^

 ATMPLOT_TIMESERIES   Makes a time series plot of vertical profiles.

    The function plots a series of vertical profiles as a function of
    some quantity. The "time" coordinate can be real time, a scan number
    or any other quantity that has a natural order. The profiles are plotted
    without any vertical interpolation.

    The profiles are given as a struct vector. Each struct must have, at 
    least, these fields:
       t        The time, or some other running quantity.
       twidth   The width of the observation in units of *t*.
       z        The altitudes, or equivalent quantity, of the observations.
       p        The profile.

    For example, profile nr. i is Ps(i).p.

    The observations are assumed to be valid for the given altitudes (z),
    during the time [t-twidth/2, t+twidth/2]. With *shadearg* = *faceted*
    or *flat*, each value will be plotted as a rectangle uniformly colored.
    The values are assumed to valid half-way to neighbouring points. The 
    values for the end points are assumed to be valid outside the given
    altitude range, over a distance equal to half the distance to the
    neighbour point.

    With *shadearg* = 'interp', the color will vary vertically in a 
    piecewise linear manner, between the given altitudes.

    The shading of the plot shall be set by the optional argument. If the
    shading is changed later, the profiles can be displayed in an incorrect
    manner.

    The profiles can contain NaNs, which result a gap in displayed profiles.

    The function performs just the plotting, without clearing the function
    before start. All other operations, such as setting label texts or
    setting the color scale, must be handled separately.

 FORMAT   atmplot_timeseries( Ps [,shadearg] )
        
 IN    Ps         Struct vector with profile data. See further above.
 OPT   shadearg   This argument is passed to *shading*. If not given, or 
                  empty, no call of *shading is done. If no shading is set
                  before the call of this function, the shading will be 
                  'faceted'.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

atmplot_timeseries.m

SOURCE CODE ^

0001 % ATMPLOT_TIMESERIES   Makes a time series plot of vertical profiles.
0002 %
0003 %    The function plots a series of vertical profiles as a function of
0004 %    some quantity. The "time" coordinate can be real time, a scan number
0005 %    or any other quantity that has a natural order. The profiles are plotted
0006 %    without any vertical interpolation.
0007 %
0008 %    The profiles are given as a struct vector. Each struct must have, at
0009 %    least, these fields:
0010 %       t        The time, or some other running quantity.
0011 %       twidth   The width of the observation in units of *t*.
0012 %       z        The altitudes, or equivalent quantity, of the observations.
0013 %       p        The profile.
0014 %
0015 %    For example, profile nr. i is Ps(i).p.
0016 %
0017 %    The observations are assumed to be valid for the given altitudes (z),
0018 %    during the time [t-twidth/2, t+twidth/2]. With *shadearg* = *faceted*
0019 %    or *flat*, each value will be plotted as a rectangle uniformly colored.
0020 %    The values are assumed to valid half-way to neighbouring points. The
0021 %    values for the end points are assumed to be valid outside the given
0022 %    altitude range, over a distance equal to half the distance to the
0023 %    neighbour point.
0024 %
0025 %    With *shadearg* = 'interp', the color will vary vertically in a
0026 %    piecewise linear manner, between the given altitudes.
0027 %
0028 %    The shading of the plot shall be set by the optional argument. If the
0029 %    shading is changed later, the profiles can be displayed in an incorrect
0030 %    manner.
0031 %
0032 %    The profiles can contain NaNs, which result a gap in displayed profiles.
0033 %
0034 %    The function performs just the plotting, without clearing the function
0035 %    before start. All other operations, such as setting label texts or
0036 %    setting the color scale, must be handled separately.
0037 %
0038 % FORMAT   atmplot_timeseries( Ps [,shadearg] )
0039 %
0040 % IN    Ps         Struct vector with profile data. See further above.
0041 % OPT   shadearg   This argument is passed to *shading*. If not given, or
0042 %                  empty, no call of *shading is done. If no shading is set
0043 %                  before the call of this function, the shading will be
0044 %                  'faceted'.
0045 
0046 % 2002-12-11   Created by Patrick Eriksson.
0047 
0048 
0049 function atmplot_timeseries(Ps,shadearg)
0050 
0051 
0052 %=== Basic ckeck of input
0053 %
0054 rqre_nargin( 1, nargin );
0055 %
0056 if nargin < 2
0057   shadearg = 'faceted';
0058 end
0059 
0060 
0061 %=== Check that the needed fields exist
0062 %
0063 if ~isfield(Ps,'t')  |  ~isfield(Ps,'twidth')  |  ...
0064    ~isfield(Ps,'z')  |  ~isfield(Ps,'p')
0065   serr = sprintf( ['The struct array Ps must have (at least) the fields:\n',...
0066                                               '   t\n   twidth\n   z\n   p'] );
0067   error( serr );
0068 end
0069 
0070 
0071 %=== Loop the profiles, check data and plot
0072 %
0073 for ip = 1: length( Ps )
0074   %
0075   n = length( Ps(ip).z );
0076   %
0077   if n ~= length( Ps(ip).p )
0078     serr = sprintf( ['The lengths of vector z and p differ for profile ', ...
0079                                                                 'nr %d'], ip );
0080     error( serr );
0081   end
0082   %
0083   if n
0084     %
0085     t = Ps(ip).t;
0086     w = Ps(ip).twidth;
0087     %
0088     if ~isscalar(w)  |  w <= 0
0089       serr = sprintf( ['The time widths must be scalars > 0, but this not ',...
0090                                            'the case for profile nr %d'], ip );
0091       error( serr );
0092     end
0093 
0094     %- Flat and faceted shading:
0095     if ~strcmp( shadearg, 'interp' )
0096       y = vec2col( Ps(ip).z );
0097       y = [ y(1)-(y(2)-y(1))/2; y(1:n-1)+diff(y)/2; y(n)+(y(n)-y(n-1))/2 ];
0098       %
0099       %- A special solution is needed if not NaNs shall make the color
0100       %- rectangle for two altitudes blank.
0101       z      = vec2col(  Ps(ip).p );
0102       nns    = find( isnan( z ) );
0103       z(nns) = z(1);
0104       z      = [ z; z(n) ];
0105       %
0106       n = n + 1;  % As there must be a dummy point to give end for last point
0107 
0108     %- Interp shading
0109     else
0110       y = vec2col( Ps(ip).z );
0111       z = vec2col(  Ps(ip).p );
0112       nns = [];
0113     end
0114 
0115     X = repmat( [t-w/2 t+w/2], n, 1 );
0116     Y = repmat( y, 1, 2 );
0117     Z = repmat( z, 1, 2 );
0118     %
0119     h=surface( X, Y, Z );
0120 
0121     if ~isempty( nns )
0122       c = get( h, 'CData' );
0123       c(nns,:) = NaN;
0124       set( h, 'CData', c );
0125     end
0126 
0127   end
0128 end
0129 
0130 
0131 %=== Set shading
0132 %
0133 shading( shadearg );

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