Skip to content

Commit

Permalink
Merge pull request #39 from virtualcell/37-single-panel-ij-plugin
Browse files Browse the repository at this point in the history
37 single panel ij plugin
  • Loading branch information
AvocadoMoon committed Mar 26, 2024
2 parents 941e6fa + 191576a commit b2d56b8
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 94 deletions.
45 changes: 32 additions & 13 deletions view-simulation-results/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,46 +112,65 @@
<groupId>org.scijava</groupId>
<artifactId>scijava-plugins-commands</artifactId>
<scope>runtime</scope>
<version>0.2.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.imglib2/imglib2 -->
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/net.imglib2/imglib2-ij -->
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-ij</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5 -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5</artifactId>
<version>3.0.2</version>
<version>3.1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-imglib2 -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-imglib2</artifactId>
<version>5.0.0</version>
<version>6.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.imglib2/imglib2 -->
<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-aws-s3 -->
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
<version>6.1.0</version>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-aws-s3</artifactId>
<version>4.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/net.imglib2/imglib2-ij -->
<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-universe -->
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-ij</artifactId>
<version>2.0.0</version>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-universe</artifactId>
<version>1.3.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-zarr -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-zarr</artifactId>
<version>1.2.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-aws-s3 -->
<!-- https://mvnrepository.com/artifact/org.janelia.saalfeldlab/n5-ij -->
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-aws-s3</artifactId>
<artifactId>n5-ij</artifactId>
<version>4.0.0</version>
</dependency>




<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class N5ImageHandler implements Command, ActionListener {
public static final String formatName = "N5";
private SimResultsLoader simResultsLoader;
@Parameter
private LogService logService;
public LogService logService;

@Override
public void actionPerformed(ActionEvent e) {
Expand Down Expand Up @@ -117,13 +117,15 @@ private void enableCriticalButtons(boolean enable) {

@Override
public void run() {
this.vGui = new N5ViewerGUI(this);
this.vGui.localFileDialog.addActionListener(this);
this.vGui.okayButton.addActionListener(this);
// this.vGui.exportTableButton.addActionListener(this);

this.vGui.remoteFileSelection.submitS3Info.addActionListener(this);
this.vGui.mostRecentExport.addActionListener(this);
// this.vGui = new N5ViewerGUI(this);
// this.vGui.localFileDialog.addActionListener(this);
// this.vGui.okayButton.addActionListener(this);
//// this.vGui.exportTableButton.addActionListener(this);
//
// this.vGui.remoteFileSelection.submitS3Info.addActionListener(this);
// this.vGui.mostRecentExport.addActionListener(this);
N5ExportTable exportTable = new N5ExportTable(this);
exportTable.displayExportTable();
}

public void displayN5Dataset(ImagePlus imagePlus) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.AmazonS3URI;
import com.google.gson.GsonBuilder;
import ij.ImagePlus;
import net.imglib2.cache.img.CachedCellImg;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.type.numeric.integer.*;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatType;
import org.janelia.saalfeldlab.n5.N5FSReader;
import org.janelia.saalfeldlab.n5.N5KeyValueReader;
import org.janelia.saalfeldlab.n5.N5Reader;
import org.janelia.saalfeldlab.n5.ij.N5IJUtils;
import org.janelia.saalfeldlab.n5.imglib2.N5Utils;
import org.janelia.saalfeldlab.n5.s3.AmazonS3KeyValueAccess;
import org.janelia.saalfeldlab.n5.s3.N5AmazonS3Reader;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -32,6 +37,7 @@ public class SimResultsLoader {
private String s3ObjectKey;
private URI uri;
private String dataSetChosen;
private String uriSafeDataSetChosen;

public SimResultsLoader(){

Expand Down Expand Up @@ -90,25 +96,15 @@ public void createS3Client(){
createS3Client(uri.toString(), null, null);
}
public void createS3Client(HashMap<String, String> credentials, HashMap<String, String> endpoint){createS3Client(uri.toString(), credentials, endpoint);}
public ArrayList<String> getS3N5DatasetList(){
public ArrayList<String> getS3N5DatasetList() throws IOException {

// used as a flag to tell that remote access is occurring, and that there is no local files
selectedLocalFile = null;

try(N5AmazonS3Reader n5AmazonS3Reader = new N5AmazonS3Reader(this.s3Client, this.bucketName)) {
return new ArrayList<>(Arrays.asList(n5AmazonS3Reader.deepListDatasets(this.s3ObjectKey)));
}
}
public N5AmazonS3Reader getN5AmazonS3Reader(){
return new N5AmazonS3Reader(this.s3Client, this.bucketName, this.s3ObjectKey);
}

public N5FSReader getN5FSReader(){
return new N5FSReader(selectedLocalFile.getPath());

}

public ArrayList<String> getN5DatasetList(){
public ArrayList<String> getN5DatasetList() throws IOException {
// auto closes reader
try (N5FSReader n5Reader = new N5FSReader(selectedLocalFile.getPath())) {
String[] metaList = n5Reader.deepList("/");
Expand All @@ -125,49 +121,33 @@ public ArrayList<String> getN5DatasetList(){
public void setSelectedLocalFile(File selectedLocalFile){
this.selectedLocalFile = selectedLocalFile;
}
public File getSelectedLocalFile() {
return selectedLocalFile;
}

public ImagePlus getImgPlusFromN5File() throws IOException {
return getImgPlusFromN5File(dataSetChosen);
public ImagePlus getImgPlusFromLocalN5File() throws IOException {
N5Reader n5Reader = new N5FSReader(selectedLocalFile.getPath());
return ImageJFunctions.wrap((CachedCellImg<DoubleType, ?>) N5Utils.open(n5Reader, dataSetChosen), dataSetChosen);
}

public ImagePlus getImgPlusFromN5File(String selectedDataset) throws IOException {
N5Reader n5Reader = selectedLocalFile != null ? getN5FSReader() : getN5AmazonS3Reader();
// Theres definitly a better way to do this, I trie using a variable to change the cached cells first parameter type but it didn't seem to work :/
switch (n5Reader.getDatasetAttributes(selectedDataset).getDataType()){
case UINT8:
return ImageJFunctions.wrap((CachedCellImg<UnsignedByteType, ?>) N5Utils.open(n5Reader, selectedDataset), selectedDataset);
case UINT16:
return ImageJFunctions.wrap((CachedCellImg<UnsignedShortType, ?>)N5Utils.open(n5Reader, selectedDataset), selectedDataset);
case UINT32:
return ImageJFunctions.wrap((CachedCellImg<UnsignedIntType, ?>)N5Utils.open(n5Reader, selectedDataset), selectedDataset);
case INT8:
return ImageJFunctions.wrap((CachedCellImg<ByteType, ?>)N5Utils.open(n5Reader, selectedDataset), selectedDataset);
case INT16:
return ImageJFunctions.wrap((CachedCellImg<ShortType, ?>)N5Utils.open(n5Reader, selectedDataset), selectedDataset);
case INT32:
return ImageJFunctions.wrap((CachedCellImg<IntType, ?>)N5Utils.open(n5Reader, selectedDataset), selectedDataset);
case FLOAT32:
return ImageJFunctions.wrap((CachedCellImg<FloatType, ?>)N5Utils.open(n5Reader, selectedDataset), selectedDataset);
case FLOAT64:
return ImageJFunctions.wrap((CachedCellImg<DoubleType, ?>)N5Utils.open(n5Reader, selectedDataset), selectedDataset);
// final ARGBARGBDoubleConverter<ARGBDoubleType> converters = new ARGBARGBDoubleConverter<>();
// final CachedCellImg<DoubleType, ?> cachedCellImg = N5Utils.open(n5Reader, selectedDataset);
// return ImageJFunctions.showRGB(cachedCellImg, converters, "");
}
return null;
public ImagePlus getImgPlusFromN5File() throws IOException {
// AmazonS3KeyValueAccess amazonS3KeyValueAccess = new AmazonS3KeyValueAccess(s3Client, bucketName, false);
// N5KeyValueReader n5KeyValueReader = new N5KeyValueReader(amazonS3KeyValueAccess, s3ObjectKey, new GsonBuilder(), true);
N5AmazonS3Reader n5AmazonS3Reader = new N5AmazonS3Reader(s3Client, bucketName, "/" + s3ObjectKey);
return ImageJFunctions.wrap((CachedCellImg<DoubleType, ?>) N5Utils.open(n5AmazonS3Reader, dataSetChosen), dataSetChosen);
}

public void setURI(URI uri){
this.uri = uri;
if(!(uri.getQuery() == null)){
dataSetChosen = uri.getQuery().split("=")[1]; // query should be "dataSetName=name", thus splitting it by = and getting the second entry gives the name
uriSafeDataSetChosen = uri.getQuery().split("=")[1]; // query should be "dataSetName=name", thus splitting it by = and getting the second entry gives the name
try {
dataSetChosen = URLDecoder.decode(uriSafeDataSetChosen, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}

public void setDataSetChosen(String dataSetChosen){
public void setDataSetChosen(String dataSetChosen) throws UnsupportedEncodingException {
this.dataSetChosen = dataSetChosen;
uriSafeDataSetChosen = URLEncoder.encode(dataSetChosen, "UTF-8");
}
}
Loading

0 comments on commit b2d56b8

Please sign in to comment.