Skip to content

Commit 4135bf8

Browse files
Merge pull request #29 from sat-utils/develop
publish 0.1.1
2 parents 404f1a4 + 7ef8ffb commit 4135bf8

File tree

8 files changed

+53
-59
lines changed

8 files changed

+53
-59
lines changed

.circleci/config.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,6 @@ references:
2525

2626
jobs:
2727

28-
build_and_test_27:
29-
docker:
30-
- image: circleci/python:2.7.13
31-
steps:
32-
- *restore_repo
33-
- checkout
34-
- *save_repo
35-
- restore_cache:
36-
keys:
37-
- v1-dependencies27-{{ checksum "requirements.txt"}}
38-
- v1-dependencies27
39-
- run: |
40-
pip install virtualenv
41-
virtualenv ~/venv27
42-
. ~/venv27/bin/activate
43-
pip install -r requirements.txt
44-
pip install -r requirements-dev.txt
45-
pip install .
46-
cd test
47-
pytest -v --cov satstac --cov-report term-missing
48-
- save_cache:
49-
key: v1-dependencies27-{{ checksum "requirements.txt"}}
50-
paths:
51-
- ~/venv27
52-
5328
build_and_test_35:
5429
docker:
5530
- image: circleci/python:3.5
@@ -149,9 +124,6 @@ jobs:
149124
150125
workflows:
151126
version: 2
152-
build_test_27:
153-
jobs:
154-
- build_and_test_27
155127
build_test_35:
156128
jobs:
157129
- build_and_test_35

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [v0.1.1] - 2019-01-15
10+
11+
### Added
12+
13+
- When adding items to a catalog the parent catalog of the item is now cached. This can greatly improve ingest speed when ingesting multiple items under the same parent, especially if the catalog is a remote catalog (i.e., updating catalog on an s3 bucket).
14+
15+
### Changed
16+
17+
- Python 3 only. With Python 2.7 going unsupported in 2020 the time has come to stop supporting 2.7. There are too many additions in Python3 that continue to make backward compatability with Python 2.7 more difficult. In the case of this release the addition of caching using `functools` made sat-stac incompatible with Python 2.7.
18+
- More lenient version requirements for `requests` (now <=2.19.1). Otherwise can cause dependency incompatibility problems in some cases.
19+
- Behavior of `path` and `filename` keyword arguments to Collection.add_item() has changed slightly. The components of `path` are now exclusively used to generate sub-catalogs, while `filename` is the relative filename (which could include a further subdirectory) from the last sub-catalog (it's parent). Before, it was assumed that Item files were always in a single subdirectory under it's parent catalog.
20+
- Tutorials updated
921

1022
## [v0.1.0] - 2019-01-13
1123

1224
Initial Release
1325

1426
[Unreleased]: https://github.com/sat-utils/sat-stac/compare/master...develop
27+
[v0.1.1]: https://github.com/sat-utils/sat-api/compare/0.1.0...v0.1.1
1528
[v0.1.0]: https://github.com/sat-utils/sat-stac/tree/0.1.0

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![CircleCI](https://circleci.com/gh/sat-utils/sat-stac.svg?style=svg&circle-token=ef97f3eea6cf901646fc2951e5a941686456b0da)](https://circleci.com/gh/sat-utils/sat-stac) [![PyPI version](https://badge.fury.io/py/sat-stac.svg)](https://badge.fury.io/py/sat-stac) [![codecov](https://codecov.io/gh/sat-utils/sat-stac/branch/master/graph/badge.svg)](https://codecov.io/gh/sat-utils/sat-stac)
44

5-
This is a Python library for working with [Spatio-Temporal Asset Catalogs (STAC)](https://github.com/radiantearth/stac-spec). It can be used to
5+
This is a Python 3 library for working with [Spatio-Temporal Asset Catalogs (STAC)](https://github.com/radiantearth/stac-spec). It can be used to
66

77
- Open and update existing catalogs
88
- Traverse through catalogs
@@ -14,7 +14,7 @@ This is a Python library for working with [Spatio-Temporal Asset Catalogs (STAC)
1414
## Installation
1515

1616
sat-stac has minimal dependencies (`requests` and `python-dateutil`). To install sat-stac from PyPi:
17-
sat-stac cam be installed from this repository, or .
17+
sat-stac can be installed from pip or the source repository.
1818

1919
```bash
2020
$ pip install sat-stac
@@ -30,7 +30,7 @@ $ pip install .
3030

3131

3232
#### Versions
33-
The initial sat-stac version is 0.1.0, which uses the STAC spec v0.6.0. To install other versions of sat-stac, install the matching version of sat-stac.
33+
The latest version of sat-stac is 0.1.1, which uses the STAC spec v0.6.0. To install other versions of sat-stac, install the matching version of sat-stac.
3434

3535
```bash
3636
pip install satstac==0.1.0
@@ -40,7 +40,7 @@ The table below shows the corresponding versions between sat-stac and STAC:
4040

4141
| sat-stac | STAC |
4242
| -------- | ---- |
43-
| 0.1.0 | 0.6.0 |
43+
| 0.1.x | 0.6.0 |
4444

4545
## Tutorials
4646

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
requests~=2.19.1
1+
requests>=2.19.1
22
python-dateutil~=2.7.5

satstac/collection.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import functools
23
import os
34

45
from datetime import datetime
@@ -48,21 +49,13 @@ def properties(self):
4849
""" Get dictionary of properties """
4950
return self.data.get('properties', {})
5051

51-
def add_item(self, item, path='', filename='${id}'):
52-
""" Add an item to this collection """
53-
start = datetime.now()
54-
if self.filename is None:
55-
raise STACError('Save catalog before adding items')
56-
item_link = item.get_filename(path, filename)
57-
item_fname = os.path.join(self.path, item_link)
58-
item_path = os.path.dirname(item_fname)
59-
root_link = self.links('root')[0]
60-
root_path = os.path.dirname(root_link)
61-
52+
@functools.lru_cache()
53+
def parent_catalog(self, path):
54+
""" Given path to a new Item find parent catalog """
6255
cat = self
63-
dirs = utils.splitall(item_link)
64-
var_names = [v.strip('$').strip('{}') for v in utils.splitall(path)]
65-
for i, d in enumerate(dirs[:-2]):
56+
dirs = utils.splitall(path)
57+
var_names = [v.strip('$').strip('{}') for v in dirs]
58+
for i, d in enumerate(dirs):
6659
fname = os.path.join(os.path.join(cat.path, d), 'catalog.json')
6760
# open existing sub-catalog or create new one
6861
try:
@@ -74,16 +67,30 @@ def add_item(self, item, path='', filename='${id}'):
7467
# add the sub-catalog to this catalog
7568
cat.add_catalog(subcat)
7669
cat = subcat
70+
return cat.filename
71+
72+
def add_item(self, item, path='', filename='${id}'):
73+
""" Add an item to this collection """
74+
start = datetime.now()
75+
if self.filename is None:
76+
raise STACError('Save catalog before adding items')
77+
item_link = item.get_filename(path, filename)
78+
item_fname = os.path.join(self.path, item_link)
79+
item_path = os.path.dirname(item_fname)
80+
root_link = self.links('root')[0]
81+
root_path = os.path.dirname(root_link)
82+
83+
parent = Catalog.open(self.parent_catalog(item.substitute(path)))
7784

7885
# create link to item
79-
cat.add_link('item', os.path.relpath(item_fname, cat.path))
80-
cat.save()
86+
parent.add_link('item', os.path.relpath(item_fname, parent.path))
87+
parent.save()
8188

8289
# create links from item
8390
item.clean_hierarchy()
8491
item.add_link('self', os.path.join(self.endpoint(), os.path.relpath(item_fname, root_path)))
8592
item.add_link('root', os.path.relpath(root_link, item_path))
86-
item.add_link('parent', os.path.relpath(cat.filename, item_path))
93+
item.add_link('parent', os.path.relpath(parent.filename, item_path))
8794
# this assumes the item has been added to a Collection, not a Catalog
8895
item.add_link('collection', os.path.relpath(self.filename, item_path))
8996

satstac/version.py

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

tutorial-1.ipynb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
],
9999
"source": [
100100
"# get first (and only in this case) sub-catalog\n",
101-
"subcat = cat.children()[0]\n",
101+
"subcat = [c for c in cat.children()][0]\n",
102102
"\n",
103103
"# print some IDs\n",
104104
"print(\"Root Catalog: \", cat.id)\n",
@@ -127,9 +127,9 @@
127127
"name": "stdout",
128128
"output_type": "stream",
129129
"text": [
130-
"<generator object Catalog.catalogs at 0x7f103a6691a8>\n",
131-
"<generator object Catalog.collections at 0x7f103a669200>\n",
132-
"<generator object Catalog.items at 0x7f103a669258>\n"
130+
"<generator object Catalog.catalogs at 0x7f119a70bf68>\n",
131+
"<generator object Catalog.collections at 0x7f119a70bfc0>\n",
132+
"<generator object Catalog.items at 0x7f119a6b6048>\n"
133133
]
134134
}
135135
],
@@ -416,7 +416,9 @@
416416
"In addition to the item's properties, there are two additional fields that may be used in the patterns:\n",
417417
"\n",
418418
"- id: The id of the item\n",
419-
"- date: The datetime property with the time portion stripped off"
419+
"- date: The datetime property with the time portion stripped off\n",
420+
"\n",
421+
"The `path` provided indicates the sub-catalogs that will be used, while the `filename` provided indicates the relative filename of the Item to it's parent catalog. In this example `path` is `${landsat:path}/${landsat:row}` which means sub-catalogs are created for each Landsat 'path' which contains catalogs for each Landsat 'row'. Each Landsat 'row' catalog in turns contains `item` links with the name `${date}/${id}`.json."
420422
]
421423
},
422424
{
@@ -441,8 +443,8 @@
441443
],
442444
"source": [
443445
"# save \n",
444-
"path = '${landsat:path}/${landsat:row}/${date}'\n",
445-
"filename = '${id}'\n",
446+
"path = '${landsat:path}/${landsat:row}'\n",
447+
"filename = '${date}/${id}'\n",
446448
"\n",
447449
"collection.add_item(item, path=path, filename=filename)\n",
448450
"print('Item filename: ', item.filename)\n",

tutorial-2.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@
391391
"cell_type": "markdown",
392392
"metadata": {},
393393
"source": [
394-
"By default the files are saved in the current directory. When downloading a lot of files this is hardly desired, so sat-stac provides a way to customize the path and filename assets are saved to. By default the filename is <id>-<key>.<extension>, as shown above but custom patterns can be provided. Tutorial-1 discussed Views, which use custom path and filename patterns when creating Catalogs, and this works much the same way."
394+
"By default the files are saved in the current directory. When downloading a lot of files this is hardly desired, so sat-stac provides a way to customize the path and filename assets are saved to. By default the filename is `<id>-<key>.<extension>`, as shown above but custom patterns can be provided. Tutorial-1 discussed Views, which use custom path and filename patterns when creating Catalogs, and this works much the same way."
395395
]
396396
},
397397
{

0 commit comments

Comments
 (0)