CenterForDigitalHumanities / SpectralRTI_Toolkit

Process Spectral RTI Images in ImageJ
GNU General Public License v3.0
1 stars 0 forks source link

Mystery Crash on New Data #75

Closed thanneken closed 6 years ago

thanneken commented 6 years ago

Last week at the workshop someone brought data that should have worked, but didn't. I just ran it under Windows and got further than I did on Linux, but not very far. It asked for the static raking light positions and created the directory "AccurateColorRTI" and then failed with the following in console:

[INFO] A directory has been created for lossless static raking images at G:\Projects\CCR\CCR_048v\StaticRaking\
[INFO] Gathered 54 raking image selections.
[INFO] [true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true]
[INFO] A directory has been created for Accurate Color RTI at G:\Projects\CCR\CCR_048v\AccurateColorRTI\
[INFO] Set stack pieces...
[INFO] On hem capture index 0
Jun 11, 2018 3:47:11 PM com.slu.imagej.SpectralRTI_Toolkit run
SEVERE: null
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:1927)
    at com.slu.imagej.SpectralRTI_Toolkit.theMacro_tested(SpectralRTI_Toolkit.java:980)
    at com.slu.imagej.SpectralRTI_Toolkit.run(SpectralRTI_Toolkit.java:1827)
    at org.scijava.command.CommandModule.run(CommandModule.java:199)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
    at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

[WARNING] Finished processing the run().

On Linux it goes only as far as creating the directory for StaticRaking then fails as follows:

[INFO] A directory has been created for lossless static raking images at /home/thanneken/Documents/2018/CCR/CCR_048v/StaticRaking/
Jun 11, 2018 4:51:34 PM com.slu.imagej.SpectralRTI_Toolkit run
SEVERE: null
java.lang.NullPointerException
    at com.slu.imagej.SpectralRTI_Toolkit.theMacro_tested(SpectralRTI_Toolkit.java:445)
    at com.slu.imagej.SpectralRTI_Toolkit.run(SpectralRTI_Toolkit.java:1787)
    at org.scijava.command.CommandModule.run(CommandModule.java:199)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
    at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

[WARNING] Finished processing the run().

I don't find these error messages meaningful. The first thing I checked was to see if the tif files had any headers that confused ImageJ. That was not the case. Then I tested the data with the macro and it worked fine. The filenames are a little different but within spec (no spaces or special characters).

Any ideas?

thehabes commented 6 years ago

I assume it revolves around

int extensionIndex = listOfHemisphereCaptures[i].getName().indexOf(".");
if (extensionIndex != -1)
                   {
                       String simpleName1 = listOfHemisphereCaptures[i].getName().substring(0, extensionIndex); 
                       String simpleName2 = projectName + "_";
                       String simpleName3 = simpleName1.substring(simpleName1.indexOf("RTI-"));
                       filePath = projectDirectory+"AccurateColorRTI"+File.separator+"AccurateColor_"+simpleName2+simpleName3;
                       simpleImageName = "AccurateColor_"+simpleName2+simpleName3;
                   }

where String simpleName3 = simpleName1.substring(simpleName1.indexOf("RTI-")); ended up as String simpleName3 = simpleName1.substring(-1); which would throw that error.

The names of your paths in your hemisphere folder did not contains "RTI-". This was a way of grabbing the file names correctly in previous runs. The check for it here is no longer needed. I will rewrite these spots.

thehabes commented 6 years ago

The second error happens from the differences in how OS's handle falsiness. In this case, I believe it revolves around

                File[] listOfTransmissiveSources_dir = new File[0];
                List<String> listOfTransmissiveSources_list = new ArrayList<>();
                List<String> listOfTransmissiveSources_short = new ArrayList<>();
                String[] listOfTransmissiveSources;
                String[] listOfTransmissiveSourcePaths;
                listOfTransmissiveSources = new String[transmissive_gamma_dir.listFiles().length];
                listOfTransmissiveSourcePaths = new String[transmissive_gamma_dir.listFiles().length];
                if(transmissive_gamma_dir.exists() && transmissive_gamma_dir.length() > 0){
                    listOfTransmissiveSources_dir=transmissive_gamma_dir.listFiles();
                    for (File f : listOfTransmissiveSources_dir){
                        listOfTransmissiveSources_list.add(f.toString());
                        listOfTransmissiveSources_short.add("..."+f.getName());
                    }
                    if(shortName){
                       listOfTransmissiveSources_short.toArray(listOfTransmissiveSources);
                    }
                    else{
                       listOfTransmissiveSources_list.toArray(listOfTransmissiveSources); 
                    }
                    listOfTransmissiveSources_list.toArray(listOfTransmissiveSourcePaths);
                }
                else{
                    listOfTransmissiveSources = new String[0];
                }
                Arrays.sort(listOfTransmissiveSourcePaths);
                Arrays.sort(listOfTransmissiveSources);

It needs to be rewritten to explicitly avoid null scenarios like

                File[] listOfTransmissiveSources_dir = new File[0];
                List<String> listOfTransmissiveSources_list = new ArrayList<>();
                List<String> listOfTransmissiveSources_short = new ArrayList<>();
                String[] listOfTransmissiveSources;
                String[] listOfTransmissiveSourcePaths;
                if(transmissive_gamma_dir.exists()){
                    listOfTransmissiveSources = new String[transmissive_gamma_dir.listFiles().length];
                    listOfTransmissiveSourcePaths = new String[transmissive_gamma_dir.listFiles().length];
                    if (transmissive_gamma_dir.length() > 0){
                        listOfTransmissiveSources_dir=transmissive_gamma_dir.listFiles();
                        for (File f : listOfTransmissiveSources_dir){
                            listOfTransmissiveSources_list.add(f.toString());
                            listOfTransmissiveSources_short.add("..."+f.getName());
                        }
                        if(shortName){
                           listOfTransmissiveSources_short.toArray(listOfTransmissiveSources);
                        }
                        else{
                           listOfTransmissiveSources_list.toArray(listOfTransmissiveSources); 
                        }
                        listOfTransmissiveSources_list.toArray(listOfTransmissiveSourcePaths);
                    }
                }
                else{
                    listOfTransmissiveSources = new String[0];
                    listOfTransmissiveSourcePaths = new String[0];
                }
thehabes commented 6 years ago

These rewrites did not cause errors on Windows 7, it should be safe to test for the same errors produced before with Linux once I upload the new .jar

thanneken commented 6 years ago

That seems to have done the trick. Successful run on Linux...