HDFGroup / hdf5-json

Specification and tools for representing HDF5 in JSON
https://hdf5-json.readthedocs.io
Other
72 stars 25 forks source link

"jsontoh5 data/json/comp_complex.json" error #73

Open ajelenak opened 2 years ago

ajelenak commented 2 years ago

jsontoh5 data/json/comp_complex.json command fails with this error:

ValueError: setting an array element with a sequence.

The error comes when converting this dataset's value (relevant HDF5/JSON content only) to a NumPy array:

        "a4afebb4-9b72-11ec-b0a3-8c8590747994": {
            "alias": [
                "/phony_compound_var"
            ],
            "shape": {
                "class": "H5S_SIMPLE",
                "dims": [
                    2
                ]
            },
            "type": {
                "class": "H5T_COMPOUND",
                "fields": [
                    {
                        "name": "yy",
                        "type": {
                            "base": {
                                "class": "H5T_COMPOUND",
                                "fields": [
                                    {
                                        "name": "x",
                                        "type": {
                                            "class": "H5T_COMPOUND",
                                            "fields": [
                                                {
                                                    "name": "i",
                                                    "type": {
                                                        "base": "H5T_STD_I16LE",
                                                        "class": "H5T_INTEGER"
                                                    }
                                                },
                                                {
                                                    "name": "j",
                                                    "type": {
                                                        "base": "H5T_STD_I32LE",
                                                        "class": "H5T_INTEGER"
                                                    }
                                                }
                                            ]
                                        }
                                    },
                                    {
                                        "name": "y",
                                        "type": {
                                            "base": {
                                                "base": "H5T_IEEE_F64LE",
                                                "class": "H5T_FLOAT"
                                            },
                                            "class": "H5T_ARRAY",
                                            "dims": [
                                                2
                                            ]
                                        }
                                    }
                                ]
                            },
                            "class": "H5T_ARRAY",
                            "dims": [
                                2
                            ]
                        }
                    }
                ]
            },
            "value": [
                [
                    [
                        [
                            [
                                1,
                                200000
                            ],
                            [
                                -100000.285657,
                                3.1415926
                            ]
                        ],
                        [
                            [
                                2,
                                400000
                            ],
                            [
                                200000.151617,
                                273.15
                            ]
                        ]
                    ]
                ],
                [
                    [
                        [
                            [
                                3,
                                600000
                            ],
                            [
                                -200000.285657,
                                6.1415926
                            ]
                        ],
                        [
                            [
                                4,
                                800000
                            ],
                            [
                                400000.151617,
                                476.15
                            ]
                        ]
                    ]
                ]
            ]
        }

jsontoh5 version of the value as a Python object is:

[((((1, 200000), (-100000.285657, 3.1415926)), ((2, 400000), (200000.151617, 273.15))),), ((((3, 600000), (-200000.285657, 6.1415926)), ((4, 800000), (400000.151617, 476.15))),)]

The NumPy dataset's value (from h5py) is:

[([((1, 200000), [-1.00000286e+05,  3.14159260e+00]), ((2, 400000), [ 2.00000152e+05,  2.73150000e+02])],), ([((3, 600000), [-2.00000286e+05,  6.14159260e+00]), ((4, 800000), [ 4.00000152e+05,  4.76150000e+02])],)]

They differ in how the H5T_ARRAY components of the dataset's value are converted. jsontoh5 exclusively uses tuples while NumPy prefers the list in this case. The dataset's NumPy dtype in both cases is the same:

dtype([('yy', [('x', [('i', '<i2'), ('j', '<i4')]), ('y', '<f8', (2,))], (2,))])