Skip to content

Commit c5b61dc

Browse files
Merge pull request #27 from sat-utils/develop
publish 0.2.1
2 parents 5cf8653 + c74493a commit c5b61dc

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010

1111
### Changed
1212
- Updated metadata fields for STAC 0.9.0-rc2
13+
- Update boto3-utils to 0.2.0
1314

1415
### Fixed
1516
- Point to correct github tag when linking to STAC collection metadata
@@ -39,4 +40,4 @@ Initial Release
3940
[Unreleased]: https://github.com/sat-utils/sat-stac-sentinel/compare/0.1.0...HEAD
4041
[v0.2.1]: https://github.com/sat-utils/sat-stac-sentinel/compare/0.2.0...0.2.1
4142
[v0.2.0]: https://github.com/sat-utils/sat-stac-sentinel/compare/0.1.0...0.2.0
42-
[v0.1.0]: https://github.com/sat-utils/sat-stac-sentinel/tree/0.1.0
43+
[v0.1.0]: https://github.com/sat-utils/sat-stac-sentinel/tree/0.1.0

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pyproj==2.4.1
22
shapely~=1.6.4.post2
3-
boto3-utils~=0.1.3
3+
boto3-utils~=0.2.0
4+
#git+git://github.com/matthewhanson/boto3-utils@develop
45
xmljson~=0.2.0
56
requests>=2.18.1

stac_sentinel/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def parse_args(args):
2929
parser.add_argument('--prefix', help='Only ingest scenes with a path starting with prefix', default=None)
3030
parser.add_argument('--start_date', help='Only ingest scenes with a Last Modified Date past provided start date', default=None)
3131
parser.add_argument('--end_date', help='Only ingest scenes with a Last Modified Date before provided end date', default=None)
32+
parser.add_argument('--direct_from_s3', help='Get metadata direct from s3 instead of free endpoint', default=False, action='store_true')
3233

3334
# output control
3435
parser.add_argument('--save', help='Save fetch Items as <id>.json files to this folder', default=None)
@@ -48,16 +49,15 @@ def cli():
4849
args = parse_args(sys.argv[1:])
4950
logging.basicConfig(stream=sys.stdout,
5051
level=args.pop('log') * 10,
51-
datefmt='%Y-%m-%d %H:%M:%S')
52+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
5253

5354
publish = args.pop('publish', None)
5455

5556
collection_id = args.pop('collection')
5657
savepath = args.pop('save')
5758
if savepath is not None:
5859
makedirs(savepath, exist_ok=True)
59-
for i, item in enumerate(SentinelSTAC.get_aws_archive(collection_id, **args)):
60-
print(item['properties']['datetime'], item['id'])
60+
for item in SentinelSTAC.get_aws_archive(collection_id, **args):
6161
# save items as JSON files
6262
if savepath:
6363
fname = op.join(savepath, '%s.json' % item['id'])

stac_sentinel/sentinel-s2-l1c.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"properties": {
5252
"constellation": "sentinel-2",
5353
"instruments": ["msi"],
54-
"gsd": 10,
54+
"eo:gsd": 10,
5555
"eo:bands": [
5656
{
5757
"name": "B01",

stac_sentinel/sentinel-s2-l2a.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"properties": {
5252
"constellation": "sentinel-2",
5353
"instruments": ["msi"],
54-
"gsd": 10,
54+
"eo:gsd": 10,
5555
"eo:bands": [
5656
{
5757
"name": "B01",

stac_sentinel/sentinel.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def kml_to_geometry(cls, filename):
106106
return cls.coordinates_to_geometry(coordinates)
107107

108108
@classmethod
109-
def get_aws_archive(cls, collection, **kwargs):
109+
def get_aws_archive(cls, collection, direct_from_s3=False, **kwargs):
110110
""" Generator function returning the archive of Sentinel data on AWS
111111
Keyword arguments:
112112
prefix -- Process only files keys begining with this prefix
@@ -120,16 +120,25 @@ def get_aws_archive(cls, collection, **kwargs):
120120
# get latest AWS inventory for this collection
121121
inventory_url = 's3://sentinel-inventory/%s/%s-inventory' % (collection, collection)
122122
inventory = s3().latest_inventory(inventory_url, **kwargs, suffix=cls.collections[collection])
123-
123+
#import pdb; pdb.set_trace()
124124
# iterate through latest inventory
125-
for i, record in enumerate(inventory):
126-
url = '%s/%s/%s' % (cls.FREE_URL, collection, record['Key'])
127-
logger.debug('Fetching initial metadata: %s' % url)
125+
from datetime import datetime
126+
for i, url in enumerate(inventory):
127+
if (i % 100) == 0:
128+
logger.info('%s records' % i)
129+
128130
try:
129-
# get initial JSON file file
130-
r = requests.get(url, stream=True)
131-
base_url = 's3://%s/%s' % (record['Bucket'], op.dirname(record['Key']))
132-
metadata = json.loads(r.text)
131+
if direct_from_s3:
132+
logger.debug('Fetching initial metadata: %s' % url)
133+
metadata = s3().read_json(url, requester_pays=True)
134+
else:
135+
# use free endpoint to access file
136+
parts = s3().urlparse(url)
137+
_url = '%s/%s/%s' % (cls.FREE_URL, collection, parts['key'])
138+
logger.debug('Fetching initial metadata: %s' % _url)
139+
r = requests.get(_url, stream=True)
140+
metadata = json.loads(r.text)
141+
133142
'''
134143
fnames = [f"{base_url}/{a}" for a in md['filenameMap'].values() if 'annotation' in a and 'calibration' not in a]
135144
metadata = {
@@ -140,11 +149,11 @@ def get_aws_archive(cls, collection, **kwargs):
140149
'''
141150
# transform to STAC Item
142151
sentinel_scene = cls(collection, metadata)
143-
item = sentinel_scene.to_stac(base_url=base_url)
152+
item = sentinel_scene.to_stac(base_url=url)
144153
yield item
145154

146155
except Exception as err:
147-
logger.error('Error creating STAC Item %s: %s' % (record['url'], err))
156+
logger.error('Error creating STAC Item from %s, Error: %s' % (url, err))
148157
continue
149158

150159
def to_stac_from_s1l1c(self, **kwargs):

0 commit comments

Comments
 (0)