Skip to content

Commit 48d48a7

Browse files
committed
get plot and hist commands working again
1 parent 5dd60bc commit 48d48a7

File tree

4 files changed

+99
-57
lines changed

4 files changed

+99
-57
lines changed

CHANGELOG.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10-
## [v0.2.0-rc.2] - 2023-10-31
10+
## [v0.2.0rc4] - 2023-10-31
11+
12+
### Fixed
13+
14+
- Histograms would not draw due to removed `plot.clp()` method
15+
16+
### Removed
17+
18+
- Support for passing input item collection as command argument: input is now
19+
always via stdin, use file redirection instead
20+
21+
## [v0.2.0rc3] - 2023-10-31
1122

1223
### Added
1324

@@ -46,7 +57,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4657

4758
Initial release.
4859

49-
[Unreleased]: <https://github.com/stac-utils/stac-terminal/compare/v0.2.0-rc.2...main>
50-
[v0.2.0-rc.2]: <https://github.com/stac-utils/stac-terminal/compare/v0.2.0-rc.1...v0.2.0-rc.2>
60+
[Unreleased]: <https://github.com/stac-utils/stac-terminal/compare/v0.2.0-rc.4...main>
61+
[v0.2.0rc4]: <https://github.com/stac-utils/stac-terminal/compare/v0.2.0-rc.1...v0.2.0rc4>
62+
[v0.2.0rc3]: <https://github.com/stac-utils/stac-terminal/compare/v0.2.0-rc.1...v0.2.0rc3>
5163
[v0.2.0-rc.1]: <https://github.com/stac-utils/stac-terminal/compare/v0.1.0...v0.2.0-rc.1>
5264
[v0.1.0]: <https://github.com/stac-utils/stac-terminal/tree/v0.1.0>

README.md

+83-46
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
# stacterm
22

3-
This library is for displaying information (tables, calendars, plots, histograms) about [STAC](https://stacspec.org/) Items in the terminal. It takes as input a STAC ItemCollection (a GeoJSON FeatureCollection of STAC Items), either by specifying a filename or by piping output from another program.
3+
This library is for displaying information (tables, calendars, plots,
4+
histograms) about [STAC](https://stacspec.org/) Items in the terminal. It takes
5+
as input a STAC ItemCollection (a GeoJSON FeatureCollection of STAC Items),
6+
either by specifying a filename or by piping output from another program.
47

58
## Installation
69

710
Install from PyPi:
811

9-
```
10-
$ pip install stacterm
12+
```cmdline
13+
pip install stacterm
1114
```
1215

13-
PySTAC and Pandas are required, along with two dependencies for rendering tables ([termtables](https://pypi.org/project/termtables/)) and plots ([plotext](https://pypi.org/project/plotext/)) in the terminal.
16+
PySTAC and Pandas are required, along with two dependencies for rendering
17+
tables ([termtables](https://pypi.org/project/termtables/)) and plots
18+
([plotext](https://pypi.org/project/plotext/)) in the terminal.
1419

1520
## Usage
1621

17-
stacterm main usage is as a CLI progam `stacterm`. Use help to see options available:
22+
stacterm main usage is as a CLI progam `stacterm`. Use help to see options
23+
available:
1824

19-
```
20-
$ stacterm -h
25+
```cmdline
26+
stacterm -h
2127
usage: stacterm [-h] {table,cal,hist,plot} ...
2228
2329
Terminal STAC
@@ -33,7 +39,8 @@ optional arguments:
3339
-h, --help show this help message and exit
3440
```
3541

36-
All of the sub-commands in `stacterm` can take optional field names. A field name is:
42+
All of the sub-commands in `stacterm` can take optional field names. A field
43+
name is:
3744

3845
- `id`: The ID of the Item
3946
- `collection`: The collection of the Item
@@ -43,22 +50,27 @@ All of the sub-commands in `stacterm` can take optional field names. A field nam
4350
- `year`: The year of the Item's `datetime` field
4451
- Any property
4552

46-
The detailed usage examples below are shown using a saved file, however `stacterm` can also read in stdin allowing other programs to pipe output to it, such as [pystac-client](https://github.com/stac-utils/pystac-client).
53+
`stacterm` reads from in stdin allowing other programs to pipe output to it,
54+
such as [pystac-client](https://github.com/stac-utils/pystac-client).
4755

48-
```
49-
$ export STAC_API_URL=https://earth-search.aws.element84.com/v0
50-
$ stac-client search --intersects aoi.json --datetime 2020-07-01/2020-12-31 -c sentinel-s2-l2a-cogs landsat-8-l1-c1 | stacterm cal --label platform
56+
```cmdline
57+
❯ export STAC_API_URL=https://earth-search.aws.element84.com/v0
58+
❯ stac-client search --intersects aoi.json \
59+
--datetime 2020-07-01/2020-12-31 \
60+
-c sentinel-s2-l2a-cogs landsat-8-l1-c1 | stacterm cal --label platform
5161
```
5262

53-
![](images/cal.png)
63+
The detailed usage examples below are all shown using the item collection from
64+
a search saved to a file and redirected to stdin.
5465

66+
![](images/cal.png)
5567

5668
### Tables
5769

5870
Use `stacterm` to display tabularized data from a saved ItemCollection.
5971

60-
```
61-
$ stacterm table items.json
72+
```cmdline
73+
❯ <input.json stacterm table
6274
6375
| id | date |
6476
|------------------------------------------|------------|
@@ -75,10 +87,13 @@ By default this is a markdown table (note the terminal will not render Markdown)
7587
| LC08_L1TP_026079_20201115_20201210_01_T1 | 2020-11-15 |
7688
| S2A_12JXQ_20201008_0_L1C | 2020-10-08 |
7789

78-
The fields displayed can be changed via the `--fields` keyword, and sorted via the `--sort` keyword.
90+
The fields displayed can be changed via the `--fields` keyword, and sorted via
91+
the `--sort` keyword.
7992

80-
```
81-
$ stacterm table items.json --fields date eo:cloud_cover collection --sort eo:cloud_cover
93+
```cmdline
94+
❯ <input.json stacterm table \
95+
--fields date eo:cloud_cover collection \
96+
--sort eo:cloud_cover
8297
8398
| date | eo:cloud_cover | collection |
8499
|------------|----------------|----------------------|
@@ -88,71 +103,93 @@ $ stacterm table items.json --fields date eo:cloud_cover collection --sort eo:cl
88103
| 2020-10-13 | 0.0 | sentinel-s2-l1c |
89104
```
90105

91-
The style of the table can also be changed via the `--style` keyword, although it will no longer be usable in a Markdown renderer. See [termtables styles](https://github.com/nschloe/termtables/blob/master/termtables/styles.py) for list of styles.
106+
The style of the table can also be changed via the `--style` keyword, although
107+
it will no longer be usable in a Markdown renderer. See [termtables
108+
styles](https://github.com/nschloe/termtables/blob/master/termtables/styles.py)
109+
for list of styles.
92110

93-
```
94-
$ stacterm table items.json --fields id date platform sentinel:grid_square --sort date --style thick
95-
96-
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
97-
┃ id ┃ date ┃ platform ┃ sentinel:grid_square ┃
98-
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━┫
99-
┃ S2B_12JXR_20201003_0_L2A ┃ 2020-10-03 ┃ sentinel-2b ┃ XR ┃
100-
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━┫
101-
┃ S2B_12JXQ_20201003_0_L1C ┃ 2020-10-03 ┃ sentinel-2b ┃ XQ ┃
102-
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━┫
103-
┃ S2B_12JXQ_20201003_0_L2A ┃ 2020-10-03 ┃ sentinel-2b ┃ XQ ┃
104-
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━┛
111+
```cmdline
112+
❯ <input.json stacterm table \
113+
--fields id date platform sentinel:grid_square\
114+
--sort date \
115+
--style thick
116+
117+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
118+
┃ id ┃ date ┃ platform ┃ sentinel:grid_square ┃
119+
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━┫
120+
┃ S2B_12JXR_20201003_0_L2A ┃ 2020-10-03 ┃ sentinel-2b ┃ XR ┃
121+
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━┫
122+
┃ S2B_12JXQ_20201003_0_L1C ┃ 2020-10-03 ┃ sentinel-2b ┃ XQ ┃
123+
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━╋━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━┫
124+
┃ S2B_12JXQ_20201003_0_L2A ┃ 2020-10-03 ┃ sentinel-2b ┃ XQ ┃
125+
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━┻━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━┛
105126
```
106127

107128
### Calendars
108129

109-
A UNIX-like calendar (see [`cal`](https://en.wikipedia.org/wiki/Cal_(Unix))) is available to show dates of individual items. By default `cal` will use the field `datetime` (the collection datetime) and group Items by their Collection. These can be overridden by the `--date_field` and `--label_field` keywords. Note that the specified `--date_field` needs to be a date field, such as `created` or `updated`. `--label_field` will group and label items by the provided field.
130+
A UNIX-like calendar (see [`cal`](https://en.wikipedia.org/wiki/Cal_(Unix))) is
131+
available to show dates of individual items. By default `cal` will use the
132+
field `datetime` (the collection datetime) and group Items by their Collection.
133+
These can be overridden by the `--date_field` and `--label_field` keywords.
134+
Note that the specified `--date_field` needs to be a date field, such as
135+
`created` or `updated`. `--label_field` will group and label items by the
136+
provided field.
110137

111-
```
112-
$ stacterm cal items.json --date_field created --label_field gsd
138+
```cmdline
139+
❯ <input.json stacterm cal --date_field created --label_field gsd
113140
```
114141

115142
![](images/cal2.png)
116143

117144
### Histograms
118145

119-
Histograms can be created for any numeric field and `datetime` and `date` (just the date portion of `datetime`). `created` and `updated` may also be specified if available in all Items.
146+
Histograms can be created for any numeric field and `datetime` and `date` (just
147+
the date portion of `datetime`). `created` and `updated` may also be specified
148+
if available in all Items.
120149

121-
```
122-
$ stacterm hist items.json eo:cloud_cover
150+
```cmdline
151+
❯ <items.json stacterm hist eo:cloud_cover
123152
```
124153

125154
![](images/hist.png)
126155

127156
### Plots
128157

129-
Plots can be created with a single numeric fields, a date field (`datetime`, `date`, `created`, or `updated`) and a numeric field, or two numeric fields. If a single field it will be plotted against the scene number. The `--sort` keyword can control how to sort the data if plotting a single field.
158+
Plots can be created with a single numeric fields, a date field (`datetime`,
159+
`date`, `created`, or `updated`) and a numeric field, or two numeric fields. If
160+
a single field it will be plotted against the scene number. The `--sort`
161+
keyword can control how to sort the data if plotting a single field.
130162

131-
```
132-
$ stacterm plot items.json eo:cloud_cover --sort eo:cloud_cover
163+
```cmdline
164+
❯ <input.json stacterm plot eo:cloud_cover --sort eo:cloud_cover
133165
```
134166

135167
![](images/plot.png)
136168

137-
138169
## Markers and Colors
139170

140-
For histograms and plots there are options for changing the marker (symbol) and color of the plot, background, and text. These options all come directly from [plotext](https://github.com/piccolomo/plotext).
171+
For histograms and plots there are options for changing the marker (symbol) and
172+
color of the plot, background, and text. These options all come directly from
173+
[plotext](https://github.com/piccolomo/plotext).
141174

142-
In addition to a marker being able to be any single character, the following names can also be provided for these symbols:
175+
In addition to a marker being able to be any single character, the following
176+
names can also be provided for these symbols:
143177

144178
![](https://raw.githubusercontent.com/piccolomo/plotext/master/images/markers.png)
145179

146180
Color names can be provided as follows:
147181

148182
![](https://raw.githubusercontent.com/piccolomo/plotext/master/images/colors.png)
149183

150-
151184
## Limitations
152185

153186
Currently any provided field must exist in all STAC Items.
154187

155-
156188
## Development
157189

158-
There are a lot more options in the [plotext library](https://github.com/piccolomo/plotext) that could be surfaced here. Additionally, if [support for datetimes](https://github.com/piccolomo/plotext/issues/7) in histograms and plots is added, `stacterm` could create temporal histograms, or plot quantities vs date.
190+
There are a lot more options in the [plotext
191+
library](https://github.com/piccolomo/plotext) that could be surfaced here.
192+
Additionally, if [support for
193+
datetimes](https://github.com/piccolomo/plotext/issues/7) in histograms and
194+
plots is added, `stacterm` could create temporal histograms, or plot quantities
195+
vs date.

src/stacterm/cli.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import json
3-
import os
43
import sys
54

65
from .calendar import print_calendar
@@ -22,7 +21,6 @@ def parse_args(args):
2221
action="version",
2322
version=__version__,
2423
)
25-
parent.add_argument("items", nargs="?", default=sys.stdin)
2624

2725
subparsers = parser0.add_subparsers(dest="command")
2826

@@ -93,11 +91,7 @@ def parse_args(args):
9391
parsed_args = {
9492
k: v for k, v in vars(parser0.parse_args(args)).items() if v is not None
9593
}
96-
if not sys.stdin.isatty():
97-
parsed_args["items"] = json.load(parsed_args["items"])
98-
elif os.path.exists(parsed_args["items"]):
99-
with open(parsed_args["items"]) as f:
100-
parsed_args["items"] = json.loads(f.read())
94+
parsed_args["items"] = json.load(sys.stdin)
10195
return parsed_args
10296

10397

src/stacterm/histogram.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def print_histogram(
1515
axes_color=None,
1616
):
1717
df = items_to_dataframe(items)
18-
plt.clp()
1918

2019
data = df["timestamp"] if field in DATE_FIELDS else df[field]
2120

0 commit comments

Comments
 (0)