Skip to content

Commit

Permalink
Merge pull request #61 from sat-utils/develop
Browse files Browse the repository at this point in the history
publish 0.4.0
  • Loading branch information
matthewhanson authored Jun 12, 2020
2 parents d6d4866 + c2fbcd0 commit 42b6743
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 60 deletions.
12 changes: 6 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.4.0-rc1] - 2020-01-26
## [v0.4.0] - 2020-06-11

### Added
- In README, Directed users who want to do large scale creation or updating of catalogs to the [PySTAC](https://github.com/azavea/pystac) library instead
- STAC_PATH_TEMPLATE envvar added to store default path template for saving downloaded files, defaults to `${collection}/${id}`, files are then downloaded in that directory with a name equal to `<id>_<assetkey>.<ext>`
- README directs users who want to do large scale creation or updating of catalogs to the [PySTAC](https://github.com/azavea/pystac) library instead
- ItemCollections.asset_defnition function for printing info on assets

### Changed
- Environment variable SATUTILS_STAC_VERSION changed to STAC_VERSION
- Default STAC_VERSION changed to 0.9.0
- Default STAC_VERSION changed to 1.0.0-beta.1
- Item.get_filename replaced with Item.get_path which takes in single template string rather than separate `path` and `filename` arguments
- Collection.add_item() function input keywords changed to `path_template` and `filename_template`
- Collection.add_item() function input keywords changed `filename_template`

### Fixed
- Substitution of templates on Windows: [issue](https://github.com/sat-utils/sat-stac/issues/51)

### Removed
- Item.get_filename removed in favor of Item.get_path
- Storing search information in an ItemCollections file (and associated functions)

## [v0.3.3] - 2020-01-23

Expand Down
9 changes: 7 additions & 2 deletions satstac/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ def assets_by_common_name(self):
if self._assets_by_common_name is None:
self._assets_by_common_name = {}
for a in self.assets:
bands = self.assets[a].get('eo:bands', [])
bands = []
col = self.collection()._data
if 'eo:bands' in self.assets[a]:
bands = self.assets[a]['eo:bands']
elif 'item_assets' in col:
bands = col['item_assets'][a].get('eo:bands', [])
if len(bands) == 1:
eo_band = bands[0].get('common_name')
if eo_band:
Expand All @@ -87,7 +92,7 @@ def assets_by_common_name(self):

def asset(self, key):
""" Get asset for this key OR common_name """
if key in self.assets:
if key in self.assets.keys():
return self.assets[key]
elif key in self.assets_by_common_name:
return self.assets_by_common_name[key]
Expand Down
49 changes: 19 additions & 30 deletions satstac/itemcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
class ItemCollection(object):
""" A GeoJSON FeatureCollection of STAC Items with associated Collections """

def __init__(self, items, collections=[], search={}):
def __init__(self, items, collections=[]):
""" Initialize with a list of Item objects """
self._collections = collections
self._items = items
self._search = search
# link Items to their Collections
cols = {c.id: c for c in self._collections}
for i in self._items:
Expand Down Expand Up @@ -58,7 +57,7 @@ def open(cls, filename):
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'))
return cls(items, collections=collections)

@classmethod
def load(cls, *args, **kwargs):
Expand All @@ -85,31 +84,6 @@ def collection(self, id):
else:
return None

def bbox(self):
""" Get bounding box of search """
if 'intersects' in self._search.get('parameters', {}):
coords = self._search['parameters']['intersects']['geometry']['coordinates']
lats = [c[1] for c in coords[0]]
lons = [c[0] for c in coords[0]]
return [min(lons), min(lats), max(lons), max(lats)]
else:
return None

def center(self):
if 'intersects' in self._search.get('parameters', {}):
coords = self._search['parameters']['intersects']['geometry']['coordinates']
lats = [c[1] for c in coords[0]]
lons = [c[0] for c in coords[0]]
return [(min(lats) + max(lats))/2.0, (min(lons) + max(lons))/2.0]
else:
return None

def search_geometry(self):
if 'intersects' in self._search.get('parameters', {}):
return self._search['parameters']['intersects']
else:
return None

def properties(self, key, date=None):
""" Set of values for 'key' property in Items, for specific date if provided """
if date is None:
Expand Down Expand Up @@ -138,6 +112,23 @@ def calendar(self, group='platform'):
date_labels[d] = groups[0]
return terminal_calendar(date_labels)

def assets_definition(self):
fields = ['Key', 'Title', 'Common Name(s)', 'Type']
w = [12, 35, 20, 50]
for c in self._collections:
txt = f"Collection: {c.id}\n"
txt += ''.join([f"{fields[i]:{w[i]}}" for i in range(len(w))]) + '\n'
for key in c._data['item_assets']:
asset = c._data['item_assets'][key]
if 'eo:bands' in asset:
bands = ', '.join([b.get('common_name', None) for b in asset['eo:bands'] if 'common_name' in b])
else:
bands = ''
#import pdb; pdb.set_trace()
vals = [key, asset['title'], bands, asset['type']]
txt += ''.join([f"{vals[i]:{w[i]}}" for i in range(len(w))]) + '\n'
return txt

def save(self, filename):
""" Save scene metadata """
with open(filename, 'w') as f:
Expand All @@ -151,8 +142,6 @@ def geojson(self):
'features': features,
'collections': [c._data for c in self._collections],
}
if self._search is not None:
geoj['search'] = self._search
return geoj

def filter(self, key, values):
Expand Down
2 changes: 1 addition & 1 deletion satstac/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.4.0-rc2'
__version__ = '0.4.0'
11 changes: 0 additions & 11 deletions test/test_itemcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ def test_no_collection(self):
col = items.collection('nosuchcollection')
assert(col is None)

def test_bbox(self):
items = self.load_items()
bbox = items.bbox()
assert(len(bbox) == 4)
assert(bbox == [11.984710693359375, 44.815941348210835, 12.752380371093748, 45.67740123855739])

def test_center(self):
items = self.load_items()
center = items.center()
assert(center == [45.24667129338411, 12.368545532226562])

def test_get_properties(self):
""" Get set of properties """
items = self.load_items()
Expand Down
20 changes: 10 additions & 10 deletions tutorial-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<generator object Catalog.catalogs at 0x7f3256ebd0d0>\n",
"<generator object Catalog.collections at 0x7f3256ebd150>\n",
"<generator object Catalog.items at 0x7f3256ebd250>\n"
"<generator object Catalog.catalogs at 0x7f5b60def050>\n",
"<generator object Catalog.collections at 0x7f5b60def0d0>\n",
"<generator object Catalog.items at 0x7f5b60def1d0>\n"
]
}
],
Expand Down Expand Up @@ -169,7 +169,8 @@
"landsat-8-l1\n",
"\n",
"**Items**\n",
"LC81530252014153LGN00\n"
"S2B_25WFU_20200610_0_L1C\n",
"LC08_L1TP_152038_20200611_20200611_01_RT\n"
]
}
],
Expand Down Expand Up @@ -362,7 +363,7 @@
"output_type": "stream",
"text": [
"Item name: landsat-8-l1\n",
"Item filename: mycat/mykitten/landsat-8-l1/LC81530252014153LGN00.json\n",
"Item filename: mycat/mykitten/landsat-8-l1/LC08_L1TP_152038_20200611_20200611_01_RT.json\n",
"\n",
"**Item links**\n",
"[ {'href': '../../catalog.json', 'rel': 'root'},\n",
Expand Down Expand Up @@ -424,21 +425,20 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Item filename: mycat/mykitten/landsat-8-l1/107/18/2014-06-02/LC81530252014153LGN00.json\n",
"Item filename: mycat/mykitten/landsat-8-l1/107/18/2020-06-11/LC08_L1TP_152038_20200611_20200611_01_RT.json\n",
"\n",
"**Item links**\n",
"[ {'href': '../../../../../catalog.json', 'rel': 'root'},\n",
" {'href': '../catalog.json', 'rel': 'parent'},\n",
" {'href': 'catalog.json', 'rel': 'parent'},\n",
" {'href': '../../../catalog.json', 'rel': 'collection'}]\n"
]
}
],
"source": [
"# save \n",
"path = '${landsat:path}/${landsat:row}'\n",
"filename = '${date}/${id}.json'\n",
"filename = '${landsat:path}/${landsat:row}/${date}/${id}.json'\n",
"\n",
"collection.add_item(item, path_template=path, filename_template=filename)\n",
"collection.add_item(item, filename_template=filename)\n",
"print('Item filename: ', item.filename)\n",
"\n",
"print('\\n**Item links**')\n",
Expand Down

0 comments on commit 42b6743

Please sign in to comment.