Image I/O Functions

Read all or parts of image files. Supports reading data from a few types of files, but full parameters and Image objects only from the ipole HDF5 format.

imtools.io.decode_all(bytes_dict)

Recursively un-bytes some HDF5 bytestrings for Python3 compatibility.

imtools.io.hdf5_to_dict(h5grp)

Recursively load group contents into nested dictionaries.

imtools.io.read(fname, **kwargs)

Read a file. In future will try to intelligently guess image/movie/etc

imtools.io.read_image(fname, name=None, load_fluid_header=False, parameters={}, format_hint='ipole', units='cgs', only_unpolarized=False)

Read image from the given path or file object.

Parameters
  • fname – name (preferably) of file. Limited support for hdf5 file objects if that’s useful for performance

  • name – Optionally add a name as an identifier in plots/text output

  • load_fluid_header – Whether to load all the GRMHD parameters in ipole HDF5 images

  • parameters – Anything that should be added to the Image parameters

  • format_hint

    Resolve ambiguous text file image formats. Currently used for:
    * “odyssey” to use odyssey format for 8-column files: alpha, beta, I, Q, U, V, unpol, tau
    * “ipole” to use ipole format for 8-column files: i, j, unpol, I, Q, U, V, tau

  • units – whether to renormalize

  • only_unpolarized – even if the image has polarization data, load just the unpolarized version into stokes I instead.

Returns

standard imtools.image.Image object read from file

Caveats of this function:

  • imtools expects the array to consist of CGS intensity values – some formats require renormalization after reading.

  • Filetype guessing is best-effort especially for text files. Parameters even more so. Use the format_hint.

  • non-square images are supported only in the ipole HDF5 format.

imtools.io.read_image_array(fname)

Sometimes you just need some numbers fast. Only supports ipole HDF5 format!

imtools.io.read_image_parameters(fname, load_fluid_header=False)

Read just the parameters dictionary from an ipole image file. Useful if reading many images run with the same parameters.