generated from stactools-packages/template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommands.py
144 lines (130 loc) · 4.21 KB
/
commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import logging
from typing import Optional
import click
from click import Command, Group
from pystac import Collection
from stactools.noaa_mrms_qpe import constants, stac
logger = logging.getLogger(__name__)
def create_noaa_mrms_qpe_command(cli: Group) -> Command:
"""Creates the stactools-noaa-mrms-qpe command line utility."""
@cli.group(
"noaa-mrms-qpe",
short_help=("Commands for working with stactools-noaa-mrms-qpe"),
)
def noaa_mrms_qpe() -> None:
pass
@noaa_mrms_qpe.command(
"create-collection",
short_help="Creates a STAC collection",
)
@click.argument("destination")
@click.option(
"--period",
default=1,
help="The time period the sub-product is for, either 1 (default), 3, 6, 12, 24, 48, or 72",
)
@click.option(
"--pass_no",
default=1,
help="The pass number of the sub-product, either 1 (default) or 2",
)
@click.option(
"--id",
default="",
help="A custom collection ID, defaults to 'noaa-mrms-qpe-{t}h-pass{p}'",
)
@click.option(
"--thumbnail",
default="",
help="URL for the PNG or JPEG collection thumbnail asset (none if empty)",
)
@click.option(
"--nocog",
default=False,
help="Does not include the COG-related metadata in the collection if set to `TRUE`.",
)
@click.option(
"--nogrib",
default=False,
help="Does not include the GRIB2-related metadata in the collection if set to `TRUE`.",
)
@click.option(
"--start_time",
default=None,
help="The start timestamp for the temporal extent, defaults to now. "
"Timestamps consist of a date and time in UTC and must be follow RFC 3339, section 5.6.",
)
def create_collection_command(
destination: str,
period: int = 1,
pass_no: int = 1,
id: str = "",
thumbnail: str = "",
nocog: bool = False,
nogrib: bool = False,
start_time: Optional[str] = None,
) -> None:
"""Creates a STAC Collection
Args:
destination (str): An HREF for the Collection JSON
"""
collection = stac.create_collection(
period, pass_no, thumbnail, nocog, nogrib, start_time
)
if len(id) > 0:
collection.id = id
collection.set_self_href(destination)
collection.save_object()
return None
@noaa_mrms_qpe.command("create-item", short_help="Create a STAC item")
@click.argument("source")
@click.argument("destination")
@click.option(
"--aoi",
type=click.Choice(constants.AOI), # type: ignore
help="The area of interest, either 'ALASKA', 'CONUS' (continental US), "
"'CARIB' (Caribbean islands), 'GUAM' or 'HAWAII'",
)
@click.option(
"--collection",
default="",
help="An HREF to the Collection JSON. "
"This adds the collection details to the item, but doesn't add the item to the collection.",
)
@click.option(
"--nocog",
default=False,
help="Does not create a COG file for the given GRIB2 file if set to `TRUE`.",
)
@click.option(
"--nogrib",
default=False,
help="Does not include the GRIB2 file in the created metadata if set to `TRUE`.",
)
@click.option(
"--epsg",
default=0,
help="Converts the COG files to the given EPSG Code (e.g. 3857), "
"doesn't reproject by default",
)
def create_item_command(
source: str,
destination: str,
aoi: constants.AOI,
collection: str = "",
nocog: bool = False,
nogrib: bool = False,
epsg: int = 0,
) -> None:
"""Creates a STAC Item
Args:
source (str): HREF of the Asset associated with the Item
destination (str): An HREF for the STAC Item
"""
stac_collection = None
if len(collection) > 0:
stac_collection = Collection.from_file(collection)
item = stac.create_item(source, aoi, stac_collection, nocog, nogrib, epsg)
item.save_object(dest_href=destination)
return None
return noaa_mrms_qpe