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

Allow vmin_vmax to be a callable #196

Open
ianhi opened this issue May 30, 2021 · 2 comments
Open

Allow vmin_vmax to be a callable #196

ianhi opened this issue May 30, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@ianhi
Copy link
Collaborator

ianhi commented May 30, 2021

Problem

You can specify vmin_vmax as a slider, and you can individual specify vmin and vmax as functions. But you cannot specify both vmin and vmax using a single function. It would be nice to be able to do something like this (percentile based thresholding)

def vmin_vmax(prange):
    return np.percentile(img, prange)

and then do iplt.imshow(img, prange(1,99,99), vmin_vmax=vmin_vmax)

Proposed Solution

Add yet more special casing to vmin_vmaxto allow this.

I think a check if it's a callable goes here: https://github.com/ianhi/mpl-interactions/blob/94cfc2a9d9f3be9091c47bf329ed2e309edbab94/mpl_interactions/controller.py#L110-L112

(and in mpl equivalent) and similarly here:
https://github.com/ianhi/mpl-interactions/blob/94cfc2a9d9f3be9091c47bf329ed2e309edbab94/mpl_interactions/controller.py#L154-L156

This will also require keeping tracking of which params the function accepts and should maintain the ability to access controls.params['vmin_vmax']

Additional context

@ianhi ianhi added the enhancement New feature or request label May 30, 2021
@ianhi
Copy link
Collaborator Author

ianhi commented May 30, 2021

I think I may have backed myself into a corner here where each controls object can only have a single vmin_vmax. This is because I really want to be able to do ctrls['vmin']

If vmin_vmax is a function then it should be possible to pass different functions to each iplt call.

def vmin_vmax1(...):

def vmin_vmax2(...):

ctrls = iplt.imshow(..., vmin_vmax = vmin_vmax1, ax = axs[0])
iplt.imshow(..., vmin_vmax = vmin_vmax2, ax = axs[1], controls=ctrls)

but if we allow that then there is no easy way to define ctrls['vmin']. I think this is an issue because this is the only dynamically defined kwarg that we have.

@ianhi
Copy link
Collaborator Author

ianhi commented May 30, 2021

Maybe the solution is to create a transformed kwarg object?

from mpl_interactions import transformed_kwarg, Controls

def vmin_vmax(prange):
    # do something complicated
    return (vmin, vmax)
vv_kwarg = transformed_kwarg('prange', vmin_vmax),  # just use signature inspect here?
# or maybe have `kwargs=None` which defaults to using signature inspect

Controls(prange= ('r', 1, 99, 99), vmin_vmax = vv_kwarg) # vmin = transformed_kwarg....

where the vmin = is a default transformation that magically does the right thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant