From 4958e0fe90d6801097f493f70fc65467aacb8409 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Thu, 19 Sep 2019 16:54:52 -0400 Subject: [PATCH 1/8] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bafbfbe..f0ec5c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,7 +56,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Initial Release [Unreleased]: https://github.com/sat-utils/sat-stac/compare/master...develop -[v0.2.1]: https://github.com/sat-utils/sat-stac/compare/0.2.0...v0.3.0 +[v0.3.0]: https://github.com/sat-utils/sat-stac/compare/0.2.0...v0.3.0 [v0.2.0]: https://github.com/sat-utils/sat-stac/compare/0.1.3...v0.2.0 [v0.1.3]: https://github.com/sat-utils/sat-stac/compare/0.1.2...v0.1.3 [v0.1.2]: https://github.com/sat-utils/sat-stac/compare/0.1.1...v0.1.2 From 9dea099926b23cc08d70cac554b801fe7d11c1f0 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Thu, 19 Sep 2019 23:01:24 -0400 Subject: [PATCH 2/8] updated readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3cb6e33..7f87f32 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ The table below shows the corresponding versions between sat-stac and STAC: | sat-stac | STAC | | -------- | ---- | -| 0.1.x | 0.6.x, 0.7.x | -| 0.2.x | 0.6.x, 0.7.x | -| 0.3.x | 0.8.x | +| 0.1.x | 0.6.x - 0.7.x | +| 0.2.x | 0.6.x - 0.7.x | +| 0.3.x | 0.6.x - 0.8.x | ## Tutorials From cd53ce37ceef2122a3d1c027b133d9b44d42b7a5 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Thu, 19 Sep 2019 23:01:47 -0400 Subject: [PATCH 3/8] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f87f32..0ee64a9 100644 --- a/README.md +++ b/README.md @@ -49,4 +49,4 @@ The table below shows the corresponding versions between sat-stac and STAC: There are two tutorials. [Tutorial-1](tutorial-1.ipynb) includes an overview of how to create and manipulate STAC static catalogs. [Tutorial-2](tutorial-2.ipynb) is on the Python classes that reflect STAC entities: Catalogs, Collections, and Items. ## About -[sat-stac](https://github.com/sat-utils/sat-stac) was created by [Development Seed]() and is part of a collection of tools called [sat-utils](https://github.com/sat-utils). +[sat-stac](https://github.com/sat-utils/sat-stac) is part of a collection of tools called [sat-utils](https://github.com/sat-utils). From 9ba1d803f5554a0db1a612071dc5883a73e6f2ca Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Fri, 6 Dec 2019 02:51:43 -0500 Subject: [PATCH 4/8] filename template now works with collection --- satstac/item.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/satstac/item.py b/satstac/item.py index cbd7094..cfa9791 100644 --- a/satstac/item.py +++ b/satstac/item.py @@ -114,7 +114,9 @@ def substitute(self, string): string = string.replace(':', '_colon_') subs = {} for key in [i[1] for i in Formatter().parse(string.rstrip('/')) if i[1] is not None]: - if key == 'id': + if key == 'collection': + subs[key] = self.collection + elif key == 'id': subs[key] = self.id elif key in ['date', 'year', 'month', 'day']: vals = {'date': self.date, 'year': self.date.year, 'month': self.date.month, 'day': self.date.day} From ec58d7b76c3636bc5b257dacbbdeedc2a4651cee Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Fri, 6 Dec 2019 02:51:53 -0500 Subject: [PATCH 5/8] bump version and update changelog --- CHANGELOG.md | 3 +++ satstac/version.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0ec5c9..1b83825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed +- Item constructor now properly accepts passing in the collection + ## [v0.3.0] - 2019-09-19 ### Fixed diff --git a/satstac/version.py b/satstac/version.py index 0404d81..e1424ed 100644 --- a/satstac/version.py +++ b/satstac/version.py @@ -1 +1 @@ -__version__ = '0.3.0' +__version__ = '0.3.1' From 414e853627cf138fa137f63f5f47e9f865b73f9a Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Fri, 6 Dec 2019 13:59:07 -0500 Subject: [PATCH 6/8] fix collection in substitution --- satstac/item.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/satstac/item.py b/satstac/item.py index cfa9791..44ded20 100644 --- a/satstac/item.py +++ b/satstac/item.py @@ -115,7 +115,7 @@ def substitute(self, string): subs = {} for key in [i[1] for i in Formatter().parse(string.rstrip('/')) if i[1] is not None]: if key == 'collection': - subs[key] = self.collection + subs[key] = self._data['collection'] elif key == 'id': subs[key] = self.id elif key in ['date', 'year', 'month', 'day']: From 52d094910448da7791be5d3bc81af99b4e9f824e Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Fri, 6 Dec 2019 22:50:52 -0500 Subject: [PATCH 7/8] change itemcollections load to open and add remote capability --- satstac/itemcollection.py | 49 +++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/satstac/itemcollection.py b/satstac/itemcollection.py index 500f545..19e7573 100644 --- a/satstac/itemcollection.py +++ b/satstac/itemcollection.py @@ -1,8 +1,14 @@ import json +import os.path as op +import requests +from logging import getLogger from .collection import Collection from .item import Item -from .utils import terminal_calendar +from .thing import STACError +from .utils import terminal_calendar, get_s3_signed_url + +logger = getLogger(__name__) class ItemCollection(object): @@ -23,13 +29,42 @@ def __init__(self, items, collections=[], search={}): i._collection = cols[col] @classmethod - def load(cls, filename): + def open_remote(self, url, headers={}): + """ Open remote file """ + resp = requests.get(url, headers=headers) + if resp.status_code == 200: + dat = resp.text + else: + raise STACError('Unable to open %s' % url) + return json.loads(dat) + + @classmethod + def open(cls, filename): + """ Load an Items class from a GeoJSON FeatureCollection """ + """ Open an existing JSON data file """ + logger.debug('Opening %s' % filename) + if filename[0:5] == 'https': + try: + data = cls.open_remote(filename) + except STACError as err: + # try signed URL + url, headers = get_s3_signed_url(filename) + data = cls.open_remote(url, headers) + else: + if op.exists(filename): + data = open(filename).read() + data = json.loads(data) + else: + raise STACError('%s does not exist locally' % filename) + collections = [Collection(col) for col in data['collections']] + items = [Item(feature) for feature in data['features']] + return cls(items, collections=collections, search=data.get('search')) + + @classmethod + def load(cls, *args, **kwargs): """ Load an Items class from a GeoJSON FeatureCollection """ - with open(filename) as f: - geoj = json.loads(f.read()) - collections = [Collection(col) for col in geoj['collections']] - items = [Item(feature) for feature in geoj['features']] - return cls(items, collections=collections, search=geoj.get('search')) + logger.warning(f"ItemCollection.load() is deprecated, use ItemCollection.open()") + return cls.open(*args, **kwargs) def __len__(self): """ Number of scenes """ From 97a77125ee0775bc4b3b11fab9e8ad45fc2b8533 Mon Sep 17 00:00:00 2001 From: Matthew Hanson Date: Fri, 6 Dec 2019 22:51:30 -0500 Subject: [PATCH 8/8] update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b83825..4ba6f5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [v0.3.1] - 2019-12-06 + ### Fixed - Item constructor now properly accepts passing in the collection +- Item.substitute and item.get_filename now properly accept ${collection} as a template parameter + +### Deprecated +- ItemCollection.load() is now ItemCollection.open() and behaves like Item.open() (able to read remote files) ## [v0.3.0] - 2019-09-19