Skip to content

Instantly share code, notes, and snippets.

@poezn
Created March 22, 2014 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poezn/9699810 to your computer and use it in GitHub Desktop.
Save poezn/9699810 to your computer and use it in GitHub Desktop.
Precipitation CA 1895-2014
{"description":"Precipitation CA 1895-2014","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data.tsv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"styles.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"index.html":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/ZRsFcGS.png"}
state region type year m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11
004 0 01 1895 9.25 2.56 2.52 1.25 1.41 0.04 0.14 0.16 0.92 0.49 1.61 2.53
004 0 01 1896 8.02 0.60 3.87 4.28 1.93 0.08 0.29 0.56 0.47 1.50 4.18 3.73
004 0 01 1897 3.12 5.89 4.46 0.62 0.35 0.58 0.11 0.24 0.39 1.94 1.83 2.42
004 0 01 1898 1.34 3.06 0.94 0.52 1.73 0.48 0.10 0.17 0.63 0.70 1.41 1.39
004 0 01 1899 4.77 0.81 5.45 0.71 0.99 0.49 0.06 0.22 0.13 3.46 4.15 3.57
004 0 01 1900 2.82 1.33 2.27 2.11 1.53 0.32 0.21 0.08 0.27 2.51 4.82 1.78
004 0 01 1901 5.33 5.36 1.14 2.29 1.11 0.04 0.02 0.32 1.09 1.50 2.57 1.67
004 0 01 1902 1.29 7.89 3.20 2.11 0.94 0.08 0.19 0.12 0.05 1.75 3.97 3.23
004 0 01 1903 4.84 1.71 5.23 1.06 0.29 0.21 0.04 0.09 0.24 0.50 5.02 1.50
004 0 01 1904 1.84 7.93 6.86 2.23 0.34 0.09 0.24 0.41 1.41 2.30 1.28 3.30
004 0 01 1905 3.96 3.87 5.31 0.95 1.84 0.13 0.02 0.16 0.29 0.18 2.17 1.48
004 0 01 1906 6.53 4.09 7.79 1.74 2.67 0.77 0.13 0.32 0.27 0.11 1.83 7.24
004 0 01 1907 6.50 3.66 8.72 1.11 0.71 0.91 0.05 0.20 0.16 1.70 0.38 4.72
004 0 01 1908 3.89 3.85 1.04 0.61 1.36 0.19 0.11 0.31 0.72 1.27 1.69 1.94
004 0 01 1909 12.32 6.39 2.86 0.12 0.23 0.21 0.12 0.50 0.56 1.40 4.22 5.53
004 0 01 1910 3.76 2.02 2.47 0.54 0.22 0.07 0.25 0.05 0.61 0.79 2.23 1.78
004 0 01 1911 10.14 3.00 5.05 1.64 0.60 0.18 0.25 0.02 0.44 0.51 0.78 1.81
004 0 01 1912 2.67 0.83 4.49 2.83 1.50 0.49 0.19 0.16 1.04 1.01 2.31 1.43
004 0 01 1913 4.05 1.85 1.60 1.30 1.00 0.79 0.67 0.51 0.15 0.10 4.15 5.44
004 0 01 1914 10.61 4.15 0.92 1.98 0.60 0.70 0.14 0.03 0.33 1.41 0.69 4.00
004 0 01 1915 6.00 7.96 1.89 1.73 2.77 0.02 0.16 0.16 0.09 0.14 1.65 4.39
004 0 01 1916 11.01 2.83 2.53 0.55 0.61 0.24 0.32 0.31 0.50 1.54 1.39 4.29
004 0 01 1917 2.51 4.58 1.37 1.52 0.83 0.02 0.22 0.22 0.19 0.01 1.56 1.19
004 0 01 1918 1.06 5.20 5.33 0.61 0.35 0.12 0.24 0.27 1.55 1.00 2.51 2.09
004 0 01 1919 2.37 6.02 3.05 0.88 0.39 0.02 0.22 0.08 1.01 0.50 0.82 3.28
004 0 01 1920 0.91 2.30 4.49 2.04 0.21 0.51 0.13 0.47 0.37 2.08 4.51 4.92
004 0 01 1921 5.60 1.98 2.22 0.49 1.67 0.19 0.12 0.27 0.43 0.88 1.45 6.58
004 0 01 1922 2.89 5.55 3.00 0.63 1.05 0.34 0.25 0.35 0.11 1.48 2.68 5.96
004 0 01 1923 2.80 0.92 0.34 3.41 0.44 0.66 0.16 0.21 1.25 0.98 0.87 1.57
004 0 01 1924 1.60 1.54 2.19 0.75 0.07 0.05 0.03 0.15 0.14 2.92 2.10 3.72
004 0 01 1925 1.38 5.34 2.33 2.82 1.59 0.54 0.25 0.35 0.70 1.04 1.74 1.70
004 0 01 1926 3.03 4.83 0.40 3.88 0.63 0.09 0.08 0.21 0.11 1.24 6.99 2.67
004 0 01 1927 3.15 7.61 2.37 1.98 0.62 0.37 0.18 0.10 0.19 1.83 3.65 2.91
004 0 01 1928 1.71 2.23 4.50 1.50 0.56 0.12 0.02 0.02 0.10 0.45 2.78 3.24
004 0 01 1929 1.57 1.83 1.84 1.82 0.12 1.06 0.03 0.24 0.28 0.17 0.00 4.38
004 0 01 1930 4.59 2.87 2.68 1.51 1.20 0.05 0.04 0.14 0.63 0.42 2.01 0.55
004 0 01 1931 3.58 2.47 1.45 1.25 0.96 0.78 0.04 0.57 0.26 1.28 2.68 7.65
004 0 01 1932 2.80 3.49 1.09 1.49 1.20 0.22 0.07 0.05 0.19 0.43 1.06 2.70
004 0 01 1933 5.69 0.79 2.54 0.58 1.62 0.21 0.08 0.12 0.14 1.43 0.11 5.39
004 0 01 1934 1.91 3.01 0.96 0.60 0.84 0.68 0.11 0.24 0.33 1.99 3.79 2.97
004 0 01 1935 4.89 2.62 3.31 4.31 0.30 0.02 0.16 0.35 0.25 1.21 1.05 2.69
004 0 01 1936 4.83 8.04 1.51 1.38 0.69 0.83 0.41 0.24 0.18 1.17 0.14 4.53
004 0 01 1937 3.40 6.20 4.86 1.49 0.30 0.75 0.18 0.01 0.09 1.17 4.09 5.26
004 0 01 1938 3.46 8.36 8.01 1.85 0.46 0.23 0.25 0.11 0.46 1.51 1.24 2.73
004 0 01 1939 3.07 1.97 2.65 0.55 1.03 0.13 0.18 0.18 1.11 0.99 0.46 3.01
004 0 01 1940 7.05 7.77 3.74 1.24 0.68 0.13 0.01 0.02 0.64 1.74 1.24 8.41
004 0 01 1941 5.78 6.79 4.52 3.82 1.27 0.45 0.15 0.50 0.20 1.55 1.91 7.92
004 0 01 1942 3.64 3.58 1.62 3.57 1.86 0.10 0.04 0.28 0.08 0.53 3.55 3.62
004 0 01 1943 7.74 2.33 4.14 2.08 0.43 0.54 0.08 0.08 0.16 1.26 0.96 2.98
004 0 01 1944 2.87 5.35 1.74 1.90 0.74 0.63 0.12 0.03 0.10 1.10 5.09 2.63
004 0 01 1945 1.19 5.04 3.91 0.59 1.49 0.40 0.14 0.53 0.17 2.93 3.12 6.87
004 0 01 1946 1.50 2.11 2.77 0.33 0.59 0.06 0.46 0.12 0.24 1.02 4.55 2.77
004 0 01 1947 0.96 1.80 2.99 0.76 0.48 0.76 0.09 0.23 0.11 2.75 0.80 1.44
004 0 01 1948 2.04 1.99 3.48 4.38 1.31 0.66 0.17 0.08 0.40 0.88 1.11 3.72
004 0 01 1949 2.09 2.76 4.49 0.21 1.33 0.09 0.07 0.15 0.11 0.30 1.72 1.90
004 0 01 1950 5.39 2.71 2.85 1.34 0.63 0.34 0.24 0.07 0.51 3.41 4.24 4.21
004 0 01 1951 4.09 2.54 1.17 1.60 1.02 0.07 0.15 0.35 0.15 1.85 3.37 7.23
004 0 01 1952 7.44 2.58 4.78 1.50 0.46 0.68 0.40 0.05 0.45 0.12 2.29 7.22
004 0 01 1953 4.52 0.55 2.32 2.23 1.63 0.61 0.10 0.31 0.04 0.79 2.94 1.15
004 0 01 1954 5.93 3.02 4.13 1.67 0.13 0.68 0.24 0.27 0.22 0.29 2.75 3.67
004 0 01 1955 3.61 1.50 0.70 2.42 0.67 0.10 0.26 0.35 0.35 0.38 2.69 10.68
004 0 01 1956 6.96 3.17 0.41 1.83 1.42 0.20 0.30 0.03 0.25 2.30 0.11 0.87
004 0 01 1957 3.92 3.64 3.00 1.71 2.52 0.14 0.10 0.12 0.90 2.76 1.73 4.01
004 0 01 1958 4.34 8.22 5.74 3.96 0.85 0.87 0.32 0.38 0.57 0.39 0.96 1.16
004 0 01 1959 4.66 5.05 0.86 0.55 0.45 0.05 0.08 0.22 1.23 0.21 0.14 1.71
004 0 01 1960 3.68 5.14 2.84 1.42 1.05 0.02 0.14 0.02 0.26 0.55 4.52 2.13
004 0 01 1961 2.09 2.17 3.04 0.97 0.98 0.24 0.08 0.59 0.27 0.63 2.99 2.48
004 0 01 1962 2.03 7.92 2.75 0.47 0.74 0.11 0.11 0.25 0.30 3.94 1.29 2.19
004 0 01 1963 2.89 3.89 3.51 4.39 1.11 0.46 0.02 0.30 0.89 1.99 4.59 0.70
004 0 01 1964 3.58 0.31 2.00 0.74 1.03 0.63 0.17 0.14 0.14 1.07 3.99 8.47
004 0 01 1965 3.83 0.78 1.46 3.94 0.19 0.32 0.28 0.65 0.16 0.17 6.17 4.03
004 0 01 1966 3.05 1.89 1.28 0.71 0.27 0.12 0.17 0.15 0.32 0.21 4.81 5.74
004 0 01 1967 6.12 0.40 4.23 4.44 0.59 0.66 0.20 0.33 0.59 0.74 2.63 2.82
004 0 01 1968 3.71 2.72 2.41 0.52 0.63 0.21 0.36 0.53 0.07 1.41 2.67 5.13
004 0 01 1969 10.80 7.33 1.39 1.74 0.34 0.60 0.24 0.05 0.26 1.33 1.34 5.18
004 0 01 1970 8.16 2.16 2.44 0.68 0.22 0.59 0.13 0.19 0.04 0.97 6.56 5.67
004 0 01 1971 2.39 0.72 3.26 1.18 1.53 0.41 0.15 0.32 0.56 0.51 2.20 5.01
004 0 01 1972 1.84 1.98 1.16 1.41 0.46 0.40 0.03 0.19 0.75 1.79 4.23 2.97
004 0 01 1973 6.05 5.35 3.34 0.41 0.41 0.06 0.06 0.17 0.53 1.91 6.58 4.06
004 0 01 1974 5.67 1.66 5.40 1.77 0.17 0.13 0.40 0.19 0.01 1.55 1.03 3.37
004 0 01 1975 1.58 5.41 5.76 2.08 0.24 0.20 0.17 0.33 0.34 2.61 1.19 1.03
004 0 01 1976 0.45 3.89 1.40 1.49 0.25 0.15 0.34 0.55 1.31 0.51 0.86 0.55
004 0 01 1977 1.98 1.16 1.64 0.23 1.88 0.35 0.08 0.75 0.87 0.50 2.18 5.91
004 0 01 1978 7.97 5.77 5.75 3.48 0.38 0.17 0.12 0.22 1.31 0.20 1.96 1.53
004 0 01 1979 5.05 4.86 3.44 1.12 0.84 0.05 0.38 0.45 0.24 2.51 2.55 3.14
004 0 01 1980 6.63 7.51 2.81 1.68 0.88 0.33 0.20 0.04 0.22 0.57 0.63 2.62
004 0 01 1981 4.39 2.08 4.04 0.97 0.90 0.09 0.04 0.10 0.58 2.44 5.99 4.62
004 0 01 1982 4.24 2.95 5.78 3.64 0.22 0.68 0.23 0.36 1.26 2.66 5.05 4.92
004 0 01 1983 5.93 6.80 9.02 3.12 0.53 0.23 0.10 1.14 0.91 1.18 6.55 6.95
004 0 01 1984 0.33 2.20 1.67 1.21 0.39 0.43 0.59 0.61 0.27 1.61 6.14 2.87
004 0 01 1985 0.81 1.85 2.88 0.24 0.20 0.21 0.28 0.07 1.08 1.15 3.84 2.09
004 0 01 1986 3.80 9.33 4.70 1.00 0.70 0.08 0.22 0.12 1.40 0.64 0.77 1.49
004 0 01 1987 3.07 2.79 3.59 0.40 0.63 0.20 0.25 0.04 0.10 1.33 2.27 5.04
004 0 01 1988 3.84 0.80 0.59 2.42 0.91 0.57 0.09 0.41 0.11 0.10 4.20 3.06
004 0 01 1989 1.59 1.57 5.10 0.83 0.77 0.31 0.04 0.29 1.33 1.95 1.05 0.12
004 0 01 1990 3.72 2.36 1.30 0.83 2.46 0.18 0.28 0.36 0.41 0.47 0.71 0.91
004 0 01 1991 1.00 2.24 9.11 0.75 0.82 0.32 0.26 0.20 0.24 1.28 1.07 2.50
004 0 01 1992 1.94 5.98 3.65 1.03 0.23 0.71 0.24 0.20 0.05 2.13 0.59 6.48
004 0 01 1993 8.86 5.98 3.05 1.45 1.44 0.87 0.03 0.22 0.04 0.82 1.42 2.52
004 0 01 1994 1.91 3.96 1.24 1.36 1.35 0.10 0.05 0.06 0.34 0.63 3.73 2.81
004 0 01 1995 12.50 1.27 9.57 2.69 1.73 0.95 0.17 0.06 0.07 0.05 0.36 5.78
004 0 01 1996 5.12 5.99 2.57 2.10 2.01 0.18 0.20 0.06 0.27 1.70 3.35 8.96
004 0 01 1997 7.62 0.71 0.84 0.89 0.38 0.65 0.31 0.27 0.94 1.08 3.95 2.96
004 0 01 1998 6.97 11.50 4.15 2.17 3.03 0.77 0.20 0.13 0.74 0.76 4.34 1.65
004 0 01 1999 3.54 4.98 2.40 1.87 0.33 0.25 0.31 0.21 0.18 0.71 2.20 0.65
004 0 01 2000 5.09 6.93 1.92 1.80 0.94 0.31 0.06 0.27 0.35 2.20 0.79 0.77
004 0 01 2001 3.52 4.42 2.21 1.75 0.15 0.23 0.28 0.05 0.30 0.65 4.21 5.25
004 0 01 2002 2.22 1.45 1.91 0.88 0.59 0.07 0.06 0.01 0.11 0.06 3.18 8.14
004 0 01 2003 1.92 2.66 2.77 3.98 1.09 0.04 0.22 0.57 0.17 0.09 2.35 5.77
004 0 01 2004 2.27 5.88 1.08 0.70 0.45 0.08 0.06 0.19 0.14 3.72 1.68 5.51
004 0 01 2005 5.56 4.03 3.69 1.79 2.54 0.67 0.14 0.29 0.32 1.00 2.26 7.81
004 0 01 2006 4.54 2.69 5.41 4.16 0.73 0.15 0.15 0.06 0.06 0.45 2.08 3.13
004 0 01 2007 0.81 4.24 0.74 1.27 0.32 0.12 0.18 0.12 0.50 1.51 0.82 3.21
004 0 01 2008 7.11 2.76 0.61 0.34 0.54 0.03 0.14 0.12 0.04 0.70 2.41 3.05
004 0 01 2009 1.27 4.64 2.26 0.57 1.24 0.60 0.05 0.12 0.09 2.07 0.99 3.15
004 0 01 2010 6.48 3.65 2.19 3.47 1.07 0.26 0.07 0.10 0.16 3.00 2.60 8.13
004 0 01 2011 1.28 3.34 6.41 1.10 1.44 0.92 0.22 0.10 0.28 1.54 1.69 0.47
004 0 01 2012 3.12 1.22 4.74 2.48 0.20 0.32 0.26 0.30 0.10 0.99 3.57 6.15
004 0 01 2013 1.18 0.58 1.33 0.71 0.62 0.38 0.28 0.38 0.77 0.26 0.99 0.44
004 0 01 2014 0.60 3.43 -9.99 -9.99 -9.99 -9.99 -9.99 -9.99 -9.99 -9.99 -9.99 -9.99
<img src="https://pbs.twimg.com/media/Bit0VzRCYAABuUc.png" style="position: absolute; left: 650px; top: 20px"/>
var rawData = tb.data;
var values = _.chain(rawData)
.map(function(d, i) {
return _.map(d3.range(0, 12), function(ind) {
var val = +d["m" + ind];
return {
data: val >= 0 ? +d["m" + ind] : null,
year: +d.year,
month: ind
}
})
})
.flatten()
.value();
values = values.slice(6);
var startYear = 1895;
var data = d3.range(startYear, new Date().getFullYear())
.map(function(d, i) {
return {
year: +d,
data: _.filter(values.slice(i*12, (i+1)*12), function(d) { return !_.isNull(d.data)})
}
});
//console.log(data)
var aggregates = _.map(data, function(d, i) {
return {
year: d.year,
data: _.map(d.data, function(val, i) {
return d3.sum(d.data.slice(0, i+1), function(d, i) { return d.data });
}),
sum: d3.sum(d.data, function(d, i) { return d.data }),
numMonths: d.data.length
}
});
var extremes = _.chain(aggregates)
.filter(function(d, i) { return d.numMonths == 12 })
.sortBy(function(d, i) { return d.sum })
.value();
//console.log(extremes)
var driest = extremes[0];
var wettest = extremes[extremes.length - 1];
var recent = aggregates[aggregates.length - 1];
var averageValues = d3.range(0, 12).map(function(d, month) {
var vals = _.chain(data)
.map(function(d, i) { return d.data[month] ? d.data[month].data : null })
.value();
return d3.mean(vals);
});
var averageYear = _.map(averageValues, function(val, i) {
return d3.sum(averageValues.slice(0, i));
});
console.log(recent)
//console.log(wettest, driest)
var w = 486,
h = 370;
var g = g.append("g")
.attr("transform", "translate(50, 50)")
var xScale = d3.scale.linear()
.domain([0, 11])
.range([0, w]);
var yScale = d3.scale.linear()
.domain([0, d3.max(aggregates, function(d, i) { return d.data[d.data.length - 1]; })])
.range([h, 0]);
var line = d3.svg.line()
.x(function(d) { return xScale(d.x); })
.y(function(d, i) { return yScale(d.y); });
var years = g.selectAll("g")
.data(aggregates);
years.enter().append("g");
years.append("path")
.datum(function(d, i) {
return _.map(d.data, function(precip, i) {
return {
x: i,
y: precip
}
})
})
.attr({
"class": "year",
"d": function(d, i) {
return line(d);
}
});
years
.on("mouseover", function(d, i) {
g.selectAll("text.year")
.style("opacity", function(t, i) {
return t.year == d.year ? 1 : 0
})
})
.on("mouseout", function(d, i) {
g.selectAll("text.year")
.style("opacity", 0)
})
;
g.append("path")
.datum(_.map(driest.data, function(precip, i) {
return {
x: i,
y: precip
}
})
)
.attr({
"class": "driest",
"d": function(d, i) {
return line(d);
}
});
g.append("path")
.datum(_.map(wettest.data, function(precip, i) {
return {
x: i,
y: precip
}
})
)
.attr({
"class": "wettest",
"d": function(d, i) {
return line(d);
}
});
g.append("path")
.datum(_.map(driest.data, function(precip, i) {
return {
x: i,
y: precip
}
})
)
.attr({
"class": "driest",
"d": function(d, i) {
return line(d);
}
});
g.append("path")
.datum(_.map(recent.data, function(precip, i) {
return {
x: i,
y: precip
}
})
)
.attr({
"class": "recent",
"d": function(d, i) {
return line(d);
}
});
g.append("path")
.datum(_.map(averageYear, function(precip, i) {
return {
x: i,
y: precip
}
})
)
.attr({
"class": "average",
"d": function(d, i) {
return line(d);
}
});
years.append("text")
.datum(function(d, i) {
return d;
})
.attr({
"x": w + 10,
"y": function(d, i) {
return yScale(d.data[d.data.length - 1]) + 7;
},
"opacity": function(d, i) {
return d == recent || d == wettest || d == driest ? 1 : 0
},
"class": function(d, i) {
return d == recent ? "recent" :
d == wettest ? "wettest" :
d == driest ? "driest" : "year"
}
})
.text(function(d, i) { return d.year + "/" + (d.year+1) });
g.append("text")
.datum(averageYear)
.attr({
"x": w + 10,
"y": function(d, i) {
return yScale(d[d.length - 1]) + 7;
},
"class": "average"
})
.text("Average");
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left");
g.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + h + ")")
.call(xAxis)
g.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Precipitation (in)");
var months = ["Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun"];
g.selectAll(".axis.x text")
.text(function(d, i) {
return months[d]
})
path {
stroke: #000;
opacity: 0.1;
fill: none;
}
path.average, path.driest, path.wettest, path.recent {
stroke-width: 2;
opacity: 1;
fill: none;
}
path.average {
stroke: #000000;
}
path.driest {
stroke: #ff0000;
}
path.wettest {
stroke: #0000FF;
}
path.recent {
stroke: #70319F;
}
path.year:hover {
stroke-width: 5;
opacity: 0.5
}
text.average {
fill: #000000;
}
text.driest {
fill: #ff0000;
}
text.wettest {
fill: #0000FF;
}
text.recent {
fill: #70319F;
}
.axis text {
font-size: 12px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment