Rasters.jl icon indicating copy to clipboard operation
Rasters.jl copied to clipboard

Feature request: `mask_and_scale`

Open vboussange opened this issue 1 year ago • 3 comments
trafficstars

Hey there, rioxarray exposes an argument mask_and_scale when opening a raster, which lazily scales the raster using the scales and offsets in metadata. Could we have this option in Rasters.jl, possibly in the Raster function?

Here is a quick proposition:

function scale(raster::Raster)
   T = typeof(raster.metadata["scale"])
   (raster .|> T) .* raster.metadata["scale"] .+ raster.metadata["offset"]
end

vboussange avatar Jul 26 '24 13:07 vboussange

It's on the way!

See: https://github.com/rafaqz/Rasters.jl/pull/695

It's a bit trickier than that because it has to work lazily on larger than memory data, on RasterStack etc.

But it's pretty much there in the PR, just a few bugs to iron out.

rafaqz avatar Jul 26 '24 16:07 rafaqz

Also this will be applied as the default when scale and offset are set. Keywords can turn it off.

rafaqz avatar Jul 27 '24 23:07 rafaqz

Excellent!

vboussange avatar Jul 28 '24 04:07 vboussange