Skip to content

Instantly share code, notes, and snippets.

@rsimmon
Last active November 12, 2015 02:13
Show Gist options
  • Save rsimmon/0976aaa89f28973a5062 to your computer and use it in GitHub Desktop.
Save rsimmon/0976aaa89f28973a5062 to your computer and use it in GitHub Desktop.
El Niño/Southern Oscillation
Year MEI ENSO_Index
2000.041667 -1.195 -1.6
2000.125 -1.252 -1.4
2000.208333 -1.151 -1.1
2000.291667 -0.548 -0.9
2000.375 0.16 -0.7
2000.458333 -0.04 -0.7
2000.541667 -0.169 -0.6
2000.625 -0.141 -0.5
2000.708333 -0.219 -0.6
2000.791667 -0.372 -0.7
2000.875 -0.75 -0.8
2000.958333 -0.582 -0.8
2001.041667 -0.539 -0.7
2001.125 -0.725 -0.6
2001.208333 -0.615 -0.5
2001.291667 -0.156 -0.3
2001.375 0.221 -0.2
2001.458333 0.032 -0.1
2001.541667 0.292 0
2001.625 0.366 -0.1
2001.708333 -0.108 -0.1
2001.791667 -0.266 -0.2
2001.875 -0.176 -0.3
2001.958333 0.005 -0.3
2002.041667 -0.049 -0.2
2002.125 -0.21 -0.1
2002.208333 -0.196 0.1
2002.291667 0.356 0.2
2002.375 0.843 0.4
2002.458333 0.948 0.7
2002.541667 0.684 0.8
2002.625 0.949 0.9
2002.708333 0.859 1.0
2002.791667 0.976 1.2
2002.875 1.063 1.3
2002.958333 1.114 1.1
2003.041667 1.185 0.9
2003.125 0.933 0.6
2003.208333 0.828 0.4
2003.291667 0.325 0
2003.375 0.088 -0.2
2003.458333 0.089 -0.1
2003.541667 0.165 0.1
2003.625 0.267 0.2
2003.708333 0.459 0.3
2003.791667 0.519 0.4
2003.875 0.528 0.4
2003.958333 0.319 0.4
2004.041667 0.31 0.3
2004.125 0.333 0.2
2004.208333 -0.117 0.1
2004.291667 0.243 0.1
2004.375 0.518 0.2
2004.458333 0.283 0.3
2004.541667 0.527 0.5
2004.625 0.665 0.7
2004.708333 0.531 0.7
2004.791667 0.497 0.7
2004.875 0.795 0.7
2004.958333 0.647 0.7
2005.041667 0.302 0.6
2005.125 0.804 0.6
2005.208333 1.032 0.5
2005.291667 0.589 0.5
2005.375 0.801 0.4
2005.458333 0.519 0.2
2005.541667 0.508 0.1
2005.625 0.329 0
2005.708333 0.288 0
2005.791667 -0.149 -0.1
2005.875 -0.4 -0.4
2005.958333 -0.583 -0.7
2006.041667 -0.469 -0.7
2006.125 -0.463 -0.6
2006.208333 -0.584 -0.4
2006.291667 -0.689 -0.2
2006.375 -0.004 0.0
2006.458333 0.592 0.1
2006.541667 0.669 0.2
2006.625 0.76 0.3
2006.708333 0.825 0.5
2006.791667 0.934 0.8
2006.875 1.299 0.9
2006.958333 0.953 1.0
2007.041667 0.972 0.7
2007.125 0.505 0.3
2007.208333 0.074 0
2007.291667 -0.053 -0.1
2007.375 0.226 -0.2
2007.458333 -0.221 -0.2
2007.541667 -0.246 -0.3
2007.625 -0.409 -0.6
2007.708333 -1.092 -0.8
2007.791667 -1.103 -1.1
2007.875 -1.165 -1.2
2007.958333 -1.164 -1.3
2008.041667 -1.009 -1.4
2008.125 -1.408 -1.3
2008.208333 -1.645 -1.1
2008.291667 -0.964 -0.9
2008.375 -0.352 -0.7
2008.458333 0.16 -0.5
2008.541667 0.073 -0.3
2008.625 -0.24 -0.2
2008.708333 -0.561 -0.2
2008.791667 -0.72 -0.3
2008.875 -0.605 -0.5
2008.958333 -0.66 -0.7
2009.041667 -0.752 -0.8
2009.125 -0.728 -0.7
2009.208333 -0.726 -0.4
2009.291667 -0.156 -0.1
2009.375 0.366 0.2
2009.458333 0.894 0.4
2009.541667 1.001 0.5
2009.625 0.991 0.6
2009.708333 0.805 0.7
2009.791667 1.038 1.0
2009.875 1.066 1.2
2009.958333 1.013 1.3
2010.041667 1.153 1.3
2010.125 1.524 1.1
2010.208333 1.385 0.8
2010.291667 0.894 0.5
2010.375 0.62 0
2010.458333 -0.269 -0.4
2010.541667 -1.073 -0.8
2010.625 -1.777 -1.1
2010.708333 -1.954 -1.3
2010.791667 -1.896 -1.4
2010.875 -1.588 -1.3
2010.958333 -1.574 -1.4
2011.041667 -1.677 -1.3
2011.125 -1.563 -1.1
2011.208333 -1.56 -0.8
2011.291667 -1.478 -0.6
2011.375 -0.273 -0.3
2011.458333 -0.048 -0.2
2011.541667 -0.05 -0.3
2011.625 -0.44 -0.5
2011.708333 -0.713 -0.7
2011.791667 -0.939 -0.9
2011.875 -0.965 -0.9
2011.958333 -0.976 -0.8
2012.041667 -1.045 -0.7
2012.125 -0.711 -0.6
2012.208333 -0.432 -0.5
2012.291667 0.052 -0.4
2012.375 0.739 -0.3
2012.458333 0.936 -0.1
2012.541667 1.168 0.1
2012.625 0.581 0.3
2012.708333 0.328 0.4
2012.791667 0.139 0.4
2012.875 0.176 0.2
2012.958333 0.041 -0.2
2013.041667 0.041 -0.4
2013.125 -0.173 -0.5
2013.208333 -0.181 -0.3
2013.291667 0.002 -0.2
2013.375 0.116 -0.2
2013.458333 -0.181 -0.2
2013.541667 -0.373 -0.2
2013.625 -0.528 -0.2
2013.708333 -0.095 -0.2
2013.791667 0.135 -0.2
2013.875 -0.08 -0.2
2013.958333 -0.3 -0.3
2014.041667 -0.312 -0.5
2014.125 -0.258 -0.6
2014.208333 0.012 -0.4
2014.291667 0.193 -0.2
2014.375 0.967 0
2014.458333 0.997 0
2014.541667 0.923 0
2014.625 0.938 0
2014.708333 0.602 0.2
2014.791667 0.411 0.4
2014.875 0.712 0.6
2014.958333 0.578 0.6
2015.041667 0.406 0.5
2015.125 0.468 0.4
2015.208333 0.65 0.5
2015.291667 0.953 0.7
2015.375 1.567 0.9
2015.458333 2.06 1.0
2015.541667 1.972 1.2
2015.625 2.367 1.5
2015.708333 2.527 1.7 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ENSO Index D3</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: black;
color: white;
font-family: Lucida Grande, sans-serif;
font-size: 13px ;
}
a:link {
color: cornsilk;
text-decoration: none;
}
a:visited {
color: bisque;
text-decoration: none;
}
.description
{
width: 640px;
margin: 26px 26px 8px 26px;
color: silver;
line-height: 1.6em;
}
h1, h2, h3, h4, h5
{
color: white;
}
svg {
background-color: black;
}
.axis path,
.axis line {
fill: none;
stroke: white;
shape-rendering: crispEdges;
}
.axis text {
font-family: Lucida Grande, sans-serif;
font-size: 10px;
fill: white;
}
.y.axis path {
display: none;
}
.bar.positive {
fill: crimson;
}
.bar.negative {
fill: cornflowerblue;
}
.bar.neutral {
fill: gray;
}
</style>
</head>
<body>
<div class="description">
<h1>Cold and Warm Episodes by Season</h1>
<p>Oceanic Niño Index (ONI) [3 month running mean of ERSST.v4 SST anomalies in the Niño 3.4 region (5oN-5oS, 120o-170oW)], based on centered 30-year base periods updated every 5 years. Source: <a href="http://www.cpc.ncep.noaa.gov/products/analysis_monitoring/ensostuff/ensoyears.shtml">NOAA Center for Weather and Climate Prediction.</a></p>
</div>
<script type="text/javascript">
var w = 1200;
var h = 400;
var padding = [ 20, 50, 50, 80 ]; //Top, right, bottom, left
var widthScale = d3.scale.linear()
.range([ padding[3], w - padding[1]]);
var heightScale = d3.scale.linear()
.range([ padding[0], h - padding[2] ]);
// .range([ padding[0], h - padding[0] - padding[2] ]);
var xAxis = d3.svg.axis()
.scale(widthScale)
.orient("bottom")
.outerTickSize(0)
.tickPadding([h/2 - (padding[2] - 20)])
.tickFormat(d3.format("d"));
var xAxis2 = d3.svg.axis()
.scale(widthScale)
.orient("bottom")
.outerTickSize(0);
var yAxis = d3.svg.axis()
.scale(heightScale)
.orient("left")
.ticks(10)
.outerTickSize(0)
.tickFormat(d3.format("d"));
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("enso_mei_2000.csv", function(data) {
heightScale.domain([
d3.max(data, function(d) {return +d.ENSO_Index; }),
d3.min(data, function(d) {return +d.ENSO_Index; }) ]);
widthScale.domain([ d3.min(data, function(d) {
return +d.Year;
}),
d3.max(data, function(d) {
return +d.Year;
}) ]);
console.log(d3.range(data.length));
var rects = svg.selectAll("rect")
.data(data)
.enter()
.append("rect")
rects.attr("x", function(d) {
return widthScale(+ d.Year);
})
.attr("class", function(d) {
var resultClass = "bar neutral";
if (d.ENSO_Index > 0.5) {
resultClass = "bar positive";
}
else if (d.ENSO_Index < -0.5) {
resultClass = "bar negative";
}
return resultClass;
})
.attr("width", 3)
.attr("y", function(d) {return heightScale(Math.max(0, d.ENSO_Index)); })
.attr("height", 0)
// .attr("y", function(d) { return y(Math.min(0, d.ENSO_Index)); })
// .attr("height", function(d) { return Math.abs(y(d.ENSO_Index) - y(0)); })
.append("title")
.text(function(d) {
return "Year is " + d.Year + " ENSO Index is " + d.ENSO_Index;
});
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate( 0 ," + heightScale(0) + ")")
.call(xAxis);
//Transition bar widths into place
rects.transition()
.delay(function(d, i) {
return i * 8;
})
.duration(1)
.attr("height", function(d) {
return Math.abs(heightScale(+ d.ENSO_Index) - heightScale(0));
});
// top axis
// svg.append("g")
// .attr("class", "x axis 2")
// .attr("transform", "translate(" + padding[3] + "," + (padding[0]) + ")")
// .call(xAxis2);
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (padding[3]) + ",0)")
.call(yAxis);
svg.append("text")
.attr("class", "x label")
.attr("text-anchor", "middle")
.attr("x", w/2 )
.attr("y", h - padding[2]/5)
.attr("fill", "white")
.text("Year");
svg.append("text")
.attr("class", "y label")
.attr("text-anchor", "end")
.attr("x", padding[3] - 12 )
.attr("y", padding[0] + 24 )
.attr("fill", "white")
.text("ONI");
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment