Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Cmr-search-after instead of paging #87

Merged
merged 51 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
94acb79
Let travis test everything in icepyx
weiji14 Jun 4, 2020
74dd0e3
Fix test_granule_info
weiji14 Jun 4, 2020
929594e
Fix test_correct_granule_list_returned
weiji14 Jun 8, 2020
8026be1
Reformat CONTRIBUTORS.rst, add myself, fix typo
dshean Jun 16, 2020
58ed1ea
Test everything except behind_NSIDC_API_login.py
weiji14 Jun 16, 2020
16f83e8
add pr builds to travis
JessicaS11 Jun 16, 2020
8da8239
Merge branch 'development' into development
JessicaS11 Jun 16, 2020
f4aee1d
Merge pull request #76 from dshean/development
JessicaS11 Jun 16, 2020
3319680
Add self to contributors
Jun 18, 2020
3760d43
Replace paging with scrolling in granule cmr query
Jun 18, 2020
a9bbdd2
Update place_order method paging
Jun 18, 2020
e49e1b8
Cleanup in granules
Jun 18, 2020
8925f75
Fix errors in tests
Jun 18, 2020
5e4187a
Rename and update tests
Jun 18, 2020
a951f6f
Remove datetime from requirements (builtin)
Jun 18, 2020
fcbe215
codeblock defined as none is not compatible with pypi markup
loudTom Jun 18, 2020
823cf34
Added T Johnson to list of contributors
loudTom Jun 18, 2020
aefbf6f
Add codecov
Jun 18, 2020
e948fa6
Updated Contributers, added my name
annavalentine Jun 18, 2020
9a7eab6
Add dev requirements and specify travis install
Jun 18, 2020
f6c064f
Merge branch 'development' into cmr-scrolling-search
wallinb Jun 18, 2020
f66388e
Update CONTRIBUTORS.rst
wallinb Jun 18, 2020
b71d574
Fix codecov badge links (use icesat2py repo)
Jun 18, 2020
35444ec
Updated installation instructions
loudTom Jun 18, 2020
96bab86
Changed installation instructions on readthedocs
loudTom Jun 18, 2020
ca0b4fe
Merge pull request #84 from icesat2py/anna_dev2
JessicaS11 Jun 18, 2020
7cd1795
Merge branch 'development' into codecov
JessicaS11 Jun 18, 2020
7bf566c
Merge pull request #88 from wallinb/codecov
JessicaS11 Jun 18, 2020
9f25d59
Merge branch 'development' into tj_dev
JessicaS11 Jun 18, 2020
67619f8
Merge pull request #85 from icesat2py/tj_dev
JessicaS11 Jun 18, 2020
9809159
Update codecov badge to point to 'development' branch
wallinb Jun 18, 2020
8c89907
Merge branch 'development' into cmr-scrolling-search
wallinb Jun 23, 2020
709cbd0
Merge branch 'development' into tj_docs
JessicaS11 Jun 24, 2020
62ce481
Merge pull request #89 from icesat2py/tj_docs
JessicaS11 Jun 24, 2020
16466f8
Merge branch 'development' into readme-fix
JessicaS11 Jun 24, 2020
98e68fa
Merge pull request #90 from icesat2py/readme-fix
JessicaS11 Jun 24, 2020
9f5e8a4
Merge branch 'development' into travis_test_all
JessicaS11 Jun 26, 2020
82f4aec
Merge pull request #61 from icesat2py/travis_test_all
JessicaS11 Jun 26, 2020
af4fc4d
Merge branch 'development' into cmr-scrolling-search
JessicaS11 Jun 26, 2020
79cc421
Merge branch 'development' into cmr-scrolling-search
JessicaS11 Feb 2, 2022
b37be51
fix missed merge conflicts
JessicaS11 Feb 2, 2022
5119cdb
manual updates from commit history
JessicaS11 Feb 2, 2022
009755f
fix missed merge conflicts
JessicaS11 Feb 2, 2022
da465bd
turn 'scroll' into a reqparam for CMR searches
JessicaS11 Feb 2, 2022
a68d71f
switch from scrolling to CMR-Search-After
JessicaS11 Feb 2, 2022
e9a7d2a
remove missed scroll kwargs
JessicaS11 Feb 2, 2022
a67848b
remove changes to example I had checked out but committed anyway
JessicaS11 Feb 2, 2022
4c8e379
add ability to only order one page by specifying 'page-num'
JessicaS11 Feb 3, 2022
02481ae
Merge branch 'development' into cmr-scrolling-search
JessicaS11 Feb 4, 2022
fe9ca49
GitHub action UML generation auto-update
betolink Feb 8, 2022
fa8bb68
undo unintentional example commit
JessicaS11 Feb 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,191 changes: 2,175 additions & 16 deletions doc/source/example_notebooks/IS2_data_access.ipynb

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions icepyx/core/APIformatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _get_possible_keys(self):
}
elif self.partype == "required":
self._poss_keys = {
"search": ["page_size", "page_num"],
"search": ["page_size"],
"download": [
"page_size",
"page_num",
Expand Down Expand Up @@ -442,28 +442,19 @@ def build_params(self, **kwargs):
reqkeys = self.poss_keys[self._reqtype]
defaults = {
"page_size": 2000,
"page_num": 1,
"page_num": 0,
"request_mode": "async",
"include_meta": "Y",
"client_string": "icepyx",
}
for key in reqkeys:
if key in kwargs:
self._fmted_keys.update({key: kwargs[key]})
# elif key in defaults:
# if key is 'page_num':
# pnum = math.ceil(len(is2obj.granules)/reqparams['page_size'])
# if pnum > 0:
# reqparams.update({key:pnum})
# else:
# reqparams.update({key:defaults[key]})
elif key in defaults:
self._fmted_keys.update({key: defaults[key]})
else:
pass

self._fmted_keys["page_num"] = 1

else:
if self.check_values == True and kwargs == None:
pass
Expand Down
54 changes: 32 additions & 22 deletions icepyx/core/granules.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,28 @@ def get_avail(self, CMRparams, reqparams):

headers = {"Accept": "application/json", "Client-Id": "icepyx"}
# note we should also check for errors whenever we ping NSIDC-API - make a function to check for errors

params = apifmt.combine_params(
CMRparams, {k: reqparams[k] for k in ["page_size"]}
)

cmr_search_after = None

while True:
params = apifmt.combine_params(
CMRparams, {k: reqparams[k] for k in ("page_size", "page_num")}
)
if cmr_search_after is not None:
headers["CMR-Search-After"] = cmr_search_after

response = requests.get(
granule_search_url,
headers=headers,
params=apifmt.to_string(params),
)

try:
cmr_search_after = response.headers["CMR-Search-After"]
except KeyError:
cmr_search_after = None

try:
response.raise_for_status()
except requests.HTTPError as e:
Expand All @@ -223,16 +235,13 @@ def get_avail(self, CMRparams, reqparams):

results = json.loads(response.content)
if not results["feed"]["entry"]:
# Out of results, so break out of loop
assert len(self.avail) == int(
response.headers["CMR-Hits"]
), "Search failure - unexpected number of results"
break

# Collect results and increment page_num
# Collect results
self.avail.extend(results["feed"]["entry"])
reqparams["page_num"] += 1

# DevNote: The above calculated page_num is wrong when mod(granule number, page_size)=0.
# print(reqparams['page_num'])
reqparams["page_num"] = int(np.ceil(len(self.avail) / reqparams["page_size"]))

assert (
len(self.avail) > 0
Expand Down Expand Up @@ -299,9 +308,7 @@ def place_order(

base_url = "https://n5eil02u.ecs.nsidc.org/egi/request"

self.get_avail(
CMRparams, reqparams
) # this way the reqparams['page_num'] is updated
self.get_avail(CMRparams, reqparams)

if subset is False:
request_params = apifmt.combine_params(
Expand All @@ -312,27 +319,30 @@ def place_order(

order_fn = ".order_restart"

total_pages = int(np.ceil(len(self.avail) / reqparams["page_size"]))
print(
"Total number of data order requests is ",
request_params["page_num"],
total_pages,
" for ",
len(self.avail),
" granules.",
)
# DevNote/05/27/20/: Their page_num values are the same, but use the combined version anyway.
# I'm switching back to reqparams, because that value is not changed by the for loop. I shouldn't cause an issue either way, but I've had issues with mutable types in for loops elsewhere.
for i in range(reqparams["page_num"]):
# for i in range(request_params['page_num']):
page_val = i + 1

if reqparams["page_num"] > 0:
pagenums = [reqparams["page_num"]]
else:
pagenums = range(1, total_pages + 1)

for page_num in pagenums:
print(
"Data request ",
page_val,
page_num,
" of ",
reqparams["page_num"],
total_pages,
" is submitting to NSIDC",
)
request_params.update({"page_num": page_val})
request_params = apifmt.combine_params(CMRparams, reqparams, subsetparams)
request_params.update({"page_num": page_num})

# DevNote: earlier versions of the code used a file upload+post rather than putting the geometries
# into the parameter dictionaries. However, this wasn't working with shapefiles, but this more general
Expand Down
2 changes: 1 addition & 1 deletion icepyx/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def reqparams(self):
--------
>>> reg_a = ipx.Query('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-28'])
>>> reg_a.reqparams
{'page_size': 2000, 'page_num': 1}
{'page_size': 2000}

>>> reg_a = ipx.Query('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-28']) # doctest: +SKIP
>>> reg_a.earthdata_login(user_id,user_email) # doctest: +SKIP
Expand Down
5 changes: 1 addition & 4 deletions icepyx/tests/is2class_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_reqconfig_params():
# test for search params
reg_a.build_reqconfig_params("search")
obs_keys = reg_a.reqparams.keys()
exp_keys_all = ["page_size", "page_num"]
exp_keys_all = ["page_size"]
assert all(keys in obs_keys for keys in exp_keys_all)

# test for download params
Expand All @@ -39,9 +39,6 @@ def test_reqconfig_params():
assert all(keys in obs_keys for keys in exp_keys_all)





# BestPractices: should do additional properties tests for each potential property type (e.g. spatial extent can have type bounding_box or polygon)


Expand Down
2 changes: 1 addition & 1 deletion icepyx/tests/test_granules.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,5 +628,5 @@ def test_avail_granule_CMR_error():
ermsg = "An error was returned from NSIDC in regards to your query: temporal start datetime is invalid: [badinput] is not a valid datetime."
with pytest.raises(NsidcQueryError, match=re.escape(ermsg)):
CMRparams = {"version": "003", "temporal": "badinput", "short_name": "ATL08"}
reqparams = {"page_size": 1, "page_num": 1}
reqparams = {"page_size": 1}
Granules().get_avail(CMRparams=CMRparams, reqparams=reqparams)