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

Add docs for accessing cogs with terra #125

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from

Conversation

moradology
Copy link

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
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
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
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
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
Author

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


View entire conversation on ReviewNB

Copy link
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
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

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