Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish 0.3.0 #99

Merged
merged 27 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f9e7800
update default STAC_API_URL
matthewhanson Jul 16, 2020
e21e05e
disable print-assets CLI option
matthewhanson Jul 16, 2020
fe7bbbd
update README
matthewhanson Jul 16, 2020
12eb5a5
update notebook tutorial
matthewhanson Jul 16, 2020
b817a4d
bump version
matthewhanson Jul 16, 2020
56227bc
update CHANGELOG
matthewhanson Jul 16, 2020
4f9fb18
update tests to account for removed printassets param in cli
matthewhanson Jul 16, 2020
80a75c6
no default URL
matthewhanson Aug 18, 2020
23ab498
remove printassets option
matthewhanson Aug 18, 2020
fcc7482
bump version
matthewhanson Aug 18, 2020
b7071bd
remove old refs to API_URL and update README about STAC API endpoints
matthewhanson Aug 19, 2020
6c73339
check for numberMatched if context not found, else return 0
matthewhanson Aug 20, 2020
80401c4
Merge branch 'develop' of github.com:sat-utils/sat-search into develop
matthewhanson Aug 20, 2020
20a6407
update pagination through results
matthewhanson Aug 20, 2020
5b2aeb9
update pagination to use STAC spec with POST
matthewhanson Aug 20, 2020
11d87e1
turn off check on maxitems and support GET method in next links
matthewhanson Aug 20, 2020
52f1f18
remove set_trace
matthewhanson Aug 20, 2020
2b971da
Fix page number and url bugs
Aug 21, 2020
0f542b7
White space
Aug 21, 2020
ff7e7a1
Add limit flag to CLI and backend
Aug 21, 2020
262443f
Write gud
Aug 21, 2020
0bf0fe0
Add docs update
Aug 21, 2020
4ef5ab1
Merge pull request #104 from trevorskaggs/develop
matthewhanson Aug 21, 2020
a2f7c32
update found and paging
matthewhanson Aug 21, 2020
e680eb1
update version and CHANGELOG
matthewhanson Aug 21, 2020
1f2e33e
update README and tutorial
matthewhanson Aug 21, 2020
6d79e5c
remove some old code, update limit
matthewhanson Aug 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [v0.3.0] - 2020-07-16

## Changed
- Updated to work with [STAC API v0.9.0-rc1](https://github.com/radiantearth/stac-spec/blob/master/CHANGELOG.md#v090-rc1---2020-01-06)
- Updated to work with STAC API v0.9.0 and v1.0.0-beta.2
- `SATUTILS_API_URL` envvar changed to `STAC_API_URL`
- Refactored how envvar was set for URL to fix issues on some platforms
- When downloading, specify `filename_template` for location instead of both `datadir` and `filename`.

## [v0.2.3] - 2019-06-25

### Changed
- Default SATUTILS_API_URL changed to account for domain name change

## [v0.2.2] - 2019-09-20

Expand Down Expand Up @@ -49,6 +56,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
Initial Release

[Unreleased]: https://github.com/sat-utils/sat-search/compare/master...develop
[v0.3.0]: https://github.com/sat-utils/sat-search/compare/0.2.3...v0.3.0
[v0.2.3]: https://github.com/sat-utils/sat-search/compare/0.2.2...v0.2.3
[v0.2.2]: https://github.com/sat-utils/sat-search/compare/0.2.1...v0.2.2
[v0.2.1]: https://github.com/sat-utils/sat-search/compare/0.2.0...v0.2.1
[v0.2.0]: https://github.com/sat-utils/sat-search/compare/0.1.0...v0.2.0
Expand Down
101 changes: 44 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The table below shows the corresponding versions between sat-search and STAC. Ad
| -------- | ---- |
| 0.1.x | 0.5.x - 0.6.x |
| 0.2.x | 0.5.x - 0.7.x |
| 0.3.x | 0.9.x |
| 0.3.x | 0.9.x - 1.0.0-beta.2 |


## Using sat-search
Expand All @@ -52,7 +52,7 @@ The sat-search CLI has an extensive online help that can be printed with the `-h
$ sat-search -h
usage: sat-search [-h] {search,load} ...

sat-search (v0.2.0)
sat-search (v0.3.0)

positional arguments:
{search,load}
Expand All @@ -69,13 +69,11 @@ As can be seen there are two subcommands, `search` and `load`, each of which has

```
$ sat-search search -h
usage: sat-search search [-h] [--version] [-v VERBOSITY]
[--print-md [PRINTMD [PRINTMD ...]]] [--print-cal]
[--save SAVE] [-c COLLECTION] [--ids [IDS [IDS ...]]]
[--bbox BBOX BBOX BBOX BBOX]
[--intersects INTERSECTS] [--datetime DATETIME]
[--sort [SORT [SORT ...]]] [--found]
[-p [PROPERTY [PROPERTY ...]]] [--url URL]
usage: sat-search search [-h] [--version] [-v VERBOSITY] [--print-md [PRINTMD [PRINTMD ...]]]
[--print-cal PRINTCAL] [--save SAVE] [-c [COLLECTIONS [COLLECTIONS ...]]]
[--ids [IDS [IDS ...]]] [--bbox BBOX BBOX BBOX BBOX] [--intersects INTERSECTS]
[--datetime DATETIME] [-q [QUERY [QUERY ...]]] [--sortby [SORTBY [SORTBY ...]]] [--found]
[--url URL] [--headers HEADERS]

optional arguments:
-h, --help show this help message and exit
Expand All @@ -86,50 +84,45 @@ optional arguments:
output options:
--print-md [PRINTMD [PRINTMD ...]]
Print specified metadata for matched scenes (default: None)
--print-cal Print calendar showing dates (default: False)
--print-cal PRINTCAL Print calendar showing dates (default: None)
--save SAVE Save results as GeoJSON (default: None)

search options:
-c COLLECTION, --collection COLLECTION
-c [COLLECTIONS [COLLECTIONS ...]], --collections [COLLECTIONS [COLLECTIONS ...]]
Name of collection (default: None)
--ids [IDS [IDS ...]]
One or more scene IDs from provided collection
(ignores other parameters) (default: None)
One or more scene IDs from provided collection (ignores other parameters) (default: None)
--bbox BBOX BBOX BBOX BBOX
Bounding box (min lon, min lat, max lon, max lat)
(default: None)
Bounding box (min lon, min lat, max lon, max lat) (default: None)
--intersects INTERSECTS
GeoJSON Feature (file or string) (default: None)
--datetime DATETIME Single date/time or begin and end date/time (e.g.,
2017-01-01/2017-02-15) (default: None)
--sort [SORT [SORT ...]]
--datetime DATETIME Single date/time or begin and end date/time (e.g., 2017-01-01/2017-02-15) (default: None)
-q [QUERY [QUERY ...]], --query [QUERY [QUERY ...]]
Query properties of form KEY=VALUE (<, >, <=, >=, = supported) (default: None)
--sortby [SORTBY [SORTBY ...]]
Sort by fields (default: None)
--found Only output how many Items found (default: False)
-p [PROPERTY [PROPERTY ...]], --property [PROPERTY [PROPERTY ...]]
Properties of form KEY=VALUE (<, >, <=, >=, =
supported) (default: None)
--url URL URL of the API (default: https://n34f767n91.execute-
api.us-east-1.amazonaws.com/prod)
--headers HEADERS
JSON Request Headers (file or string) (default: None)
--url URL URL of the API (default: https://earth-search.aws.element84.com/v0/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no more default here!

--headers HEADERS Additional request headers (JSON file or string) (default: None)
```

**Search options**

- **collection** - Search only a specific collection. This is a shortcut, collection can also be provided as a property (e.g., `-p "collection=landsat-8-l1"`)
- **collections** - Search only a specific collections. This is a shortcut, collection can also be provided as a query (e.g., `-q "collection=landsat-8-l1"`)
- **ids** - Fetch the Item for the provided IDs in the given collection (collection must be provided). All other search options will be ignored.
- **intersects** - Provide a GeoJSON Feature string or the name of a GeoJSON file containing a single Feature that is a Polygon of an AOI to be searched.
- **datetime** - Provide a single partial or full datetime (e.g., 2017, 2017-10, 2017-10-11, 2017-10-11T12:00), or two seperated by a slash that defines a range. e.g., 2017-01-01/2017-06-30 will search for scenes acquired in the first 6 months of 2017.
- **property** - Allows searching for any other scene properties by providing the pair as a string (e.g. `-p "landsat:row=42"`, `-p "eo:cloud_cover<10"`). Supported symbols include: =, <, >, >=, and <=
- **sort** - Sort by specific properties in ascending or descending order. A list of properties can be provided which will be used for sorting in that order of preference. By default a property will be sorted in descending order. To specify the order the property can be preceded with '<' (ascending) or '>' (descending). e.g., `--sort ">datetime" "<eo:cloud_cover" will sort by descending date, then by ascending cloud cover
- **found** - This will print out the total number of scenes found, then exit without fetching the actual items.
- **url** - The URL endpoint of a STAC compliant API, this can also be set with the environment variable SATUTILS_API_URL
- **query** - Allows searching for any other scene properties by providing the pair as a string (e.g. `-p "landsat:row=42"`, `-p "eo:cloud_cover<10"`). Supported symbols include: =, <, >, >=, and <=
- **sortby** - Sort by specific properties in ascending or descending order. A list of properties can be provided which will be used for sorting in that order of preference. By default a property will be sorted in descending order. To specify the order the property can be preceded with '<' (ascending) or '>' (descending). e.g., `--sort ">datetime" "<eo:cloud_cover" will sort by descending date, then by ascending cloud cover
- **found** - This will print out the total number of scenes found, then exit without fetching the actual items (i.e., the query is made with limit=0).
- **url** - The URL endpoint of a STAC compliant API, this can also be set with the environment variable STAC_API_URL
- **headers** - Additional request headers useful for specifying authentication parameters

**Output options**
These options control what to do with the search results, multiple switches can be provided.

- **print-md** - Prints a list of specific metadata fields for all the scenes. If given without any arguments it will print a list of the dates and scene IDs. Otherwise it will print a list of fields that are provided. (e.g., --print-md date eo:cloud_cover eo:platform will print a list of date, cloud cover, and the satellite platform such as WORLDVIEW03)
- **print-cal** - Prints a text calendar (see iumage below) with specific days colored depending on the platform of the scene (e.g. landsat-8), along with a legend.
- **print-cal** - Prints a text calendar (see image below) with specific days colored grouped by a provided property name (e.g. platform), along with a legend.
- **save** - Saves results as a FeatureCollection. The FeatureCollection 'properties' contains all of the arguments used in the search and the 'features' contain all of the individual scenes, with individual scene metadata merged with collection level metadata (metadata fields that are the same across all one collection, such as eo:platform)

![](images/calendar.png)
Expand All @@ -140,11 +133,9 @@ These options control what to do with the search results, multiple switches can
Scenes that were previously saved with `sat-search search --save ...` can be loaded with the `load` subcommand.

```
$ sat-search load -h
usage: sat-search load [-h] [--version] [-v VERBOSITY]
[--print-md [PRINTMD [PRINTMD ...]]] [--print-cal]
[--save SAVE] [--datadir DATADIR] [--filename FILENAME]
[--download [DOWNLOAD [DOWNLOAD ...]]]
usage: sat-search load [-h] [--version] [-v VERBOSITY] [--print-md [PRINTMD [PRINTMD ...]]] [--print-cal PRINTCAL]
[--save SAVE] [--filename_template FILENAME_TEMPLATE]
[--download [DOWNLOAD [DOWNLOAD ...]]] [--requester-pays]
items

positional arguments:
Expand All @@ -154,23 +145,21 @@ optional arguments:
-h, --help show this help message and exit
--version Print version and exit
-v VERBOSITY, --verbosity VERBOSITY
0:quiet, 1:error, 2:warning, 3:info, 4:debug (default:
2)
0:quiet, 1:error, 2:warning, 3:info, 4:debug (default: 2)

output options:
--print-md [PRINTMD [PRINTMD ...]]
Print specified metadata for matched scenes (default:
None)
--print-cal Print calendar showing dates (default: False)
Print specified metadata for matched scenes (default: None)
--print-cal PRINTCAL Print calendar showing dates (default: None)
--save SAVE Save results as GeoJSON (default: None)

download options:
--datadir DATADIR Directory pattern to save assets (default:
./${eo:platform}/${date})
--filename FILENAME Save assets with this filename pattern based on
metadata keys (default: ${id})
--filename_template FILENAME_TEMPLATE
Save assets with this filename pattern based on metadata keys (default:
${collection}/${date}/${id})
--download [DOWNLOAD [DOWNLOAD ...]]
Download assets (default: None)
--requester-pays Acknowledge paying egress costs for downloads (if in request pays bucket) (default: False)
```

Note that while the search options are gone, output options are still available and can be used with the search results loaded from the file. There is also a new series of options for downloading data.
Expand All @@ -180,18 +169,16 @@ When loading results from a file, the user now has the option to download assets

**Download options**
These control the downloading of assets. Both datadir and filename can include metadata patterns that will be substituted per scene.
- **datadir** - This specifies where downloaded assets will be saved to. It can also be specified by setting the environment variable SATUTILS_DATADIR.
- **filename** - The name of the file to save. It can also be set by setting the environment variable SATUTILS_FILENAME
- **download** - Provide a list of keys to download these assets. More information on downloading data is provided below.

**Metadata patterns**
Metadata patterns can be used in **datadir** and **filename** in order to have custom path and filenames based on the Item metadata. For instance specifying datadir as "./${eo:platform}/${date}" will save assets for each Item under directories of the platform and the date. So a landsat-8 Item from June 20, 2018 will have it's assets saved in a directory './landsat-8/2017-06-20'. For filenames these work exactly the same way, except the filename will contain a suffix containing the asset key and the appropriate extension.

```
sat-search load scenes.json --download thumbnail MTL
```

In this case the defaults for `datadir` ("./${eo:platform}/${date}") and `filename` ("${id}") are used so the download files are saved like this:
- **filename_template** - This specifies the filename prefix where downloaded assets will be saved to based on a template using properties from the specific STAC Item. Supported fields:
- ${id}: The ID of the STAC Item
- ${collection}: The collection of the STAC Item
- ${date}: The date portion of the `datetime` property
- ${year}: The year of the `datetime` property
- ${month}: The month of the `datetime` property
- ${day}: The day of the month of the `datetime` property
- ${<property>}: Any STAC Item property may be used, e.g. "${eo:cloud_cover}", "${platform}
The actual filename will be this prefix followed by the asset key and an appropriate extension. For example, specifying `filename_template` as "./${eo:platform}/${date}/${id}" will save assets for each Item under directories of the platform and the date. Thus, a landsat-8 Item from June 20, 2018 will have it's assets saved in a directory './landsat-8/2017-06-20/'. A metadata asset with the key `MTL` would be saved as './landsat-8/2017-06-20/LC80090292018275LGN00_MTL.TIF'. The last component of the filename_template is taken as the filename. See example directory structure below.

```
landsat-8/
Expand All @@ -212,4 +199,4 @@ A shortcut to download all of the assets is available by providing "ALL" as the
This [Jupyter notebook tutorial](tutorial-1.ipynb) covers all the main features of the library.

## About
sat-search was created by [Development Seed](<http://developmentseed.org>) and is part of a collection of tools called [sat-utils](https://github.com/sat-utils).
sat-search is part of a collection of tools called [sat-utils](https://github.com/sat-utils).
9 changes: 5 additions & 4 deletions satsearch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __init__(self, *args, **kwargs):
self.output_group.add_argument('--print-md', help=h, default=None, nargs='*', dest='printmd')
h = 'Print calendar showing dates'
self.output_group.add_argument('--print-cal', help=h, dest='printcal')
self.output_group.add_argument('--print-assets', help=h, dest='printassets', default=False, action='store_true')
#h = 'Print Item Asset definition from Collections'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

#self.output_group.add_argument('--print-assets', help=h, dest='printassets', default=False, action='store_true')
self.output_group.add_argument('--save', help='Save results as GeoJSON', default=None)

def parse_args(self, *args, **kwargs):
Expand Down Expand Up @@ -112,7 +113,7 @@ def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, n, {'eq': v})


def main(items=None, printmd=None, printcal=None, printassets=None,
def main(items=None, printmd=None, printcal=None, #printassets=None,
found=False, filename_template='${collection}/${date}/${id}',
save=None, download=None, requester_pays=False, headers=None, **kwargs):
""" Main function for performing a search """
Expand All @@ -139,8 +140,8 @@ def main(items=None, printmd=None, printcal=None, printassets=None,
if printcal:
print(items.calendar(printcal))

if printassets:
print(items.assets_definition())
#if printassets:
# print(items.assets_definition())

# save all metadata in JSON file
if save is not None:
Expand Down
2 changes: 1 addition & 1 deletion satsearch/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

logger = logging.getLogger(__name__)

API_URL = os.getenv('STAC_API_URL', 'https://1tqdbvsut9.execute-api.us-west-2.amazonaws.com/v0').rstrip('/') + '/'
API_URL = os.getenv('STAC_API_URL', 'https://earth-search.aws.element84.com/v0').rstrip('/') + '/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @matthewhanson what do you think about removing any hardcoded URL? you could still use STAC_API_URL environ but I think it will be better if stac-search wasn't tied to any URL.

We (Devseed) will love to fix the API we are hosting but it means first we have to wait for the specification do be complete.



class SatSearchError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion satsearch/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.3.0-rc1'
__version__ = '0.3.0'
4 changes: 2 additions & 2 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_empty_parse_search_args(self):
""" Parse empty arguments """
parser = self.get_test_parser()
args = parser.parse_args(['search'])
self.assertEqual(len(args), 4)
self.assertEqual(len(args), 3)
self.assertFalse(args['found'])

def test_parse_args(self):
Expand All @@ -39,7 +39,7 @@ def test_parse_args(self):
args = 'search --datetime 2017-01-01 -q eo:cloud_cover<10 platform=sentinel-2a'.split(' ')

args = parser.parse_args(args)
self.assertEqual(len(args), 6)
self.assertEqual(len(args), 5)
self.assertEqual(args['datetime'], '2017-01-01')
#assert(args['eo:cloud_cover'] == '0/20')
#self.assertEqual(args['cloud_from'], 0)
Expand Down
Loading