Skip to content

Commit

Permalink
Specify the saved file name
Browse files Browse the repository at this point in the history
Instead of using the dataset name within the URL, it utilizes a property of the JSON file for it's saved file name.
  • Loading branch information
AvocadoMoon committed Mar 28, 2024
1 parent b2d56b8 commit 9f9db4c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@
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.real.DoubleType;
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 @@ -37,14 +32,15 @@ public class SimResultsLoader {
private String s3ObjectKey;
private URI uri;
private String dataSetChosen;
private String uriSafeDataSetChosen;
private String userSetFileName;

public SimResultsLoader(){

}

public SimResultsLoader(String stringURI){
public SimResultsLoader(String stringURI, String userSetFileName){
uri = URI.create(stringURI);
this.userSetFileName = userSetFileName;
setURI(uri);
}

Expand Down Expand Up @@ -124,30 +120,29 @@ public void setSelectedLocalFile(File selectedLocalFile){

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

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);
return ImageJFunctions.wrap((CachedCellImg<DoubleType, ?>) N5Utils.open(n5AmazonS3Reader, dataSetChosen), userSetFileName);
}

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

public void setDataSetChosen(String dataSetChosen) throws UnsupportedEncodingException {
public void setDataSetChosen(String dataSetChosen) {
this.dataSetChosen = dataSetChosen;
uriSafeDataSetChosen = URLEncoder.encode(dataSetChosen, "UTF-8");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void actionPerformed(ActionEvent e) {
ArrayList<SimResultsLoader> filesToOpen = new ArrayList<>();
for(int row: exportListTable.getSelectedRows()){
String uri = n5ExportTableModel.getRowData(row).uri;
SimResultsLoader simResultsLoader = new SimResultsLoader(uri);
SimResultsLoader simResultsLoader = new SimResultsLoader(uri, n5ExportTableModel.getRowData(row).savedFileName);
filesToOpen.add(simResultsLoader);
}
openN5FileDataset(filesToOpen, openInMemory.isSelected());
Expand All @@ -289,7 +289,7 @@ public void actionPerformed(ActionEvent e) {
} else if (e.getSource().equals(useN5Link)) {
remoteFileSelection.setVisible(true);
} else if (e.getSource().equals(remoteFileSelection.submitS3Info)) {
SimResultsLoader simResultsLoader = new SimResultsLoader(remoteFileSelection.getS3URL());
SimResultsLoader simResultsLoader = new SimResultsLoader(remoteFileSelection.getS3URL(), "");
openN5FileDataset(new ArrayList<SimResultsLoader>(){{add(simResultsLoader);}}, openInMemory.isSelected());
remoteFileSelection.setVisible(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testS3Client() throws IOException {

final String s3ProxyURI = "http://localhost:4000/" + this.n5FileName + "?datasetName=" + datasetName;

SimResultsLoader simResultsLoader = new SimResultsLoader(s3ProxyURI);
SimResultsLoader simResultsLoader = new SimResultsLoader(s3ProxyURI, "");

// Environment variables are set in github actions VM

Expand All @@ -95,7 +95,7 @@ public void testS3Client() throws IOException {
public void testS3AlphaInstance() throws IOException{
N5DataSetFile[] n5DataSetFiles = N5DataSetFile.alphaTestFiles();
for(N5DataSetFile n5DataSetFile : n5DataSetFiles) {
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri);
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri, "");
simResultsLoader.createS3Client();
ImagePlus imagePlus = simResultsLoader.getImgPlusFromN5File();

Expand All @@ -110,7 +110,7 @@ public void testS3AlphaInstance() throws IOException{
public void testS3AlphaInstanceLoadedIntoMemory() throws IOException {
N5DataSetFile[] n5DataSetFiles = N5DataSetFile.alphaTestFiles();
for(N5DataSetFile n5DataSetFile : n5DataSetFiles) {
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri);
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri, "");
simResultsLoader.createS3Client();
ImagePlus imagePlus = simResultsLoader.getImgPlusFromN5File();
alphaStatsTest(new Duplicator().run(imagePlus), n5DataSetFile, stats.HISTMAX);
Expand Down

0 comments on commit 9f9db4c

Please sign in to comment.