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

Add new option to list pixels in getUsedFiles #58

Closed
wants to merge 2 commits into from
Closed
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
28 changes: 26 additions & 2 deletions src/loci/formats/in/ZarrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class ZarrReader extends FormatReader {
private HashMap<String, ArrayList<String>> pathArrayDimensions = new HashMap<String, ArrayList<String>>();
private boolean planesPrePopulated = false;
private boolean hasSPW = false;

public static final String LIST_PIXELS_KEY = "omezarr.list_pixels";
public static final boolean LIST_PIXELS_DEFAULT = false;

public ZarrReader() {
super("Zarr", "zarr");
Expand Down Expand Up @@ -863,9 +866,13 @@ public String[] getUsedFiles(boolean noPixels) {
FormatTools.assertId(currentId, true, 1);
String zarrRootPath = currentId.substring(0, currentId.indexOf(".zarr") + 5);
ArrayList<String> usedFiles = new ArrayList<String>();
boolean skipPixels = noPixels || !listPixels();
try (Stream<Path> paths = Files.walk(Paths.get(zarrRootPath), FileVisitOption.FOLLOW_LINKS)) {
paths.filter(Files::isRegularFile)
.forEach(path -> usedFiles.add(path.toFile().getAbsolutePath()));
paths.filter(Files::isRegularFile)
.forEach(path -> {if (!skipPixels ||
(skipPixels && (path.endsWith(".zgroup") || path.endsWith(".zattrs") || path.endsWith(".xml"))))
usedFiles.add(path.toFile().getAbsolutePath());
});
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -883,4 +890,21 @@ public String[] getDomains() {
FormatTools.NON_SPECIAL_DOMAINS;
}

/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected ArrayList<String> getAvailableOptions() {
ArrayList<String> optionsList = super.getAvailableOptions();
optionsList.add(LIST_PIXELS_KEY);
return optionsList;
}

public boolean listPixels() {
MetadataOptions options = getMetadataOptions();
if (options instanceof DynamicMetadataOptions) {
return ((DynamicMetadataOptions) options).getBoolean(
LIST_PIXELS_KEY, LIST_PIXELS_DEFAULT);
}
return LIST_PIXELS_DEFAULT;
}

}