Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Last active September 23, 2020 21:25
Show Gist options
  • Save bogovicj/d022e17abcf05324f1427aa59e208abe to your computer and use it in GitHub Desktop.
Save bogovicj/d022e17abcf05324f1427aa59e208abe to your computer and use it in GitHub Desktop.
a groovy script that reproduces some aws errors in sept 2020
import org.janelia.saalfeldlab.n5.N5Reader;
import org.janelia.saalfeldlab.n5.N5TreeNode;
import org.janelia.saalfeldlab.n5.imglib2.N5Utils;
import org.janelia.saalfeldlab.n5.metadata.*;
import org.janelia.saalfeldlab.n5.s3.N5AmazonS3Reader;
import net.imglib2.util.Intervals;
import com.amazonaws.services.s3.*;
import com.amazonaws.regions.Regions;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import se.sawano.java.text.AlphanumericComparator;
import javax.swing.tree.DefaultMutableTreeNode;
import java.io.IOException;
import java.nio.file.Paths;
import java.text.Collator;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Optional;
def discover( N5Reader n5, node ){
if( !node.isDataset )
{
for ( String childGroup in n5.list( node.path ) )
{
String childPath = Paths.get( node.path, childGroup ).toString();
println( " discover recursion: " + childPath );
N5TreeNode childNode = new N5TreeNode( childPath, n5.datasetExists( childPath ) );
node.children.add( childNode );
discover( n5, childNode );
}
}
}
def parseMetadata( N5Reader n5, N5TreeNode node, N5MetadataParser parser )
{
for ( N5TreeNode childNode in node.children){
parseMetadata( n5, childNode, parser );
}
try
{
node.metadata = parser.parseMetadata( n5, node );
}
catch( Exception e ) {}
println( " parse " + node.path );
println( " -> " + (node.metadata==null) );
}
uriString = "s3://janelia-cosem-datasets-dev/jrc_ctl-id8-1/jrc_ctl-id8-1.n5/fibsem/aligned/s5";
bucketName = "janelia-cosem-datasets-dev";
//datasetName = "jrc_ctl-id8-1/jrc_ctl-id8-1.n5/fibsem/aligned/s5";
datasetName = "jrc_ctl-id8-1/jrc_ctl-id8-1.n5";
objectName = datasetName + "/attributes.json";
blockTestdatasetName = "jrc_ctl-id8-1/jrc_ctl-id8-1.n5/fibsem/aligned/s5";
gsonBuilder = N5Metadata.getGsonBuilder();
s3 = AmazonS3ClientBuilder.standard().withRegion( Regions.US_EAST_1 )
.withCredentials( new StaticCredentialsProvider( new AnonymousAWSCredentials()))
.build();
n5 = new N5AmazonS3Reader( s3, bucketName, "", gsonBuilder );
N5TreeNode root = new N5TreeNode( datasetName, n5.datasetExists( datasetName ));
println( root );
metaParser = new N5CosemMetadata()
println( "try discover" )
discover( n5, root )
println( "discover returned" )
println( "try parse" )
parseMetadata( n5, root, metaParser );
println( "parse returned" )
println( "try reading attrs" )
datasetAttributes = n5.getDatasetAttributes( blockTestdatasetName );
println( " worked? : " + (datasetAttributes != null) );
println( "attr reading returned" )
println( "try reading single block" )
block = n5.readBlock( blockTestdatasetName, datasetAttributes, [0,0,0] as long[] )
println( " worked? : " + (block != null) );
println( "single block reading returned" )
println( "try reading volume" )
img = N5Utils.open( n5, blockTestdatasetName );
println( " read volume size: " + Intervals.dimensionsAsIntArray( img ));
println( "volume reading returned" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment