Skip to content

Add docs for accessing cogs with terra #125

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

Merged
merged 7 commits into from
Jun 9, 2025

Conversation

moradology
Copy link
Contributor

This PR adds some documentation about accessing data within cogs in R with terra without loading the whole file. Some (as yet unclear) combination of terra and the r kernel's behaviors prevented the kind of byte-range logging in #124, so this short guide sticks to demonstrating the API and describing its cloud-optimized behaviors

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

review-notebook-app bot commented Jan 14, 2025

View / edit / reply to this conversation on ReviewNB

wildintellect commented on 2025-01-14T00:59:03Z
----------------------------------------------------------------

Be clear the NO SIGN is particular to this dataset that's in a public bucket.

Should we also add

terra::setGDALconfig("GDAL_DISABLE_READDIR_ON_OPEN", "EMPTY_DIR") which is a speed up to keep GDAL from looking for things like TFW and other external files?


Copy link

review-notebook-app bot commented Jan 14, 2025

View / edit / reply to this conversation on ReviewNB

wildintellect commented on 2025-01-14T00:59:04Z
----------------------------------------------------------------

this is an interesting approach, nice because it operates with only 1 file, but a little weird at the same time in terms of arbitrarily calculating some neighboring extents based on the image.

I wonder if it's better to have a known bbox and two images to pull partials. I don't really want to complicate it by adding STAC (which we have some example to borrow from)

Maybe this would make sense with a plot of the full extent that has a box from the crop extents to be used.


@moradology
Copy link
Contributor Author

I agree the 1/100th square is pretty arbitrary. Perhaps it would make sense to build out and draw geojson for the extents to grab and the geotiff tiles to motivate the role of tiling in reducing necessary requests?

@wildintellect
Copy link
Contributor

I also realized that this example only shows AWS, we probably need a note that this method is valid for all "vsi" methods in gdal, and that the stars package can also be used. TBD link to the page about vectors which doesn't exist yet.

@moradology
Copy link
Contributor Author

I included a little note about VSI and a reference to the docs that explain such filesystems. I've also replaced the 1/100th (arbitrary) read with a couple of reads that specifically articulate the impact of internal tile structure on how (and how many) requests get made

@moradology
Copy link
Contributor Author

So far, there's no stars coverage but this is only because it appears stars requires a version of sf we don't have and which appears to not be installed (non zero exit) via either install.packages("stars") or, more specifically install.packages("stars") in the MAAP jupyter R kernel

Copy link

review-notebook-app bot commented Jan 15, 2025

View / edit / reply to this conversation on ReviewNB

zacdezgeo commented on 2025-01-15T16:17:26Z
----------------------------------------------------------------

maybe we can link the https://guide.cloudnativegeo.org/ in the introduction?


Copy link

review-notebook-app bot commented Jan 15, 2025

View / edit / reply to this conversation on ReviewNB

jsignell commented on 2025-01-15T18:14:17Z
----------------------------------------------------------------

I think in the very first sentence you should say what COGs are (a file format for storing raster data with a 2D aligned grid?)

The key benefits section feels like some double counting. I think you should remove "Subset Access" and "Cloud-Native Efficiency" those feel like more the mechanisms that enable "Cost Savings" and "Fast Workflows". Also don't COGs enable pyramiding? That feels like it could be mentioned somehow as well.


moradology commented on 2025-01-15T19:55:36Z
----------------------------------------------------------------

Good call. I even explicitly use overviews later on so I should probably acknowledge that

Copy link

review-notebook-app bot commented Jan 15, 2025

View / edit / reply to this conversation on ReviewNB

jsignell commented on 2025-01-15T18:14:18Z
----------------------------------------------------------------

This is kind of a meta comment, but I tend to glaze over inline comments in notebooks. Maybe just put these each in their own cell with markdown cells describing what is happening.


moradology commented on 2025-01-15T19:54:49Z
----------------------------------------------------------------

Wondered about that. They're so nice for getting the information right up next to the place where it has context but I think I do the same...

Copy link

review-notebook-app bot commented Jan 15, 2025

View / edit / reply to this conversation on ReviewNB

jsignell commented on 2025-01-15T18:14:18Z
----------------------------------------------------------------

The tile information is block size and layout right?

Statistics are block level right? Might be useful to make that explicit.


Copy link

review-notebook-app bot commented Jan 15, 2025

View / edit / reply to this conversation on ReviewNB

jsignell commented on 2025-01-15T18:14:19Z
----------------------------------------------------------------

what are these axes? I guess they are meters in EPSG 9807 or something, but good to make it clear


Copy link

review-notebook-app bot commented Jan 15, 2025

View / edit / reply to this conversation on ReviewNB

jsignell commented on 2025-01-15T18:14:20Z
----------------------------------------------------------------

Just a question I had in reading this: can you read the header for the COG without downloading the file?

Also: is there a way to prove that only one tile was downloaded?


wildintellect commented on 2025-01-15T21:52:42Z
----------------------------------------------------------------

  • Reading the header before download is effectively what rast does before crop
  • The only way I've ever been able to tell is external byte/network logging OR how fast it is. You can easily Time loading a crop vs loading the whole thing, and see just how much faster a partial read is.

moradology commented on 2025-01-22T16:17:51Z
----------------------------------------------------------------

In the python docs, I have some custom logging that demonstrates the byte-ranges being read. Unfortunately, not so easily done with terra's use of GDAL

Copy link

review-notebook-app bot commented Jan 15, 2025

View / edit / reply to this conversation on ReviewNB

jsignell commented on 2025-01-15T18:14:21Z
----------------------------------------------------------------

Line #6.    block_size_y <- block_size_pixels * r_res[2]

Do you think it would be clearer to just give a bounding box without showing how it is created? If we think about a real world scenario it doesn't matter that people know how to create the box. Actually maybe the whole code cell here should just be hidden since the visual serves a didactic purpose. Same with the other plot that shows gridlines.


moradology commented on 2025-01-15T20:06:31Z
----------------------------------------------------------------

I think I disagree on this point because it might be good to show how these APIs for pixel and geospatial coordinates work. I'll change things over if your take here is seconded though - I can totally see your point

wildintellect commented on 2025-01-16T00:10:50Z
----------------------------------------------------------------

the question is who is the target audience? I think the initial target is data users who almost always just need a bbox (or polygon) of data. I'm ok hiding some of that magic from them, maybe a collapsed cell block is the right answer.

Copy link
Contributor Author

Wondered about that. They're so nice for getting the information right up next to the place where it has context but I think I do the same...


View entire conversation on ReviewNB

Copy link
Contributor Author

Good call. I even explicitly use overviews later on so I should probably acknowledge that


View entire conversation on ReviewNB

Copy link
Contributor Author

I think I disagree on this point because it might be good to show how these APIs for pixel and geospatial coordinates work. I'll change things over if your take here is seconded though - I can totally see your point


View entire conversation on ReviewNB

Copy link
Contributor

  • Reading the header before download is effectively what rast does before crop
  • The only way I've ever been able to tell is external byte/network logging OR how fast it is. You can easily Time loading a crop vs loading the whole thing, and see just how much faster a partial read is.

View entire conversation on ReviewNB

Copy link
Contributor

the question is who is the target audience? I think the initial target is data users who almost always just need a bbox (or polygon) of data. I'm ok hiding some of that magic from them, maybe a collapsed cell block is the right answer.


View entire conversation on ReviewNB

Copy link
Contributor Author

In the python docs, I have some custom logging that demonstrates the byte-ranges being read. Unfortunately, not so easily done with terra's use of GDAL


View entire conversation on ReviewNB

@wildintellect
Copy link
Contributor

@smk0033 and @hrodmn you probably want to check this one too

@smk0033
Copy link
Collaborator

smk0033 commented Jan 29, 2025

Additional thought: is it worth adding/possible to add a TL;DR section for this notebook similar to the Python version?

It might also be worth linking and mentioning the Python version in this notebook and vice versa. Other than that I don't think I have any additional comments - I really like the detail and explanations in both notebooks!

Copy link

review-notebook-app bot commented Feb 25, 2025

View / edit / reply to this conversation on ReviewNB

wildintellect commented on 2025-02-25T23:09:21Z
----------------------------------------------------------------

Link to STARS documentation https://r-spatial.github.io/stars/


@smk0033 smk0033 requested a review from wildintellect April 15, 2025 20:20
@wildintellect
Copy link
Contributor

@moradology it's looking pretty good. Can you close the resolved comments so we know what remains?

@wildintellect
Copy link
Contributor

Minor note to check what the Navigation text will be for this tutorials with a local render or wait until we open the PR to main

@smk0033
Copy link
Collaborator

smk0033 commented Jun 2, 2025

@moradology it's looking pretty good. Can you close the resolved comments so we know what remains?

Hey @moradology! I know you've been busy with Black Marble, have you had a chance to close out resolved comments for this PR yet?

@moradology
Copy link
Contributor Author

Nope, this slipped from my agenda. I'll aim to get this taken care of before standup this week

@moradology
Copy link
Contributor Author

OK, that was much easier than I'd expected. Was afraid that there were new tasks I'd missed but it appears all comments had been resolved already 😅

@smk0033 smk0033 requested a review from hrodmn June 4, 2025 19:08
@smk0033
Copy link
Collaborator

smk0033 commented Jun 4, 2025

Great, thanks! Since Zac is out, adding Henry as an additional reviewer

@smk0033
Copy link
Collaborator

smk0033 commented Jun 9, 2025

Thanks @jsignell! Would this be good to merge now? @wildintellect

Copy link
Contributor

@wildintellect wildintellect left a comment

Choose a reason for hiding this comment

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

We'll need to update the Branch, and then plan to run this PR after merging some others to main first. cc: @jsignell

@jsignell jsignell force-pushed the feature/r-cog-access branch from 6f3536a to b20b9ec Compare June 9, 2025 20:52
Copy link

netlify bot commented Jun 9, 2025

Deploy Preview for harmonious-cajeta-5542ab ready!

Name Link
🔨 Latest commit b20b9ec
🔍 Latest deploy log https://app.netlify.com/projects/harmonious-cajeta-5542ab/deploys/6847498d299a970008e67584
😎 Deploy Preview https://deploy-preview-125--harmonious-cajeta-5542ab.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@jsignell jsignell merged commit 7e253a0 into cloudnativegeo:staging Jun 9, 2025
6 of 8 checks passed
wildintellect pushed a commit that referenced this pull request Jun 10, 2025
* Add docs for accessing cogs with terra
* Update docs to better illustrate internal tiling
* Add more information on gdal configs
* Add dependencies for stars and implement stars guide for R
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.

4 participants