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.

best_tavg.m
function [best_temp,best_dates,best_temp_unc] = best_tavg(start_date,end_date,moving_average)
%[best_temp,best_dates,best_temp_unc] = best_tavg(start_date,end_date,moving_average)
% Retrieves land surface temperature averages calculated by the Berkeley
% Earth Surface Temperature Study. Temperatures are plotted as anomalies relative 
% to the 1950 to 1980 average. For information on the study, see 
% http://www.berkeleyearth.org. 
% 
%
% *********************************************************************** %
% 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'
%     For five-year averaging: '5 year' or 'pentadal'
%     For ten-year averaging: '10 year' or 'decadal'
%     For twenty-year averaging: '20 year','score', or 'scorely'
% 
%
% OUTPUTS: 
% best_temp = time series of temperature anomalies (C) relative to the
%   1950 to 1980 average. 
%
% best_dates = corresponding date vector in Matlab's datenum format. 
% 
% best_temp_unc = vector of 95% uncertainty values in degrees centigrade
% 
% 
% *********************************************************************** %
% A FEW EXAMPLES OF VALID SYNTAX: 
% best_tavg; % returns full record of monthly temperature anomalies. 
% 
% [best_temp,best_dates] = best_tavg; % returns full record of monthly
%   temperature anomalies, with their corresponding dates. 
% 
% [best_temp,best_dates,best_temp_unc] = best_tavg; % returns full record
%   of monthly temperature anomalies, with corresponding dates and
%   uncertainty values. 
% 
% [best_temp,best_dates,best_temp_unc] = best_tavg(datenum('Feb 1, 1998'));
%   returns monthly temperatures, dates, and uncertainties from February 1,
%   1998 to the end of the record. 
% 
% [best_temp,best_dates,best_temp_unc] = best_tavg(datenum('Feb 1, 1998'),datenum('Jan 1, 2009'));
%   returns monthly temperatures, dates, and uncertainties from February 1,
%   1998 to January 1, 2009.
% 
% [best_temp,best_dates,best_temp_unc] = best_tavg(datenum('Jan 1, 1900'),datenum('Jan 1, 2010'),'decadal');
%   returns decadally-averaged temperatures, sampled monthly, corresponding
%   dates, and uncertainties from January 1 1900 to January 1, 2010.
% 
% 
% *********************************************************************** %
% EXAMPLE (generates BEST_example.png): 
% [best_temp,best_dates,best_temp_unc] = best_tavg(datenum('Jan 1, 1850'),datenum('Jan 1, 2011'),'decadal');
% 
% figure
% set(gcf,'position',[100 100 900 500])
% bestfill = fill([best_dates;flipud(best_dates)],[best_temp+best_temp_unc;flipud(best_temp-best_temp_unc)],'b');hold on
% set(bestfill,'facealpha',.2,'edgealpha',0);
% plot(best_dates,best_temp,'b');
% datetick
% axis tight
% ylabel('temperature anomalies (C)')
% xlabel('date')
% box off 
% text(0,.9,'  Berkeley Earth Surface Temperature, decadally-averaged land record','units','normalized')
% 
% 
% *********************************************************************** %
% Coded by Chad A. Greene, October 2012. 
% http://www.chadagreene.com
%
% See also giss_tavg, noaa_tavg, and temp_record_examples. 



% Import the data:
best_txt = urlread('http://berkeleyearth.lbl.gov/auto/Global/Full_TAVG_complete.txt');
best_struct = textscan(best_txt,'%n %n %n %n %n %n %n %n %n %n %n %n','headerlines',28); 
best_mat = cell2mat(best_struct); % converts cell structure to matrix
best_dates = datenum(best_mat(:,1),best_mat(:,2),15); 

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

switch moving_average
    case {'monthly','month','1 month',''} 
        best_temp = best_mat(:,3); % monthly temperature anomalies 
        best_temp_unc = best_mat(:,4); % monthly temp. anomaly uncertainty 
        
    case {'annual','yearly','year','12 month','1 year'}
        best_temp = best_mat(:,5);  
        best_temp_unc = best_mat(:,6);
        
    case {'5 year','pentadal'}
        best_temp = best_mat(:,7);  
        best_temp_unc = best_mat(:,8);
        
    case {'10 year','decadal'}
        best_temp = best_mat(:,9);  
        best_temp_unc = best_mat(:,10);
        
    case {'20 year','score','scorely'}
        best_temp = best_mat(:,11);  
        best_temp_unc = best_mat(:,12);
end


% Snip NaN data and corresponding dates: 
best_dates = best_dates(isfinite(best_temp));
best_temp_unc = best_temp_unc(isfinite(best_temp));
best_temp = best_temp(isfinite(best_temp));


% Snip data to date range of interest: 
if exist('start_date','var')==1 
    if start_date<datenum(1753,1,1)
        warning('BEST Temperature record begins in January 1753.')
    end
    if end_date>datenum(2011,12,1)
        warning('BEST Temperature record ends in November 2011.')
    end
    if exist('end_date','var')~=1
        end_date = best_dates(end);
    end
    
    nn = find(best_dates>=start_date&best_dates<=end_date); 
    best_temp = best_temp(nn);
    best_temp_unc = best_temp_unc(nn);
    best_dates = best_dates(nn);

end



Contact us