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

/compute transparent pixel, np.nan instead of zero #221

Closed
chapmanjacobd opened this issue Jul 8, 2021 · 3 comments
Closed

/compute transparent pixel, np.nan instead of zero #221

chapmanjacobd opened this issue Jul 8, 2021 · 3 comments
Labels
question Further information is requested

Comments

@chapmanjacobd
Copy link
Contributor

chapmanjacobd commented Jul 8, 2021

Looking over the expression parser I'm not sure if requesting nan squares is possible.

v1 * (v1 >= {filter_slider1[0]}) * (v1 <= {filter_slider1[1]})

This works great in general but I'm wondering if it would be possible to show a transparent pixel if the expression evaluates to 0.

in pseudo-code:

f"v1 if (v1 >= {filter_slider1[0]}) * (v1 <= {filter_slider1[1]}) else np.nan"
@chapmanjacobd chapmanjacobd changed the title /compute transparent pixel desiring np.nan instead of zero /compute transparent pixel, np.nan instead of zero Jul 8, 2021
@j08lue
Copy link
Collaborator

j08lue commented Jul 8, 2021

Nice case, @chapmanjacobd.

Maybe we could make this possible by adding a parameter that lets you specify a NaN / transparent value and mask with that after the expression got evaluated. By default, this could be the raster NaN value.

@j08lue j08lue added the question Further information is requested label Jul 8, 2021
@dionhaefner
Copy link
Collaborator

dionhaefner commented Jul 8, 2021

Now that #222 is merged, both invalid values (nan / inf) and masked values will be transparent. Most of the masked_* functions from numpy.ma are now allowed in expressions.

So your expression should reduce to a one-liner:

masked_outside(v1, lower, upper)

Could you try this and report back?

@chapmanjacobd
Copy link
Contributor Author

chapmanjacobd commented Jul 8, 2021

works great!!

    expr1 = f"masked_outside(v1, {filter_slider1[0]}, {filter_slider1[1]})"
    expr2 = f"masked_outside(v2, {filter_slider2[0]}, {filter_slider2[1]})"
    # expr = expr1
    expr = f"({expr1}) + ({expr2})"

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants