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

Sign vrt-strings #33

Merged
merged 6 commits into from
Nov 19, 2021
Merged

Sign vrt-strings #33

merged 6 commits into from
Nov 19, 2021

Conversation

TomAugspurger
Copy link

@TomAugspurger TomAugspurger commented Nov 10, 2021

xref #32, which also includes feature requests for signing files. This handles the in-memory string portion of things.

The imagined workflow here is something like

$ gdal_translate "STACIT:\"https://planetarycomputer.microsoft.com/api/stac/v1/search?collections=naip&bbox=-100,40,-99,41&datetime=2019-01-01T00:00:00Z%2F..\":asset=image" out.vrt

And then using it from Python like

In [1]: import pathlib, planetary_computer, rioxarray

In [2]: signed_vrt = planetary_computer.sign(pathlib.Path("out.vrt").read_text())

In [3]: ds = rioxarray.open_rasterio(signed_vrt)

In [4]: ds
Out[4]:
<xarray.DataArray (band: 4, y: 25023, x: 161196)>
[16134430032 values with dtype=uint8]
Coordinates:
  * band         (band) int64 1 2 3 4
  * x            (x) float64 4.09e+05 4.09e+05 4.09e+05 ... 5.057e+05 5.057e+05
  * y            (y) float64 4.436e+06 4.436e+06 ... 4.421e+06 4.421e+06
    spatial_ref  int64 0
Attributes:
    scale_factor:  1.0
    add_offset:    0.0
    long_name:     ('Red', 'Green', 'Blue', 'NIR')

@TomAugspurger
Copy link
Author

Seems like the pinned version of black didn't work with the latest Python 3.9:

Running black...
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.8/x64/bin/black", line 5, in <module>
    from black import patched_main
  File "/opt/hostedtoolcache/Python/3.9.8/x64/lib/python3.9/site-packages/black/__init__.py", line 52, in <module>
    from typed_ast import ast3, ast27
  File "/opt/hostedtoolcache/Python/3.9.8/x64/lib/python3.9/site-packages/typed_ast/ast3.py", line 40, in <module>
    from typed_ast import _ast3
ImportError: /opt/hostedtoolcache/Python/3.9.8/x64/lib/python3.9/site-packages/typed_ast/_ast3.cpython-39-x86_64-linux-gnu.so: undefined symbol: _PyUnicode_DecodeUnicodeEscape

I bumped those deps in c937cb1

planetary_computer/sas.py Show resolved Hide resolved
planetary_computer/sas.py Show resolved Hide resolved
planetary_computer/sas.py Show resolved Hide resolved
Returns:
str: The signed HREF or VRT
"""
if is_vrt_string(url):
Copy link
Author

Choose a reason for hiding this comment

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

For the record, this doesn't seem to have a measurable effect on the timing of planetary_computer.sign(url):

# main, after signing a URL to get a cached token
In [5]: %timeit planetary_computer.sign(url)
12.2 µs ± 1.97 µs per loop (mean ± std. dev. of 7 runs, 100000 loops each)

# HEAD
In [4]: %timeit planetary_computer.sign(url)
11.3 µs ± 1.7 µs per loop (mean ± std. dev. of 7 runs, 100000 loops each)

@TomAugspurger
Copy link
Author

FYI @lossyrob, I plan to merge this sometime today. It shouldn't have any effect on existing behavior and I think is pretty uncontroversial.

Copy link
Contributor

@lossyrob lossyrob left a comment

Choose a reason for hiding this comment

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

🚀

@TomAugspurger TomAugspurger merged commit 3d67a64 into main Nov 19, 2021
@TomAugspurger TomAugspurger deleted the feature/vrt branch November 19, 2021 16:32
@TomAugspurger TomAugspurger mentioned this pull request Nov 19, 2021
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