Skip to content

Add support for plugin preference #93

Closed

Description

@blink1073

It would be nice to be able to handle preferences for plugins.
For example, tifffile.py should be always used as the default plugin for TIF files, if available, since it handles the widest assortment of TIF foibles.
Also, the user should be able to specify the desired plugin three ways:

  • A global default
  • A default for a given file extension
  • As a keyword argument to imread or imwrite

Activity

  1. almarklein commented on Jul 4, 2015

    @almarklein
    Member

    The global preference order can be determined by the order in which plugins are registered, or imported in https://github.com/imageio/imageio/blob/master/imageio/plugins/__init__.py.

    If we put the tifffile import beforr the freeimage, it should be fine.

    How automatic format selection works: when a file should be read or written, imageio asks each format (a plugin provides one or more formats) whether it can handle it, in the order that they're registered. The first format that says it can do it, gets to do it. Formats can look at file extensions but most also inspects the first few bytes.

    The user can also provide the format explicitly as the second arg to imread or imwrite.

    So IIUC you propose to allow users to specify the plugins based on extensions too? I suppose we can do that, though I am not sure how necessary it is; for tiff we should just make tiffile the default, and if people really want to use freeimage, they can.

  2. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    But, then they wouldn't benefit from the wrappers you have in place.  

    —
    Sent from Mailbox

    On Sat, Jul 4, 2015 at 8:35 AM, Almar Klein [email protected]
    wrote:

    The global preference order can be determined by the order in which plugins are registered, or imported in https://github.com/imageio/imageio/blob/master/imageio/plugins/__init__.py.
    If we put the tifffile import beforr the freeimage, it should be fine.
    How automatic format selection works: when a file should be read or written, imageio asks each format (a plugin provides one or more formats) whether it can handle it, in the order that they're registered. The first format that says it can do it, gets to do it. Formats can look at file extensions but most also inspects the first few bytes.
    The user can also provide the format explicitly as the second arg to imread or imwrite.

    So IIUC you propose to allow users to specify the plugins based on extensions too? I suppose we can do that, though I am not sure how necessary it is; for tiff we should just make tiffile the default, and if people really want to use freeimage, they can.

    Reply to this email directly or view it on GitHub:
    #93 (comment)

  3. almarklein commented on Jul 4, 2015

    @almarklein
    Member

    Sorry, I don't follow ...

  4. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    If the user knows that the only way to open their particular files properly is to use a specific plugin, they should be able to select that plugin.  The plugin is guaranteed to have uniform behavior with other plugins in imageio.  If they wanted to use the other library to load it (such as astropy), they could do so, but then they just find ways not to use imageio directly...

    —
    Sent from Mailbox

    On Sat, Jul 4, 2015 at 8:41 AM, Almar Klein [email protected]
    wrote:

    Sorry, I don't follow ...

    Reply to this email directly or view it on GitHub:
    #93 (comment)

  5. almarklein commented on Jul 4, 2015

    @almarklein
    Member

    So, you mean that imageio.imread('myfile.tif', 'tifffile') is not sufficient, because the user might be using astropy.imread('myfile.tif'), which might use imageio, but now there is no way to specify the plugin?

  6. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    Let's say tifffile were not the first plugin. If the user had a TIFF file that freeimage could not load, they would be sunk, unless they could use imageio.imread('myfile.tif', use_plugin='tifffile').

  7. west-rynes commented on Jul 4, 2015

    @west-rynes
    Contributor

    @blink1073 what you are saying imageio.imread('myfile.tif', 'tifffile') does already work. A user can specify the plugin as the 2nd argument. Right @almarklein?

  8. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    The docstring is not clear enough in this regard, if that is the case.  

    —
    Sent from Mailbox

    On Sat, Jul 4, 2015 at 11:46 AM, Anthony Tanbakuchi
    [email protected] wrote:

    @blink1073 what you are saying imageio.imread('myfile.tif', 'tifffile') does already work. A user can specify the plugin as the 2nd argument. Right @almarklein?

    Reply to this email directly or view it on GitHub:
    #93 (comment)

  9. almarklein commented on Jul 4, 2015

    @almarklein
    Member

    http://imageio.readthedocs.org/en/latest/userapi.html#imageio.imread

    Mmm, maybe it can be more clear how the format can be specified, perhaps with an example.

    BTW: if there are two plugins that can read the same format, the "best" one should be tried first. tiffile > freeimage, ffmpeg > avbin.

  10. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    Agreed. You're also missing the word "plugin" in the description of format.

  11. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    Or, I am really confused and just need to read the source at this point.

  12. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    Okay, so a plugin registers one or more formats that each have one or more possible extensions.

  13. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    So in the case of astropy, we would register a gdal format.

  14. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    Okay, I think this is fine as long as you expose a list of available formats by name.

    Right now it is available as [f.name for f in imageio.formats._formats], but perhaps this could be imageio.available_formats. This would also show the order of precedence.

  15. blink1073 commented on Jul 4, 2015

    @blink1073
    Author

    I will submit a PR if you agree.

  16. almarklein commented on Jul 4, 2015

    @almarklein
    Member

    There's a list in the docs, but to get a list from the repl would be good, yes.

  17. almarklein commented on Dec 6, 2016

    @almarklein
    Member

    This is implemented in #167:

    • There is an env variable IMAGEIO_FORMAT_ORDER, it is split on commas and fed to ...
    • which ends up in imageio.formats.sort(...), which sorts the plugins so that plugin selection can be influenced.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions