rafaqz / Rasters.jl

Raster manipulation for the Julia language
MIT License
206 stars 36 forks source link

Feature request: `mask_and_scale` #702

Open vboussange opened 1 month ago

vboussange commented 1 month ago

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
rafaqz commented 1 month ago

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 commented 1 month ago

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

vboussange commented 1 month ago

Excellent!