Skip to content

About

NetCDF4 WebAssembly port with TypeScript bindings for browser and Node.js, enabling NetCDF read/write and interactive dataset exploration.

Topics

Resources

Contributing

Stars

16 stars

Watchers

1 watching

Forks

Repository files navigation

netcdf4-wasm viewer

npm version License: MIT NetCDF4 TypeScript WebAssembly Emscripten Vitest

Partial WebAssembly port of the NetCDF4 C library with TypeScript bindings for browser and Node.js

netcdf4-wasm brings the power of NetCDF4 to web browsers and Node.js through WebAssembly. Read and write NetCDF files directly in JavaScript with a familiar, Python-inspired API.

Features:

  • 🌐 Works in browsers and Node.js
  • 📦 Partial NetCDF4 file format support
  • 🐍 API modeled after netcdf4-python
  • 🚀 High-performance WASM compilation
  • 📝 Complete TypeScript type definitions

Tip

Want to do more? Plot, visualize, and explore your data at browzarr.io

Installation

npm install @earthyscience/netcdf4-wasm

Quick Start

import { NetCDF4, DataTree } from "@earthyscience/netcdf4-wasm";

// Open existing file
const ds = await NetCDF4.fromBlobLazy(file);
const dt = new DataTree(ds);
await dt.buildTree();

Remote files

NetCDF4.fromUrl opens a file over HTTP(S) without downloading it: a Web Worker fetches only the byte ranges netCDF-C reads, and keeps them in a block cache. Dataset(url) and NetCDF4.Dataset(url) do the same for http(s):// strings and URL objects.

const ds = await NetCDF4.fromUrl("https://example.org/data.nc", {
  headers: { Authorization: "Bearer TOKEN" }, // sent with every request
  withCredentials: false, // send cookies cross-origin
});
try {
  const values = await ds.getSlicedVariableArray(
    "temperature",
    [0, 0],
    [1, 10],
  );
} finally {
  await ds.close();
}

Remote files are read-only. The server must allow CORS and should support Range requests; if it ignores them, the whole file is downloaded once.

To prevent large full downloads, set maxFullDownload to a size limit in bytes. If the server ignores Range and the file is larger than this limit (or its size is unknown), opening fails with an error instead. Set it to 0 to always require Range support.

If a file is too large to open this way, download it and open it from disk with NetCDF4.fromBlobLazy instead, which reads only the parts it needs from the local file.

API Reference

The API closely follows netcdf4-python conventions, making it intuitive for scientists familiar with Python.

Advanced Usage

Memory Configuration

If you encounter memory-related errors with large files, you can increase the initial memory allocation:

// TODO: Add example once API is stable

Building from Source

See our Contributing Guide for detailed build instructions.

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Resources

Acknowledgments

This project builds upon the initial work from oceanum-io/netcdf4-wasm. We're grateful for their foundational efforts in bringing NetCDF4 to WebAssembly and are continuing their work with additional features and improvements.

About

NetCDF4 WebAssembly port with TypeScript bindings for browser and Node.js, enabling NetCDF read/write and interactive dataset exploration.

Topics

Resources

Contributing

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages