Skip to content

Commit

Permalink
Measured depth linear interpolation (equinor#401)
Browse files Browse the repository at this point in the history
* Added measured depth values to well trajectory example data.

* Added mathjs dependency.

Co-authored-by: Havard Bjerke <[email protected]>
  • Loading branch information
hkfb and Havard Bjerke authored Jun 23, 2021
1 parent 31693a0 commit 83dc678
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"leaflet": "^1.6.0",
"leaflet-draw": "^1.0.4",
"lodash": "^4.17.21",
"mathjs": "^9.4.2",
"nebula.gl": "^0.22.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
56 changes: 55 additions & 1 deletion src/lib/components/DeckGLMap/layers/wells/wellsLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { CompositeLayer } from "@deck.gl/core";
import { CompositeLayerProps } from "@deck.gl/core/lib/composite-layer";
import { GeoJsonLayer, PathLayer } from "@deck.gl/layers";
import { RGBAColor } from "@deck.gl/core/utils/color";
import { PickInfo } from "@deck.gl/core/lib/deck";
import { PickInfo } from "deck.gl";
import { subtract, distance, dot } from "mathjs";
import { interpolateRgbBasis } from "d3-interpolate";
import { color } from "d3-color";

Expand Down Expand Up @@ -103,6 +104,48 @@ function squared_distance(a, b): number {
return dx * dx + dy * dy;
}

function getMd(pickInfo): number | null {
if (!pickInfo.object.properties || !pickInfo.object.geometry) return null;

const measured_depths = pickInfo.object.properties.md[0];
const trajectory = pickInfo.object.geometry.geometries[1].coordinates;

// Get squared distance from survey point to picked point.
const d2 = trajectory.map((element) =>
squared_distance(element, pickInfo.coordinate)
);

// Enumerate squared distances.
let index: number[] = Array.from(d2.entries());

// Sort by squared distance.
index = index.sort((a: number, b: number) => a[1] - b[1]);

// Get the nearest indexes.
const index0 = index[0][0];
const index1 = index[1][0];

// Get the nearest MD values.
const md0 = measured_depths[index0];
const md1 = measured_depths[index1];

// Get the nearest survey points.
const survey0 = trajectory[index0];
const survey1 = trajectory[index1];

const dv = distance(survey0, survey1) as number;

// Calculate the scalar projection onto segment.
const v0 = subtract(pickInfo.coordinate, survey0);
const v1 = subtract(survey1, survey0);
const scalar_projection: number = dot(v0 as number[], v1 as number[]) / dv;

// Interpolate MD value.
const c0 = scalar_projection / dv;
const c1 = dv - c0;
return (md0 * c1 + md1 * c0) / dv;
}

export interface WellsPickInfo extends PickInfo<unknown> {
logName?: string;
propertyValue?: number;
Expand Down Expand Up @@ -207,6 +250,17 @@ export default class WellsLayer extends CompositeLayer<
}: {
info: PickInfo<unknown>;
}): WellsPickInfo | PickInfo<unknown> {
if (!info.object) return info;

// Return MD if a trajectory has been picked.
const measured_depth = getMd(info);
if (measured_depth != null) {
return {
...info,
propertyValue: measured_depth,
};
}

if (!info.object || !(info.object as LogCurveDataType)?.data)
return info;

Expand Down

0 comments on commit 83dc678

Please sign in to comment.