Import
import { openGsf, renderScientificPlane } from 'purejsimage/scientific'Minimal Node.js example
import { FileSource } from 'purejsimage'
import { openGsf, renderScientificPlane } from 'purejsimage/scientific'
const dataset = await openGsf(await FileSource.open('surface.gsf'))
const display = await renderScientificPlane(dataset, {
plane: { z: 0, c: 0, t: 0 },
range: { mode: 'dataset' },
palette: 'viridis',
relief: { azimuth: 315, elevation: 45, strength: 0.5 },
})
for await (const pixels of display.pixels) console.log(pixels.data)Minimal browser example
import { openGsf } from 'purejsimage/scientific'
const input = document.querySelector<HTMLInputElement>('#surface')
const file = input?.files?.[0]
if (!file) throw new Error('Choose a GSF file')
const dataset = await openGsf(file, { maxInputBytes: file.size })
for await (const block of dataset.readPlane({ z: 0, c: 0, t: 0 })) {
console.log(block.format.sampleType) // float32
}Supported features
| Feature | Support |
|---|---|
| Gwyddion Simple Field 1.0 | Read and write |
| Samples | Little-endian float32 |
| Physical metadata | X/Y extent, offsets, units, title |
| Unknown header fields | Retained |
| Regions | Bounded row reads |
Dataset mapping
XRes maps to X and YRes maps to Y. Z, C, and T are 1. XReal / XRes and YReal / YRes become physical pixel sizes. ZUnits becomes the scalar channel unit. Samples remain float32.
Bounded reads
The small text header is read first. Region reads calculate each selected row offset and return bounded RasterBlock values. The writer accepts the complete sample array because writing requires the complete output.
Display rendering
renderScientificPlane() maps the quantitative values into RGB display blocks. Percentiles use bounded approximate sampling. Relief is display hillshading, not a quantitative surface-slope measurement. The current relief calculation uses sample coordinates and does not apply physical X/Y spacing.
Unsupported features
Multiple fields, alternate sample types, compressed wrappers, charting, contour plots, and AFM analysis are not implemented. Extra trailing bytes and malformed headers reject.