Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: read_odim_hdf5 - TypeError: 'numpy.float32' object cannot be interpreted as an integer #1408

Closed
Vforcell opened this issue Mar 29, 2023 · 7 comments · Fixed by #1425
Closed
Labels
Bug Issue in the Code

Comments

@Vforcell
Copy link
Contributor

Vforcell commented Mar 29, 2023

  • Py-ART version: 1.14.6
  • Python version: 3.11 (same with 3.10)
  • Operating System: Linux / Ubuntu

Description

An error is raised when using pyart.aux_io.odim_hdf5.read_odim_hdf5:

TypeError: 'numpy.float32' object cannot be interpreted as an integer

The line to blame is

start_time = datetime.datetime.utcfromtimestamp(start_epoch)

The datetime.datetime.utcfromtimestamp function doesn't seem to like numpy.float32 dtype anymore.

A fix (that worked for me) is to specify "float64" in the dtype of t_data, instead of "float32":

t_data = np.empty((total_rays,), dtype="float32")

@mgrover1
Copy link
Collaborator

Do you have a sample file that could be used here? For testing?

@mgrover1 mgrover1 added the Bug Issue in the Code label Mar 29, 2023
@Vforcell
Copy link
Contributor Author

radar_file.zip

@Vforcell
Copy link
Contributor Author

Vforcell commented Apr 17, 2023

This ODIM .hdf5 file has been produced by the Météo-France quality control chain.

It might be that there is something with the file and the way it encodes time. But I don't see anything wrong on that part.

I think the problem is that float32 type has been somehow deprecated for datetime.datetime.utcfromtimestamp, or it messes up with it.

@kmuehlbauer
Copy link
Contributor

kmuehlbauer commented Apr 17, 2023

@Vforcell My guess, too, is that it's connected to the dtype. ODIM_H5 is referencing these values as array of double so float64 should work. Maybe this just surfaces now, where more systems really use 64bit resolution.

One special thing is still to this file as it contains a compound type dataset (legend) attached to data7. This part cannot be read by netCDF4, which has to kept in mind when exploring this via xarray or the like (using engine=netcdf4, it might work with engine=h5netcdf).

@tealmill
Copy link

tealmill commented May 3, 2023

ODIM spec explicitly states the time of the startazT and stopazT must be a double aka float64. The array initialization here will coerce it into an array of float32. This seems like a fairly straightforwardly a bug, that array should be initialized as float64 and changing it to such fixes this error.

@Vforcell
Copy link
Contributor Author

Vforcell commented May 3, 2023

@kmuehlbauer @tealmill thanks for your answers.

@mgrover1 thanks for the Fix being implemented.

Didn't know about the legend type not being read for my files. Thanks for noticing

@mgrover1
Copy link
Collaborator

mgrover1 commented May 3, 2023

@Vforcell testing on that file to make sure things are fixed before merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issue in the Code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants