Skip to content
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

Fix class cast and labels issue. #98

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: mvn ${{ env.maven_commands }}
- name: Upload JAR as artifact
if: matrix.os == 'ubuntu-latest' && matrix.java == '1.8'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: ZarrReader
path: target/*.jar
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Retrieve version
id: get_version
run: |
Expand All @@ -86,7 +86,7 @@ jobs:
echo server='ome.releases' >> $GITHUB_OUTPUT
fi
- name: Set up Repository
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 8
distribution: 'zulu'
Expand Down
29 changes: 16 additions & 13 deletions src/loci/formats/in/ZarrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* #%L
* Implementation of Bio-Formats readers for the next-generation file formats
* %%
* Copyright (C) 2020 - 2022 Open Microscopy Environment
* Copyright (C) 2020 - 2024 Open Microscopy Environment
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -44,7 +44,6 @@
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import javax.xml.parsers.ParserConfigurationException;
Expand All @@ -68,17 +67,13 @@
import loci.formats.FormatReader;
import loci.formats.FormatTools;
import loci.formats.MetadataTools;
import loci.formats.in.DynamicMetadataOptions;
import loci.formats.in.MetadataOptions;
import loci.formats.meta.MetadataStore;
import loci.formats.ome.OMEXMLMetadata;
import loci.formats.services.JZarrServiceImpl;
import ome.xml.meta.MetadataConverter;
import ome.xml.meta.MetadataRoot;
import ome.xml.model.MapAnnotation;
import ome.xml.model.OME;
import ome.xml.model.Plate;
import ome.xml.model.Screen;
import ome.xml.model.StructuredAnnotations;
import ome.xml.model.primitives.NonNegativeInteger;
import ome.xml.model.primitives.PositiveInteger;
Expand Down Expand Up @@ -930,7 +925,9 @@ private void parseOmeroMetadata(String root, Map<String, Object> attr) throws IO
for (int i = 0; i < channels.size(); i++) {
Map<String, Object> channel = (Map<String, Object>) channels.get(i);
Boolean channelActive = (Boolean) channel.get("active");
Double channelCoefficient = (Double) channel.get("coefficient");
Double channelCoefficient = channel.get("coefficient") instanceof Double ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also #95 an alternative to the intanceof check would be to read these as Number

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks, so that actually already has been fixed in another PR, should have checked properly. Maybe we could merge the other PR first...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only obvious caveat is that #95 needs additional work to get the test to compile first. But if that was the preferred option, no objection from my side to splitting these fixes into 2 separate PRs.

((Double) channel.get("coefficient")) :
((Integer) channel.get("coefficient")).doubleValue();
String channelColor = (String) channel.get("color");
String channelFamily = (String) channel.get("family");
Boolean channelInverted = (Boolean) channel.get("inverted");
Expand Down Expand Up @@ -1125,19 +1122,25 @@ private Double getDouble(Map<String, Object> src, String key) {
public String[] getUsedFiles(boolean noPixels) {
FormatTools.assertId(currentId, true, 1);
String zarrRootPath = currentId.substring(0, currentId.indexOf(".zarr") + 5);
int rootPathLength = zarrRootPath.length();
ArrayList<String> usedFiles = new ArrayList<String>();
reloadOptionsFile(zarrRootPath);

boolean skipPixels = noPixels || !listPixels() || !systemEnvListPixels();
boolean includeLabels = includeLabels();
try (Stream<Path> paths = Files.walk(Paths.get(zarrRootPath), FileVisitOption.FOLLOW_LINKS)) {
paths.filter(Files::isRegularFile)
.forEach(path -> {if ((!skipPixels && includeLabels) ||
(!skipPixels && !includeLabels && !path.toString().toLowerCase().contains("labels")) ||
(skipPixels && includeLabels && (path.endsWith(".zgroup") || path.endsWith(".zattrs") || path.endsWith(".xml"))) ||
(skipPixels && !includeLabels && !path.toString().toLowerCase().contains("labels") &&(path.endsWith(".zgroup") || path.endsWith(".zattrs") || path.endsWith(".xml"))))
usedFiles.add(path.toFile().getAbsolutePath());
});
.forEach(path -> {
if (
(!skipPixels && includeLabels) ||
(!skipPixels && !includeLabels && (path.toString().toLowerCase().lastIndexOf("labels")<rootPathLength) ||
(skipPixels && includeLabels && (path.endsWith(".zgroup") || path.endsWith(".zattrs") || path.endsWith(".xml"))) ||
(skipPixels && !includeLabels && (path.toString().toLowerCase().lastIndexOf("labels")<rootPathLength) &&(path.endsWith(".zgroup") || path.endsWith(".zattrs") || path.endsWith(".xml")))))
{
usedFiles.add(path.toFile().getAbsolutePath());
}
}
);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down