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

to_image changes image mode #2300

Open
gerritholl opened this issue Nov 28, 2022 · 1 comment
Open

to_image changes image mode #2300

gerritholl opened this issue Nov 28, 2022 · 1 comment

Comments

@gerritholl
Copy link
Collaborator

Describe the bug

Calling to_image changes a dataset with mode P to one with mode L.

To Reproduce

import xarray as xr
from trollimage.xrimage import XRImage
from satpy.writers import to_image
da = xr.DataArray(
        data=[[[1, 2, 3], [4, 5, 6]]],
        dims=("bands", "y", "x"),
        coords={"bands": ["P"]},
        attrs={"mode": "P"})
im = to_image(da)
print(im.mode)
# direct does retain it
im = XRImage(da)
print(im.mode)

Expected behavior

Expected output:

P
P

Actual results

Actual output:

L
P

Environment Info:

  • OS: openSUSE Leap 13.0
  • Satpy Version: v0.38.0-65-g6dfb9b93

Additional context

This happens due to the .squeeze() call in satpy.writers.to_image:

dataset = dataset.squeeze()

This deletes the bands dimension for mode P or L. Then XRImage.__init__ adds a bands dimension again with mode L.

The conversion presents an obstacle for handling P-mode images.

@djhoese
Copy link
Member

djhoese commented Nov 28, 2022

Wow nice catch! This looks like it was added in #83 in one of the first PRs adding dask/xarray support to Satpy.

I don't think we need the squeeze. Maybe try removing it and if tests pass then 👍

CC @mraspaud who originally added the code.

gerritholl added a commit to gerritholl/satpy that referenced this issue Aug 8, 2024
For ninjogeotiff mode p, force scale/offset to be 1 and 0, respectively.

As a workaround for pytroll#2300, do not
check image.mode, but use image.data.attrs["mode"] instead.
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

2 participants