Skip to content

Commit

Permalink
JZarrServiceImpl: Refactor fetching of ZarrArray and ZarrGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
dgault committed May 14, 2024
1 parent 7ab9c35 commit 93ee98d
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions src/loci/formats/services/JZarrServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@ public JZarrServiceImpl(String root) {
@Override
public void open(String file) throws IOException, FormatException {
currentId = file;
if (s3fs == null) {
zarrArray = ZarrArray.open(file);
}
else {
s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(file));
zarrArray = ZarrArray.open(s3fs);
}
zarrArray = getArray(file);
}

public void open(String id, ZarrArray array) {
Expand All @@ -109,15 +103,7 @@ public void open(String id, ZarrArray array) {
}

public Map<String, Object> getGroupAttr(String path) throws IOException, FormatException {
ZarrGroup group = null;
if (s3fs == null) {
group = ZarrGroup.open(path);
}
else {
s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path));
group = ZarrGroup.open(s3fs);
}
return group.getAttributes();
return getGroup(path).getAttributes();
}

public Map<String, Object> getArrayAttr(String path) throws IOException, FormatException {
Expand All @@ -129,31 +115,15 @@ public Map<String, Object> getArrayAttr(String path) throws IOException, FormatE
s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path));
array = ZarrArray.open(s3fs);
}
return array.getAttributes();
return getArray(path).getAttributes();
}

public Set<String> getGroupKeys(String path) throws IOException, FormatException {
ZarrGroup group = null;
if (s3fs == null) {
group = ZarrGroup.open(path);
}
else {
s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path));
group = ZarrGroup.open(s3fs);
}
return group.getGroupKeys();
return getGroup(path).getGroupKeys();
}

public Set<String> getArrayKeys(String path) throws IOException, FormatException {
ZarrGroup group = null;
if (s3fs == null) {
group = ZarrGroup.open(path);
}
else {
s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path));
group = ZarrGroup.open(s3fs);
}
return group.getArrayKeys();
return getGroup(path).getArrayKeys();
}

public DataType getZarrPixelType(int pixType) {
Expand Down Expand Up @@ -379,4 +349,27 @@ private String getZarrRoot(String path) {
return path.substring(0, path.indexOf(".zarr")+5);
}

private ZarrGroup getGroup(String path) throws IOException {
ZarrGroup group = null;
if (s3fs == null) {
group = ZarrGroup.open(path);
}
else {
s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path));
group = ZarrGroup.open(s3fs);
}
return group;
}

private ZarrArray getArray(String path) throws IOException {
ZarrArray array = null;
if (s3fs == null) {
array = ZarrArray.open(path);
}
else {
s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path));
array = ZarrArray.open(s3fs);
}
return array;
}
}

0 comments on commit 93ee98d

Please sign in to comment.