<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/global-temp-raw-adjusted-sea-surface-temps/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://data-steve.github.io/global-temp-pt2/"> data_steve</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img alt="" src="https://i2.wp.com/data-steve.github.io/images/had_raw_adj_readings.png?w=456" data-recalc-dims="1"></p>
<p>In <a target="_blank" rel="nofollow" href="http://data-steve.github.io/glob-temp-data-pt1">the last post I created a gif</a> summarizing the HadCRUT4 sea-surface temperature (HadSST3) data as its data collection evolved over time.</p>
<p>The goal of the last post was simply to visualize presence of any temperature measurement in a given matrix gridcell for that year-month global snapshot. In this post I thought it’d be interesting to sum up the raw data per year-month snapshot to see how the raw data compare to the adjusted data for the global trends.</p>
<p>I’ve pasted in again the necessary code to get the HadSST3 data downloaded and ready for processing. As in last post, we’re starting off using the raw data provided by HadCRUT at their official page for HadSST, and then we’ll grab the adjusted data next for the comparison. Both the raw and adjusted data come as text files. But because the raw data comes is a year-month series of global 36-by-72 gridded matrices, we need to do some light parsing to get the text into a list of matrices.</p>
<h4>Getting and Cleaning the HadSST3 raw data</h4>
<div>
<pre><code>pacman::p_load(tidyverse, curl)

home &lt;- getwd()
temp &lt;- tempfile()
url &lt;- &quot;http://hadobs.metoffice.com/hadsst3/data/HadSST.3.1.1.0/ascii/HadSST.3.1.1.0.unadjusted.zip&quot;
curl_download(url,temp)
data &lt;- readLines(unz(temp, &quot;HadSST.3.1.1.0.unadjusted.txt&quot;))
unlink(temp)
data[1:2]

# meta-data pattern defining when each new matrix begin
ii &lt;- grepl(&quot;\\d+\\s+\\d{4}\\s+\\d+\\s+Rows&quot;, data)
counter &lt;- 0
index &lt;- rep(NA,length(ii))

for (j in 1:length(data)){
  if(ii[j]){
    counter=counter+1
    index[j]=counter
  } else {
    index[j] = counter
  } }
</code></pre>
</div>
<h4>Parsing raw data and Aggregating the Global Trend</h4>
<p>The main difference from the code I used last time for prepping the data for the gif is: now instead of looking the presence of the missing code <code>-99.99</code> vs anything else in each year-month matrix and giving it a 0 if missing and 1 if not, we’re just going to changing <code>-99.99</code> to <code>NA</code> so we can sum over the values in the matrix. The non-missing values are in Celsius anomalies from global average over the period 1961-1990.</p>
<div>
<pre><code>dat_mat_measures &lt;- lapply(split(data,index), function(x) {
    meta &lt;- x[1]
    yr &lt;- regmatches(meta,regexec(&quot;\\d{4}&quot;,meta))[[1]]
    mo &lt;- regmatches(meta,regexec(&quot;\\d{1,2}&quot;,meta))[[1]][1]
    mo &lt;- ifelse(as.integer(mo)&lt;10,paste0(&quot;0&quot;,mo),mo)
    mx &lt;- x[2:37]
    mx &lt;- sapply(mx, function(y) {
      m &lt;- as.numeric(strsplit(trimws(y),&quot;\\s+&quot;)[[1]])
      ifelse(m==-99.99, NA,m) })
    
    m &lt;- matrix(mx,36,72)
    colnames(m) &lt;- c(paste0(seq(175,5,by=-5),&quot;W&quot;),0,paste0(seq(5,180, by=5),&quot;E&quot;))
    rownames(m) &lt;- c(paste0(seq(85,5,by=-5),&quot;S&quot;),&quot;Eq&quot;,paste0(seq(5,90, by=5),&quot;N&quot;))
  
    stats::setNames(list(paste0(yr,&quot;/&quot;,mo),mean(m,na.rm = T),m)
                    , c(&quot;ym&quot;,&quot;mean&quot;, &quot;raw&quot;) )
  }) %>% transpose()
</code></pre>
</div>
<p>At this step, I can’t tell you how handy I found <code>purrr::transpose</code> to be in inverting the list structures from year-month at level one in the list with values of interest at level 2, to having all the values of interest being level 1 lists with their year-months as values. Super convenient to then put these into a dataframe!!</p>
<div>
<pre><code>ym_mean &lt;- data_frame(ym = unlist(dat_mat_measures$ym),
                      mean = as.numeric( unlist(dat_mat_measures$mean) ) )
</code></pre>
</div>
<h4>Getting/Joining HadSST3 adjusted global monthly data</h4>
<p>The HadCRUT website has several resources I found helpful in explaining the main reasons for their needing to make adjustments to the raw data. I’d start with the <a target="_blank" rel="nofollow" href="http://hadobs.metoffice.com/hadsst3/faq.html">FAQ page</a>, but they’ve also release 2 white papers. To give you the basic gist: <a target="_blank" rel="nofollow" href="http://hadobs.metoffice.com/hadsst3/part_1_figinline.pdf">the first one</a> deals with adjustments made to the data due to differences in methods of measuring the temperature of the water over time since 1880. <a target="_blank" rel="nofollow" href="http://hadobs.metoffice.com/hadsst3/part_2_figinline.pdf">The second paper</a> deals with adjustments needed for some of the sampling problems the HadSST data.</p>
<p>I found all three resources quite helpful in explain why they’ve made adjustments to the raw data. The opening to the second white paper summarizes their case quite plainly:</p>
<blockquote>
<p>“SSTs have been observed by diverse means in the past 160 years. As a result, measurements of SST recorded in historical archives are prone to systematic errors – often referred to as biases – that are of a similar magnitude to the expected climate change signal. That biases exist is well documented….”</p>
</blockquote>
<p>After reading that passage, I thought it would be useful to see how much “a similar magnitude to the expected climate change signal” actually looked like.</p>
<div>
<pre><code>mon_gl &lt;- &quot;http://hadobs.metoffice.com/hadsst3/data/HadSST.3.1.1.0/diagnostics/HadSST.3.1.1.0_monthly_globe_ts.txt&quot;
had_m_avg &lt;- readLines(mon_gl)

had_m_avg2 &lt;- lapply(had_m_avg, function(x) {#browser()
          v &lt;-  strsplit(x,&quot;\\s+&quot;)[[1]]
          data_frame(ym=v[1], avg=as.numeric(v[2]))
        }) %>% bind_rows()

raw_adj &lt;- ym_mean %>%
  left_join(had_m_avg2, by=&quot;ym&quot;) %>%
  setNames(c(&quot;ym&quot;, &quot;HadRaw&quot;, &quot;HadAdj&quot;))

ticks &lt;- ym_mean$ym[seq(12,2000,by=96)]

raw_adj %>%
  mutate(ym=factor(ym,levels=ym, ordered=T)) %>%
  gather(source, temp, -ym) %>%
  mutate(source=factor(source)) %>%
  ggplot() + geom_point( aes(x=ym, y=temp,  color=source)) +
  ylab(&quot;Anamolies from 1961-90 avg.\n(Raw v. Adj HadSST3)&quot;) + xlab(&quot;Date (y/m)&quot;) +
  ggtitle(&quot;Global Sea-Surface Temperature Trends: Raw vs. Adjusted HadSST3&quot;) +
  scale_x_discrete(breaks = ticks) +
  theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1))
</code></pre>
</div>
<h4>Some Comments</h4>
<p>For ease of reading I reproduce the same plot again here.</p>
<p><img alt="" src="https://i2.wp.com/data-steve.github.io/images/had_raw_adj_readings.png?w=456" data-recalc-dims="1"></p>
<p>As you can see, during the pre-1950ish part of the trend the raw data are uniformly cooler than the adjusted data. Post-1950ish the raw and adjusted data line up almost exactly. The gap in trends seems largest for the 1910-1950 period, witha max difference of around 0.48 Celsius (0.86 F).</p>
<div>
<pre><code>raw_adj %>% summarize(max(HadAdj-HadRaw))
</code></pre>
</div>
<p>After reading the two white papers, as a matter of quick visual gut check for our own aggregation step it is encouraging to see in the plot agrees with the papers.</p>
<p>The FAQs do mention that the same adjustments are applied over the full trend, which was one of the HadSST3 improvements over the HadSST2 data. But it would appear that that the pre-1950ish data suffered from some data quality issues that the post-1950 data doesn’t: especially when temperature measuring methods allowed water to cool in the interim between when it was drawn from the water and when it was measured. Indeed, the first and second white papers detail several such sources and the ways in which they are addressed: interestingly, the reasons are a mix of technological and data provenance.</p>
<p>Spurred on by the closing statements of the second HadCRUT white paper,</p>
<blockquote>
<p>“Until multiple, independent estimates of SST biases exist, a significant contribution to the total uncertainty will remain unexplored. This remains a key weakness of historical SST analysis.”</p>
</blockquote>
<p>I’ll continue my exploration of the HadSST3 data and white papers. I encourage others who are using HadCRUT data, if you haven’t yet, to also read their suggested resources and dig into the raw data.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://data-steve.github.io/global-temp-pt2/"> data_steve</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/7hPQKxry74Y"></a></div>