-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore(deps)--update-ice-floe-tracker-to-0.6.…
…3-registry
- Loading branch information
Showing
10 changed files
with
143 additions
and
96 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
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,89 +1,122 @@ | ||
testlisteq = (a, b) -> @test Set(a) == Set(b) | ||
pathtosampleimg = joinpath(@__DIR__, "test_inputs/input_pipeline/20220914.aqua.falsecolor.250m.tiff") | ||
resdir = joinpath(dirname(pathtosampleimg), "h5") | ||
|
||
originalbbox = (latitude=[81, 79], longitude=[-22, -12]) | ||
|
||
latlondata = getlatlon(pathtosampleimg) | ||
|
||
getcorners(m) = [m[1, 1], m[end, end]] | ||
latcorners = getcorners(latlondata["latitude"]) | ||
loncorners = getcorners(latlondata["longitude"]) | ||
|
||
ptpath = joinpath(resdir, "passtimes.jls") | ||
passtimes = deserialize(ptpath) | ||
ptsunix = Int64.(Dates.datetime2unix.(passtimes)) | ||
|
||
fnpath = joinpath(resdir, "filenames.jls") | ||
truecolor_refs, falsecolor_refs = deserialize(fnpath) | ||
|
||
floespath = joinpath(resdir, "segmented_floes.jls") # for labeled_image | ||
floes = deserialize(floespath) | ||
|
||
propspath = joinpath(resdir, "floe_props.jls") | ||
props = deserialize(propspath) | ||
|
||
lb = label_components(floes[1]) | ||
|
||
makeh5files(; pathtosampleimg, resdir) | ||
|
||
h5path = joinpath(resdir, "hdf5-files", "20220914T1244.aqua.labeled_image.250m.h5") | ||
|
||
@testset "h5.jl" begin | ||
|
||
# validate computed lat/lon corners | ||
@test all(originalbbox.latitude .≈ round.(latcorners)) | ||
@test all(originalbbox.longitude .≈ round.(loncorners)) | ||
|
||
|
||
# open h5 file | ||
fid = h5open(h5path, "r") | ||
|
||
@test typeof(fid) == HDF5.File | ||
|
||
# top level attributes | ||
@test attrs(fid)["iftversion"] == string(IceFloeTracker.IFTVERSION) | ||
@test attrs(fid)["fname_falsecolor"] == falsecolor_refs[1] | ||
@test attrs(fid)["fname_truecolor"] == truecolor_refs[1] | ||
@test attrs(fid)["crs"] == latlondata["crs"] | ||
|
||
# groups | ||
testlisteq(keys(fid), ["floe_properties", "index"]) | ||
keys_index = [k for k in keys(fid["index"]) if k ∉ ["latitude", "longitude"]] | ||
testlisteq(keys_index, ["time", "x", "y"]) | ||
testlisteq(keys(fid["floe_properties"]), ["column_names", "labeled_image", "properties"]) | ||
|
||
# check index group datasets | ||
g = fid["index"] | ||
t = read(g["time"]) | ||
x = read(g["x"]) | ||
y = read(g["y"]) | ||
|
||
@test t == ptsunix[1] | ||
@test x == latlondata["X"] | ||
@test y == latlondata["Y"] | ||
|
||
# check floe_properties group datasets | ||
g = fid["floe_properties"] | ||
colnames = read(g["column_names"]) | ||
lb = read(g["labeled_image"]) | ||
props = read(g["properties"]) | ||
|
||
testlisteq(colnames, ["area", "convex_area", "major_axis_length", "minor_axis_length", "orientation", "perimeter", "latitude", "longitude", "x", "y"]) | ||
|
||
@test typeof(lb) == Matrix{UInt8} | ||
@test typeof(props) == Matrix{Float64} | ||
close(fid) | ||
|
||
@test_throws "can't be represented" choose_dtype(-1) | ||
@test choose_dtype(100) == UInt8 | ||
@test choose_dtype(300) == UInt16 | ||
@test choose_dtype(70_000) == UInt32 | ||
@test choose_dtype(BigInt(2)^64 - 1) == UInt64 | ||
@test choose_dtype(BigInt(2)^64) == UInt128 | ||
@test choose_dtype(BigInt(2)^128 - 1) == UInt128 | ||
@test_throws "can't be represented" choose_dtype(BigInt(2)^128) | ||
@testset "hdf5 export" begin | ||
@testset "normal case" begin | ||
testlisteq = (a, b) -> @test Set(a) == Set(b) | ||
pathtosampleimg = joinpath( | ||
@__DIR__, "test_inputs/input_pipeline/20220914.aqua.falsecolor.250m.tiff" | ||
) | ||
resdir = joinpath(dirname(pathtosampleimg), "h5") | ||
|
||
originalbbox = (latitude=[81, 79], longitude=[-22, -12]) | ||
|
||
latlondata = getlatlon(pathtosampleimg) | ||
|
||
getcorners(m) = [m[1, 1], m[end, end]] | ||
latcorners = getcorners(latlondata["latitude"]) | ||
loncorners = getcorners(latlondata["longitude"]) | ||
|
||
ptpath = joinpath(resdir, "passtimes.jls") | ||
passtimes = deserialize(ptpath) | ||
ptsunix = Int64.(Dates.datetime2unix.(passtimes)) | ||
|
||
fnpath = joinpath(resdir, "filenames.jls") | ||
truecolor_refs, falsecolor_refs = deserialize(fnpath) | ||
|
||
floespath = joinpath(resdir, "segmented_floes.jls") # for labeled_image | ||
floes = deserialize(floespath) | ||
|
||
propspath = joinpath(resdir, "floe_props.jls") | ||
props = deserialize(propspath) | ||
|
||
lb = label_components(floes[1]) | ||
|
||
makeh5files(; pathtosampleimg, resdir) | ||
|
||
h5path = joinpath(resdir, "hdf5-files", "20220914T1244.aqua.labeled_image.250m.h5") | ||
|
||
@testset "h5.jl" begin | ||
|
||
# validate computed lat/lon corners | ||
@test all(originalbbox.latitude .≈ round.(latcorners)) | ||
@test all(originalbbox.longitude .≈ round.(loncorners)) | ||
|
||
# open h5 file | ||
fid = h5open(h5path, "r") | ||
|
||
@test typeof(fid) == HDF5.File | ||
|
||
# top level attributes | ||
@test attrs(fid)["iftversion"] == string(IceFloeTracker.IFTVERSION) | ||
@test attrs(fid)["fname_falsecolor"] == falsecolor_refs[1] | ||
@test attrs(fid)["fname_truecolor"] == truecolor_refs[1] | ||
@test attrs(fid)["crs"] == latlondata["crs"] | ||
|
||
# groups | ||
testlisteq(keys(fid), ["floe_properties", "index"]) | ||
keys_index = [k for k in keys(fid["index"]) if k ∉ ["latitude", "longitude"]] | ||
testlisteq(keys_index, ["time", "x", "y"]) | ||
testlisteq( | ||
keys(fid["floe_properties"]), | ||
["column_names", "labeled_image", "properties"], | ||
) | ||
|
||
# check index group datasets | ||
g = fid["index"] | ||
t = read(g["time"]) | ||
x = read(g["x"]) | ||
y = read(g["y"]) | ||
|
||
@test t == ptsunix[1] | ||
@test x == latlondata["X"] | ||
@test y == latlondata["Y"] | ||
|
||
# check floe_properties group datasets | ||
g = fid["floe_properties"] | ||
colnames = read(g["column_names"]) | ||
lb = read(g["labeled_image"]) | ||
props = read(g["properties"]) | ||
|
||
testlisteq( | ||
colnames, | ||
[ | ||
"area", | ||
"convex_area", | ||
"major_axis_length", | ||
"minor_axis_length", | ||
"orientation", | ||
"perimeter", | ||
"latitude", | ||
"longitude", | ||
"x", | ||
"y", | ||
], | ||
) | ||
|
||
@test typeof(lb) == Matrix{UInt8} | ||
@test typeof(props) == Matrix{Float64} | ||
close(fid) | ||
|
||
@test_throws "can't be represented" choose_dtype(-1) | ||
@test choose_dtype(100) == UInt8 | ||
@test choose_dtype(300) == UInt16 | ||
@test choose_dtype(70_000) == UInt32 | ||
@test choose_dtype(BigInt(2)^64 - 1) == UInt64 | ||
@test choose_dtype(BigInt(2)^64) == UInt128 | ||
@test choose_dtype(BigInt(2)^128 - 1) == UInt128 | ||
@test_throws "can't be represented" choose_dtype(BigInt(2)^128) | ||
end | ||
|
||
# clean up | ||
rm(dirname(h5path); recursive=true) | ||
end | ||
@testset "empty props" begin | ||
example_data_dir = joinpath(test_data_dir, "cloudy") | ||
IFTPipeline.makeh5files_single(; | ||
passtime=Dates.DateTime("2006-05-13T14:55:34"), | ||
truecolor=joinpath(example_data_dir, "truecolor.tiff"), | ||
falsecolor=joinpath(example_data_dir, "falsecolor.tiff"), | ||
labeled=joinpath(example_data_dir, "labeled.tiff"), | ||
props=joinpath(example_data_dir, "labeled.props.csv"), | ||
output="example.h5", #mktemp()[1], | ||
) | ||
end | ||
end | ||
|
||
# clean up | ||
rm(dirname(h5path), recursive=true) |
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 @@ | ||
These data are from the Fram Strait, observed using Terra on 2006-05-13 and resolved at 250m. |
Binary file not shown.
Binary file not shown.
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 @@ | ||
"area","min_row","min_col","max_row","max_col","row_centroid","col_centroid","convex_area","label","major_axis_length","minor_axis_length","orientation","perimeter" |
Binary file not shown.
Binary file not shown.
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 @@ | ||
2006-05-13T14:55:34Z |
Binary file not shown.