Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ctroupin committed Jan 30, 2025
1 parent a01c167 commit b82f51b
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 108 deletions.
11 changes: 5 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ APItoken = ENV["beaconAPItoken"];

# Define period of interest and domain
domain = [12.1, 17.85, 43.12, 45.95]
datestart = Dates.Date(1990, 1, 1)
dateend = Dates.Date(1991, 1, 1)
datestart = Dates.Date(2010, 1, 1)
dateend = Dates.Date(2011, 1, 1)

minlon = domain[1]
maxlon = domain[2]
minlat = domain[3]
maxlat = domain[4]
mindepth = 10. #Minimum water depth
maxdepth = 400.
mindepth = 10.0 #Minimum water depth
maxdepth = 400.0

const beacon_services = OrderedDict(
"Euro-Argo" => "https://beacon-argo.maris.nl",
Expand All @@ -31,10 +31,9 @@ const beacon_services = OrderedDict(
);

parameter1 = "TEMP"
parameter2 = "PSAL"

include("./test_CORA_Timeseries.jl")
include("./test_CORA_Profiles.jl")
include("./test_WOD.jl")
include("./test_SDN.jl")
include("./test_EuroArgo.jl")
include("./test_EuroArgo.jl")
104 changes: 68 additions & 36 deletions test/test_CORA_Profiles.jl
Original file line number Diff line number Diff line change
@@ -1,59 +1,91 @@

@testset "CORA profile download" begin
datasource = "CORA Profile"

query = DIVAndFairEase.prepare_query_new(datasource, parameter1, parameter2, datestart, dateend,
mindepth, maxdepth, minlon, maxlon, minlat, maxlat)

outputfile = tempname() * ".nc"

@time open(outputfile, "w") do io
r = HTTP.request("POST", joinpath(beacon_services[datasource], "api/query"),
["Content-type"=> "application/json",
"Authorization" => "Bearer $(APItoken)"
],
query,
response_stream=io);
@test r.status == 200
end

NCDataset(outputfile) do nc
@test length(nc["TEMP"][:]) == 1764
@test sort(nc["TEMP"][:])[3] == 8.839001f0
@test sort(nc["TIME"][:])[end] == DateTime("1990-12-19T00:00:00")
@test sort(nc["LONGITUDE"][:])[1] == 12.347
@test sort(nc["dataset_id"][:])[5] == 42773
end
end

@testset "CORA Profile query" begin
datasource = "CORA Profile"
dateref = Date(1950, 1, 1)
datestart = Dates.Date(2010, 1, 1)
dateend = Dates.Date(2012, 1, 1)

query = DIVAndFairEase.prepare_query_new(datasource, parameter1, parameter2, datestart, dateend,
mindepth, maxdepth, minlon, maxlon, minlat, maxlat)
query = DIVAndFairEase.prepare_query(
datasource,
parameter1,
datestart,
dateend,
mindepth,
maxdepth,
minlon,
maxlon,
minlat,
maxlat,
)

jsondata = JSON3.read(query)

@test length(keys(jsondata)) == 3
@test length(jsondata["output"]) == 1
@test jsondata["output"]["format"] == "netcdf"

@test jsondata["filters"][1]["for_query_parameter"] == "TIME"
@test jsondata["filters"][1]["min"] == "1990-01-01T00:00:00"
@test jsondata["filters"][1]["max"] == "1991-01-01T00:00:00"
@test jsondata["filters"][1]["for_query_parameter"] == "datetime"
@test jsondata["filters"][1]["min"] == Dates.format(datestart, "yyyy-mm-ddT00:00:00")
@test jsondata["filters"][1]["max"] == Dates.format(dateend, "yyyy-mm-ddT00:00:00")

@test jsondata["filters"][2]["for_query_parameter"] == "DEPTH"
@test jsondata["filters"][2]["min"] == mindepth
@test jsondata["filters"][2]["max"] == maxdepth
@test jsondata["filters"][2]["min"] == mindepth
@test jsondata["filters"][2]["max"] == maxdepth

@test jsondata["filters"][3]["for_query_parameter"] == "LONGITUDE"
@test jsondata["filters"][3]["min"] == minlon
@test jsondata["filters"][3]["max"] == maxlon

@test jsondata["query_parameters"][1]["column_name"] == parameter1
@test jsondata["query_parameters"][1]["alias"] == parameter1
@test jsondata["query_parameters"][5]["column_name"] == "LATITUDE"
@test jsondata["query_parameters"][5]["alias"] == "LATITUDE"

end
end

@testset "CORA profile download" begin
datasource = "CORA Profile"
parameter1 = "TEMP"

datestart = Dates.Date(2010, 1, 1)
dateend = Dates.Date(2012, 1, 1)
minlon = -40
maxlon = -30
minlat = 40
maxlat = 50

query = DIVAndFairEase.prepare_query(
datasource,
parameter1,
datestart,
dateend,
mindepth,
maxdepth,
minlon,
maxlon,
minlat,
maxlat,
)

outputfile = tempname() * ".nc"

@time open(outputfile, "w") do io
r = HTTP.request(
"POST",
joinpath(beacon_services[datasource], "api/query"),
["Content-type" => "application/json", "Authorization" => "Bearer $(APItoken)"],
query,
response_stream = io,
)
@test r.status == 200
end

NCDataset(outputfile) do nc
@test length(nc[parameter1][:]) == 10653
@test sort(nc[parameter1][:])[3] == 5.6720004f0
@test sort(nc["datetime"][:])[end] == DateTime("2011-10-30T20:24:00")
@test sort(nc["LONGITUDE"][:])[1] == -39.885
@test sort(nc["dataset_id"][:])[5] == 78002
end
end

97 changes: 74 additions & 23 deletions test/test_CORA_Timeseries.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,80 @@
@testset "CORA time series" begin
datasource = "CORA Timeseries"
parameter1 = "TEMP"

query = DIVAndFairEase.prepare_query(
datasource,
parameter1,
datestart,
dateend,
mindepth,
maxdepth,
minlon,
maxlon,
minlat,
maxlat,
)

jsondata = JSON3.read(query)

@test length(keys(jsondata)) == 3
@test length(jsondata["output"]) == 1
@test jsondata["output"]["format"] == "netcdf"

@test jsondata["filters"][1]["for_query_parameter"] == "datetime"
@test jsondata["filters"][1]["min"] == Dates.format(datestart, "yyyy-mm-ddT00:00:00")
@test jsondata["filters"][1]["max"] == Dates.format(dateend, "yyyy-mm-ddT00:00:00")

@test jsondata["filters"][2]["for_query_parameter"] == "DEPTH"
@test jsondata["filters"][2]["min"] == mindepth
@test jsondata["filters"][2]["max"] == maxdepth

@test jsondata["filters"][3]["for_query_parameter"] == "LONGITUDE"
@test jsondata["filters"][3]["min"] == minlon
@test jsondata["filters"][3]["max"] == maxlon

@test jsondata["query_parameters"][1]["column_name"] == parameter1
@test jsondata["query_parameters"][1]["alias"] == parameter1
@test jsondata["query_parameters"][5]["column_name"] == "LATITUDE"
@test jsondata["query_parameters"][5]["alias"] == "LATITUDE"

end

@testset "CORA time series download" begin
datasource = "CORA Timeseries"
parameter1 = "TEMP"

query = DIVAndFairEase.prepare_query_new(datasource, parameter1, parameter2, Dates.Date(datestart), Dates.Date(dateend), mindepth,maxdepth, minlon, maxlon, minlat, maxlat)
query = DIVAndFairEase.prepare_query(
datasource,
parameter1,
datestart,
dateend,
mindepth,
maxdepth,
minlon,
maxlon,
minlat,
maxlat,
)

outputfile = tempname() * ".nc"
@time open(outputfile, "w") do io
r = HTTP.request(
"POST",
joinpath(beacon_services[datasource], "api/query"),
["Content-type" => "application/json", "Authorization" => "Bearer $(APItoken)"],
query,
response_stream = io,
)
@test r.status == 200
end

@info(query);
@info(outputfile);

#@time open(outputfile, "w") do io
endpoint = "https://beacon-cora-ts.maris.nl/api/query"

r = HTTP.request("POST", endpoint,
["Content-type"=> "application/json",
"Authorization" => "Bearer $(APItoken)"
],
query);
@test r.status == 200
# end

# NCDataset(outputfile) do nc
# @test length(nc["TEMP"][:]) == 50
# @test sort(nc["TEMP"][:])[10] == 10.319f0
# @test sort(nc["TIME"][:])[end] == DateTime(1990, 11, 12, 0, 12, 1)
# @test sort(nc["LONGITUDE"][:])[1] == 13.3494
# @test sort(nc["dataset_id"][:])[5] == 19931
# end
end
# No data found in this case
NCDataset(outputfile) do nc
@test length(nc[parameter1][:]) == 0
# @test sort(nc[parameter1][:])[10] == 10.319f0
# @test sort(nc["TIME"][:])[end] == DateTime(1990, 11, 12, 0, 12, 1)
# @test sort(nc["LONGITUDE"][:])[1] == 13.3494
# @test sort(nc["dataset_id"][:])[5] == 19931
end
end
49 changes: 35 additions & 14 deletions test/test_EuroArgo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@
parameter1 = "PSAL"
dateref = Dates.Date(1950, 1, 1)

query = DIVAndFairEase.prepare_query(datasource, parameter1, datestart, dateend,
mindepth, maxdepth, minlon, maxlon, minlat, maxlat)
query = DIVAndFairEase.prepare_query(
datasource,
parameter1,
datestart,
dateend,
mindepth,
maxdepth,
minlon,
maxlon,
minlat,
maxlat,
)

jsondata = JSON3.read(query)

Expand All @@ -17,13 +27,13 @@
@test jsondata["filters"][1]["max"] == Dates.format(dateend, "yyyy-mm-ddT00:00:00")

@test jsondata["filters"][2]["for_query_parameter"] == "DEPTH"
@test jsondata["filters"][2]["min"] == mindepth
@test jsondata["filters"][2]["max"] == maxdepth
@test jsondata["filters"][2]["min"] == mindepth
@test jsondata["filters"][2]["max"] == maxdepth

@test jsondata["filters"][3]["for_query_parameter"] == "LONGITUDE"
@test jsondata["filters"][3]["min"] == minlon
@test jsondata["filters"][3]["max"] == maxlon

@test jsondata["query_parameters"][1]["column_name"] == parameter1
@test jsondata["query_parameters"][1]["alias"] == parameter1

Expand All @@ -35,18 +45,29 @@ end
@testset "Euro-Argo download" begin
datasource = "Euro-Argo"

query = DIVAndFairEase.prepare_query(datasource, parameter1, datestart, dateend,
mindepth, maxdepth, minlon, maxlon, minlat, maxlat)
query = DIVAndFairEase.prepare_query(
datasource,
parameter1,
datestart,
dateend,
mindepth,
maxdepth,
minlon,
maxlon,
minlat,
maxlat,
)

outputfile = tempname() * ".nc"

@time open(outputfile, "w") do io
r = HTTP.request("POST", joinpath(beacon_services[datasource], "api/query"),
["Content-type"=> "application/json",
"Authorization" => "Bearer $(APItoken)"
],
query,
response_stream=io);
r = HTTP.request(
"POST",
joinpath(beacon_services[datasource], "api/query"),
["Content-type" => "application/json", "Authorization" => "Bearer $(APItoken)"],
query,
response_stream = io,
)
@test r.status == 200
end

Expand All @@ -57,4 +78,4 @@ end
@test sort(nc["LONGITUDE"][:])[1] == 15.39
@test sort(nc["dataset_id"][:])[5] == 2288342
end
end
end
Loading

0 comments on commit b82f51b

Please sign in to comment.