Skip to content

Add Log10 display transform mode and WebGL-safe NaN handling #161

@eeholmes

Description

@eeholmes

Background

For many of my datasets the data are highly skewed and strictly positive. It is helpful to allow data transforms for display. This was fairly easy to implement but surfaced an issue with fragile NaN generation in the current code.

Two related issues came up in visualization:

  1. Some environmental variables are much easier to interpret on a logarithmic scale than a linear scale.
  2. Shader code that generates NaN via expressions like sqrt(-1.0) can be driver-dependent and unreliable (black globe while the histogram showed values)

Shader safety

Replaced sqrt(-1.0)-style NaN generation with a helper based on uintBitsToFloat(0x7FC00000u).

Example code sketch

function applyDisplayTransformToData(data: Float32Array, mode: "linear" | "log10") {
  if (mode === "linear") return data;
  for (let i = 0; i < data.length; i++) {
    const v = data[i];
    data[i] = Number.isFinite(v) && v > 0 ? Math.log10(v) : Number.NaN;
  }
  return data;
}
float makeNaN() {
  return uintBitsToFloat(0x7FC00000u);
}

How this was solved in my fork

In my fork, I:

  • added linear and log10 transform modes to shared types/store state,
  • added a transform control in the colormap UI,
  • applied the transform across all grid renderers before computing final bounds/histograms,
  • normalized HEALPix missing/fill handling so transforms do not mis-handle sentinel values,
  • replaced shader NaN generation with a quiet-NaN helper.

Related PR

  • Fork PR: https://github.com/eeholmes/gridlook/pull/23

Untransformed

Image

Transformed

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions