Skip to content

Commit

Permalink
Empty Tables should have the same return type as non-empty ones (#75)
Browse files Browse the repository at this point in the history
* Empty Tables should have the same return type.

* Convert bbox to Extent.
  • Loading branch information
evetion authored Mar 3, 2024
1 parent ec2c630 commit e069f1b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/GEDI/L2A.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ function points(
datetime = Dates.DateTime[],
intensity = Float32[],
sensitivity = Float32[],
surface = Bool[],
quality = Bool[],
surface = BitVector(),
quality = BitVector(),
nmodes = UInt8[],
track = Fill(track, 0),
strong_beam = Fill(power, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/ICESat-2/ATL06.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function points(
height = Float32[],
height_error = Float32[],
datetime = Dates.DateTime[],
quality = Bool[],
quality = BitVector(),
track = Fill(track, 0),
strong_beam = Fill(atlas_beam_type == "strong", 0),
detector_id = Fill(parse(Int8, spot_number), 0),
Expand Down
14 changes: 8 additions & 6 deletions src/ICESat-2/ATL08.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,24 @@ function points(
spot_number = read_attribute(group, "atlas_spot_number")::String

nt = (;
longitude = Float64[],
latitude = Float64[],
longitude = Float32[],
latitude = Float32[],
height = Float32[],
height_error = Float64[],
height_error = Float32[],
datetime = Dates.DateTime[],
quality = Bool[],
phr = Bool[],
quality = BitVector(),
phr = BitVector(),
sensitivity = Float32[],
scattered = Int8[],
saturated = Int8[],
clouds = Bool[],
clouds = BitVector(),
track = Fill(track, 0),
strong_beam = Fill(atlas_beam_type == "strong", 0),
classification = Fill("ground", 0),
height_reference = Float32[],
detector_id = Fill(parse(Int8, spot_number), 0),
reflectance = Float32[],
nphotons = Int32[],
)
return nt
end
Expand Down
2 changes: 1 addition & 1 deletion src/ICESat/GLAH06.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function points(
height = Float64[],
datetime = Dates.DateTime[],
# quality defined according [^1]
quality = Bool[],
quality = BitVector(),
height_reference = Float64[],
)
return Table(gt, granule)
Expand Down
6 changes: 3 additions & 3 deletions src/ICESat/GLAH14.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ function points(
stop = findlast(ind)

if isnothing(start)
@warn "no data found within bbox of track $track in $(file.filename)"
@warn "no data found within bbox in $(file.filename)"

gt = (
longitude = Float64[],
latitude = Float64[],
height = Float64[],
datetime = Dates.DateTime[],
quality = Bool[],
clouds = Bool[],
quality = BitVector(),
clouds = BitVector(),
height_reference = Float64[],
gain = Int32[],
reflectivity = Float64[],
Expand Down
2 changes: 1 addition & 1 deletion src/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Tables.columns(g::SpaceLiDAR.Table) = getfield(g, :table)

function materialize!(df::DataFrame)
for (name, col) in zip(names(df), eachcol(df))
if col isa CategoricalArray
if col isa CategoricalArray || eltype(col) <: CategoricalValue
df[!, name] = String.(col)
elseif col isa Fill
df[!, name] = Vector(col)
Expand Down
28 changes: 27 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ GEDI02_fn = download_artifact(v"0.1", "GEDI02_A_2019242104318_O04046_01_T02343_0
GLAH14_fn = download_artifact(v"0.1", "GLAH14_634_1102_001_0071_0_01_0001.H5")
GLAH06_fn = download_artifact(v"0.1", "GLAH06_634_2131_002_0084_4_01_0001.H5")

empty_bbox = (min_x = 4.0, min_y = 40.0, max_x = 5.0, max_y = 50.0)
empty_bbox = (min_x = 0.0, min_y = 0.0, max_x = 0.0, max_y = 0.0)
empty_extent = convert(Extent, empty_bbox)

@testset "SpaceLiDAR.jl" begin

Expand Down Expand Up @@ -159,6 +160,10 @@ empty_bbox = (min_x = 4.0, min_y = 40.0, max_x = 5.0, max_y = 50.0)
df = DataFrame(SL.points(g))
dff = DataFrame(g)
@test isequal(df, dff)

points = SL.points(g)
epoints = SL.points(g, ; bbox = empty_extent)
@test typeof(points) == typeof(epoints)
end

@testset "GLAH14" begin
Expand All @@ -179,6 +184,11 @@ empty_bbox = (min_x = 4.0, min_y = 40.0, max_x = 5.0, max_y = 50.0)
df = DataFrame(points)
dff = DataFrame(g)
@test isequal(df, dff)


points = SL.points(g)
epoints = SL.points(g, ; bbox = empty_extent)
@test typeof(points) == typeof(epoints)
end

@testset "ATL03" begin
Expand Down Expand Up @@ -210,6 +220,10 @@ empty_bbox = (min_x = 4.0, min_y = 40.0, max_x = 5.0, max_y = 50.0)
@test df.classification isa CategoricalVector{String,Int8}
SL.materialize!(df)
@test df.classification isa Vector{String}

points = SL.points(g)
epoints = SL.points(g, ; bbox = empty_extent)
@test typeof(points) == typeof(epoints)
end

@testset "ATL06" begin
Expand All @@ -229,6 +243,10 @@ empty_bbox = (min_x = 4.0, min_y = 40.0, max_x = 5.0, max_y = 50.0)
df = reduce(vcat, DataFrame.(points))
dff = DataFrame(g6)
@test isequal(df, dff)

points = SL.points(g6)
epoints = SL.points(g6, ; bbox = empty_extent)
@test typeof(points) == typeof(epoints)
end

@testset "ATL08" begin
Expand Down Expand Up @@ -259,6 +277,10 @@ empty_bbox = (min_x = 4.0, min_y = 40.0, max_x = 5.0, max_y = 50.0)

ps = SL.points(g; highres = true)
@test length(ps[1].longitude) == (998 * 5)

points = SL.points(g)
epoints = SL.points(g, ; bbox = empty_extent)
@test typeof(points) == typeof(epoints)
end

@testset "ATL12" begin
Expand Down Expand Up @@ -302,6 +324,10 @@ empty_bbox = (min_x = 4.0, min_y = 40.0, max_x = 5.0, max_y = 50.0)
df = reduce(vcat, DataFrame.(SL.points(gg)))
dff = DataFrame(gg)
@test isequal(df, dff)

points = SL.points(gg)
epoints = SL.points(gg, ; bbox = empty_extent)
@test typeof(points) == typeof(epoints)
end

@testset "Geometry" begin
Expand Down

0 comments on commit e069f1b

Please sign in to comment.