-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addressed PR change requests from Victor
- Loading branch information
1 parent
57863a2
commit dd6c557
Showing
6 changed files
with
36 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Scaling and compressing methods for datacubes.""" | ||
|
||
import openeo | ||
|
||
|
||
def compress_uint16( | ||
cube: openeo.DataCube, alpha: float = 1.0, beta: float = 0.0 | ||
) -> openeo.DataCube: | ||
"""Scales the data linearly using the formula `output = (input * a) + b` and compresses values | ||
from float32 to uint16 for memory optimization. | ||
Parameters | ||
---------- | ||
cube : openeo.DataCube | ||
The input datacube to compress, only meteo data should be present. | ||
alpha : float, optional (default=1.0) | ||
The scaling factor. Values in the input datacube are multiplied by this coefficient. | ||
beta : float, optional (default=0.0) | ||
The offset. Values in the input datacube are added by this value. | ||
Returns | ||
------- | ||
cube : openeo.DataCube | ||
The datacube with the data linearly scaled and compressed to uint16 and rescaled frome. | ||
""" | ||
if ( | ||
alpha != 1.0 or beta != 0.0 | ||
): # Avoid adding a node in the computing graph if scaling is not necessary | ||
cube = (cube * alpha) + beta | ||
|
||
return cube.linear_scale_range(0, 65534, 0, 65534) |