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.

giss_tavg.m
function [giss_temp,giss_dates] = giss_tavg(start_date,end_date,moving_average)
% [giss_temp,giss_dates] = giss_tavg(start_date,end_date,moving_average) 
% retrieves land surface temperature history from the Goddard Institute for 
% Space Studies (GISS). Anomalies are plotted relative to the 1951-1980 
% global average land surface temperature. Sources: GHCN-v3 1880-09/2012 
% (meteorological stations only), using elimination of outliers and 
% homogeneity adjustment. See http://data.giss.nasa.gov/gistemp/
% 
%
% *********************************************************************** %
% 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: 
% giss_temp = time series of temperature anomalies (C) relative to the
%   1950 to 1980 average. 
%
% giss_dates = corresponding date vector in Matlab's datenum format. 
% 
% giss_temp_unc = vector of 95% uncertainty values in degrees centigrade
% 
% 
% *********************************************************************** %
% A FEW EXAMPLES OF VALID SYNTAX: 
% giss_tavg; % returns full record of monthly temperature anomalies. 
% 
% [giss_temp,giss_dates] = giss_tavg; % returns full record of monthly
%   temperature anomalies, with their corresponding dates. 
% 
% [giss_temp,giss_dates] = giss_tavg(datenum('Feb 1, 1998')); % returns 
%   monthly temperatures and corresponding date vector from February 1,
%   1998 to the end of the record. 
% 
% [giss_temp,giss_dates] = giss_tavg(datenum('Feb 1, 1998'),datenum('Jan 1, 2009'));
%   returns monthly temperatures, and dates from February 1, 1998 to January 1, 2009.
% 
% [giss_temp,giss_dates] = giss_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 GISS_example.png): 
%  
% [giss_temp,giss_dates] = giss_tavg(datenum('Jan 1, 1880'),datenum('Jan 1, 2011'),'annual');
% 
% figure
% set(gcf,'position',[100 100 900 500])
% plot(giss_dates,giss_temp,'b');
% datetick
% axis tight
% ylabel('temperature anomalies (C)')
% xlabel('date')
% box off 
% text(0,.9,'  Goddard Institute for Space Studies, annually-averaged land temperature record','units','normalized')
% 
% 
% *********************************************************************** %
% Coded by Chad A. Greene, October 2012. 
% http://www.chadagreene.com
%
% See also best_tavg, noaa_tavg, and temp_record_examples. 


% Import the data from GISS site: 
giss_txt = urlread('http://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts.txt');
giss_txt = strrep(giss_txt,'*',' '); % replaces missing values
giss_struct = textscan(giss_txt,'%n %n %n %n %n %n %n %n %n %n %n %n %n %n %n %n %n %n %n %n',...
    'headerlines',8,'CommentStyle','Y'); % CommentStyle ignores text lines starting with the letter Y
giss_mat = cell2mat(giss_struct); % converts cell structure to matrix

 
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'}
        giss_dates = datenum(giss_mat(:,1),7,2); % middle day of each year
        giss_temp = giss_mat(:,14)/100; % Values divided by 100 b/c GISS
                % publishes anomalies in hundredths of a degree centigrade  

    case {'monthly','month','1 month',''} 
        % Reshape the calendar-style data grid into a time series vector: 
        giss_dates = NaN(size(giss_mat,1)*12,1);  % preallocate date vector
        giss_temp = NaN(size(giss_dates));        % preallocate temp vector
        k = 0;                                    % initializes counter
        for m = 1:length(giss_mat); 
            for n = 2:13
                k = k+1; 
                giss_dates(k) = datenum(giss_mat(m,1),n-1,15);  
                giss_temp(k) = giss_mat(m,n)/100; % Values divided by 100 b/c
                % GISS publishes anomalies in hundredths of a degree centigrade
            end
        end
end


% 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('GISS data record begins in January 1880.')
    end
    if exist('end_date','var')~=1
        end_date = giss_dates(end); % uses today as end_date if not specified
    end
    nn = find(giss_dates>=start_date&giss_dates<=end_date); 
    giss_temp = giss_temp(nn);
    giss_dates = giss_dates(nn);
end

% Fix missing data: 
giss_temp(giss_temp>10) = NaN;
giss_dates = giss_dates(isfinite(giss_temp)); 
giss_temp = giss_temp(isfinite(giss_temp)); 

Contact us