Skip to content

Commit fe7d7ee

Browse files
Merge remote-tracking branch 'upstream/main' into public-axes
2 parents 6943dde + 269ca05 commit fe7d7ee

File tree

8 files changed

+72
-50
lines changed

8 files changed

+72
-50
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Support for parsing the [BioImage Model Zoo spec](https://github.com/bioimage-io/spec-bioimage-io) in Java.
44

5-
With thanks to the @bioimage-io for all their work in creating this spec and the model zoo.
5+
With thanks to @bioimage-io for all their work in creating this spec and the model zoo.
66

77
## Purpose
88

@@ -12,7 +12,7 @@ It's separated out from QuPath's code in case it could be useful to anyone else.
1212

1313
## Dependencies
1414

15-
The spec is implemented in a single Java file with 3 dependencies:
15+
The spec has 3 dependencies:
1616

1717
* SnakeYAML
1818
* Gson
@@ -22,9 +22,9 @@ Gson might be removed as a dependency in the future.
2222

2323
## Compatibility
2424

25-
The code here should be compatible with Java 11.
25+
The code here should be compatible with Java 17.
2626

27-
It was written for the model spec v0.4.x, but attempts too also handle most yaml files written with the model spec v0.3.x.
27+
It was written for the model spec v0.4.x, and updated to handle v0.5.x models, but attempts to also handle most yaml files written with the model spec v0.3.x.
2828

2929
## Building
3030

@@ -39,4 +39,4 @@ To test more, you can pass a base directory and the test code will search recurs
3939
gradlew test -Ptest.models=path/to/base/directory
4040
```
4141

42-
> Note: The testing isn't very extensive. Currently, it just checks the models can be parsed without exceptions.
42+
> Note: The testing isn't very extensive. Currently, it just checks the models can be parsed without exceptions.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repositories {
1919

2020
description = 'Support for parsing the BioImage Model Zoo spec in Java'
2121

22-
version = "0.2.0-SNAPSHOT"
22+
version = "0.2.0"
2323

2424
dependencies {
2525
// These are included in QuPath distribution

src/main/java/qupath/bioimageio/spec/Model.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,12 @@ private static Path findRdf(Path path, Collection<String> names) throws IOExcept
426426
}
427427
} else if (path.toAbsolutePath().toString().toLowerCase().endsWith(".zip")) {
428428
// Check zip file
429-
try (var fs = FileSystems.newFileSystem(path, (ClassLoader) null)) {
430-
for (var dir : fs.getRootDirectories()) {
431-
for (var name : MODEL_NAMES) {
432-
var p = dir.resolve(name);
433-
if (Files.exists(p))
434-
return p;
435-
}
429+
var fs = FileSystems.newFileSystem(path, (ClassLoader) null);
430+
for (var dir : fs.getRootDirectories()) {
431+
for (var name : MODEL_NAMES) {
432+
var p = dir.resolve(name);
433+
if (Files.exists(p))
434+
return p;
436435
}
437436
}
438437
}

src/main/java/qupath/bioimageio/spec/tensor/axes/Axes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Axis[] deserialize(JsonElement jsonElement, Type type, JsonDeserializatio
7373
axes[i] = switch (oj.get("type").getAsString()) {
7474
case "time" -> new TimeAxes.TimeAxis(
7575
id, desc,
76-
TimeAxes.TimeUnit.valueOf(oj.get("unit").getAsString().toUpperCase()),
76+
TimeAxes.TimeUnit.getUnit(oj.get("unit").getAsString()),
7777
oj.get("scale").getAsDouble(),
7878
size
7979
);

src/main/java/qupath/bioimageio/spec/tensor/axes/SpaceAxes.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
package qupath.bioimageio.spec.tensor.axes;
1818

19+
import java.util.List;
20+
21+
import qupath.bioimageio.spec.tensor.BaseTensor;
1922
import qupath.bioimageio.spec.tensor.sizes.ReferencedSize;
2023
import qupath.bioimageio.spec.tensor.sizes.Size;
21-
import qupath.bioimageio.spec.tensor.BaseTensor;
22-
23-
import java.util.List;
2424

2525
/**
2626
* Axes relating to physical space.
2727
*/
2828
public class SpaceAxes {
2929

3030
/**
31-
* Possible SI and imperial units for distance in physical space (some more likely to be used than others).
31+
* Possible SI and imperial units for distance in physical space.
3232
*/
3333
public enum SpaceUnit {
3434
ATTOMETER("attometer"),
@@ -61,22 +61,22 @@ public enum SpaceUnit {
6161

6262
private final String unit;
6363

64-
SpaceUnit(String s) {
65-
this.unit = s;
64+
SpaceUnit(String unit) {
65+
this.unit = unit;
6666
}
6767

6868
/**
6969
* Get the SpaceUnit corresponding to a String value.
70-
* @param unit The unit as a string
71-
* @return The corresponding unit, or null if not found.
70+
* @param unit the unit as a string
71+
* @return the corresponding unit, or NO_UNIT if not found.
7272
*/
7373
public static SpaceUnit getUnit(String unit) {
74-
for (var su: SpaceUnit.values()) {
74+
for (var su: values()) {
7575
if (su.unit.equalsIgnoreCase(unit)) {
7676
return su;
7777
}
7878
}
79-
return null;
79+
return NO_UNIT;
8080
}
8181
}
8282

@@ -90,7 +90,7 @@ public static class SpaceAxis extends AxisBase implements ScaledAxis {
9090
private final boolean concatenable = false;
9191

9292
SpaceAxis(String id, String description, String unit, double scale, Size size) {
93-
this(id, description, SpaceUnit.valueOf(unit.toUpperCase()), scale, size);
93+
this(id, description, SpaceUnit.getUnit(unit), scale, size);
9494
}
9595

9696
SpaceAxis(String id, String description, SpaceUnit unit, double scale, Size size) {

src/main/java/qupath/bioimageio/spec/tensor/axes/TimeAxes.java

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,32 +88,55 @@ public int getHalo() {
8888
}
8989

9090
/**
91-
* Possible SI units for time.
91+
* Possible units for time.
9292
*/
9393
public enum TimeUnit {
94-
ATTOSECOND,
95-
CENTISECOND,
96-
DAY,
97-
DECISECOND,
98-
EXASECOND,
99-
FEMTOSECOND,
100-
GIGASECOND,
101-
HECTOSECOND,
102-
HOUR,
103-
KILOSECOND,
104-
MEGASECOND,
105-
MICROSECOND,
106-
MILLISECOND,
107-
MINUTE,
108-
NANOSECOND,
109-
PETASECOND,
110-
PICOSECOND,
111-
SECOND,
112-
TERASECOND,
113-
YOCTOSECOND,
114-
YOTTASECOND,
115-
ZEPTOSECOND,
116-
ZETTASECOND
94+
ATTOSECOND("attosecond"),
95+
CENTISECOND("centisecond"),
96+
DAY("day"),
97+
DECISECOND("decisecond"),
98+
EXASECOND("exasecond"),
99+
FEMTOSECOND("femtosecond"),
100+
GIGASECOND("gigasecond"),
101+
HECTOSECOND("hectosecond"),
102+
HOUR("hour"),
103+
KILOSECOND("kilosecond"),
104+
MEGASECOND("megasecond"),
105+
MICROSECOND("microsecond"),
106+
MILLISECOND("millisecond"),
107+
MINUTE("minute"),
108+
NANOSECOND("nanosecond"),
109+
PETASECOND("petasecond"),
110+
PICOSECOND("picosecond"),
111+
SECOND("second"),
112+
TERASECOND("terasecond"),
113+
YOCTOSECOND("yoctosecond"),
114+
YOTTASECOND("yottasecond"),
115+
ZEPTOSECOND("zeptosecond"),
116+
ZETTASECOND("zettasecond"),
117+
NO_UNIT("");
118+
119+
private final String unit;
120+
121+
TimeUnit(String unit) {
122+
this.unit = unit;
123+
}
124+
125+
/**
126+
* Get the TimeUnit corresponding to a String value.
127+
* @param unit the unit as a string
128+
* @return the corresponding unit, or NO_UNIT if not found.
129+
*/
130+
public static TimeUnit getUnit(String unit) {
131+
for (var tu: values()) {
132+
if (tu.unit.equalsIgnoreCase(unit)) {
133+
return tu;
134+
}
135+
}
136+
return NO_UNIT;
137+
}
117138
}
118139

140+
141+
119142
}

src/test/java/qupath/bioimageio/spec/TestBioImageIoSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static Collection<Path> provideYamlPaths() throws IOException, URISyntaxExceptio
4545
else if (Files.isDirectory(path)) {
4646
try (var fstream = Files.walk(path, testDepth)) {
4747
return fstream
48-
.filter(TestBioImageIoSpec::containsModel)
48+
.filter(p -> containsModel(p) || p.toString().endsWith(".zip"))
4949
.collect(Collectors.toSet());
5050
}
5151
} else {
995 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)