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

'NoData' area is not black(clean) in the Sentinel-2 MSI output #1727

Closed
yukaribbba opened this issue Jun 12, 2021 · 10 comments · Fixed by #1628
Closed

'NoData' area is not black(clean) in the Sentinel-2 MSI output #1727

yukaribbba opened this issue Jun 12, 2021 · 10 comments · Fixed by #1628

Comments

@yukaribbba
Copy link
Contributor

Describe the bug
I generate an image with fill_value=0 option, but the result is 1. This will cause problems when doing mosaic.
image

Without fill_value=0, there should be an alpha band with transparent area, however the outcome is black this time. Also the alpha band is completely white.
image

This happens on every 'edge' dataset I've tested, whether atmospheric corrected or not.

To Reproduce

#!/usr/bin/env python
from satpy import Scene, find_files_and_readers
files = find_files_and_readers(base_dir="/mnt/hgfs/Downloads/Sat/",
                               reader='msi_safe')
scn = Scene(filenames=files)
composite = 'true_color_raw'
scn.load([composite])
scn.save_dataset(composite, filename='{name}_{start_time:%Y%m%d_%H%M%S}.tif', writer='geotiff', base_dir="/mnt/hgfs/Downloads/Sat/", num_threads=8, compress=None)

Expected behavior
'NoData' area should be set correctly.

Environment Info:

  • OS: Ubuntu 20.04 64bit
  • Satpy Version: 0.29

Additional context
Add any other context about the problem here.

@mraspaud
Copy link
Member

Thanks @yukaribbba for reporting this issue.

It is strange, but maybe the no data value is wrongly assigné in the msi safe reader?

I will try to have a look on Monday if no one beats me to it.

@yukaribbba
Copy link
Contributor Author

@mraspaud Thanks. I just discovered it yesterday but I think it could’ve been here for some time since it also exists in the images generated several months ago.

@mraspaud
Copy link
Member

Ah, the problem is that the data is integers. We should convert it to floats in the reader.

@mraspaud
Copy link
Member

@yukaribbba ok, I had a better look, and the problem is simply that the no-data value is never defined in the reader. According to the MTD file, it should be zero. I don't have much time right now, so if you want to give it a try... it's just about replacing zeros in the data with np.nan.

@yukaribbba
Copy link
Contributor Author

@mraspaud Sorry I'm not good at coding...so could you give me more hints about this? Thanks

@mraspaud
Copy link
Member

I was thinking that around here: https://github.com/pytroll/satpy/blob/main/satpy/readers/msi_safe.py#L79
we should add something like data = da.where(data > 0, data, np.nan)

But I can try to do a PR later today

@yukaribbba
Copy link
Contributor Author

@mraspaud I just found an image created last April, by 0.20 or 0.21, not sure. No problem there. So maybe it's due to the changes of some dependencies?

@mraspaud
Copy link
Member

@yukaribbba I now completed the PR I made earlier (#1628) and added the masking of the invalid data. I also added tests, so hopefully that PR can now be merged. Would you mind testing this and tell me if it fixes your problem?

@yukaribbba
Copy link
Contributor Author

@mraspaud It truely works. I've tested about 100 datasets and both issues got fixed. Thank you!

@mraspaud
Copy link
Member

Thanks for testing! I will merge the PR now.

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

Successfully merging a pull request may close this issue.

2 participants