diff --git a/src/IFTPipeline.jl b/src/IFTPipeline.jl index aeb21d2d..c5613abf 100644 --- a/src/IFTPipeline.jl +++ b/src/IFTPipeline.jl @@ -21,6 +21,37 @@ include("feature-extraction.jl") include("tracker.jl") include("h5.jl") +const iftversion = [] +function __init__() + function getiftversion() + deps = Pkg.dependencies() + iftversion = [] + for (_, dep) in deps + dep.is_direct_dep || continue + dep.version === nothing && continue + dep.name != "IceFloeTracker" && continue + push!(iftversion, dep.version) + break + end + + # For CI tests where IceFloeTracker is not a dependency + try + ift = iftversion[1] + catch + return "unknown" + end + + ift = iftversion[1] + maj = Int(ift.major) + min = Int(ift.minor) + patch = Int(ift.patch) + return "v$maj.$min.$patch" + end + + push!(iftversion, getiftversion()) + return nothing +end + export cache_vector, sharpen, sharpen_gray, preprocess, @@ -40,7 +71,8 @@ export cache_vector, sharpen, mkclitrack!, mkfilenames, makeh5files, - getlatlon + getlatlon, + iftversion export IceFloeTracker end diff --git a/src/h5.jl b/src/h5.jl index cf841af7..27b73b84 100644 --- a/src/h5.jl +++ b/src/h5.jl @@ -1,28 +1,3 @@ -function getiftversion() - deps = Pkg.dependencies() - iftversion = [] - for (_, dep) in deps - dep.is_direct_dep || continue - dep.version === nothing && continue - dep.name != "IceFloeTracker" && continue - push!(iftversion, dep.version) - break - end - - # For CI tests where IceFloeTracker is not a dependency - try - ift = iftversion[1] - catch - return "unknown" - end - - ift = iftversion[1] - maj = Int(ift.major) - min = Int(ift.minor) - patch = Int(ift.patch) - return "v$maj.$min.$patch" -end - """ makeh5filename(imgfname, ts) @@ -125,7 +100,7 @@ The `index` group contains the spatial coordinates in the source image coordinat function makeh5files(; pathtosampleimg::String, resdir::String) latlondata = getlatlon(pathtosampleimg) - iftversion = getiftversion() + iftver = iftversion[1] ptpath = joinpath(resdir, "passtimes.jls") passtimes = deserialize(ptpath) @@ -153,7 +128,7 @@ function makeh5files(; pathtosampleimg::String, resdir::String) # Add top-level attributes attrs(file)["fname_reflectance"] = reflectance_refs[i] attrs(file)["fname_truecolor"] = truecolor_refs[i] - attrs(file)["iftversion"] = iftversion + attrs(file)["iftversion"] = iftver attrs(file)["crs"] = latlondata["crs"] attrs(file)["reference"] = "https://doi.org/10.1016/j.rse.2019.111406" attrs(file)["contact"] = "mmwilhelmus@brown.edu" diff --git a/test/test-h5.jl b/test/test-h5.jl index f59de688..01f1d15f 100644 --- a/test/test-h5.jl +++ b/test/test-h5.jl @@ -10,7 +10,7 @@ getcorners(m) = [m[1, 1], m[end, end]] latcorners = getcorners(latlondata["latitude"]) loncorners = getcorners(latlondata["longitude"]) -iftversion = IFTPipeline.getiftversion() +_iftversion = IFTPipeline.iftversion[1] ptpath = joinpath(resdir, "passtimes.jls") passtimes = deserialize(ptpath) @@ -44,7 +44,7 @@ h5path = joinpath(resdir, "hdf5-files", "20220914T1244.aqua.labeled_image.250m.h @test typeof(fid) == HDF5.File # top level attributes - @test attrs(fid)["iftversion"] == iftversion + @test attrs(fid)["iftversion"] == _iftversion @test attrs(fid)["fname_reflectance"] == reflectance_refs[1] @test attrs(fid)["fname_truecolor"] == truecolor_refs[1] @test attrs(fid)["crs"] == latlondata["crs"]