Skip to content

Commit

Permalink
Merge branch 'main' into line_extract
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz authored Dec 8, 2024
2 parents 23c7ace + 5aa8914 commit a8ffc09
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 31 deletions.
4 changes: 2 additions & 2 deletions ext/RastersArchGDALExt/gdal_source.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ function RA._dims(raster::AG.RasterDataset, crs=nokw, mappedcrs=nokw)
xorder = xstep > 0 ? ForwardOrdered() : ReverseOrdered()
yorder = ystep > 0 ? ForwardOrdered() : ReverseOrdered()
# Create lookup index. LinRange is easiest always the right size after fp error
xindex = LinRange(xmin, xmax, xsize)
yindex = LinRange(ymax, ymin, ysize)
xindex = range(; start=xmin, stop=xmax, length=xsize)
yindex = range(; start=ymax, stop=ymin, length=ysize)

# Define `Projected` lookups fo X and Y dimensions
xlookup = Projected(xindex;
Expand Down
4 changes: 4 additions & 0 deletions src/series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ DD.modify(f, A::AbstractRasterSeries) = map(child -> modify(f, child), values(A)
RasterSeries(paths::AbstractArray{<:AbstractString}, dims; child, duplicate_first, kw...)
RasterSeries(path:::AbstractString, dims; ext, separator, child, duplicate_first, kw...)
RasterSeries(objects::AbstractBasicDimArray; kw...)
Concrete implementation of [`AbstractRasterSeries`](@ref).
A `RasterSeries` is an array of `Raster`s or `RasterStack`s, along some dimension(s).
Expand Down Expand Up @@ -127,6 +129,8 @@ function RasterSeries(
) where {A<:AbstractArray{T,N},D<:Tuple,R<:Tuple} where {T,N}
RasterSeries{T,N,D,R,A}(data, dims, refdims)
end
RasterSeries(data::DD.AbstractBasicDimArray; kw...) =
RasterSeries(data, dims(data); kw...)
function RasterSeries(data::AbstractArray{<:Union{AbstractRasterStack,AbstractRaster}}, dims;
refdims=()
)
Expand Down
4 changes: 2 additions & 2 deletions src/sources/grd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ function _dims(A::RasterDiskArray{GRDsource}, crs=nokw, mappedcrs=nokw)
# Not fully implemented yet
xy_metadata = _metadatadict(GRDsource())

xindex = LinRange(xbounds[1], xbounds[2] - xspan, xsize)
yindex = LinRange(ybounds[2] + yspan, ybounds[1], ysize)
xindex = range(; start=xbounds[1], stop=xbounds[2] - xspan, length=xsize)
yindex = range(; start=ybounds[2] + yspan, stop=ybounds[1], length=ysize)

xlookup = Projected(xindex;
order=GRD_X_ORDER,
Expand Down
59 changes: 33 additions & 26 deletions test/resample.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Rasters, ArchGDAL, GeoInterface, Extents
using Rasters, ArchGDAL, GeoInterface
using Extents
using Test
using Rasters.Lookups
import DimensionalData: @dim, YDim
Expand Down Expand Up @@ -135,31 +136,6 @@ include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))
@test eltype(r1) == UInt8
end

@testset "resample to the same size or resolution leaves raster unchanged" begin
res = 2
ys = LinRange((90 - res / 2):-res:(-90 + res / 2))
xs = LinRange((-180 + res / 2):res:(180 - res / 2))

point_dims = Y(ys), X(xs)
interval_dims = Y(ys; sampling=Intervals(Center())), X(xs; sampling=Intervals(Center()))
rev_y_point_dims = Y(reverse(ys)), X(xs)
rev_y_interval_dims = reverse(interval_dims[1]), interval_dims[2]
rev_x_point_dims = Y(ys), X(reverse(xs))
rev_x_interval_dims = interval_dims[1], reverse(interval_dims[2])
test_dims = (point_dims, interval_dims, rev_x_point_dims, rev_x_interval_dims, rev_y_point_dims, rev_y_interval_dims)
ds_fwd = point_dims; f = identity
ds_fwd = point_dims; f = reverse

for ds_fwd in test_dims, f in (identity, reverse)
ds = f(ds_fwd)
raster = Raster(rand(ds), crs=EPSG(4326), missingval=NaN)
resampled_res = resample(raster; res)
resampled_size = resample(raster; size=size(raster), method=:near)
@test resampled_res == resampled_size == raster
@test dims(resampled_res) == dims(resampled_size) == dims(raster)
end
end

@testset "dimensions matcha after resampling with only `to`" begin
# some weird dimensions
to = (
Expand All @@ -176,4 +152,35 @@ include(joinpath(dirname(pathof(Rasters)), "../test/test_utils.jl"))
@test dims(resampled_3D, (1,2)) == to
@test dims(resampled_3D, Z) == Z(1:2)
end

@testset "resample to the same size or resolution leaves raster unchanged" begin
res = 2
ys = range(; start=(90 - res / 2), step=-res, stop=(-90 + res / 2))
xs = range(; start=(-180 + res / 2), step=res, stop=(180 - res / 2))

point_dims = Y(ys), X(xs)
interval_dims = Y(ys; sampling=Intervals(Center())), X(xs; sampling=Intervals(Center()))
rev_y_point_dims = Y(reverse(ys)), X(xs)
rev_y_interval_dims = reverse(interval_dims[1]), interval_dims[2]
rev_x_point_dims = Y(ys), X(reverse(xs))
rev_x_interval_dims = interval_dims[1], reverse(interval_dims[2])
test_dims = (point_dims, interval_dims, rev_x_point_dims, rev_x_interval_dims, rev_y_point_dims, rev_y_interval_dims)
ds_fwd = point_dims; f = identity
ds_fwd = point_dims; f = reverse

ds = ds_fwd
raster = Raster(rand(ds), crs=EPSG(4326), missingval=NaN)
resampled_res = resample(raster; res)
resampled_size = resample(raster; size=size(raster), method=:near)
@test resampled_res == resampled_size == raster
@test dims(resampled_res) == dims(resampled_size) == dims(raster)

ds = reverse(ds_fwd)
raster = Raster(rand(ds), crs=EPSG(4326), missingval=NaN)
resampled_res = resample(raster; res)
resampled_size = resample(raster; size=size(raster), method=:near)
@test resampled_res == resampled_size == raster
@test dims(resampled_res) == dims(resampled_size) == dims(raster)
end

end
1 change: 1 addition & 0 deletions test/series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ stack1 = RasterStack(r1, r2; name=(:r1, :r2))
stack2 = RasterStack(r1a, r2a; name=(:r1, :r2))
dates = [DateTime(2017), DateTime(2018)]
ser = RasterSeries([stack1, stack2], Ti(dates))
@test RasterSeries(DimArray([stack1, stack2],Ti(dates))) == ser
@test issorted(dates)

@testset "getindex returns the currect types" begin
Expand Down
2 changes: 1 addition & 1 deletion test/sources/gdal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ gdalpath = maybedownload(url)
@test order(dims(rast)) == (ForwardOrdered(), ForwardOrdered())
@test span(rast) == (Regular(1.0), Regular(1.0))
@test sampling(rast) == (Intervals(Start()), Intervals(Start()))
@test index(rast) == (LinRange(0.0, 239.0, 240), LinRange(0.0, 179.0, 180))
@test index(rast) == (range(; start=0.0, stop=239.0, length=240), range(start=0.0, stop=179.0, length=180))
end

end
Expand Down

0 comments on commit a8ffc09

Please sign in to comment.