Java Code Examples for org.scijava.Context#dispose()
The following examples show how to use
org.scijava.Context#dispose() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScijavaKernel.java From scijava-jupyter-kernel with Apache License 2.0 | 6 votes |
public static void main(String... args) { final Context context = new Context(); // Remove the Display and Results post-processors to prevent output // windows from being displayed final PluginService pluginService = context.service(PluginService.class); final PluginInfo<SciJavaPlugin> display = pluginService.getPlugin(DisplayPostprocessor.class); final PluginInfo<SciJavaPlugin> results = pluginService.getPlugin(ResultsPostprocessor.class); pluginService.removePlugin(display); pluginService.removePlugin(results); JupyterService jupyter = context.service(JupyterService.class); jupyter.runKernel(args); context.dispose(); }
Example 2
Source File: TestScriptEngine.java From scijava-jupyter-kernel with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws ScriptException { // Only for testing purpose Context context = new Context(); ScriptService scriptService = context.getService(ScriptService.class); ScriptLanguage scriptLanguage = scriptService.getLanguageByName("python"); ScriptEngine engine = scriptLanguage.getScriptEngine(); Object result = engine.eval("p=999\n555"); System.out.println(result); scriptService = context.getService(ScriptService.class); scriptLanguage = scriptService.getLanguageByName("python"); engine = scriptLanguage.getScriptEngine(); result = engine.eval("555"); System.out.println(result); context.dispose(); }
Example 3
Source File: AbstractSyntheticWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * @param configuration Configuration to use for saving * @return The {@link FileLocation} saeved to. */ public FileLocation testOverwritingBehavior(SCIFIOConfig configuration) throws IOException { Context ctx = new Context(); try { final FileLocation saveLocation = createTempFileLocation("test" + suffix); ImgSaver saver = new ImgSaver(ctx); ImgOpener opener = new ImgOpener(ctx); ImgPlus<?> sourceImg = opener.openImgs(new TestImgLocation.Builder() .name("testimg").pixelType("uint8").axes("X", "Y").lengths(100, 100) .build()).get(0); saver.saveImg(saveLocation, sourceImg, configuration); saver.saveImg(saveLocation, sourceImg, configuration); return saveLocation; } finally { ctx.dispose(); } }
Example 4
Source File: InstallScijavaKernel.java From scijava-jupyter-kernel with Apache License 2.0 | 5 votes |
public static void main(String... args) { Context context = new Context(); LogService log = context.service(LogService.class); log.setLevel(LogLevel.INFO); JupyterService jupyter = context.service(JupyterService.class); jupyter.installKernel(args); context.dispose(); }
Example 5
Source File: TestRunKernel.java From scijava-jupyter-kernel with Apache License 2.0 | 5 votes |
public static void main(final String[] args) { // Warning : if run from your IDE the classpath won't be set to your Fiji installation Context context = new Context(); JupyterService jupyter = context.service(JupyterService.class); jupyter.runKernel("jython", "info", ""); context.dispose(); }
Example 6
Source File: AbstractSyntheticWriterTest.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
public void testWriting(final ImgPlus<?> sourceImg, final SCIFIOConfig config) throws IOException { final FileLocation out = createTempFileLocation(suffix); final Context ctx = new Context(); new ImgSaver(ctx).saveImg(out, sourceImg, config); final ImgPlus<?> written = new ImgOpener(ctx).openImgs(out).get(0); ctx.dispose(); assertEquals(ImageHash.hashImg(written), ImageHash.hashImg(sourceImg)); }
Example 7
Source File: ConvertImg.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
private static void convertImg(final File file) throws Exception { final Context c = new Context(); final SCIFIOConfig config = new SCIFIOConfig().imgOpenerSetImgModes( ImgMode.ARRAY); final ImgPlus<?> img = new ImgOpener(c).openImgs(new FileLocation(file .getAbsolutePath()), config).get(0); final String outPath = file.getParent() + File.separator + "out_" + img .getName(); new ImgSaver(c).saveImg(new FileLocation(outPath), img); c.dispose(); }
Example 8
Source File: AxisGuesserTest.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
/** Method for testing pattern guessing logic. */ @Test public void testAxisguessing() throws FormatException, IOException { final Context context = new Context(); final SCIFIO scifio = new SCIFIO(context); final LogService log = scifio.log(); final DataHandleService dataHandleService = context.getService( DataHandleService.class); final URL resource = this.getClass().getResource( "img/axisguesser/test_stack/img_000000000_Cy3_000.tif"); final FileLocation file = new FileLocation(resource.getFile()); final String pat = scifio.filePattern().findPattern(file); if (pat == null) log.info("No pattern found."); else { assertEquals("Wrong pattern:", "img_00000000<0-1>_Cy3_00<0-4>.tif", pat); final FilePattern fp = new FilePattern(file, pat, dataHandleService); assertTrue(fp.isValid()); final Location id = fp.getFiles()[0]; // read dimensional information from first file final Reader reader = scifio.initializer().initializeReader(id); final AxisType[] dimOrder = reader.getMetadata().get(0).getAxes().stream() .map(CalibratedAxis::type).toArray(AxisType[]::new); final long sizeZ = reader.getMetadata().get(0).getAxisLength(Axes.Z); final long sizeT = reader.getMetadata().get(0).getAxisLength(Axes.TIME); final long sizeC = reader.getMetadata().get(0).getAxisLength( Axes.CHANNEL); final boolean certain = reader.getMetadata().get(0).isOrderCertain(); assertArrayEquals("Dimension Order", new AxisType[] { Axes.X, Axes.Y }, dimOrder); assertFalse(certain); assertEquals(1, sizeZ); assertEquals(1, sizeT); assertEquals(1, sizeC); // guess axes final AxisGuesser ag = new AxisGuesser(fp, dimOrder, sizeZ, sizeT, sizeC, certain); // output results final String[] blocks = fp.getBlocks(); final String[] prefixes = fp.getPrefixes(); final AxisType[] axes = ag.getAxisTypes(); final AxisType[] newOrder = ag.getAdjustedOrder(); final boolean isCertain = ag.isCertain(); assertFalse(isCertain); assertEquals("<0-1>", blocks[0]); assertEquals("img_00000000", prefixes[0]); assertEquals(Axes.Z, axes[0]); assertEquals("<0-4>", blocks[1]); assertEquals("_Cy3_00", prefixes[1]); assertEquals(Axes.TIME, axes[1]); assertArrayEquals(dimOrder, newOrder); } context.dispose(); }
Example 9
Source File: AxisGuesserTest.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
@Test public void testAxisguessing2() throws FormatException, IOException { final Context context = new Context(); final SCIFIO scifio = new SCIFIO(context); final LogService log = scifio.log(); final DataHandleService dataHandleService = context.getService( DataHandleService.class); final URL resource = this.getClass().getResource( "img/axisguesser/leica_stack/leica_stack_Series014_z000_ch00.tif"); final FileLocation file = new FileLocation(resource.getFile()); final String pat = scifio.filePattern().findPattern(file); if (pat == null) log.info("No pattern found."); else { assertEquals("Wrong pattern:", "leica_stack_Series014_z00<0-2>_ch00.tif", pat); final FilePattern fp = new FilePattern(file, pat, dataHandleService); assertTrue(fp.isValid()); final Location id = fp.getFiles()[0]; // read dimensional information from first file final Reader reader = scifio.initializer().initializeReader(id); final AxisType[] dimOrder = reader.getMetadata().get(0).getAxes().stream() .map(CalibratedAxis::type).toArray(AxisType[]::new); final long sizeZ = reader.getMetadata().get(0).getAxisLength(Axes.Z); final long sizeT = reader.getMetadata().get(0).getAxisLength(Axes.TIME); final long sizeC = reader.getMetadata().get(0).getAxisLength( Axes.CHANNEL); final boolean certain = reader.getMetadata().get(0).isOrderCertain(); assertArrayEquals("Dimension Order", new AxisType[] { Axes.X, Axes.Y }, dimOrder); assertFalse(certain); assertEquals(1, sizeZ); assertEquals(1, sizeT); assertEquals(1, sizeC); // guess axes final AxisGuesser ag = new AxisGuesser(fp, dimOrder, sizeZ, sizeT, sizeC, certain); // output results final String[] blocks = fp.getBlocks(); final String[] prefixes = fp.getPrefixes(); final AxisType[] axes = ag.getAxisTypes(); final AxisType[] newOrder = ag.getAdjustedOrder(); final boolean isCertain = ag.isCertain(); assertFalse(isCertain); assertEquals("<0-2>", blocks[0]); assertEquals("leica_stack_Series014_z00", prefixes[0]); assertEquals(Axes.Z, axes[0]); assertArrayEquals(dimOrder, newOrder); } context.dispose(); }
Example 10
Source File: TestInstallKernel.java From scijava-jupyter-kernel with Apache License 2.0 | 3 votes |
public static void main(String... args) { String pythonBinaryPath = "/home/hadim/local/conda/bin/python"; Context context = new Context(); JupyterService jupyter = context.service(JupyterService.class); ScriptService scriptService = context.service(ScriptService.class); //jupyter.installKernel("groovy", "info", pythonBinaryPath); System.out.println(scriptService.getLanguages()); context.dispose(); }