Last updated

Read Trace Headers

This tutorial demonstrates how trace headers can be retrieved from the reader. The logic is based on MemoryReader, but can be used with any other reader.

# Create a Reader

In this example, the memory reader is used. It has several callbacks to provide trace samples "getTraceData", trace headers "getTraceHeader", trace headers fields "getTraceHeaderFields" with information about available headers, and data statistics. The code below creates memory reader and fills traces and headers by request.

# Read trace headers

The code below gets values for the first traces and displays them in the a table trace by trace as rows. First, the method select of the reader is called. It returns traces as a parameter of callback. Second, in the loop retrieves each trace with method getTrace and requests trace headers values using method getHeader of the trace.

import { Group } from "@int/geotoolkit/scene/Group.ts";
import { CssLayout } from "@int/geotoolkit/layout/CssLayout.ts";
import { DataSheet } from "@int/geotoolkit/widgets/datasheet/DataSheet.ts";
import { MemoryReader } from "@int/geotoolkit/seismic/data/MemoryReader.ts";
import { FieldDesc } from "@int/geotoolkit/seismic/data/FieldDesc.ts";
import { Plot } from "@int/geotoolkit/plot/Plot.ts";
import { DataTable } from "@int/geotoolkit/data/DataTable.ts";
const createReader = () => {
  const sampleRate = 1;
  const sampleCount = 600;
  const traceCount = 500;
  const inlineMin = 1;
  const xlineMin = 1;
  const inlineCount = 50;
  const xlineCount = 10;
  return new MemoryReader({
    "numberoftraces": traceCount,
    "numberofsamples": sampleCount,
    "samplerate": sampleRate
  }).setTraceProcessor({
    "getTraceData": function(reader, samples, traceId) {
      for (let i = 0; i < sampleCount; i++) {
        samples[i] = Math.sin((i / 10 + traceId / 4) * Math.PI);
      }
    },
    "getTraceHeaderFields": function() {
      return [
        new FieldDesc(0, "TraceNumber"),
        new FieldDesc(1, "INLINE"),
        new FieldDesc(2, "XLINE")
      ];
    },
    "getTraceHeader": function(reader, header, headerData, traceId) {
      headerData[0] = traceId;
      headerData[1] = inlineMin + Math.round(traceId / xlineCount) * xlineCount;
      headerData[2] = xlineMin + traceId % inlineCount;
    },
    "getDataStatistics": function() {
      return {
        "average": 0,
        "min": -1,
        "max": 1,
        "rms": Math.sqrt(2) / 2
      };
    }
  });
};
function createScene(canvas) {
  const rootContainer = new Group().setAutoModelLimitsMode(true).setLayout(new CssLayout());
  const plot = new Plot({
    "canvaselement": canvas,
    "root": rootContainer
  });
  const reader = createReader();
  reader.select({
    "from": 0,
    "to": 9
  }, (result) => {
    const traceFields = reader.getTraceHeaderFields();
    const headerInlineIndex = traceFields.findIndex((item) => item.getName() === "INLINE");
    const headerXlineIndex = traceFields.findIndex((item) => item.getName() === "XLINE");
    const datatable = new DataTable({
      cols: [
        { name: "Trace", type: "number" },
        { name: "Inline", type: "number" },
        { name: "Xline", type: "number" }
      ]
    });
    for (let i = 0; i < 10; i++) {
      const trace = result.getTrace(i);
      const inline = trace.getHeader(headerInlineIndex);
      const xline = trace.getHeader(headerXlineIndex);
      datatable.addRow([i + 1, inline, xline]);
    }
    const dataSheet = new DataSheet({
      "header": {
        "headerdata": ["Trace", "INLINE", "XLINE"]
      },
      "data": datatable,
      "mincolumnwidth": 100,
      "indexvisible": false,
      "horizontalscroll": false,
      "verticalscroll": false
    });
    dataSheet.getToolByName("TableViewSplitter").setEnabled(false);
    rootContainer.addChild([
      dataSheet.setLayoutStyle({
        "top": 0,
        "bottom": 0,
        "left": 0,
        "right": 0
      })
    ]);
  });
  return plot;
}
export { createScene };

createScene(document.querySelector('[ref="plot"]'));