-
Notifications
You must be signed in to change notification settings - Fork 17
jzarr read/write (close #36) #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0046d44
Initial data generation commit for jzarr
joshmoore 716922f
Add jzarr reading test
joshmoore 33ec3dc
pom cleanup
joshmoore 6b6b450
Cleanup test additions
joshmoore 3aa27b5
Add Brockmann-Consult repository
joshmoore 2e8336f
Merge 'origin/master' into jzarr
joshmoore 1f24c8d
Add workaround for >u1 in jzarr
joshmoore 6d02348
Handle None jzarr return in tabulation
joshmoore 1ad9af0
Fix retcode and properly test shape
joshmoore 9c980ac
use subprocess.check_output to call jzarr test script
grlee77 301bc4d
Merge pull request #1 from grlee77/subprocess-check-output
joshmoore b85deff
Correct filetype keys
joshmoore c68abfd
Add full test data comparison
joshmoore b1dc5f4
Unsign returned ints
joshmoore 4c4d2ac
Bump to jzarr 0.3.3
joshmoore 0fd59c7
Improve maven builds in GHA
joshmoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# cd to this directory | ||
# https://stackoverflow.com/a/6393573/2700168 | ||
cd "${0%/*}" | ||
|
||
set -e | ||
set -u | ||
set -x | ||
|
||
MVN_FLAGS=${MVN_FLAGS:-"--no-transfer-progress"} | ||
mvn "${MVN_FLAGS}" clean package | ||
|
||
java -cp target/jzarr-1.0.0.jar zarr_implementations.jzarr.App "$@" && { | ||
# Workaround for: https://github.com/bcdev/jzarr/issues/25 | ||
find ../../data/jzarr* -name .zarray -exec sed -ibak 's/>u1/|u1/' {} \; | ||
} || { | ||
echo jzarr failed | ||
exit 2 | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>zarr_implementations</groupId> | ||
<artifactId>jzarr</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0.0</version> | ||
<name>jzarr</name> | ||
<url>http://maven.apache.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.bc.zarr</groupId> | ||
<artifactId>jzarr</artifactId> | ||
<version>0.3.3</version> | ||
</dependency> | ||
</dependencies> | ||
<repositories> | ||
<repository> | ||
<id>bc-nexus-repo</id> | ||
<name>Brockmann-Consult Public Maven Repository</name> | ||
<url>https://nexus.senbox.net/nexus/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-enforcer-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>enforce-rules</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.3</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.4.3</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<createDependencyReducedPom>true</createDependencyReducedPom> | ||
<dependencyReducedPomLocation> | ||
${java.io.tmpdir}/dependency-reduced-pom.xml | ||
</dependencyReducedPomLocation> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
129 changes: 129 additions & 0 deletions
129
generate_data/jzarr/src/main/java/zarr_implementations/jzarr/App.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package zarr_implementations.jzarr; | ||
|
||
import com.bc.zarr.ArrayParams; | ||
import com.bc.zarr.CompressorFactory; | ||
import com.bc.zarr.DataType; | ||
import com.bc.zarr.ZarrArray; | ||
import com.bc.zarr.ZarrGroup; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.awt.image.DataBuffer; | ||
import java.awt.image.DataBufferByte; | ||
import java.awt.image.DataBufferInt; | ||
import java.awt.image.WritableRaster; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import java.util.stream.IntStream; | ||
|
||
|
||
public class App { | ||
|
||
enum Compression { | ||
raw("null"), | ||
zlib("zlib"), | ||
blosc("blosc"); | ||
|
||
private final String value; | ||
|
||
private Compression(final String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
} | ||
|
||
// NOTE for now we use 100, 100, 1 as block-size in all examples | ||
// maybe it's a better idea to make this more irregular though | ||
private static final int WIDTH = 512; | ||
private static final int HEIGHT = 512; | ||
private static final int CHANNELS = 3; | ||
private static final int[] CHUNKS = new int[]{100, 100, 1}; | ||
private static final int[] SHAPE = new int[] {WIDTH, HEIGHT, CHANNELS}; | ||
private static final Path IN_PATH = Paths.get("..", "..", "data", "reference_image.png"); | ||
private static final Path OUT_PATH = Paths.get("..", "..", "data", "jzarr_flat.zr"); | ||
|
||
private static int[] getTestData() throws IOException { | ||
final BufferedImage image = ImageIO.read(new File(IN_PATH.toString())); | ||
int[] result = new int[WIDTH * HEIGHT * CHANNELS]; | ||
for (int i = 0; i < WIDTH; i++) { | ||
for (int j = 0; j < HEIGHT; j++) { | ||
Color color = new Color(image.getRGB(i, j)); | ||
int index = (WIDTH*3*j) + (3*i); | ||
result[index + 0] = color.getRed(); | ||
result[index + 1] = color.getGreen(); | ||
result[index + 2] = color.getBlue(); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
|
||
private static int[] getArrayData(ZarrArray zarr) throws Exception { | ||
int[] data = new int[WIDTH * HEIGHT * CHANNELS]; | ||
zarr.read(data, SHAPE, new int[]{0, 0, 0}); | ||
int[] unsigned = new int[data.length]; | ||
for (int i = 0; i < data.length; i++) { | ||
unsigned[i] = data[i] & 0xff; | ||
} | ||
return unsigned; | ||
} | ||
|
||
public static void main(String args[]) throws Exception { | ||
|
||
if (args.length != 0 && args.length != 3) { | ||
System.out.println("usage: App"); | ||
System.out.println("usage: App -verify fpath dsname"); | ||
System.exit(2); // EARLY EXIT | ||
} else if (args.length == 3) { | ||
String fpath = args[1]; | ||
String dsname = args[2]; | ||
ZarrArray verification = ZarrGroup.open(fpath).openArray(dsname); | ||
int[] shape = verification.getShape(); | ||
if (!Arrays.equals(SHAPE, shape)) { | ||
throw new RuntimeException(String.format( | ||
"shape-mismatch expected:%s found:%s", | ||
Arrays.toString(SHAPE), Arrays.toString(shape) | ||
)); | ||
} | ||
|
||
int[] test = getTestData(); | ||
int[] verify = getArrayData(verification); | ||
if (!Arrays.equals(test, verify)) { | ||
throw new RuntimeException(String.format( | ||
"values don't match")); | ||
} | ||
return; // EARLY EXIT | ||
} | ||
|
||
int[] data = getTestData(); | ||
|
||
final ZarrGroup container = ZarrGroup.create(OUT_PATH); | ||
for (final Compression compressionType : Compression.values()) { | ||
ArrayParams arrayParams = new ArrayParams() | ||
.shape(SHAPE) | ||
.chunks(CHUNKS) | ||
.dataType(DataType.u1) | ||
// .nested(nested) FIXME: requires a different branch | ||
.compressor(CompressorFactory.create(compressionType.toString())); // jzarr name, "null" | ||
|
||
String dsname = compressionType.name(); // zarr_implementation name, "raw" | ||
if ("blosc".equals(dsname)) { | ||
dsname = "blosc/lz4"; // FIXME: better workaround? | ||
} | ||
Path subdir = OUT_PATH.resolve(dsname); | ||
ZarrArray zArray = ZarrArray.create(subdir, arrayParams); | ||
// final ZarrArray zarr = ZarrArray.open(getRootPath().resolve(pathName)); | ||
zArray.write(data, SHAPE, new int[]{0, 0, 0}); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.