-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
266 additions
and
203 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "Rasters" | ||
uuid = "a3a2b9e3-a471-40c9-b274-f788e487c689" | ||
authors = ["Rafael Schouten <[email protected]>"] | ||
version = "0.11.4" | ||
version = "0.11.8" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
|
@@ -82,6 +82,7 @@ ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" | |
CFTime = "179af706-886a-5703-950a-314cd64e0468" | ||
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
GeoDataFrames = "62cb38b5-d8d2-4862-a48e-6a340996859f" | ||
GRIBDatasets = "82be9cdb-ee19-4151-bdb3-b400788d9abc" | ||
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" | ||
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" | ||
|
@@ -94,4 +95,4 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | |
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Aqua", "ArchGDAL", "CFTime", "CoordinateTransformations", "DataFrames", "GeometryBasics", "GRIBDatasets", "NCDatasets", "Plots", "RasterDataSources", "SafeTestsets", "Shapefile", "Statistics", "Test", "ZarrDatasets"] | ||
test = ["Aqua", "ArchGDAL", "CFTime", "CoordinateTransformations", "DataFrames", "GeoDataFrames", "GeometryBasics", "GRIBDatasets", "NCDatasets", "Plots", "RasterDataSources", "SafeTestsets", "Shapefile", "Statistics", "Test", "ZarrDatasets"] |
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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,33 @@ | ||
using DimensionalData | ||
|
||
fractional_resample(x, res; kw...) = fractional_resample(x; res, kw...) | ||
fractional_resample(xs::RasterStackOrArray...; kw...) = fractional_resample(xs; kw...) | ||
function fractional_resample(ser::AbstractRasterSeries, args...; kw...) | ||
map(x -> resample(x, args...; kw...), ser) | ||
end | ||
function fractional_resample(A::AbstractRaster; | ||
categories::NamedTuple, to=nothing, res=nothing, size=nothing | ||
) | ||
ds = _extent2dims(to; size, res, crs(A)) | ||
shared_dims = commondims(A, ds) | ||
isintervals(shared_dims) || throw(ArgumentError("Fractional resampling only supported for `Intervals`.")) | ||
outputdims = setdims(dims(A), ds) | ||
outputdata = Array{typeof(categories)}(undef, outputdims) | ||
output = rebuild(A; data=outputdata, dims=outputdims, refdims=()) | ||
map(DimIndices(otherdims(A, ds))) do D | ||
slice = view(A, D...) | ||
fractions = read_fractions(slice, categories, weights) | ||
end | ||
end | ||
|
||
function read_fractions(slice, categories, weights, indices::CartesianIndices) | ||
vals = view(slice, indices) | ||
map(categories) do c | ||
sum(zip(vals, weights)) do (v, w) | ||
_compare(c, v) * w | ||
end / sum(weights) | ||
end | ||
end | ||
|
||
_compare(c::Interval, v) = v in c | ||
_compare(c, v) = v == c |
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 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
Oops, something went wrong.