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

Cutout2D partial behavior with mask #7659

Open
wtgee opened this issue Jul 17, 2018 · 4 comments
Open

Cutout2D partial behavior with mask #7659

wtgee opened this issue Jul 17, 2018 · 4 comments

Comments

@wtgee
Copy link
Contributor

wtgee commented Jul 17, 2018

Hello, I'm not sure if this is expected behavior but it threw me for a bit. astropy.nddata.Cutout2D works fine for data that is masked unless you are using mode="partial" and there is an overlap error, in which cases it seems to ignore the mask. Trivial example:

>>> import numpy as np
>>> from astropy.nddata import Cutout2D
>>> foo = np.random.randint(0, 1000, 36).reshape(6, 6)
[[362 291 495 381 915 328]
 [809 476   3  67 368 598]
 [910 936 782 677  31 988]
 [ 69 541 941 232 585 354]
 [431 219 140 673  75 224]
 [136 648 530 754 228 391]]

>>> bar = np.ma.array(foo, mask=foo > 300)
[[-- 291 -- -- -- --]
 [-- -- 3 67 -- --]
 [-- -- -- -- 31 --]
 [69 -- -- 232 -- --]
 [-- 219 140 -- 75 224]
 [136 -- -- -- 228 --]]

>>> Cutout2D(bar, (3, 3), size=5, mode='partial', fill_value=0).data
[[-- 3 67 -- --]
 [-- -- -- 31 --]
 [-- -- 232 -- --]
 [219 140 -- 75 224]
 [-- -- -- 228 --]]

>>> Cutout2D(bar, (4, 3), size=5, mode='partial', fill_value=0).data
[[  3  67 368 598   0]
 [782 677  31 988   0]
 [941 232 585 354   0]
 [140 673  75 224   0]
 [530 754 228 391   0]]

It's the last case that seems odd to me. If I've masked a bad pixel in there I would expect that to stay masked even with the fill_value.

Is this expected behavior?

@pllim
Copy link
Member

pllim commented Jul 17, 2018

@mwcraig or @MSeifert04 ?

@MSeifert04
Copy link
Contributor

MSeifert04 commented Jul 17, 2018

Good question. I don't think we explicitly support masked arrays there. Maybe accidentally but definitely not on purpose (there are no test cases for masked data and no docs on masked data).

It would be really nice if we could support masked arrays (if we can support them relatively easily). But that requires someone who wants to step up and completely checks the masked-array compatibility for Cutout2D and fix the "problems" (like the one you encountered). But I don't know how much work that'll be and I'm a bit stretched currently (no time to do this myself).

@wtgee
Copy link
Contributor Author

wtgee commented Jul 17, 2018

Ok, thanks @MSeifert04. I suppose for now the best plan would be to do the cutout and then use one of the bbox_original properties to apply the mask after the fact.

I'll read through the docs and see if there isn't a good place to add some kind of sentence or note that mentions that masks are not explicitly supported yet. And maybe if I magically find time I'll take a stab at looking over the related code.

I will leave open in case it's helpful but feel free to close. Cheers!

@MSeifert04
Copy link
Contributor

MSeifert04 commented Jul 21, 2018

@wtgee I don't think we should close this. I think there could be lots of use-cases for masked array cutouts.

It's just that it's not a bug. However it's a totally fine feature-request (at least if one interprets the title and original post that way). :)

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

No branches or pull requests

4 participants