Skip to content

Add tutorial on streaming data (vs downloading) - #1427

Open
betolink wants to merge 17 commits into
earthaccess-dev:mainfrom
betolink:streaming-docs
Open

betolink wants to merge 17 commits into
earthaccess-dev:mainfrom
betolink:streaming-docs

Conversation

@betolink

@betolink betolink commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

Description

This PR adds a tutorial on what streaming data is, attempting to explain when to use it vs when to download files. It's missing some of the final profiling numbers to have a better idea on memory usage but I think is in good shape to be published. I ran into 2 interesting things when working on it, readthedocs switched environment variables to public (guessing here) and that's the reason we got our CI account "hacked", I deleted the env variables and we are now using a token, is public but has no security implications. Second thing, memray detected a bigger memory peak when we are streaming vs when we download files, an overhead of 100% which is significant. We need to investigate that, apparently coming from AIOHttp allocations, so that and the hypy driver can be doing something funny.

As part of the PR work I did an override on the mkdocs theme to make the page TOC collapsible so we have more space for the rendered notebook. Looks better IMO.

This PR closes #1390


"Ready for review" checklist

  • Place this Pull Request (PR) in draft until it is ready for review (see below)
  • Please review our Pull Request Guide
  • Mark "ready for review" after following instructions in the guide

Merge checklist

  • PR title is descriptive
  • PR body contains links to related and resolved issues (e.g. closes #1)
  • If needed, CHANGELOG.md updated
  • If needed, docs and/or README.md updated
  • If needed, unit tests added (unsure how? see below!)
  • All checks passing (tip: comment pre-commit.ci autofix if pre-commit is failing)
  • At least one approval

Need help? We welcome contributions at every experience level. You don't have to
write tests alone — open your PR and ask for help. It's also fine to let GitHub run tests
for you, via Continuous Integration (CI),
instead of running them locally. If anything fails and you're not sure why, just
mention @earthaccess-dev/maintainers in a comment and we'll work with you!


📚 Documentation preview 📚: https://earthaccess--1427.org.readthedocs.build/en/1427/

@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Binder 👈 Launch a binder notebook on this branch for commit 6ad3e80

I will automatically update this comment whenever this PR is modified

Binder 👈 Launch a binder notebook on this branch for commit 233e727

Binder 👈 Launch a binder notebook on this branch for commit 149a516

Binder 👈 Launch a binder notebook on this branch for commit c0dd7e6

@betolink
betolink marked this pull request as ready for review August 18, 2026 15:15
@mfisher87

mfisher87 commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

Not sure I like the TOC toggle. It kinda flashes on the screen and disappears, but that's not my real concern. Is there a way to toggle it back on? I don't see the button I expected from reading the source.

My biggest concern is that some pages are very hard to use without a TOC. The API reference is a good example. We made authoring decisions based on the assumption that the TOC would be present.

What do you think of making the page wider instead so the TOC and the notebook content both reasonably fit? The margin on the sides is kinda ridiculously huge and we could reclaim some of that space.

@andypbarrett

Copy link
Copy Markdown
Contributor

The notebook is too long for a how-to. There is also a larger question about whether we even need tutorials as part of the earthaccess documents. The earthaccess library really only does two or three things. These are mostly well covered in the user guide and how-tos.

My suggestion is we split out the few lines of code that show how to stream into the how-to section, and then the rest can go into explanation.

The tutorial itself can sit on the NSIDC tutorials repo.

@saberbrasher

Copy link
Copy Markdown
Contributor

Yes to the question of what to do with tutorials! See #1400. I also miss the TOC, as Matt mentioned. Agree with Andy that this is far too long, in current form, for a How-to. The terms you have in the glossary at the end would be great to add to a linkable glossary (see our Reference > Glossary section which currently is very slim and not linkable anywhere). I haven't ran all the code yet, but in reading through it, it does seem like a great candidate for our NSIDC cookbook (if edited to use a NSIDC product) or the tutorials repo, as Andy suggested, if you want to leave the product as is. Wherever it ends up living, it could potentially be linked to in our (maybe) tutorial "directory" in the earthaccess docs (if that is what Tutorials ends up becoming).

@betolink

Copy link
Copy Markdown
Member Author

I think I can edit the notebook location so it goes to tutorials here and move the glossary to a global glossary, then we can also link the auth section to the howto auth... I can revert the change of the TOC and reduce the margins.

Working on that tomorrow!

@mikala-nsidc

Copy link
Copy Markdown
Collaborator

The Openscapes Earthdata Cloud Cookbook is another good candidate for housing this tutorial. There is so much informative and helpful content about the how and when to cloud. And the information is not specific to NSIDC, so in the context of the hub and spoke model, this makes sense for living in the "hub".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the documentation site to replace the “coming soon” cloud how-to with a new tutorial notebook explaining streaming vs downloading data with earthaccess, and adds a small MkDocs Material theme override to make the in-page TOC collapsible to better accommodate rendered notebooks.

Changes:

  • Add a new how-to tutorial notebook: streaming data vs downloading (docs/user/howto/streaming.ipynb) and wire it into the docs nav.
  • Add MkDocs theme overrides + CSS to provide a collapsible right-hand TOC (floating toggle button).
  • Remove the placeholder “Direct S3 access…” page, and adjust repo ignores / link-check settings accordingly.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
overrides/main.html Adds a JS snippet to hide/show the right-hand TOC via a floating toggle button.
mkdocs.yml Enables the custom theme overrides directory.
docs/user/howto/streaming.ipynb New tutorial notebook covering streaming vs downloading, with examples and appendices.
docs/user/howto/cloud.md Removes the placeholder “coming soon” page content.
docs/css/styles.css Styles the TOC toggle button and hides it on smaller viewports.
docs/.nav.yml Updates the docs nav to point to the new streaming tutorial notebook.
.gitignore Adds ignores for .cache and docs/user/howto/data/.
.github/workflows/check-links.yml Minor formatting tweak + adds an allowlist regex for a new docs link.
Suppressed comments (4)

docs/user/howto/streaming.ipynb:343

  • Spelling/wording issues in this comparison table (e.g., "Time to sience" → "Time to science"). Since this is user-facing documentation, these typos should be corrected before publishing.
    "* Disk: ~768MB \n",
    "* Memory: ? \n",
    "* Time to sience (out of region) (good internet): ~1m\n",
    "* TTS in-region(): ~ < 1m\n",
    "\n",

docs/user/howto/streaming.ipynb:321

  • Grammar: "streaming lets we look" should be corrected (e.g., "streaming lets us look" / "streaming lets you look").
    "> - **we're running in-region on AWS**, so egress is free/fast and streaming reads are cheap.\n",
    "> - **we only need a subset** of each file — a few variables, a spatial subset, a handful of time steps — out of a much larger granule.\n",
    "> - **we're doing exploratory analysis** and don't yet know which files/variables we'll actually need; streaming lets we look before committing to a download.\n",
    "> - **we don't want to manage storage** — no local disk cleanup, no worrying about running out of space when scaling across hundreds or thousands of granules.\n",

docs/user/howto/streaming.ipynb:509

  • Heading capitalization/typo: "## GLossary" should be "## Glossary".
    "## GLossary\n",
    "\n",

docs/user/howto/streaming.ipynb:392

  • This explanation says earthaccess configures fsspec caching at 4 MB by default. In earthaccess/store.py, the default block_size is selected based on file size (4/8/16 MB) and cache_type defaults to "background" (see earthaccess/store.py:111-155). The narrative should be updated so readers don’t assume block caching is always 4 MB.
    "`fsspec` solves this with **block-based caching (`AbstractBufferedFile`)**: rather than fetching exactly the bytes requested, it fetches in fixed-size blocks — **`earthaccess` configures this at 4 MB by default** — and caches each block in memory. So:\n",
    "\n",
    "- A small read for, say, 200 bytes of header still triggers a fetch of a full 4 MB block containing those bytes.\n",
    "- Any *subsequent* read that falls within that already-cached block is served from memory — **no network request at all**.\n",
    "- Reads are effectively pre-fetched in bulk, which amortizes request/connection overhead (and any per-request latency, like S3's or EDL's auth roundtrip) over many logical reads.\n",

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/user/howto/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
@betolink

Copy link
Copy Markdown
Member Author

The notebook is ready for a second review

  • Moved it to tutorials for now
  • Glossary is a link to the updated glossary
  • login() is not a whole section
  • Margins are better and per page TOC is back

cc @andypbarrett @saberbrasher

@betolink
betolink requested a review from mikala-nsidc August 19, 2026 17:23

@saberbrasher saberbrasher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I learned some things myself by going through this! Let me know if you have any questions about my comments, Luis. Also, take or leave what you do/ don't like!

Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
Comment thread docs/user/tutorials/streaming.ipynb Resolved
betolink and others added 3 commits August 19, 2026 14:21
Co-authored-by: Saber Brasher <134096880+saberbrasher@users.noreply.github.com>

@mikala-nsidc mikala-nsidc left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This tutorial and reference material will be such a great resource for data users. I like the amount of technical detail in the explanations - there is enough information to stand alone, and also enough information that if I wanted to do a deeper dive into anything, I have something to start my search on.
I like how the technical reference section is broken out separately. Could stay here, or could be moved to an "explanation" section.
The discussion and explanation around when to stream and when to download is so helpful. It really clarifies some concepts for me. Same with the discussion around why something is streamable vs. not-streamable. I can see this being used over and over in support of workshops and teaching.

Comment thread docs/user/tutorials/streaming.ipynb Outdated
"source": [
"## Requirements\n",
"\n",
"We need a recent version of `earthaccess` (the API changed a few times as the project matured — this notebook targets the current release, where `earthaccess.login()` is required *before* we can search, download, or open/stream anything).\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It might be good to give an actual version number here - e.g. v0.15.0 or later.

"source": [
"## 1. Downloading vs. Streaming — what's the actual difference?\n",
"\n",
"Both paths start the same way: we search the Common Metadata Repository (CMR) for granules, `earthaccess` resolves the data URLs (increasingly these are direct S3 URLs in the Earthdata Cloud, not just HTTPS), and it opens an authenticated connection. Concretely, that means either exchanging our EDL bearer token for short-lived, temporary AWS credentials via NASA's S3 credential endpoint (for direct `s3://` access from in-region compute), or attaching the bearer token as an `Authorization` header on HTTPS requests (for out-of-region / non-AWS access, redirected through EDL's OAuth flow). `earthaccess` picks whichever path applies automatically based on where our code is running and what the granule's links support.\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I might replace "paths" with "methods", but take or leave that advice.

Comment thread docs/user/tutorials/streaming.ipynb Outdated
"| **Disk footprint** | One full copy of every granule we touch | None (until/unless we explicitly write something out) |\n",
"| **Best when...** | We need the raw file for other tools, we'll reuse it repeatedly, or we're outside AWS `us-west-2`, file format does not support streaming* | We're doing an analysis that only touches a slice of the data, we are using cloud compute, or we don't want to manage local storage at all |\n",
"\n",
"The key mental shift: **streaming doesn't mean \"no data movement.\"** It still moves bytes over the network — it just moves *only the bytes our analysis actually asks for*, and it does so lazily, mediated by `fsspec` under the hood (more on this in Section 6)."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

really appreciate this explanation

"id": "a57d3bee",
"metadata": {},
"source": [
"Each item in `results` is an `earthaccess.DataGranule` — it carries the metadata *and* the resolvable data links (both HTTPS and, where available, direct S3 URLs), without moving any of the actual science data yet. Searching CMR is metadata-only regardless of which path we take next.\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

when you mention data links ("both HTTPS and, where available, direct S3 URLs"), do you mean that some data are still on premises and accessible via https, and other data are on AWS and have both https and s3 urls?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No. When you are out-of-region, access to data in Earthdata Cloud is by HTTPS. When you are in-region, access is by S3.

Comment thread docs/user/tutorials/streaming.ipynb Outdated
"id": "38446391",
"metadata": {},
"source": [
"Compare that to the download path: with `xr.open_mfdataset` over local files, the read is fast because the bytes are already on disk, but we paid the download cost earlier, for the *entire* file, whether or not we needed all of it. With streaming, the cost is paid incrementally, only where we touch the data. If all we needed was `T2M`, we never move the bytes for the other ~30 variables in the file at all.\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Really appreciate this comparison and the explanation.

"id": "15b35b8b",
"metadata": {},
"source": [
"This block-caching behavior is *why* streaming can be competitive with — or faster than — downloading when we only need part of a file: we're not paying for a full sequential transfer, but we're also not paying a network round trip for every single small read either. The 4 MB block size is a sensible default for typical Earth science granule sizes and access patterns, but it's worth knowing it exists if we ever see unexpectedly heavy data transfer for what feels like a \"small\" read — e.g., touching one value from every chunk of a variable can still pull in a lot of 4 MB blocks.\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

such a good explanation.

"### T2. Streamable Data Formats\n",
"---\n",
"\n",
"Reading remote geospatial data efficiently comes down to one core difference: whether the format's underlying library demands an actual file on a hard drive, or if it can accept a flexible data stream. Formats like Zarr, HDF5, and NetCDF4 (using the h5netcdf engine) are flexible. They allow tools like fsspec to read just the exact bytes we need directly from cloud storage. Other formats achieve similar remote access through pure Python readers (NetCDF3), server-side queries (OPeNDAP), or GDAL's virtual file system (VSI) for Cloud Optimized GeoTIFFs.\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I might write "one core characteristic" or "one core feature", rather than "one core difference". but take or leave that advice.

"\n",
"Reading remote geospatial data efficiently comes down to one core difference: whether the format's underlying library demands an actual file on a hard drive, or if it can accept a flexible data stream. Formats like Zarr, HDF5, and NetCDF4 (using the h5netcdf engine) are flexible. They allow tools like fsspec to read just the exact bytes we need directly from cloud storage. Other formats achieve similar remote access through pure Python readers (NetCDF3), server-side queries (OPeNDAP), or GDAL's virtual file system (VSI) for Cloud Optimized GeoTIFFs.\n",
"\n",
"On the flip side, older formats like HDF4, GRIB, and compressed Zip archives are rigid. Because they require a real, local file path to function, we are forced to download or cache the data before we can work with it. This technical divide is exactly why our ITS_LIVE pipeline succeeds with tools like VirtualiZarr and Kerchunk—they thrive on flexible, cloud-ready HDF5 data. If we were forced to incorporate rigid formats like HDF4, that entire remote-reading model would break down.\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you provide a link to ITS_LIVE, or ITS_LIVE documentation here? people could google it, but it might be nice to point them right to where they can learn about that project. It's mentioned a bit "out of the blue" here.

"\n",
"| Format | Engine | How | Notes |\n",
"|---|---|---|---|\n",
"| **HDF5 / NetCDF4** | `h5netcdf` | `h5py.File(fileobj)` — h5py's core driver accepts any object with `read`/`seek`/`tell` | This is why fsspec/S3 remote reads work at all. Must use `engine=\"h5netcdf\"`, not `engine=\"netcdf4\"` (see below). |\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what about xarray?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These are engines available in xarray.

"| **Parquet / GeoParquet** | *(not xarray directly, but PyArrow)* | PyArrow accepts fsspec file objects natively, lazy row-group/column reads | Relevant even though xarray doesn't read Parquet itself. |\n",
"\n",
"#### Not Streamable\n",
"> **The C library demands a real path (GDAL VSI, or Virtualization as the only workarounds)**\n",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

are these workarounds that allow streaming? could you clarify what you mean by workaround here?

@andypbarrett

Copy link
Copy Markdown
Contributor

I'm really struggling with seeing this as what get's presented in the webinar and what is preserved as a stand-alone tutorial.

The current tutorial is designed more as a stand alone tutorial rather than something that could be presented in a webinar. At least how I would present it.

My comments here relate to a stand-alone tutorial.

  1. I would move the "Downloading vs Streaming" section to the top. This can act as an introduction.
  2. Section 1 is too technical. I think most of the first paragraph can be deleted. It is good material for the Explanation section but the whole point of earthaccess is so that users do not have to know this stuff.
  3. I think the table is good but it needs to be explained.
  4. Under the download section we say we are "streaming" the data.
  5. I would change the headings to "Download" and "Steaming". The earthaccess methods can be in the table.
  6. Move the requirements to be with the code.
  7. Add "We use earthaccess.search_data to find data for July 1 and 2 in 2023." before code block 4.

Suggested text for section 1. At least something like this.

When we Download data, we copy the entire file from Earthdata Cloud to our local disk or the storage attached to our cloud compute instance. Once the data is downloaded it is available for use at any time, even when we are offline. When we Stream data, we copy only the parts of the file we need into our computer's memory (RAM). Streaming data is useful is we only need to work with part of the data, for example to create a plot. It is also useful is we are working in the cloud and do not want to copy data to our cloud compute. This saves storage costs.

The earthaccess library provides a simple way for users to either download or stream data using the earthaccess.download or earthaccess.open methods. The table below provides some of the key differences in more detail.

  1. I think we need to explain "lazy-loading" in the text. Suggest "Lazy-loading data, loads only information about what is in the file, e.g. variable names, coordinates and data attributes. The actual data is not loaded until we need to use it, for example to plot the data or do a calculation."
  2. Section 3 - Add "First we'll demonstrate the traditional download method. This is the workflow most people are used to using when they are working on a local machine. We'll time the download to get an idea of how much time this workflow takes."
  3. Suggest "Now that the data are downloaded, we will use xarray to load the data and compute a time mean for a region over Colorado in the United States."
  4. Suggest removing Example A and B from headings. I think it detracts from the flow.
  5. Suggest "Comparing the streaming workflow to the downloading workflow, we can see that reading the downloaded files from our local disk using xr.open_mfdataset is fast but downloading the whole files, whether or not we needed all that data, was slow. With streaming, the time required to get only the data we need is small and increases incrementally. In the example above, we only needed a subset of the T2M variable, so only the bytes required to get that data was transferred over the internet."
  6. Section 5. Suggest having the "factors to weigh" as bullet points or separate paragraphs. With the parentheses, I think it is easier to read.
  7. Section 5. Maybe use factors instead of variables to avoid confusion with data variables.
  8. Section 5: "When running inside AWS" needs defining or a better explanation.
  9. Section 5: Suggest "S3 access is essentially free and extremely fast because we're on the same network as the data". "network fabric" is too jargony.
  10. Section 5 and general: "I think we might need to explain the three "setups" in the tutorial introduction (I am working on a figure): 1) local machine and download data; 2) local machine and stream data; 3) cloud compute instance and access to S3. Or something like that.
  11. Section 5: "streaming trades network-request overhead for storage and full-file transfer cost". This is too much jargon. Need to explain network-request overhead and full-file transfer cost.
  12. Like "Cloud-conomics"
  13. The diagrams are cool but suggest four separate panels to show the four separate workflows. I would also delete the HDD from the ea.open example and not required
  14. Section 6. replace touch with read.
  15. Section 6. define lazy
  16. Section 6. Suggest "Choosing between streaming and download..." Add that it is also about use patterns.
  17. Section 6. This should go in the technical appendix.

@betolink

betolink commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

Should we merge this as is and work on it later @andypbarrett ?

@saberbrasher

Copy link
Copy Markdown
Contributor

Long comment incoming!

In different meetings we started discussing how this content could be added to the earthaccess User guide following Diátaxis themes. If you open the preview for this tutorial, I gave this a first go by putting all the major TOC items into a category (along with some of the sub-items). Some of this I think could be a part of one tutorial on streaming (wether it lives here or another cookbook is TBD, though), and a lot of this would make great Explanation and Reference content (imo).

Everything with "Tutorial 1" would be a part of the same tutorial/ live together on one page. Basically, not every TOC item needs a brand new page, but sections of this content could be kept together with a new focus. Everything with "Explanation 1" would be put together on one new page, etc. The "?" means I am not sure if the content makes sense for the earthaccess docs in particular, but I do think it goes "together". The "OR" means I think it will depend on how we want to frame the content. Would love @mfisher87, @andypbarrett, and @asteiker to put eyes on this as well (more Diátaxis expertise please)! :-)

TOC section Diátaxis Logic
1. Requirements (and intro) Tutorial 1 The intro establishes a learning journey: use earthaccess to access MERRA-2 remotely and work with it in Python. That gives the tutorial a clear goal.
2. Downloading vs. Streaming — what's the actual difference? Explanation 1 This section's primary purpose is conceptual understanding. It explains what distinguishes the two access models, where bytes go, and when they move. That answers “Why/How does this work?”, not “How do I complete a task?”
3. Search for MERRA-2 data Tutorial 1 Searching for a collection and obtaining granules is the next action required to complete the earlier-mentioned tutorial.
4. Example A — the traditional “download and open” workflow Explanation 1 The purpose of this section is mainly comparative: establish the conventional workflow so the user can understand what streaming changes. It is not really teaching someone how to download data for its own sake. This shows what happens after downloading and why local reads behave differently.
5. Example B — the “streaming” workflow Tutorial 1 This is the core practical skill the learner came to acquire: opening remote Earthdata files and using them with Xarray. This should become the central hands-on portion of the tutorial. The comparison explanation content above can be linked to.
Lazy-loading / data on-demand speed Explanation ? Lazy loading is a concept the user needs to understand beyond this one example. It answers why opening a remote dataset can be fast and why data transfer happens later. Could be more content, elsewhere.
Comparison between local reads and streamed reads Explanation 1 This is not a procedural step. Could be in the explanation content that covers local download vs. streaming.
Computing on a remote dataset Tutorial 1, Explanation ? Computing the subset and mean is the last tutorial step. However, the detailed explanation of lazy computation belongs in Explanation. The tutorial should simply say that computation triggers the required data reads.
6. When to download vs. when to stream How-to 1 OR Explanation 1 This section is decision oriented. Users arrive with a problem (which access approach should I use?) and need guidance based on their situation. That said, it could also fit within Explanation—it all depends on how you want to organize/add detail/etc.
7. “Cloud-conomics” How-to 1 OR Explanation 1 Most of the content is guidance about when downloading or streaming makes sense. The user can apply the criteria to their own workflow. This adds more context to the content above.
8. Key takeaways Split across categories The current takeaways summarize everything; each new page should end with its own version of this.
Additional resources Split across categories In the new pages, link what makes best sense.
T1. Under the hood: how earthaccess actually fetches bytes Explanation 1 This section explains the mechanism behind remote access and why streaming can be efficient. It is a direct “How does this work?” section. It also kinda follows some of the other fsspec content that recently got moved to Explanation.
T2. Streamable Data Formats Reference 1 This feels more like a lookup resource. Users want to know whether a format supports remote access or not.
T3. Streaming and downloading data in other languages Reference 1 This could probably be a part of the page above / it could all live together.

@andypbarrett andypbarrett left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great! I've made some suggested edits that I hope improve readbility. Feel free to ignore.

Comment thread docs/user/tutorials/streaming.ipynb Resolved
"source": [
"## 1. Requirements\n",
"\n",
"We need a recent version of `earthaccess` as the library changed a few times as the project matured, this notebook uses the current release (v0.18.0), where `earthaccess.login()` is required *before* we can search, download, or open/stream anything.\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have text about needing to authenticate as separate sentence.

"\n",
"We need a recent version of `earthaccess` as the library changed a few times as the project matured, this notebook uses the current release (v0.18.0), where `earthaccess.login()` is required *before* we can search, download, or open/stream anything.\n",
"\n",
"We'll also need an Earthdata Login (EDL) account. If you don't have one yet, create one for free at https://urs.earthdata.nasa.gov/users/new.\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is required to authenticate so suggest:

We need to run earthaccess.login() before we can download or open/stream any data, so we do this first. We will need an Earthdata Login (EDL) account to do this.

"source": [
"## 2. Downloading vs. Streaming — what's the actual difference?\n",
"\n",
"Both paths start the same way: we search the Common Metadata Repository (CMR) for granules, `earthaccess` resolves the data URLs (increasingly these are direct S3 URLs in the Earthdata Cloud, not just HTTPS), and it opens an authenticated connection. Concretely, that means either exchanging our EDL bearer token for short-lived, temporary AWS credentials via NASA's S3 credential endpoint (for direct `s3://` access from in-region compute), or attaching the bearer token as an `Authorization` header on HTTPS requests (for out-of-region / non-AWS access, redirected through EDL's OAuth flow). `earthaccess` picks whichever path applies automatically based on where our code is running and what the granule's links support.\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Both paths start the same way: we search the Common Metadata Repository (CMR) for granules, `earthaccess` resolves the data URLs (increasingly these are direct S3 URLs in the Earthdata Cloud, not just HTTPS), and it opens an authenticated connection. Concretely, that means either exchanging our EDL bearer token for short-lived, temporary AWS credentials via NASA's S3 credential endpoint (for direct `s3://` access from in-region compute), or attaching the bearer token as an `Authorization` header on HTTPS requests (for out-of-region / non-AWS access, redirected through EDL's OAuth flow). `earthaccess` picks whichever path applies automatically based on where our code is running and what the granule's links support.\n",
"Whether we choose to download or stream data, we start the same way: we search the Common Metadata Repository (CMR) for granules, then `earthaccess` resolves the data URLs and opens an authenticated connection. Authentication and the data URLs resolved depend on whether we are using _in-region_ compute and utilizing direct `s3://` access, or if we are out-of-region using our local machine, HPC or non-AWS compute resources.\n
If we are _in-region_, data URLs resolve to direct `s3://` links in the Earthdata Cloud and authentication is by short-lived, temporary AWS credentials via NASA's S3 credential endpoint. If we are _out-of-region_, URL's resolve to HTTPS links and our EDL bearer-token is attached as an `Authorization` header to our HTTPS request.\n
`earthaccess` automatically picks the authentication method and URL based on where we run our code and what granule links support.\n"

"\n",
"Both paths start the same way: we search the Common Metadata Repository (CMR) for granules, `earthaccess` resolves the data URLs (increasingly these are direct S3 URLs in the Earthdata Cloud, not just HTTPS), and it opens an authenticated connection. Concretely, that means either exchanging our EDL bearer token for short-lived, temporary AWS credentials via NASA's S3 credential endpoint (for direct `s3://` access from in-region compute), or attaching the bearer token as an `Authorization` header on HTTPS requests (for out-of-region / non-AWS access, redirected through EDL's OAuth flow). `earthaccess` picks whichever path applies automatically based on where our code is running and what the granule's links support.\n",
"\n",
"The difference is what happens *after* that connection is open:\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"The difference is what happens *after* that connection is open:\n",
"The difference between the two access methods is what happens *after* that connection is open:\n",

"\n",
"An important feature is that earthaccess chooses block_size based on file size (4/8/16 MB) via `_optimal_fsspec_block_size()` and passes it to `fsspec.open()` this way block size is adaptive but can be overriden via `open_kwargs`. See the way this works with the NISAR mission: **<a href=\"https://nisar-docs.asf.alaska.edu/earthaccess/\">Using NISAR data with earthaccess</a>.**\n",
"\n",
"- A small read for, say, 200 bytes of header still triggers a fetch of a full 4 MB block containing those bytes.\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See comment about default block size above with regards to this and following paragraph.

"- Any *subsequent* read that falls within that already-cached block is served from memory — **no network request at all**.\n",
"- Reads are effectively pre-fetched in bulk, which amortizes request/connection overhead (and any per-request latency, like S3's or EDL's auth roundtrip) over many logical reads.\n",
"\n",
"This is exactly the same idea as page caching in an OS, or read-ahead buffering on a local disk — just implemented over HTTP range requests instead of a block device. The 4 MB size is a deliberate tradeoff: large enough to make each network request worthwhile and amortize latency, small enough not to waste bandwidth pulling data we'll never touch when we only need a small slice of a big file."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add some wikipedia links for page caching and read-ahead buffering?

"tags": []
},
"source": [
"This block-caching behavior is *why* streaming can be competitive with — or faster than — downloading when we only need part of a file: we're not paying for a full sequential transfer, but we're also not paying a network round trip for every single small read either. The 4 MB block size is a sensible default for typical Earth science granule sizes and access patterns, but it's worth knowing it exists if we ever see unexpectedly heavy data transfer for what feels like a \"small\" read — e.g., touching one value from every chunk of a variable can still pull in a lot of 4 MB blocks.\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we do see heavy data transfer, should a user increase block size? Is it worth adding some heuristics here for users?

"\n",
"| Format | Engine | How | Notes |\n",
"|---|---|---|---|\n",
"| **HDF5 / NetCDF4** | `h5netcdf` | `h5py.File(fileobj)` — h5py's core driver accepts any object with `read`/`seek`/`tell` | This is why fsspec/S3 remote reads work at all. Must use `engine=\"h5netcdf\"`, not `engine=\"netcdf4\"` (see below). |\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These are engines available in xarray.

"| **Kerchunk references** | `zarr` (via `fsspec.filesystem(\"reference\")`) | Wraps byte-range references into a virtual Zarr store | Works *for HDF5-based sources*. Kerchunk has no real HDF4 backend, so this doesn't rescue HDF4. |\n",
"| **NetCDF3 classic / 64-bit offset** | `scipy` | `scipy.io.netcdf_file` is a pure-Python parser, reads from any file-like object | Older/simpler format; no compression, so this is genuinely lazy-capable. |\n",
"| **OPeNDAP** | `pydap` or `netcdf4` (via DAP URL) | Not \"file-like\" in the fsspec sense — it's a query protocol, server does the subsetting | Effectively remote-native; different mechanism than byte-range reads. |\n",
"| **COG / GeoTIFF** | `rasterio`/`rioxarray` | GDAL's own VSI virtual filesystem (`/vsicurl/`, `/vsis3/`, `/vsiaz/`) | Not a Python file-like object, but functionally equivalent — GDAL issues range requests itself. Works well because COGs are internally tiled/overviewed for exactly this. |\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The COG/GeoTIFF engine in xarray is rasterio (engine="rastereio"). rioxarray is the package that makes this engine available. I suggest deleting rioxarray.

This branch has not been deployed

No deployments
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.

Add content to Direct S3 access - Open/stream files in the cloud how-to

6 participants