-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ctroupin
committed
Jan 30, 2025
1 parent
a01c167
commit b82f51b
Showing
7 changed files
with
254 additions
and
108 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,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 | ||
|
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,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 |
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
Oops, something went wrong.