image thumbnail

Get Land Surface Temperatures

by

 

22 Oct 2012 (Updated )

Acquire land surface temps from Berkeley Earth Surface Temperature study, NOAA, and NASA-Goddard.

noaa_tavg.m
function [noaa_temp,noaa_dates] = noaa_tavg(start_date,end_date,moving_average)
% [noaa_temp,noaa_dates] = noaa_tavg(start_date,end_date,moving_average) 
% retrieves land surface temperature history from the United States National 
% Oceanic and Atmospheric Administration (NOAA)'s National Climate Data 
% Center (NCDC). Anomalies are plotted relative to the 1901-2000 global 
% average land surface temperature. See http://www.ncdc.noaa.gov/. 
% 
%
% *********************************************************************** %
% INPUTS (optional): 
% start_date = beginning of date range of interest in Matlab's datenum format 
%   (e.g. datenum(1936,4,1) or datenum('Apr 1 1936') for April 1, 1936). 
%   Valid for Jan. 1753 or after. start_date is an optional input and can 
%   be used without declaring an end_date. 
% 
% end_date = end of date range of interest in Matlab's datenum format. 
% 
% moving_average = averaging period of data. Note that start_date and
%   end_date must be declared if any non-monthly averaging is desired. 
%   Valid arguments include the following: 
%     For monthly averaging: 'month','monthly', or '1 month'
%     For yearly averaging: 'annual','yearly','year','12 month', or '1 year'
% 
%
% OUTPUTS: 
% noaa_temp = time series of temperature anomalies (C) relative to the
%   1950 to 1980 average. 
%
% noaa_dates = corresponding date vector in Matlab's datenum format. 
% 
% noaa_temp_unc = vector of 95% uncertainty values in degrees centigrade
% 
% 
% *********************************************************************** %
% A FEW EXAMPLES OF VALID SYNTAX: 
% noaa_tavg; % returns full record of monthly temperature anomalies. 
% 
% [noaa_temp,noaa_dates] = noaa_tavg; % returns full record of monthly
%   temperature anomalies, with their corresponding dates. 
% 
% [noaa_temp,noaa_dates] = noaa_tavg(datenum('Feb 1, 1998')); % returns 
%   monthly temperatures and corresponding date vector from February 1,
%   1998 to the end of the record. 
% 
% [noaa_temp,noaa_dates] = noaa_tavg(datenum('Feb 1, 1998'),datenum('Jan 1, 2009'));
%   returns monthly temperatures, and dates from February 1, 1998 to January 1, 2009.
% 
% [noaa_temp,noaa_dates] = noaa_tavg(datenum('Jan 1, 1900'),datenum('Jan 1, 2010'),'decadal');
%   returns decadally-averaged temperatures, sampled monthly and corresponding
%   dates from January 1 1900 to January 1, 2010.
% 
% 
% *********************************************************************** %
% EXAMPLE (generates noaa_example.png): 
%  
% [noaa_temp,noaa_dates] = noaa_tavg(datenum('Jan 1, 1880'),datenum('Jan 1, 2011'),'annual');
% 
% figure
% set(gcf,'position',[100 100 900 500])
% plot(noaa_dates,noaa_temp,'b');
% datetick
% axis tight
% ylabel('temperature anomalies (C)')
% xlabel('date')
% box off 
% text(0,.9,'  NOAA''s annually-averaged land temperature record','units','normalized')
% 
% 
% *********************************************************************** %
% Coded by Chad A. Greene, October 2012. 
% http://www.chadagreene.com
%
% See also best_tavg, giss_tavg, and temp_record_examples. 


if exist('moving_average','var')~=1
    moving_average = 'monthly'; % uses monthly data if no moving average is selected
end

switch moving_average
    case {'annual','yearly','year','12 month','1 year'} 
        noaa_txt = urlread('ftp://ftp.ncdc.noaa.gov/pub/data/anomalies/annual.land.90S.90N.df_1901-2000mean.dat');
        noaa_txt = strrep(noaa_txt,'-999.0000','NaN'); % replaces missing values
        noaa_struct = textscan(noaa_txt,'%n %n'); 
        noaa_mat = cell2mat(noaa_struct); % converts cell structure to matrix

        noaa_dates = datenum(noaa_mat(:,1),7,2); % places yearly average at year's middle date 
        noaa_temp = noaa_mat(:,2); 

    case {'monthly','month','1 month',''} 
        noaa_txt = urlread('ftp://ftp.ncdc.noaa.gov/pub/data/anomalies/monthly.land.90S.90N.df_1901-2000mean.dat');
        noaa_txt = strrep(noaa_txt,'-999.0000','NaN'); % replaces missing values
        noaa_struct = textscan(noaa_txt,'%n %n %n'); 
        noaa_mat = cell2mat(noaa_struct); % converts cell structure to matrix

        noaa_dates = datenum(noaa_mat(:,1),noaa_mat(:,2),15); % places yearly average at year's middle date 
        noaa_temp = noaa_mat(:,3); 
end


% Snip NaN data: 
noaa_dates = noaa_dates(isfinite(noaa_temp)); 
noaa_temp = noaa_temp(isfinite(noaa_temp)); 


% If input arguments (start and/or end dates) are used, rewrite time series
% data to include only dates of interest: 
if exist('start_date','var')==1 
    if start_date<datenum(1880,1,1)
        warning('NOAA data record begins in January 1880.')
    end
    if end_date>datenum(date)
        warning('NOAA Temperature record ends last month.')
    end
    if exist('end_date','var')~=1
        end_date = noaa_dates(end); % uses today as end_date if not specified
    end
    nn = find(noaa_dates>=start_date&noaa_dates<=end_date); 
    noaa_temp = noaa_temp(nn);
    noaa_dates = noaa_dates(nn);
end

Contact us