Skip to content

Commit

Permalink
add "id" to seach + test (#78)
Browse files Browse the repository at this point in the history
* add "id" to seach + test

* remove extra "="
  • Loading branch information
alex-s-gardner authored Mar 5, 2024
1 parent 570f685 commit 759e6d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function search(
version::Int = 2,
before::Union{Nothing,DateTime} = nothing,
after::Union{Nothing,DateTime} = nothing,
id::Union{Nothing,String}=nothing,
provider::String = "LPDAAC_ECS",
)::Vector{GEDI_Granule}
startswith(string(product), prefix(m)) || throw(ArgumentError("Wrong product $product for $(mission(m)) mission."))
Expand All @@ -37,7 +38,7 @@ function search(
end

granules =
earthdata_search(short_name = string(product), bounding_box = extent, version = version, provider = provider, before = before, after = after)
earthdata_search(short_name = string(product), bounding_box = extent, version = version, provider = provider, before = before, after = after, id = id)
length(granules) == 0 && @warn "No granules found, did you specify the correct parameters, such as version?"
filter!(g -> !isnothing(g.https_url), granules)
map(
Expand All @@ -58,6 +59,7 @@ function search(
version::Int = 6,
before::Union{Nothing,DateTime} = nothing,
after::Union{Nothing,DateTime} = nothing,
id::Union{Nothing,String}=nothing,
s3::Bool = false,
provider::String = s3 ? "NSIDC_CPRD" : "NSIDC_ECS",
)::Vector{ICESat2_Granule}
Expand All @@ -68,7 +70,7 @@ function search(
end

granules =
earthdata_search(short_name = string(product), bounding_box = extent, version = version, provider = provider, before = before, after = after)
earthdata_search(short_name = string(product), bounding_box = extent, version = version, provider = provider, before = before, after = after, id = id)
length(granules) == 0 && @warn "No granules found, did you specify the correct parameters, such as version?"
s3 ? filter!(g -> !isnothing(g.s3_url), granules) : filter!(g -> !isnothing(g.https_url), granules)
map(
Expand All @@ -89,6 +91,7 @@ function search(
version::Int = 34,
before::Union{Nothing,DateTime} = nothing,
after::Union{Nothing,DateTime} = nothing,
id::Union{Nothing,String}=nothing,
s3::Bool = false,
provider::String = s3 ? "NSIDC_CPRD" : "NSIDC_ECS",
)::Vector{ICESat_Granule}
Expand All @@ -99,7 +102,7 @@ function search(
end

granules =
earthdata_search(short_name = string(product), bounding_box = extent, version = version, provider = provider, before = before, after = after)
earthdata_search(short_name = string(product), bounding_box = extent, version = version, provider = provider, before = before, after = after, id = id)
length(granules) == 0 && @warn "No granules found, did you specify the correct parameters, such as version?"
s3 ? filter!(g -> !isnothing(g.s3_url), granules) : filter!(g -> !isnothing(g.https_url), granules)
map(
Expand Down Expand Up @@ -214,6 +217,7 @@ function earthdata_search(;
provider::Union{Nothing,String} = "NSIDC_CPRD",
before::Union{Nothing,DateTime} = nothing,
after::Union{Nothing,DateTime} = nothing,
id::Union{Nothing,String} = nothing,
all_pages::Bool = true,
page_size = 2000,
page_num = 1, # unused
Expand All @@ -234,6 +238,10 @@ function earthdata_search(;
q["temporal"] = "$(isnothing(after) ? "" : after),$(isnothing(before) ? "" : before)"
end

if !isnothing(id)
q["producer_granule_id"] = id
end

qurl = umm ? earthdata_url : replace(earthdata_url, "umm_json_v1_6_4" => "json")
r = HTTP.get(qurl, query = q, verbose = verbose, status_exception = false)
HTTP.iserror(r) && error(parse_cmr_error(r))
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ empty_extent = convert(Extent, empty_bbox)
@test length(granules) > 0
@test length(granules[1].polygons) > 0

id = "GEDI02_A_2023003040347_O22988_03_T06105_02_003_02_V002.h5";
@test length(search(:GEDI, :GEDI02_A; version = 2, id = id)) == 1

@test_throws ArgumentError find(:ICESat2, "GLAH14")
@test_throws ArgumentError find(:Foo, "GLAH14")

Expand Down

0 comments on commit 759e6d8

Please sign in to comment.