Home > atmlab > math > land_sea_mask.m

land_sea_mask

PURPOSE ^

LAND_SEA_MASK Returns land-water masks of various sizes

SYNOPSIS ^

function varargout = land_sea_mask(varargin)

DESCRIPTION ^

 LAND_SEA_MASK   Returns land-water masks of various sizes

 Returns a land-water mask of various sizes. For backward compatibility,
 when called without arguments, returns a 1-degree land-sea-mask from
 arts-xml-data. In all other cases, returns a land-water-mask at the
 indicated resolution from atmlab-data (obtained with GMT).


 NOTE: To get a collection of all AVAILABLE land-water-masks, call this
 function with a single argument, being a string of length 1 equal to '?'
 (ASCII character number 63).

 NOTE: The new land-sea masks (obtained with GMT), the last longitude
 value is a repetition of the first, so the 1-deg mask from GMT contains
 one column more than the previous 1-deg mask in atmlab-xml-data. To
 configure this, you need to checkout the svn repo 'atmlab-data' and set
 the environment variable ATMLAB_DATA_PATH appropiately.

 For implementation notes (how to add masks etc.), see
 atmlab-data/land_water_mask/README

 FORMAT   [lat,lon,M] = land_sea_mask(gridsize)

 IN

   gridsize    string      size of the grid (The available grids are '1min','5min','60min','1deg')
        
 OUT   lat   Latitude grid for M.
       lon   Longitude grid for M.
       M     Mask matrix, with nonzero (may be 1) for land and 0 for sea.
             Is of type logical or uint8.
    ----- or -----
       cell array of strings: valid resolutions

 EXAMPLE

   >> [lat lon M] = land_sea_mask('5min');         
   >> pcolor(lon, lat, double(M)); shading('flat');
  ------- or -----------
   >> gmt_plot(struct('data',M,'lat',lat,'lon',lon))

 WARNING

   Beware of memory issues! The 1-min mask is a 10801x21601 matrix.
   That's 233 MB in uint8, almost 1.9 GB when converted to double.

 $Id: land_sea_mask.m 8570 2013-08-10 18:36:48Z seliasson $
 Created by Gerrit Holl

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

land_sea_mask.m

SOURCE CODE ^

0001 % LAND_SEA_MASK   Returns land-water masks of various sizes
0002 %
0003 % Returns a land-water mask of various sizes. For backward compatibility,
0004 % when called without arguments, returns a 1-degree land-sea-mask from
0005 % arts-xml-data. In all other cases, returns a land-water-mask at the
0006 % indicated resolution from atmlab-data (obtained with GMT).
0007 %
0008 %
0009 % NOTE: To get a collection of all AVAILABLE land-water-masks, call this
0010 % function with a single argument, being a string of length 1 equal to '?'
0011 % (ASCII character number 63).
0012 %
0013 % NOTE: The new land-sea masks (obtained with GMT), the last longitude
0014 % value is a repetition of the first, so the 1-deg mask from GMT contains
0015 % one column more than the previous 1-deg mask in atmlab-xml-data. To
0016 % configure this, you need to checkout the svn repo 'atmlab-data' and set
0017 % the environment variable ATMLAB_DATA_PATH appropiately.
0018 %
0019 % For implementation notes (how to add masks etc.), see
0020 % atmlab-data/land_water_mask/README
0021 %
0022 % FORMAT   [lat,lon,M] = land_sea_mask(gridsize)
0023 %
0024 % IN
0025 %
0026 %   gridsize    string      size of the grid (The available grids are '1min','5min','60min','1deg')
0027 %
0028 % OUT   lat   Latitude grid for M.
0029 %       lon   Longitude grid for M.
0030 %       M     Mask matrix, with nonzero (may be 1) for land and 0 for sea.
0031 %             Is of type logical or uint8.
0032 %    ----- or -----
0033 %       cell array of strings: valid resolutions
0034 %
0035 % EXAMPLE
0036 %
0037 %   >> [lat lon M] = land_sea_mask('5min');
0038 %   >> pcolor(lon, lat, double(M)); shading('flat');
0039 %  ------- or -----------
0040 %   >> gmt_plot(struct('data',M,'lat',lat,'lon',lon))
0041 %
0042 % WARNING
0043 %
0044 %   Beware of memory issues! The 1-min mask is a 10801x21601 matrix.
0045 %   That's 233 MB in uint8, almost 1.9 GB when converted to double.
0046 %
0047 % $Id: land_sea_mask.m 8570 2013-08-10 18:36:48Z seliasson $
0048 % Created by Gerrit Holl
0049 
0050 
0051 function varargout = land_sea_mask(varargin)
0052 
0053 switch nargin
0054     case 0
0055         [varargout{1:3}] = land_sea_mask_old;
0056     otherwise
0057         gridsize = varargin{1};
0058         if strcmp(gridsize, '?')
0059             S = dir(fullfile(atmlab('ATMLAB_DATA_PATH'), 'land_water_mask'));
0060             [~, ~, ~, ~, tokenStr]= regexp({S.name}, 'land_water_mask_(.*)\.png');
0061             varargout{1} = cellfun(@(v) v{1}, tokenStr(~cellfun(@isempty, tokenStr)));
0062         else
0063             [varargout{1:3}] = land_sea_mask_new(varargin{:});
0064         end
0065 end
0066 
0067 end 
0068 function [lat, lon, M] = land_sea_mask_new(gridsize)
0069 
0070 atmlab('require', {'ATMLAB_DATA_PATH'});
0071 maskdir = fullfile(atmlab('ATMLAB_DATA_PATH'), 'land_water_mask');
0072 maskfile = fullfile(maskdir, sprintf('land_water_mask_%s.png', strrep(gridsize,'60min','1deg')));
0073 latlon = fullfile(maskdir, sprintf('land_water_mask_%s_latlon.nc', strrep(gridsize,'60min','1deg')));
0074 
0075 % since strjoin only comes to matlab in 2013, I do it by hand here
0076 x = land_sea_mask('?');
0077 y = cellfun(@(x)(['"' x '", ']),x,'uniformoutput',0); y=[y{:}];
0078 
0079 assert(any(strcmp(gridsize,{'1min','5min','60min','1deg'})),['atmlab:' mfilename],...
0080     'Grid="%s" is not available\nThe available gridsizes are %s',gridsize,y(1:end-2))
0081 nc = loadncfile(latlon);
0082 lat = nc.lat;
0083 lon = nc.lon;
0084 M = imread(maskfile);
0085 
0086 end
0087 
0088 function [lat, lon, data] = land_sea_mask_old
0089 
0090 atmlab( 'require', {'ARTS_XMLDATA_PATH'} );
0091 
0092 logtext(atmlab('OUT'),['Loading 1 degree landmask from ARTS_XML_DATA. '...
0093     'If you want another gridsize input e.g., gridsize = ''5min''\n'])
0094 M = xmlLoad( fullfile(atmlab('ARTS_XMLDATA_PATH'), 'planets','Earth', ...
0095     'ERA40', sprintf('LandSeaMask_ERA40_1.0Degree.xml.gz') ) );
0096 
0097 lat = M.grids{1};
0098 lon = M.grids{2};
0099 data = 255 * cast( M.data, 'uint8' );
0100 end

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