ngff- sarr 类型脚本
用于读取和写 OME-Zarr 文件的 ngff- sarr 的 TypeScript 执行, 兼容 Node.js 和浏览器.
特征
- 📘 类型脚本第一: 用 TypeScript 编写, 随声明一起运出
- 📦 npm 软件包:为节点J、捆绑机和浏览器建立无害环境管理
- 🔍 类型安全: 用 Zod schema 验证的完整类型脚本支持
- 🗂️ OME- Zarr 支持:读取 OME-Zarr v0.4, v0.5, 和 v0. 6, 并使用 fizarrita 写入 v0. 5 和 v. 6. 6 ( Zarr v3)
- 🧪 测试良好: 与Vitest、Node和Playwright一起运行的综合测试套房
- 🏗️ 镜像 Python API: TypeScript 类和类型镜像 Python 数据类
安装
节点.js/npm
npm install @fideus-labs/ngff-zarr
import * as ngffZarr from "@fideus-labs/ngff-zarr";
解码器工船作为单独的文档 dist/workers/ 被产出
与 new Worker(new URL("../workers/omero_codec_worker.js", import.meta.url), { type: "module" }), (中文(简体) ),
vite 和 Webpack 5 等窗体捆绑器被确认为工人条目
在不配置的情况下,在捆绑的同时发射.
快速启动
正在读取 OME- Zarr 文件
import { OMEZarrReader } from "@fideus-labs/ngff-zarr";
const reader = new OMEZarrReader({ validate: true });
const multiscales = await reader.fromNgffZarr("path/to/image.ome.zarr");
console.log(`Loaded ${multiscales.images.length} scale levels`);
console.log(`Image shape: ${multiscales.images[0].data.shape}`);
写入 OME- Zarr 文件
import {
createMetadata,
createMultiscales,
createNgffImage,
OMEZarrWriter,
} from "@fideus-labs/ngff-zarr";
// Create a simple 2D image
const image = createNgffImage(
new ArrayBuffer(256 * 256),
[256, 256],
"uint8",
["y", "x"],
{ y: 1.0, x: 1.0 },
{ y: 0.0, x: 0.0 },
);
// Create metadata
const axes = [
{ name: "y", type: "space" },
{ name: "x", type: "space" },
];
const datasets = [
{
path: "0",
coordinateTransformations: [
{ type: "scale", scale: [1.0, 1.0] },
{ type: "translation", translation: [0.0, 0.0] },
],
},
];
const metadata = createMetadata(axes, datasets);
// Create multiscales
const multiscales = createMultiscales([image], metadata);
// Write to OME-Zarr
const writer = new OMEZarrWriter();
await writer.toOmeZarr("output.ome.zarr", multiscales);
Schema 验证
import { MetadataSchema, validateMetadata } from "@fideus-labs/ngff-zarr";
const metadata = {
axes: [
{ name: "y", type: "space" },
{ name: "x", type: "space" },
],
datasets: [
{
path: "0",
coordinateTransformations: [
{ type: "scale", scale: [1.0, 1.0] },
{ type: "translation", translation: [0.0, 0.0] },
],
},
],
name: "test_image",
version: "0.4",
};
// Validate using Zod schema
const validatedMetadata = MetadataSchema.parse(metadata);
// Or use utility function
const validatedMetadata2 = validateMetadata(metadata);
API 参考
核心类型
NgffImage: 与相关元数据相映像Multiscales: 图像多级容器DaskArray: 工作缸数组元数据表示Metadata: OME-Zarr元数据结构
I/O类
OMEZarrReader: 使用 fizarrita 读取 OME- Zarr 文件OMEZarrWriter: 使用 fizarrita 写入 OME- Zarr 文件
验证
- 所有数据结构的 Zod 方案
- 用于验证的功能
- 类型安全解析和验证
工厂功能
createNgffImage(): 创建 Ngff 图像实例createMetadata(): 创建元数据结构createMultiscales(): 创建多比例容器
发展
先决条件
工具链是 维特+ (单位:千美元)vp),作为dev安装
依赖性:用于测试的活性测试,用于起伏和格式化的Oxlint和Oxfmt,
t倒为所建.
设置
cd ts/
npm ci # or: pixi run install
图标
# Run tests
npm test # or: pixi run test
# Format code
npm run fmt # or: pixi run fmt
# Lint code
npm run lint # or: pixi run lint
# Format + lint + type check in one pass
npm run check # or: pixi run check
# Build the npm package into dist/
npm run build # or: pixi run build
# Node tests against the built package
npm run test:node # or: pixi run test-node
# Browser testing with Playwright
npm run test:browser # or: pixi run test-browser
# Browser testing with UI
npm run test:browser:ui
# Run all tests (including browser tests)
npm run test:all # or: pixi run test-all
浏览器测试
该项目包括使用Playwright进行综合浏览器测试. 这个 浏览器测试验证 npm- transpiled 软件包是否真实正确 浏览器环境.
特征 :
- 多浏览器测试(Chrome、Firefox、Safari、Mobile)
- 浏览器上下文中的国家预防机制软件包验证
- 依赖性导入分辨率测试
- 浏览器环境中的Schema 验证
快速启动 :
# Build the package, inline the worker, bundle, and run the browser tests
npm run test:browser
# Run browser tests with interactive UI
npm run test:browser:ui
# Debug browser tests
npm run test:browser:debug
测试文件 :
/test/browser-npm/- 浏览器测试文件和配置/test/browser/server.ts- 测试服务资产的服务器/scripts/run_playwright.mjs- 用于执行Playwright的节点.js包装器
见 测试/浏览器/README.md 用于详细浏览器 测试文档.
项目结构
ts/
├── src/
│ ├── types/ # TypeScript type definitions
│ ├── schemas/ # Zod validation schemas
│ ├── io/ # Zarr I/O operations
│ ├── utils/ # Utility functions
│ └── mod.ts # Main module exports
├── test/ # Test files
├── scripts/ # Build scripts
├── package.json # npm package manifest and scripts
├── vite.config.ts # Vite+ configuration (test, lint, fmt, pack)
├── tsconfig.json # TypeScript configuration
├── pixi.toml # Pixi environment
└── README.md
与 Python 软件包的关系
此类型脚本包镜像 Python ngff- zarr 包 :
- 类型: TypeScript 接口/类对应 Python 数据类
- API 密码: 类似的函数名称和模式
- 验证: Zod schemas 提供运行时间验证, 如 Python
- 一. 业务: fizarrita 提供 Zarr 操作像 sarr-python
捐款
- 叉子存储器
- 创建特性分支
- 做你的改变
- 添加测试
- 运行测试套件 :
npm test - 提交拉动请求
许可证
麻省理工学院许可证 - 详情见LICENSE文件.