Giter VIP home page Giter VIP logo

zarrita.js's Introduction

zarrita.js's People

Contributors

github-actions[bot] avatar manzt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

valarlabs

zarrita.js's Issues

Remove special "KeyError" and return undefined from stores for missing key

Adapted from: gzuidhof/zarr.js#69

A KeyError is a built in python error that's thrown when a key is missing from a MutableMapping. In JavaScript, the equivalent behavior is to just return undefined when a key is missing. Making this change would remove a lot of the try/catch blocks from the core implementation and instead we would just call:

// Store returns 'undefined' instead of throwing custom error if chunk is missing.
// Otherwise the store can throw any other error and it will propagate up.
const chunk = await this.store.get(ckey);
if (!chunk) {
  /* create the missing chunk */ 
} else {
  /* decode the chunk */
}

Remove `ZarrArray.do`

I introduced ZarrArray.do to allow tree-shaking of class methods:

import { v2, get, set } from 'zarrita';

const a = await v2.get_hierarchy(...).get_array('/');
a.do(get, null) // set can be tree-shaken as it is not used

However, the inferred return types from .do aren't very precise, and the alternative of just passing ZarrArray as a parameter to get/set is much more simple:

import { v2, get, set } from 'zarrita';

const a = await v2.get_hierarchy(...).get_array('/');
get(a, null) // set can be tree-shaken as it is not used

Support float16 data type

I implemented optional float16 support in zarr.js recently. I believe the same strategy should work here, but I'm not sure how type inference will work.

More tests for slicing + indexing

I tried porting some of the strided array set functionality to zarr-lite and seem to be getting errors for slicing (empty arrays), specifically when the output is a lower dimension than the chunk shape.

I should come up with some separate tests for src/opts.js to test various slicing and indexing. Just need to find some time...

[idea]: Web API `Response` for `Store`?

Rather than returning Promise<Uint8Array> , we could unify the store interface around Web-standard Response to expose additional features to zarr.Array instances.

Changes:

  • Use the Response.ok or response.status to determine if the item is in the store or not (rather than Uint8Array | undefined).
  • Exposes conveniences to read response directly via .json(), .text(), .arrayBuffer(), and .blob(), rather than copying array buffers etc.
  • Ability process Response.body as a stream. This is the most interesting/exciting to me, but it's not clear if it would be useful. Ideally there is a world were chunks could be partially decoded, etc.

Rather than handling Responses within zarr.Array, we could look into something like a StorageTransformer layer, which by default just reads the response in full.

Move ops to same namespace

It's a little clunky to use ops methods because they require a separate import. For those concerned with bundle size, this is fine, but it might be unintuitive to a new user. As an alternative, we could export the builtin ops and add a namespace for ndarray:

Current

import * as zarr from "zarrita/v2";
import { get, set } from "zarrita/ops";
import * as ndops from "zarrita/ndarray";
import FetchStore from "zarrita/storage/fetch";

let root = await zarr.get(new FetchStore("http://localhost:8080/data.zarr");
let res = get(root);
set(root, ...);
ndops.get(root);
ndopts.set(root, ...);

Proposed

import * as zarr from "zarrita/v2";
import FetchStore from "zarrita/storage/fetch";

let root = await zarr.get_node(new FetchStore("http://localhost:8080/data.zarr")); // or `zarr.open` ?
let res = zarr.get(root);
zarr.set(root, ...);
zarr.ndarray.get(root);
zarr.ndarray.set(root, ...);

The primary issue I see is that by default import * as zarr imports both ops and would likely increase bundle size on average. However, for those concerned with bundle size, named imports will remain treeshakeable.

import { get_node, get } from "zarrita/v2";
import FetchStore from "zarrita/storage/fetch";

let root = await get_node(new FetchStore("http://localhost:8080/data.zarr"));
let res = get(root);

Use string literal for key error

Similar to zarr.js, rather than returning undefined to indicate a missing key, maybe explore throwing a an error with a literal __zarr__ key.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.