Skip to content

Commit

Permalink
Merge branch 'main' into fix/732-special-use-domains
Browse files Browse the repository at this point in the history
  • Loading branch information
duckontheweb authored Mar 31, 2022
2 parents 4ab3bb6 + 037fd73 commit 3ab25f2
Show file tree
Hide file tree
Showing 11 changed files with 592 additions and 671 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
- Enum MediaType entry for PDF documents ([#758](https://github.com/stac-utils/pystac/pull/758))
- Updated Link to obtain stac_io from owner root ([#762](https://github.com/stac-utils/pystac/pull/762))
- Replace test.com with special-use domain name. ([#769](https://github.com/stac-utils/pystac/pull/769))
- Updated AssetDefinition to have create, apply methods ([#768](https://github.com/stac-utils/pystac/pull/768))

### Removed

### Changed

### Fixed

- "How to create STAC catalogs" tutorial ([#775](https://github.com/stac-utils/pystac/pull/775))

## [v1.4.0]

### Added
Expand Down
7 changes: 3 additions & 4 deletions docs/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ for reading from AWS's S3 cloud object storage using `boto3
from pystac.stac_io import DefaultStacIO, StacIO
class CustomStacIO(DefaultStacIO):
def __init__():
def __init__(self):
self.s3 = boto3.resource("s3")
def read_text(
Expand All @@ -302,8 +302,7 @@ for reading from AWS's S3 cloud object storage using `boto3
if parsed.scheme == "s3":
bucket = parsed.netloc
key = parsed.path[1:]
s3 = boto3.resource("s3")
s3.Object(bucket, key).put(Body=txt, ContentEncoding="utf-8")
self.s3.Object(bucket, key).put(Body=txt, ContentEncoding="utf-8")
else:
super().write_text(dest, txt, *args, **kwargs)
Expand All @@ -322,7 +321,7 @@ to take advantage of connection pooling using a `requests.Session
from pystac.stac_io import DefaultStacIO, StacIO
class ConnectionPoolingIO(DefaultStacIO):
def __init__():
def __init__(self):
self.session = requests.Session()
def read_text(
Expand Down
9 changes: 0 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import subprocess
from typing import Any, Dict, List

from sphinx.util import logging

sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.abspath("../"))
Expand Down Expand Up @@ -239,11 +238,3 @@
# -- Substutition variables

rst_epilog = f".. |stac_version| replace:: {STACVersion.DEFAULT_STAC_VERSION}"

# -- Suppress warnings from the extlinks extension
# We do this to avoid warnings like the following in our Jupyter notebook tutorials
# where we do not want to use Sphinx constructs:
# WARNING: hardcoded link 'https://github.com/stac-extensions/eo' could be replaced
# by an extlink (try using ':stac-ext:`eo`' instead)
linklogger = logging.getLogger("sphinx.ext.extlinks")
linklogger.setLevel(40) # Ignore messages less severe than ERROR
1,152 changes: 504 additions & 648 deletions docs/tutorials/how-to-create-stac-catalogs.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pystac/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Catalog(STACObject):
Args:
id : Identifier for the catalog. Must be unique within the STAC.
description : Detailed multi-line description to fully explain the catalog.
`CommonMark 0.28 syntax <https://commonmark.org/>`_ MAY be used for rich
`CommonMark 0.29 syntax <https://commonmark.org/>`_ MAY be used for rich
text representation.
title : Optional short descriptive one-line title for the catalog.
stac_extensions : Optional list of extensions the Catalog implements.
Expand Down
2 changes: 1 addition & 1 deletion pystac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class Collection(Catalog):
Args:
id : Identifier for the collection. Must be unique within the STAC.
description : Detailed multi-line description to fully explain the
collection. `CommonMark 0.28 syntax <https://commonmark.org/>`_ MAY
collection. `CommonMark 0.29 syntax <https://commonmark.org/>`_ MAY
be used for rich text representation.
extent : Spatial and temporal extents that describe the bounds of
all items contained within this Collection.
Expand Down
62 changes: 60 additions & 2 deletions pystac/extensions/item_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,64 @@ def __eq__(self, o: object) -> bool:
return NotImplemented
return self.to_dict() == o.to_dict()

@classmethod
def create(
cls,
title: Optional[str],
description: Optional[str],
media_type: Optional[str],
roles: Optional[List[str]],
) -> "AssetDefinition":
"""
Creates a new asset definition.
Args:
title : Displayed title for clients and users.
description : Description of the Asset providing additional details,
such as how it was processed or created.
`CommonMark 0.29 <http://commonmark.org/>`__ syntax MAY be used
for rich text representation.
media_type : `media type\
<https://github.com/radiantearth/stac-spec/tree/v1.0.0/catalog-spec/catalog-spec.md#media-types>`__
of the asset.
roles : `semantic roles
<https://github.com/radiantearth/stac-spec/tree/v1.0.0/item-spec/item-spec.md#asset-role-types>`__
of the asset, similar to the use of rel in links.
"""
asset_defn = cls({})
asset_defn.apply(
title=title, description=description, media_type=media_type, roles=roles
)
return asset_defn

def apply(
self,
title: Optional[str],
description: Optional[str],
media_type: Optional[str],
roles: Optional[List[str]],
) -> None:
"""
Sets the properties for this asset definition.
Args:
title : Displayed title for clients and users.
description : Description of the Asset providing additional details,
such as how it was processed or created.
`CommonMark 0.29 <http://commonmark.org/>`__ syntax MAY be used
for rich text representation.
media_type : `media type\
<https://github.com/radiantearth/stac-spec/tree/v1.0.0/catalog-spec/catalog-spec.md#media-types>`__
of the asset.
roles : `semantic roles
<https://github.com/radiantearth/stac-spec/tree/v1.0.0/item-spec/item-spec.md#asset-role-types>`__
of the asset, similar to the use of rel in links.
"""
self.title = title
self.description = description
self.media_type = media_type
self.roles = roles

@property
def title(self) -> Optional[str]:
"""Gets or sets the displayed title for clients and users."""
Expand Down Expand Up @@ -65,7 +123,7 @@ def description(self, v: Optional[str]) -> None:
@property
def media_type(self) -> Optional[str]:
"""Gets or sets the `media type
<https://github.com/radiantearth/stac-spec/tree/v1.0.0-rc.1/catalog-spec/catalog-spec.md#media-types>`__
<https://github.com/radiantearth/stac-spec/tree/v1.0.0/catalog-spec/catalog-spec.md#media-types>`__
of the asset."""
return self.properties.get(ASSET_TYPE_PROP)

Expand All @@ -79,7 +137,7 @@ def media_type(self, v: Optional[str]) -> None:
@property
def roles(self) -> Optional[List[str]]:
"""Gets or sets the `semantic roles
<https://github.com/radiantearth/stac-spec/tree/v1.0.0-rc.1/item-spec/item-spec.md#asset-role-types>`__
<https://github.com/radiantearth/stac-spec/tree/v1.0.0/item-spec/item-spec.md#asset-role-types>`__
of the asset, similar to the use of rel in links."""
return self.properties.get(ASSET_ROLES_PROP)

Expand Down
4 changes: 2 additions & 2 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ipython==8.1.1
Sphinx==4.4.0
ipython==8.2.0
Sphinx==4.5.0
sphinxcontrib-fulltoc==1.2.0
nbsphinx==0.8.8
pydata-sphinx-theme==0.8.0
Expand Down
6 changes: 3 additions & 3 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mypy==0.941
mypy==0.942
flake8==4.0.1
black==22.1.0
black==22.3.0

codespell==2.1.0

jsonschema==4.4.0
coverage==6.3.2
doc8==0.10.1
doc8==0.11.0

types-python-dateutil==2.8.10
types-orjson==3.6.2
Expand Down
3 changes: 2 additions & 1 deletion tests/extensions/test_eo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ def test_create(self) -> None:
description=Band.band_description("red"),
center_wavelength=0.65,
full_width_half_max=0.1,
solar_illumination=42.0,
)

self.assertEqual(band.name, "B01")
self.assertEqual(band.common_name, "red")
self.assertEqual(band.description, "Common name: red, Range: 0.6 to 0.7")
self.assertEqual(band.center_wavelength, 0.65)
self.assertEqual(band.full_width_half_max, 0.1)

self.assertEqual(band.solar_illumination, 42.0)
self.assertEqual(band.__repr__(), "<Band name=B01>")

def test_band_description_unknown_band(self) -> None:
Expand Down
13 changes: 13 additions & 0 deletions tests/extensions/test_item_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ def setUp(self) -> None:
TestCases.get_path("data-files/item-assets/example-landsat8.json")
)

def test_create(self) -> None:
title = "Coastal Band (B1)"
description = "Coastal Band Top Of the Atmosphere"
media_type = "image/tiff; application=geotiff"
roles = ["data"]
asset_defn = AssetDefinition.create(
title=title, description=description, media_type=media_type, roles=roles
)
self.assertEqual(asset_defn.title, title)
self.assertEqual(asset_defn.description, description)
self.assertEqual(asset_defn.media_type, media_type)
self.assertEqual(asset_defn.roles, roles)

def test_title(self) -> None:
asset_defn = AssetDefinition({})
title = "Very Important Asset"
Expand Down

0 comments on commit 3ab25f2

Please sign in to comment.