Skip to content

FixedScaleOffset flattens arrays, breaking further image codecs #852

Open

Description

@raphaeljolivet

I've just noticed that FixedScaleOffset flattens arrays on encoding.

This is not stated in the documentation

This breaks further images encoding in the pipeline.

Minimal test to reproduce:

import numpy as np
from numcodecs import FixedScaleOffset
shape = (8, 4, 5)

x = (200.0 + np.arange(np.prod(shape), dtype=np.float32).reshape(shape) * 0.001)
fso = FixedScaleOffset(offset=200.0, scale=1000.0, dtype="<f4", astype="<u2")

# Expected  (8, 4, 5)
# Actuel (160, )
print(fso.shape)

Activity

  1. d-v-b commented on Aug 3, 2026

    @d-v-b
    Contributor

    that's an unfortunate bug! how are you using FixedScaleOffset? If you are working with zarr v3 data, then there are alternatives that don't have this problem (the cast_value and scale_offset codecs, which are defined here: https://github.com/zarr-developers/cast-value.py)

  2. raphaeljolivet commented on Aug 3, 2026

    @raphaeljolivet
    Author

    Thanks, I didn't notice there were several scal/offset codec.
    I am working with both zarr2 and zarr3 actually.

    I will try wih this one.

    I still think this should be fixed, or stated in the documentation.
    Maybe an option like "keep_dimensions" would make the change backward compatible.

  3. d-v-b commented on Aug 3, 2026

    @d-v-b
    Contributor

    Maybe an option like "keep_dimensions" would make the change backward compatible.

    This makes sense, i don't have time to add this but if you want to open a PR i can review it

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions