Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion USERGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ zarr-java is a Java implementation of the [Zarr specification](https://zarr.dev/
### Key Features
- **Full Zarr v2 and v3 support**: Read and write arrays in both formats
- **Multiple storage backends**: Filesystem, HTTP, S3, ZIP, and in-memory storage
- **Compression codecs**: Blosc, Gzip, Zstd, and more
- **Compression codecs**: Blosc, Gzip, Zstd, Zfp, and more
- **Sharding support**: Efficient storage for many small chunks (v3)
- **Parallel I/O**: Optional parallel reading and writing for performance
- **Type-safe API**: Strong typing with covariant return types
Expand Down Expand Up @@ -448,6 +448,19 @@ Array array = Array.create(
```java
.withCodecs(c -> c.withZstd(3)) // Level 1-22
```
#### Zfp Compression
Compresses numerical chunks with [zfp](https://zfp.io), lossless or with a chosen error bound:
```java
.withCodecs(c -> c.withZfpReversible()) // Lossless
.withCodecs(c -> c.withZfpFixedAccuracy(0.05)) // Absolute error bound
.withCodecs(c -> c.withZfpFixedRate(8)) // Compressed bits per value
.withCodecs(c -> c.withZfpFixedPrecision(19)) // Bit planes retained
.withCodecs(c -> c.withZfpExpert(1, 13, 19, -2)) // zfp's expert mode parameters
```
Zfp replaces the `bytes` codec, so it cannot be combined with it. Chunks may have at most four
dimensions, and `bool` is not supported. Data types narrower than 32 bits are promoted to `int32`;
`uint32` and `uint64` values beyond the signed range are clamped, so they do not survive a round trip
even in reversible mode.
#### Transpose Codec
```java
.withCodecs(c -> c
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<aws.version>2.34.6</aws.version>
<netcdfJavaVersion>5.9.1</netcdfJavaVersion>
<zstdVersion>1.5.5-7</zstdVersion>
<zfpVersion>0.1-1.0.1</zfpVersion>
<junit-jupiter-version>5.14.0</junit-jupiter-version>
<findbugs.version>3.0.2</findbugs.version>
</properties>
Expand Down Expand Up @@ -104,6 +105,11 @@
<artifactId>blosc-java</artifactId>
<version>0.3-1.21.6</version>
</dependency>
<dependency>
<groupId>com.scalableminds</groupId>
<artifactId>zfp-java</artifactId>
<version>${zfpVersion}</version>
</dependency>
<dependency>
<groupId>com.github.luben</groupId>
<artifactId>zstd-jni</artifactId>
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/dev/zarr/zarrjava/v3/codec/CodecBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,66 @@ public CodecBuilder withZstd(int level) {
return withZstd(level, true);
}

public CodecBuilder withZfp(ZfpCodec.Configuration configuration) {
codecs.add(new ZfpCodec(configuration));
return this;
}

/**
* Compresses chunks losslessly with zfp.
*/
public CodecBuilder withZfpReversible() {
try {
return withZfp(ZfpCodec.Configuration.reversible());
} catch (ZarrException e) {
throw new RuntimeException(e);
}
}

/**
* Compresses chunks with zfp, with a guaranteed absolute error bound.
*/
public CodecBuilder withZfpFixedAccuracy(double tolerance) {
try {
return withZfp(ZfpCodec.Configuration.fixedAccuracy(tolerance));
} catch (ZarrException e) {
throw new RuntimeException(e);
}
}

/**
* Compresses chunks with zfp, at a fixed number of compressed bits per value.
*/
public CodecBuilder withZfpFixedRate(double rate) {
try {
return withZfp(ZfpCodec.Configuration.fixedRate(rate));
} catch (ZarrException e) {
throw new RuntimeException(e);
}
}

/**
* Compresses chunks with zfp, retaining a fixed number of bit planes.
*/
public CodecBuilder withZfpFixedPrecision(int precision) {
try {
return withZfp(ZfpCodec.Configuration.fixedPrecision(precision));
} catch (ZarrException e) {
throw new RuntimeException(e);
}
}

/**
* Compresses chunks with zfp, setting all four of zfp's expert mode parameters directly.
*/
public CodecBuilder withZfpExpert(int minbits, int maxbits, int maxprec, int minexp) {
try {
return withZfp(ZfpCodec.Configuration.expert(minbits, maxbits, maxprec, minexp));
} catch (ZarrException e) {
throw new RuntimeException(e);
}
}

public CodecBuilder withSharding(int[] chunkShape) {
try {
codecs.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CodecRegistry {
addType("blosc", BloscCodec.class);
addType("gzip", GzipCodec.class);
addType("zstd", ZstdCodec.class);
addType("zfp", ZfpCodec.class);
addType("crc32c", Crc32cCodec.class);
addType("sharding_indexed", ShardingIndexedCodec.class);
}
Expand Down
Loading
Loading