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

Codec for LogScale #661

Open
gauteh opened this issue Nov 28, 2024 · 4 comments
Open

Codec for LogScale #661

gauteh opened this issue Nov 28, 2024 · 4 comments
Labels
New codec Suggestion for a new codec

Comments

@gauteh
Copy link

gauteh commented Nov 28, 2024

Hi,

We're thinking about how to improve compression of values of ocean models with large value spans. We would like to encode them using a log-scale/ln-scale. Would it be interesting to add official support for a LogScale(base, offset,etc..) codec?

Regards, Gaute

@ehgus
Copy link
Contributor

ehgus commented Nov 30, 2024

I don't know the details of the ocean model, but the floating-point number expression seems reasonable in your case.
Floating point separately saves exponents and fractions according to IEEE 754.
By doing so, significant digits are saved even for large numbers.
I think you can achieve the similar thing using less precise floating point expression.

@gauteh
Copy link
Author

gauteh commented Dec 1, 2024

That's a very good point. The next question is whether float16 is supported?

@ehgus
Copy link
Contributor

ehgus commented Dec 2, 2024

Numpy support np.float16 and try using AsType.

import numpy as np
from numcodecs import AsType
x = np.arange(100,120,2,dtype = np.float32)
f = AsType(encode_dtype=np.float16, decode_dtype=np.float32)
y = f.encode(x)
print(y, y.dtype)
# [100. 102. 104. 106. 108. 110. 112. 114. 116. 118.] float16

@ehgus
Copy link
Contributor

ehgus commented Dec 3, 2024

By the way, a similar issue was raised in #237.

@dstansby dstansby added the New codec Suggestion for a new codec label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New codec Suggestion for a new codec
Projects
None yet
Development

No branches or pull requests

3 participants