Skip to content

Add valid fill_value to Uint16 range reduction scale_offset codec example - #68

Open
bogovicj wants to merge 3 commits into
zarr-developers:mainfrom
bogovicj:scale_offset-fill_value
Open

Add valid fill_value to Uint16 range reduction scale_offset codec example#68
bogovicj wants to merge 3 commits into
zarr-developers:mainfrom
bogovicj:scale_offset-fill_value

Conversation

@bogovicj

Copy link
Copy Markdown

I think it would be informative to readers to emphasize the valid range that fill_value can take for the "Uint16 range reduction" example.

* also add brief explanatory sentence
@normanrz
normanrz requested a review from d-v-b July 21, 2026 05:35
### Uint16 range reduction

In this example, a `uint16` array with values in the range `[1000, 1255]` is shifted down by `1000` so that values fall in the range `[0, 255]`, then cast to `uint8` via the `cast_value` codec.
In this example, a `uint16` array with values in the range `[1000, 1255]` is shifted down by `1000` so that values fall in the range `[0, 255]`, then cast to `uint8` via the `cast_value` codec. Note that with these codecs,`fill_value` is constrained to the range `[1000, 1255]`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can handle fill values outside the decoded range of [1000, 1255] by prepending a cast_value codec with a scalar map that sends fill_value to -> 1256 on the encode path, and sends 1256 -> fill_value on the decode path. Would that example be helpful here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would make the transformation lossy because we would be squeezing 257 input values (256 consecutive numbers + fill value) into 256 outputs, so maybe we need to reduce the number of input values by 1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that example be helpful here?

Yes, I agree that would be useful too. I think it'd be useful to include two examples

  1. this one - with a "simple" cast_value codec that emphasizes the constraints on fill_value
  2. a more involved cast_value like what you suggest to make fill_value less constrained.'

If you agree, I can add (2).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so maybe we need to reduce the number of input values by 1

agreed. maybe we show that for what I'm calling example (2) above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be great!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, latest commit adds such an example, though as you'll see I decided to just map 0 -> 1000 without shrinkng the range of values as I feel it gets the point across, but feel free to edit if you prefer.

* prepend with cast_value with scalar_map enables use of any fill_value
Comment thread codecs/scale_offset/README.md Outdated
Co-authored-by: Davis Bennett <davis.v.bennett.git@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants