Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Jan 20, 2025
1 parent 4493974 commit 58bc86a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/methods/mosaic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,24 @@ Combine `regions` in `Raster` or `RasterStack` `x` using the function `f`.
# Example
Cut out Australia and Africa stacks, then combined them
into a single stack.
Cut out scandinavian countries and plot:
```jldoctest
using Rasters, RasterDataSources, ArchGDAL, Statistics, Plots
st = read(RasterStack(WorldClim{Climate}; month=1))
aus = st[X=100.0 .. 160.0, Y=-50.0 .. -10.0]
africa = st[X=-20.0 .. 60.0, Y=-40.0 .. 35.0]
mosaic!(first, st, aus, africa)
plot(st)
using Rasters, RasterDataSources, NaturalEarth, DataFrames
# Get climate data form worldclim
climate = RasterStack(WorldClim{Climate}, (:tmin, :tmax, :prec, :wind); month=July)
# And country borders from natural earth
countries = naturalearth("admin_0_countries", 110) |> DataFrame
# Cut out each country
country_climates = map(("Norway", "Denmark", "Sweden")) do name
country = subset(countries, :NAME => ByRow(==("Norway")))
trim(mask(climate; with=country); pad=10)
end
# Mosaic together to a single raster
scandinavia_climate = mosaic(first, country_climates)
# And plot
plot(scandinavia_climate)
savefig("build/mosaic_bang_example.png")
nothing
# output
```
Expand Down Expand Up @@ -204,7 +210,7 @@ function mosaic!(
end
# Where there is a known reduction operator we can apply each region as a whole
function _mosaic!(
f::Function, op::Function, dest::RasterStackOrArray, regions::Union{Tuple,AbstractArray};
f::Function, op, dest::RasterStackOrArray, regions::Union{Tuple,AbstractArray};
kw...
)
for region in regions
Expand Down

0 comments on commit 58bc86a

Please sign in to comment.