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

Update batch regional download example #2

Merged
merged 3 commits into from
Apr 18, 2024
Merged

Conversation

ansoncfit
Copy link
Member

To use new /all grid endpoint

To use new /all grid endpoint
@ansoncfit ansoncfit requested a review from abyrd April 17, 2024 18:23
batch-result-download.ipynb Outdated Show resolved Hide resolved
"\n",
" # Save result to a local .zip file\n",
" with open('results/' + analysisId + '.zip', 'wb') as f:\n",
" for chunk in zipRequest.iter_content(chunk_size=128):\n",
Copy link
Member

@abyrd abyrd Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the library's syntax implies this is operating on a stream of chunks (and the documentation at https://fr.python-requests.org/en/latest/api.html also seems to imply this is the point of chunk_size), I wonder if this may actually buffer the entire response in memory. While that wouldn't be much of an issue when working with one geotiff at a time, it's probably not ideal to buffer an entire zip containing an unknown number of geotiffs. Commentary on stackoverflow seems to echo this concern: https://stackoverflow.com/q/16694907/778449
But other commentary specifically says iter_chunks exists to solve the buffering problem:
https://stackoverflow.com/questions/46205586/why-to-use-iter-content-and-chunk-size-in-python-requests

There are also several edge cases that could occur when downloading and saving a large file, which might be better handled by a purpose-built "save a file" method instead of a simple loop over the content.

Side note: chunk_size is in bytes according to the Requests docs. 128 bytes is a very small chunk size for file IO. It is probably more efficient to work with larger sizes. But ideally a detail like this will be encapsulated in whatever method we use to save the file.

I will research better ways to handle this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corresponding PR at #3.

@ansoncfit ansoncfit merged commit 01bfd61 into master Apr 18, 2024
@ansoncfit ansoncfit deleted the update-batch-download branch April 18, 2024 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants