Skip to content

Commit 42b6743

Browse files
Merge pull request #61 from sat-utils/develop
publish 0.4.0
2 parents d6d4866 + c2fbcd0 commit 42b6743

File tree

6 files changed

+43
-60
lines changed

6 files changed

+43
-60
lines changed

CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

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

1111
### Added
12-
- 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
13-
- 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>`
12+
- README directs users who want to do large scale creation or updating of catalogs to the [PySTAC](https://github.com/azavea/pystac) library instead
13+
- ItemCollections.asset_defnition function for printing info on assets
1414

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

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

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

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

satstac/item.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ def assets_by_common_name(self):
7878
if self._assets_by_common_name is None:
7979
self._assets_by_common_name = {}
8080
for a in self.assets:
81-
bands = self.assets[a].get('eo:bands', [])
81+
bands = []
82+
col = self.collection()._data
83+
if 'eo:bands' in self.assets[a]:
84+
bands = self.assets[a]['eo:bands']
85+
elif 'item_assets' in col:
86+
bands = col['item_assets'][a].get('eo:bands', [])
8287
if len(bands) == 1:
8388
eo_band = bands[0].get('common_name')
8489
if eo_band:
@@ -87,7 +92,7 @@ def assets_by_common_name(self):
8792

8893
def asset(self, key):
8994
""" Get asset for this key OR common_name """
90-
if key in self.assets:
95+
if key in self.assets.keys():
9196
return self.assets[key]
9297
elif key in self.assets_by_common_name:
9398
return self.assets_by_common_name[key]

satstac/itemcollection.py

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
class ItemCollection(object):
1515
""" A GeoJSON FeatureCollection of STAC Items with associated Collections """
1616

17-
def __init__(self, items, collections=[], search={}):
17+
def __init__(self, items, collections=[]):
1818
""" Initialize with a list of Item objects """
1919
self._collections = collections
2020
self._items = items
21-
self._search = search
2221
# link Items to their Collections
2322
cols = {c.id: c for c in self._collections}
2423
for i in self._items:
@@ -58,7 +57,7 @@ def open(cls, filename):
5857
raise STACError('%s does not exist locally' % filename)
5958
collections = [Collection(col) for col in data['collections']]
6059
items = [Item(feature) for feature in data['features']]
61-
return cls(items, collections=collections, search=data.get('search'))
60+
return cls(items, collections=collections)
6261

6362
@classmethod
6463
def load(cls, *args, **kwargs):
@@ -85,31 +84,6 @@ def collection(self, id):
8584
else:
8685
return None
8786

88-
def bbox(self):
89-
""" Get bounding box of search """
90-
if 'intersects' in self._search.get('parameters', {}):
91-
coords = self._search['parameters']['intersects']['geometry']['coordinates']
92-
lats = [c[1] for c in coords[0]]
93-
lons = [c[0] for c in coords[0]]
94-
return [min(lons), min(lats), max(lons), max(lats)]
95-
else:
96-
return None
97-
98-
def center(self):
99-
if 'intersects' in self._search.get('parameters', {}):
100-
coords = self._search['parameters']['intersects']['geometry']['coordinates']
101-
lats = [c[1] for c in coords[0]]
102-
lons = [c[0] for c in coords[0]]
103-
return [(min(lats) + max(lats))/2.0, (min(lons) + max(lons))/2.0]
104-
else:
105-
return None
106-
107-
def search_geometry(self):
108-
if 'intersects' in self._search.get('parameters', {}):
109-
return self._search['parameters']['intersects']
110-
else:
111-
return None
112-
11387
def properties(self, key, date=None):
11488
""" Set of values for 'key' property in Items, for specific date if provided """
11589
if date is None:
@@ -138,6 +112,23 @@ def calendar(self, group='platform'):
138112
date_labels[d] = groups[0]
139113
return terminal_calendar(date_labels)
140114

115+
def assets_definition(self):
116+
fields = ['Key', 'Title', 'Common Name(s)', 'Type']
117+
w = [12, 35, 20, 50]
118+
for c in self._collections:
119+
txt = f"Collection: {c.id}\n"
120+
txt += ''.join([f"{fields[i]:{w[i]}}" for i in range(len(w))]) + '\n'
121+
for key in c._data['item_assets']:
122+
asset = c._data['item_assets'][key]
123+
if 'eo:bands' in asset:
124+
bands = ', '.join([b.get('common_name', None) for b in asset['eo:bands'] if 'common_name' in b])
125+
else:
126+
bands = ''
127+
#import pdb; pdb.set_trace()
128+
vals = [key, asset['title'], bands, asset['type']]
129+
txt += ''.join([f"{vals[i]:{w[i]}}" for i in range(len(w))]) + '\n'
130+
return txt
131+
141132
def save(self, filename):
142133
""" Save scene metadata """
143134
with open(filename, 'w') as f:
@@ -151,8 +142,6 @@ def geojson(self):
151142
'features': features,
152143
'collections': [c._data for c in self._collections],
153144
}
154-
if self._search is not None:
155-
geoj['search'] = self._search
156145
return geoj
157146

158147
def filter(self, key, values):

satstac/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.4.0-rc2'
1+
__version__ = '0.4.0'

test/test_itemcollection.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,6 @@ def test_no_collection(self):
4848
col = items.collection('nosuchcollection')
4949
assert(col is None)
5050

51-
def test_bbox(self):
52-
items = self.load_items()
53-
bbox = items.bbox()
54-
assert(len(bbox) == 4)
55-
assert(bbox == [11.984710693359375, 44.815941348210835, 12.752380371093748, 45.67740123855739])
56-
57-
def test_center(self):
58-
items = self.load_items()
59-
center = items.center()
60-
assert(center == [45.24667129338411, 12.368545532226562])
61-
6251
def test_get_properties(self):
6352
""" Get set of properties """
6453
items = self.load_items()

tutorial-1.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@
126126
"name": "stdout",
127127
"output_type": "stream",
128128
"text": [
129-
"<generator object Catalog.catalogs at 0x7f3256ebd0d0>\n",
130-
"<generator object Catalog.collections at 0x7f3256ebd150>\n",
131-
"<generator object Catalog.items at 0x7f3256ebd250>\n"
129+
"<generator object Catalog.catalogs at 0x7f5b60def050>\n",
130+
"<generator object Catalog.collections at 0x7f5b60def0d0>\n",
131+
"<generator object Catalog.items at 0x7f5b60def1d0>\n"
132132
]
133133
}
134134
],
@@ -169,7 +169,8 @@
169169
"landsat-8-l1\n",
170170
"\n",
171171
"**Items**\n",
172-
"LC81530252014153LGN00\n"
172+
"S2B_25WFU_20200610_0_L1C\n",
173+
"LC08_L1TP_152038_20200611_20200611_01_RT\n"
173174
]
174175
}
175176
],
@@ -362,7 +363,7 @@
362363
"output_type": "stream",
363364
"text": [
364365
"Item name: landsat-8-l1\n",
365-
"Item filename: mycat/mykitten/landsat-8-l1/LC81530252014153LGN00.json\n",
366+
"Item filename: mycat/mykitten/landsat-8-l1/LC08_L1TP_152038_20200611_20200611_01_RT.json\n",
366367
"\n",
367368
"**Item links**\n",
368369
"[ {'href': '../../catalog.json', 'rel': 'root'},\n",
@@ -424,21 +425,20 @@
424425
"name": "stdout",
425426
"output_type": "stream",
426427
"text": [
427-
"Item filename: mycat/mykitten/landsat-8-l1/107/18/2014-06-02/LC81530252014153LGN00.json\n",
428+
"Item filename: mycat/mykitten/landsat-8-l1/107/18/2020-06-11/LC08_L1TP_152038_20200611_20200611_01_RT.json\n",
428429
"\n",
429430
"**Item links**\n",
430431
"[ {'href': '../../../../../catalog.json', 'rel': 'root'},\n",
431-
" {'href': '../catalog.json', 'rel': 'parent'},\n",
432+
" {'href': 'catalog.json', 'rel': 'parent'},\n",
432433
" {'href': '../../../catalog.json', 'rel': 'collection'}]\n"
433434
]
434435
}
435436
],
436437
"source": [
437438
"# save \n",
438-
"path = '${landsat:path}/${landsat:row}'\n",
439-
"filename = '${date}/${id}.json'\n",
439+
"filename = '${landsat:path}/${landsat:row}/${date}/${id}.json'\n",
440440
"\n",
441-
"collection.add_item(item, path_template=path, filename_template=filename)\n",
441+
"collection.add_item(item, filename_template=filename)\n",
442442
"print('Item filename: ', item.filename)\n",
443443
"\n",
444444
"print('\\n**Item links**')\n",

0 commit comments

Comments
 (0)