Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "testdata/ome/v0.6/examples"]
path = testdata/ome/v0.6/examples
url = https://github.com/jo-mueller/ngff-rfc5-coordinate-transformation-examples
[submodule "testdata/ome/v0.6/ngff-spec"]
path = testdata/ome/v0.6/ngff-spec
url = https://github.com/ome/ngff-spec
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package dev.zarr.conventions.ome.metadata;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/** OMERO channel rendering metadata. */
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand All @@ -16,6 +21,7 @@ public final class OmeroChannel {
@Nullable public final Boolean inverted;
@Nullable public final String label;
@Nullable public final OmeroWindow window;
private final Map<String, Object> extraFields;

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public OmeroChannel(
Expand All @@ -25,7 +31,8 @@ public OmeroChannel(
@Nullable @JsonProperty("family") String family,
@Nullable @JsonProperty("inverted") Boolean inverted,
@Nullable @JsonProperty("label") String label,
@Nullable @JsonProperty("window") OmeroWindow window
@Nullable @JsonProperty("window") OmeroWindow window,
@Nullable @JsonAnySetter Map<String, Object> extraFields
) {
this.active = active;
this.coefficient = coefficient;
Expand All @@ -34,5 +41,31 @@ public OmeroChannel(
this.inverted = inverted;
this.label = label;
this.window = window;
this.extraFields = extraFields == null
? Collections.<String, Object>emptyMap()
: Collections.unmodifiableMap(new LinkedHashMap<>(extraFields));
}

public OmeroChannel(
@Nullable Boolean active,
@Nullable Double coefficient,
@Nullable String color,
@Nullable String family,
@Nullable Boolean inverted,
@Nullable String label,
@Nullable OmeroWindow window
) {
this(active, coefficient, color, family, inverted, label, window, null);
}

/**
* Members zarr-java does not model, such as {@code wavelength_id}. The omero block is
* transitional and open-ended, so they are written back unchanged.
*
* @return the extra fields, never {@code null}
*/
@JsonAnyGetter
public Map<String, Object> extraFields() {
return extraFields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ public dev.zarr.conventions.ome.metadata.MultiscalesEntry getMultiscaleNode(int
mappedDatasets.add(new dev.zarr.conventions.ome.metadata.Dataset(ds.path, mapped));
}
List<Axis> axes = entry.axes;
if ((axes == null || axes.isEmpty()) && entry.coordinateSystems != null && !entry.coordinateSystems.isEmpty()) {
axes = entry.coordinateSystems.get(0).axes;
if ((axes == null || axes.isEmpty()) && entry.intrinsicCoordinateSystem() != null) {
axes = entry.intrinsicCoordinateSystem().axes;
}
return new dev.zarr.conventions.ome.metadata.MultiscalesEntry(
axes != null ? axes : Collections.<Axis>emptyList(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package dev.zarr.conventions.ome.v0_6.metadata;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import dev.zarr.conventions.ome.metadata.Axis;
import dev.zarr.conventions.ome.v0_6.metadata.transform.CoordinateSystemRef;
import dev.zarr.conventions.ome.v0_6.metadata.transform.CoordinateTransformation;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -21,6 +26,7 @@ public final class MultiscalesEntry {
@Nullable public final String name;
@Nullable public final String type;
@Nullable public final Map<String, Object> metadata;
private final Map<String, Object> extraFields;

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public MultiscalesEntry(
Expand All @@ -30,7 +36,8 @@ public MultiscalesEntry(
@Nullable @JsonProperty("coordinateSystems") List<CoordinateSystem> coordinateSystems,
@Nullable @JsonProperty("name") String name,
@Nullable @JsonProperty("type") String type,
@Nullable @JsonProperty("metadata") Map<String, Object> metadata
@Nullable @JsonProperty("metadata") Map<String, Object> metadata,
@Nullable @JsonAnySetter Map<String, Object> extraFields
) {
this.axes = axes;
this.datasets = datasets;
Expand All @@ -39,16 +46,69 @@ public MultiscalesEntry(
this.name = name;
this.type = type;
this.metadata = metadata;
this.extraFields = extraFields == null
? Collections.<String, Object>emptyMap()
: Collections.unmodifiableMap(new LinkedHashMap<>(extraFields));
}

public MultiscalesEntry(
@Nullable List<Axis> axes,
List<Dataset> datasets,
@Nullable List<CoordinateTransformation> coordinateTransformations,
@Nullable List<CoordinateSystem> coordinateSystems,
@Nullable String name,
@Nullable String type,
@Nullable Map<String, Object> metadata
) {
this(axes, datasets, coordinateTransformations, coordinateSystems, name, type, metadata, null);
}

public MultiscalesEntry(List<Dataset> datasets, List<CoordinateSystem> coordinateSystems, String name) {
this(null, datasets, null, coordinateSystems, name, null, null);
}

/**
* The coordinate system the datasets map into (named by the {@code output} of their
* transformations), or the first listed coordinate system if no dataset names one.
*/
@Nullable
public CoordinateSystem intrinsicCoordinateSystem() {
if (coordinateSystems == null || coordinateSystems.isEmpty()) {
return null;
}
for (Dataset dataset : datasets) {
if (dataset.coordinateTransformations == null || dataset.coordinateTransformations.isEmpty()) {
continue;
}
CoordinateSystemRef output = dataset.coordinateTransformations.get(0).getOutput();
if (output == null || output.name == null) {
continue;
}
for (CoordinateSystem coordinateSystem : coordinateSystems) {
if (output.name.equals(coordinateSystem.name)) {
return coordinateSystem;
}
}
break;
}
return coordinateSystems.get(0);
}

/** Returns a new MultiscalesEntry with the given dataset appended. */
public MultiscalesEntry withDataset(Dataset dataset) {
List<Dataset> updated = new ArrayList<>(this.datasets);
updated.add(dataset);
return new MultiscalesEntry(axes, updated, coordinateTransformations, coordinateSystems, name, type, metadata);
return new MultiscalesEntry(axes, updated, coordinateTransformations, coordinateSystems, name, type, metadata, extraFields);
}

/**
* Members zarr-java does not model, such as the JSON-LD key {@code @id}.
* They are written back unchanged, so that a metadata rewrite does not drop them.
*
* @return the extra fields, never {@code null}
*/
@JsonAnyGetter
public Map<String, Object> extraFields() {
return extraFields;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.zarr.conventions.ome.v0_6.metadata;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -9,7 +11,10 @@
import dev.zarr.conventions.ome.metadata.WellMetadata;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/** OME-Zarr v0.6 metadata stored under {@code attributes["ome"]}. */
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand All @@ -32,6 +37,7 @@ public final class OmeMetadata {
public final ImageLabel imageLabel;
/** Image paths of a bioformats2raw collection, present in the metadata of the {@code OME} group. */
@Nullable public final List<String> series;
private final Map<String, Object> extraFields;

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public OmeMetadata(
Expand All @@ -44,7 +50,8 @@ public OmeMetadata(
@Nullable @JsonProperty("well") WellMetadata well,
@Nullable @JsonProperty("labels") List<String> labels,
@Nullable @JsonProperty("image-label") ImageLabel imageLabel,
@Nullable @JsonProperty("series") List<String> series
@Nullable @JsonProperty("series") List<String> series,
@Nullable @JsonAnySetter Map<String, Object> extraFields
) {
this.version = version;
this.multiscales = multiscales;
Expand All @@ -56,6 +63,24 @@ public OmeMetadata(
this.labels = labels;
this.imageLabel = imageLabel;
this.series = series;
this.extraFields = extraFields == null
? Collections.<String, Object>emptyMap()
: Collections.unmodifiableMap(new LinkedHashMap<>(extraFields));
}

public OmeMetadata(
String version,
@Nullable List<MultiscalesEntry> multiscales,
@Nullable OmeroMetadata omero,
@Nullable Integer bioformats2rawLayout,
@Nullable SceneMetadata scene,
@Nullable PlateMetadata plate,
@Nullable WellMetadata well,
@Nullable List<String> labels,
@Nullable ImageLabel imageLabel,
@Nullable List<String> series
) {
this(version, multiscales, omero, bioformats2rawLayout, scene, plate, well, labels, imageLabel, series, null);
}

public OmeMetadata(
Expand Down Expand Up @@ -94,6 +119,17 @@ public OmeMetadata(
/** Returns a copy with {@code multiscales} replaced and all other fields preserved. */
public OmeMetadata withMultiscales(@Nullable List<MultiscalesEntry> multiscales) {
return new OmeMetadata(version, multiscales, omero, bioformats2rawLayout, scene, plate, well,
labels, imageLabel, series);
labels, imageLabel, series, extraFields);
}

/**
* Members zarr-java does not model, such as the JSON-LD keys {@code @id} and {@code @type}.
* They are written back unchanged, so that a metadata rewrite does not drop them.
*
* @return the extra fields, never {@code null}
*/
@JsonAnyGetter
public Map<String, Object> extraFields() {
return extraFields;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dev.zarr.conventions.ome.v0_6.metadata.transform;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import javax.annotation.Nullable;
Expand All @@ -15,6 +17,7 @@
* rather than rejecting the entire OME payload.
*/
public final class GenericCoordinateTransformation extends BaseCoordinateTransformation {
@JsonIgnore
public final Map<String, Object> raw = new LinkedHashMap<>();

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
Expand All @@ -31,4 +34,9 @@ public GenericCoordinateTransformation(
public void capture(String key, Object value) {
raw.put(key, value);
}

@JsonAnyGetter
Map<String, Object> rawProperties() {
return raw;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ void createScaleLevelWithoutCoordinateSystemsFails() throws Exception {

@Test
void legacyStringFixtureOpensAndIsWrittenBackAsObjects() throws Exception {
// the rfc5 examples still use the pre-release string form ("input": "s0", "output": "physical")
Path fixture = TESTDATA.resolve("ome/v0.6/examples/2d/basic/scale_multiscale.zarr");
// written in the pre-release string form ("input": "s0", "output": "physical") of 0.6.dev3
Path fixture = TESTDATA.resolve("ome/v0.6_legacy/scale_multiscale.zarr");
JsonNode raw = readOmeAttributes(fixture).get("multiscales").get(0).get("datasets").get(0)
.get("coordinateTransformations").get(0);
assertTrue(raw.get("input").isTextual());
Expand Down
Loading
Loading