Skip to content

Instantly share code, notes, and snippets.

@iaindillingham
Last active December 21, 2017 10:59
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 iaindillingham/f8484341da2f943ef623255b2c0faffa to your computer and use it in GitHub Desktop.
Save iaindillingham/f8484341da2f943ef623255b2c0faffa to your computer and use it in GitHub Desktop.
Animated Stratigraphic Profile
license: mit
height: 600
scrolling: no
border: yes
{
"env": {
"browser": true
},
"extends": "eslint:recommended",
"globals": {
"d3": false,
"ss": false,
"topojson": false
},
"parserOptions": {
"ecmaFeatures": {
"impliedStrict": true
}
},
"rules": {
"indent": ["warn", 4],
"no-tabs": "error"
}
}

This stratigraphic profile shows the measured depth (MD) and the true vertical depth (TVD) of the rock layers (strata) at four locations.

We can't use d3.stack for this stratigraphic profile because the rock layers are not the same at each location. Instead, we derive top and bottom properties for each element in each stack.* We then create a group for each stack and, within each group, create a rectangle for each element.

*This is necessary because the data have an unusual structure. For each well, rows are in depth order. The first row is the top depth; subsequent rows are offsets from the previous row.

/* Remember: Use four-space indents.
* However, use two-space indents for operations that change the selection.
* For more information, see:
* https://bost.ocks.org/mike/d3/workshop/#35
*/
var svg = d3.select("svg"),
margin = {top: 20, right: 20, bottom: 20, left: 40},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom;
var g = svg.append("g")
.attr("transform", translate(margin.left, margin.top));
d3.csv("data.csv", row, function (error, data) {
var nest = d3.nest()
.key(function (d) { return d.well; }).sortKeys(d3.ascending)
.entries(data);
// We need to derive new data to produce the stratigraphic profile.
// We could do it in Excel.
// But if we do it here, then we have a record of what we did.
nest.forEach(function (entry) {
// Derive the top depth for each formation.
entry.values.forEach(function (value, i) {
value.MD = {};
value.TVD = {};
if (i > 0) {
value.MD.top = entry.values[i - 1].MD.top + value.md;
value.TVD.top = entry.values[i - 1].TVD.top + value.tvd;
} else {
value.MD.top = value.md;
value.TVD.top = value.tvd;
}
});
// Derive the bottom depth for each formation.
entry.values.forEach(function (value, i) {
if (i < entry.values.length - 1) {
value.MD.bottom = entry.values[i + 1].MD.top;
value.TVD.bottom = entry.values[i + 1].TVD.top;
}
});
// Pop (delete) the last formation because it won't have a bottom depth.
entry.values.pop();
});
// Create option elements as children of the select element.
d3.select("select")
.on("change", update)
.selectAll("option")
.data(["MD", "TVD"])
.enter().append("option")
.text(function (d) { return d; });
var x = d3.scaleBand()
.domain(nest.map(function (d) { return d.key; }))
.range([0, width])
.padding(0.5);
var y = d3.scaleLinear()
.domain([-1800, 100])
.range([height, 0]);
// Create a group for all stacks.
g.append("g")
.attr("class", "stacks");
// Create a group for the x axis.
g.append("g")
.attr("class", "x axis")
.attr("transform", translate(0, height))
.call(d3.axisBottom(x));
// Create a group for the y axis.
g.append("g")
.attr("class", "y axis")
.call(d3.axisLeft(y));
update();
function update() {
var depth = this.value ? this.value : "MD";
// Create a group for each stack.
var stack = d3.select(".stacks")
.selectAll(".stack")
.data(nest);
stack = stack.enter().append("g")
.attr("class", "stack")
.attr("transform", function (d) { return translate(x(d.key), 0); })
.merge(stack);
// Create a rectangle for each element.
var element = stack.selectAll(".element")
.data(function (d) { return d.values; });
element = element.enter().append("rect")
.attr("class", "element")
.attr("x", 0)
.attr("y", function (d) { return y(d[depth].top); })
.attr("width", x.bandwidth())
.attr("height", function (d) { return Math.abs(y(d[depth].top) - y(d[depth].bottom)); })
.merge(element).transition()
.duration(1000)
.attr("y", function (d) { return y(d[depth].top); })
.attr("height", function (d) { return Math.abs(y(d[depth].top) - y(d[depth].bottom)); });
}
});
function translate(x, y) {
return "translate(" + x + "," + y + ")";
}
function row(d) {
d.md = +d.md;
d.tvd = +d.tvd;
return d;
}
well formation md tvd
AUPAMPARI-01 Rolling Downs Group - Manuka Subgroup - Winton Formation 31.1 21.1
AUPAMPARI-01 Rolling Downs Group - Manuka Subgroup - Winton Formation -478.2 -488.2
AUPAMPARI-01 Rolling Downs Group - Manuka Subgroup - Mackunda Formation -68 -78
AUPAMPARI-01 Rolling Downs Group - Marree Subgroup - Oodnadatta Formation -271.3 -281.3
AUPAMPARI-01 Rolling Downs Group - Marree Subgroup - Coorikiana Sandstone Formation -20.7 -30.7
AUPAMPARI-01 Bulldog Formation -217.9 -227.9
AUPAMPARI-01 Cadna-Owie Formation -56.1 -66.1
AUPAMPARI-01 Murta Formation -43.6 -53.6
AUPAMPARI-01 Murta Formation - McKinlay Member -17.4 -27.4
AUPAMPARI-01 Namur Sandstone Formation -215.5 -225.5
AUPAMPARI-01 Injune Creek Group - Birkhead Formation -8.2 -18.2
AUPAMPARI-01 Bundamba Group - Hutton Sandstone Formation -70.4 -80.4
AUPAMPARI-01 Dullingari Group - Lycosa Formation -28.4 -38.4
AUMYPONGA-01 Missing -546 -556
AUMYPONGA-01 Rolling Downs Group - Manuka Subgroup - Mackunda Formation -84 -94
AUMYPONGA-01 Rolling Downs Group - Marree Subgroup - Oodnadatta Formation -194.5 -204.5
AUMYPONGA-01 Rolling Downs Group - Marree Subgroup - Coorikiana Sandstone Formation -10.5 -20.5
AUMYPONGA-01 Bulldog Formation -210 -220
AUMYPONGA-01 Cadna-Owie Formation -55 -65
AUMYPONGA-01 Murta Formation -44 -54
AUMYPONGA-01 Murta Formation - McKinlay Member -15 -25
AUMYPONGA-01 Namur Sandstone Formation -195.5 -205.5
AUMYPONGA-01 Injune Creek Group - Birkhead Formation -14.5 -24.5
AUMYPONGA-01 Bundamba Group - Hutton Sandstone Formation -57 -67
AUMYPONGA-01 Basement -14 -24
AUZOGG-01 Missing -1103.9 -1113.9
AUZOGG-01 Cadna-Owie Formation -53.1 -63.1
AUZOGG-01 Murta Formation -43.2 -53.2
AUZOGG-01 Murta Formation - McKinlay Member -5.5 -15.5
AUZOGG-01 Namur Sandstone Formation -213.9 -223.9
AUZOGG-01 Injune Creek Group - Birkhead Formation -21.3 -31.3
AUZOGG-01 Bundamba Group - Hutton Sandstone Formation -57.6 -67.6
AUOGG-01 Rolling Downs Group - Manuka Subgroup - Winton Formation 30.1 20.1
AUOGG-01 Rolling Downs Group - Manuka Subgroup - Winton Formation -886.2 -896.2
AUOGG-01 Rolling Downs Group - Marree Subgroup - Coorikiana Sandstone Formation -6.7 -16.7
AUOGG-01 Bulldog Formation -217.6 -227.6
AUOGG-01 Cadna-Owie Formation -58 -68
AUOGG-01 Murta Formation -46 -56
AUOGG-01 Murta Formation - McKinlay Member -10.3 -20.3
AUOGG-01 Namur Sandstone Formation -185.7 -195.7
AUOGG-01 Injune Creek Group - Birkhead Formation -26.5 -36.5
AUOGG-01 Bundamba Group - Hutton Sandstone Formation -60 -70
AUOGG-01 Poolowanna Formation -59.4 -69.4
AUOGG-01 Gidgealpa Group - Patchawarra Formation -137.4 -147.4
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.element {
fill: lightgrey;
stroke: grey;
shape-rendering: crispEdges;
}
</style>
<svg width="960" height="500"></svg>
<select></select>
<script src="https://unpkg.com/d3@4/build/d3.min.js"></script>
<script src="block.js"></script>
MIT License
Copyright (c) 2017 Iain Dillingham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment