关于我尝试读取 .FIT 文件时的异常

飞行员

我有一个包含 .FIT 文件的文件夹,我有这个代码来读取它们:

private static void readFitFile() {

    try {
        List<File> filesdebuglder = Files.walk(Paths.get(LOCAL_EXPANDED_DATA_PATH))
                                         .filter(Files::isRegularFile)
                                         .map(Path::toFile)
                                         .collect(Collectors.toList());
        System.out.println("There are " + filesdebuglder.size() + " .FIT files in folder " + LOCAL_EXPANDED_DATA_PATH);

        for (File afile : filesdebuglder) {
            System.out.println("Doing something cool with file " + afile.getName() + " ...");
            Fits fitsFile = new Fits(afile);
            ImageHDU imageHDU = (ImageHDU) fitsFile.readHDU();
            StandardImageTiler tiler = imageHDU.getTiler();
            // The exception happens with getCompleteImage() method
            float[][][][] tmp = (float[][][][]) tiler.getCompleteImage();
            System.out.println("tmp is " + tmp);
            float[][] imgData = tmp[0][0];
            System.out.println("imgData is " + imgData );


        }

    } catch (FitsException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch(ClassCastException e) {
        e.printStackTrace();
    }

}

我得到这个输出:

There are 409 .FIT files in folder resources/wetransfer-39ab61
Doing something cool with file RN20130622_1x1_SIN FILTRO_000102206.REDUCED.FIT ...
java.lang.ClassCastException: [[S cannot be cast to [[[[F
at com.aironman.deeplearning4j.TrainFITSImageNetVG16.readFitFile(TrainFITSImageNetVG16.java:86)
at com.aironman.deeplearning4j.TrainFITSImageNetVG16.main(TrainFITSImageNetVG16.java:68)

我正在使用最新的库依赖项,并且可以使用 GIMP 打开 FIT 文件。

    <dependency>
        <groupId>gov.nasa.gsfc.heasarc</groupId>
        <artifactId>nom-tam-fits</artifactId>
        <version>${nom-tam-fits.version}</version>
    </dependency>

<properties>
    <nom-tam-fits.version>1.15.2</nom-tam-fits.version>
</properties>

我正在尝试读取带有 .FIT 文件的文件夹并训练使用 deeplearning4j 来训练模型来识别这些文件的内容,但由于异常,我无法读取任何文件。我做错了什么?

编辑。这是正确的代码:

private static void readFitFile() {

    try {
        List<File> filesdebuglder = Files.walk(Paths.get(LOCAL_EXPANDED_DATA_PATH))
                                         .filter(Files::isRegularFile)
                                         // .filter(line -> line.getName(0).toString().contains(".FIT"))
                                         .map(Path::toFile)
                                         .collect(Collectors.toList());
        System.out.println("There are " + filesdebuglder.size() + " .FIT files in folder " + LOCAL_EXPANDED_DATA_PATH);
        int count = 1;
        for (File afile : filesdebuglder) {
            System.out.println("Doing something cool with file " + afile.getName() + " ...");
            Fits fitsFile = new Fits(afile);
            ImageHDU imageHDU = (ImageHDU) fitsFile.readHDU();
            StandardImageTiler tiler = imageHDU.getTiler();
            short[][] tmp = (short[][] ) tiler.getCompleteImage();
            System.out.println("tmp is " + tmp);
            short imgData = tmp[0][0];
            System.out.println("imgData is " + imgData );

            count ++;
            System.out.println("Done with the file " + afile.getName() + " ... " + count);
            fitsFile.close();

        }

    } catch (FitsException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch(ClassCastException e) {
        e.printStackTrace();
    }

}
水手安

tiler.getCompleteImage()返回一个2维short数组,并尝试将其转换为4维float数组。这在java中是不可能的。

见下文:

public static void main(String[] args) {
    Object s = new short[][]{};
    float[][][][] f = new float[][][][]{};
    f=(float[][][][])s;
}

java.lang.ClassCastException: [[S 不能转换为 [[[[F

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

CSV尝试读取时为空

尝试读取属性文件Spring时获取NULL

打开/尝试读取文件

Errno13,尝试读取文件时权限被拒绝

w +在尝试读取文件内容时不起作用

从API提取文件并进行管道传输会导致我尝试读取文件时找不到文件错误

尝试读取docx文件时出现UnicodeDecodeError

我在尝试读取本地JSON文件的python文件中收到MissingSchema错误

无效的操作配置:尝试读取任务定义工件文件时发生异常

为什么在我尝试读取文件时将其更改为null?

尝试读取文本文件

为什么在尝试读取.DOCX文件时出现异常?

尝试读取Excel文件时出现非法状态异常

尝试读取大文件时出现System.OutOfMemory异常

尝试读取int时出现InputMismatchException

我的bash脚本在Java尝试读取文件时将其锁定

尝试读取时找不到文件

当我尝试读取通过Intent传递的Vector时,出现NullPointerException

我尝试读取包含文件的数据文件夹,运行代码后显示异常

尝试读取文件并同时遍历

尝试读取压缩文件时提示

Android - InvalidKeySpecException - java lang 运行时异常 SSLInternal:TOO_LONG 尝试读取 .der 文件时

尝试读取文件时,我不断收到 java.io.FileNotFoundException

如果我尝试读取一个不存在的文件会抛出什么异常?

Read() 坚持尝试读取文件

尝试读取文件时出现奇怪的 NoSuchFileException

Pandas ImportError:当我尝试读取 .csv 文件时无法导入名称“OrderedDict”

当我尝试读取 2 个 txt 文件时,我的输出中显示了很多 0

调用类时尝试读取属性