24
24
from rich .progress import BarColumn , Progress , TextColumn , TimeElapsedColumn
25
25
from rich .syntax import Syntax
26
26
from rich .table import Table
27
+ from rich .panel import Panel
28
+ from rich .tree import Tree
29
+
27
30
28
31
from .wlts import WLTS
29
32
@@ -43,13 +46,22 @@ def __init__(self):
43
46
console = Console ()
44
47
45
48
46
-
47
49
@click .group ()
48
- @click .option ('--url' , type = click .STRING , default = 'https://data.inpe.br/bdc/wlts/v1/' ,
49
- help = 'The WLTS server address (an URL).' )
50
- @click .option ('--lccs-url' , type = click .STRING , default = 'https://brazildatacube.dpi.inpe.br/lccs' ,
51
- help = 'The LCCS-WS address (an URL).' )
52
- @click .option ('--access-token' , default = None , help = 'Personal Access Token of the BDC Auth' )
50
+ @click .option (
51
+ "--url" ,
52
+ type = click .STRING ,
53
+ default = "https://data.inpe.br/bdc/wlts/v1/" ,
54
+ help = "The WLTS server address (an URL)." ,
55
+ )
56
+ @click .option (
57
+ "--lccs-url" ,
58
+ type = click .STRING ,
59
+ default = "https://brazildatacube.dpi.inpe.br/lccs" ,
60
+ help = "The LCCS-WS address (an URL)." ,
61
+ )
62
+ @click .option (
63
+ "--access-token" , default = None , help = "Personal Access Token of the BDC Auth"
64
+ )
53
65
@click .version_option ()
54
66
@pass_config
55
67
def cli (config , url , lccs_url , access_token ):
@@ -59,79 +71,115 @@ def cli(config, url, lccs_url, access_token):
59
71
60
72
61
73
@cli .command ()
62
- @click .option ('-v' , ' --verbose' , is_flag = True , default = False )
74
+ @click .option ("-v" , " --verbose" , is_flag = True , default = False )
63
75
@pass_config
64
76
def list_collections (config : Config , verbose ):
65
77
"""Return the list of available collections in the service provider."""
66
78
if verbose :
67
- console .print (f'[bold black]Server: [green]{ config .url } [/green]' , style = "bold" )
68
- console .print ('[black]\t Retrieving the list of available coverages...[/black]' )
69
-
70
- table = Table (title = "Available Collections" , show_header = True , header_style = "bold magenta" )
79
+ console .print (f"[bold black]Server: [green]{ config .url } [/green]" , style = "bold" )
80
+ console .print (
81
+ "[black]\t Retrieving the list of available collections...[/black]"
82
+ )
83
+
84
+ table = Table (
85
+ title = "Available Collections" , show_header = True , header_style = "bold magenta"
86
+ )
71
87
table .add_column ("Collection Name" , style = "green" , no_wrap = True )
88
+ table .add_column ("Collection Title" , style = "green" , no_wrap = True )
72
89
73
90
for collection in config .service .collections :
74
- table .add_row (collection )
91
+ describe_collection = config .service [collection ]
92
+ table .add_row (collection , describe_collection ["title" ])
75
93
76
94
console .print (table )
77
- console .print (' [black]\t Finished![/black]' )
95
+ console .print (" [black]\t Finished![/black]" )
78
96
79
97
else :
80
98
for collection in config .service .collections :
81
- console .print (f' [green]{ collection } [/green]' , style = "bold" )
99
+ console .print (f" [green]{ collection } [/green]" , style = "bold" )
82
100
83
101
84
102
@cli .command ()
85
- @click .option ('-v' , '--verbose' , is_flag = True , default = False )
86
- @click .option ('-c' , '--collection' , required = True , type = str ,
87
- help = 'The collection name' )
103
+ @click .option ("-v" , "--verbose" , is_flag = True , default = False )
104
+ @click .option ("-c" , "--collection" , required = True , type = str , help = "The collection name" )
88
105
@pass_config
89
106
def describe (config : Config , verbose , collection ):
90
107
"""Retrieve the collection metadata."""
91
- import json
92
- if verbose :
93
- console .print (f'[bold black]Server: [green]{ config .url } [/green]' , style = "bold" )
94
- console .print ('[black]\t Retrieving the collection metadata...[/black]' )
95
-
96
108
# Retrieve the collection metadata
97
109
cv = config .service [collection ]
98
110
99
- # Convert the metadata to a formatted JSON string
100
- formatted_json = json .dumps (cv , indent = 4 ,ensure_ascii = False )
111
+ if verbose :
112
+ console .print (f"[bold black]Server: [green]{ config .url } [/green]" , style = "bold" )
113
+ console .print ("[black]\t Retrieving the collection metadata...[/black]" )
114
+
115
+ tree = Tree (cv ["title" ], guide_style = "bold cyan" )
101
116
102
- # Use Syntax from rich to display JSON nicely formatted
103
- syntax = Syntax (formatted_json , "json" , theme = "monokai" , line_numbers = True )
104
- console .print (f'\t [green bold]- Collection Metadata:[/green bold]' )
105
- console .print (syntax ) # Pretty formatted JSON with syntax highlighting
106
117
107
- if verbose :
108
- console .print ('[black]\t Finished![/black]' )
118
+ tree .add (f"[bold green]ID[/bold green]: { cv ['classification_system' ]['id' ]} " )
119
+ tree .add (f"[bold green]Name[/bold green]: { cv ['classification_system' ]['name' ]} " )
120
+ tree .add (f"[bold green]Title[/bold green]: { cv ['classification_system' ]['title' ]} " )
121
+ tree .add (f"[bold green]Version[/bold green]: { cv ['classification_system' ]['version' ]} " )
122
+ tree .add (f"[bold green]Type[/bold green]: { cv ['classification_system' ]['type' ]} " )
123
+
124
+ table = Table (title = "Overview" , expand = True )
125
+ table .add_column ("Key" , justify = "right" , style = "cyan" , no_wrap = True )
126
+ table .add_column ("Value" , style = "magenta" )
127
+
128
+ table .add_row ("Collection Type" , cv ["collection_type" ])
129
+ table .add_row ("Description" , cv ["description" ])
130
+ table .add_row ("Period" , f"{ cv ['period' ]['start_date' ]} a { cv ['period' ]['end_date' ]} " )
131
+ table .add_row ("Spatial Extent" ,
132
+ f"Xmin: { cv ['spatial_extent' ]['xmin' ]} , Xmax: { cv ['spatial_extent' ]['xmax' ]} , Ymin: { cv ['spatial_extent' ]['ymin' ]} , Ymax: { cv ['spatial_extent' ]['ymax' ]} " )
133
+ table .add_row ("Temporal Resolution" ,
134
+ f"{ cv ['temporal_resolution' ]['value' ]} { cv ['temporal_resolution' ]['unit' ]} " )
135
+
136
+ console .print (Panel (tree , title = "Classification System" ))
137
+ console .print (table )
138
+
139
+ console .print ("[black]\t Finished![/black]" )
140
+
141
+ else :
142
+ import json
143
+ # Convert the metadata to a formatted JSON string
144
+ formatted_json = json .dumps (cv , indent = 4 , ensure_ascii = False )
145
+
146
+ # Use Syntax from rich to display JSON nicely formatted
147
+ syntax = Syntax (formatted_json , "json" , theme = "monokai" , line_numbers = True )
148
+ console .print (f"\t [green bold]- Collection Metadata:[/green bold]" )
149
+ console .print (syntax ) # Pretty formatted JSON with syntax highlighting
109
150
110
151
111
152
@cli .command ()
112
- @click .option ('-v' , '--verbose' , is_flag = True , default = False )
113
- @click .option ('-a' , '--collections' , required = False , type = str ,
114
- help = 'Collections list (items separated by comma)' )
115
- @click .option ('--latitude' , required = True , type = float ,
116
- help = 'Latitude in EPSG:4326' )
117
- @click .option ('--longitude' , required = True , type = float ,
118
- help = 'Longitude in EPSG:4326' )
119
- @click .option ('--start-date' , required = False , default = None , type = str ,
120
- help = 'Start date' )
121
- @click .option ('--end-date' , required = False , default = None , type = str ,
122
- help = 'End date' )
123
- @click .option ('--start-date' , required = False , default = None , type = str ,
124
- help = 'Start date' )
125
- @click .option ('--end-date' , required = False , default = None , type = str ,
126
- help = 'End date' )
127
- @click .option ('--language' , required = False , default = None , type = str ,
128
- help = 'Language' )
153
+ @click .option ("-v" , "--verbose" , is_flag = True , default = False )
154
+ @click .option (
155
+ "-a" ,
156
+ "--collections" ,
157
+ required = False ,
158
+ type = str ,
159
+ help = "Collections list (items separated by comma)" ,
160
+ )
161
+ @click .option ("--latitude" , required = True , type = float , help = "Latitude in EPSG:4326" )
162
+ @click .option ("--longitude" , required = True , type = float , help = "Longitude in EPSG:4326" )
163
+ @click .option ("--start-date" , required = False , default = None , type = str , help = "Start date" )
164
+ @click .option ("--end-date" , required = False , default = None , type = str , help = "End date" )
165
+ @click .option ("--start-date" , required = False , default = None , type = str , help = "Start date" )
166
+ @click .option ("--end-date" , required = False , default = None , type = str , help = "End date" )
167
+ @click .option ("--language" , required = False , default = None , type = str , help = "Language" )
129
168
@pass_config
130
- def trajectory (config : Config , verbose , collections , start_date , end_date , latitude , longitude , language ):
169
+ def trajectory (
170
+ config : Config ,
171
+ verbose ,
172
+ collections ,
173
+ start_date ,
174
+ end_date ,
175
+ latitude ,
176
+ longitude ,
177
+ language ,
178
+ ):
131
179
"""Return the trajectory associated to the location."""
132
180
if verbose :
133
181
console .print (f"[bold black]Server: [green]{ config .url } [/green]" )
134
- console .print (' [black]\t Retrieving trajectory...[/black]' )
182
+ console .print (" [black]\t Retrieving trajectory...[/black]" )
135
183
136
184
# Prepare query parameters
137
185
args = dict ()
@@ -179,10 +227,12 @@ def trajectory(config: Config, verbose, collections, start_date, end_date, latit
179
227
180
228
# Add rows from the trajectory data
181
229
for entry in retval .trajectory :
182
- table .add_row (entry ['class' ], entry ['collection' ], entry ['date' ], str (entry ['point_id' ]))
230
+ table .add_row (
231
+ entry ["class" ], entry ["collection" ], entry ["date" ], str (entry ["point_id" ])
232
+ )
183
233
184
234
# Display the table
185
235
console .print (table )
186
236
187
237
if verbose :
188
- console .print (f' [black]\t Finished in { total_time :.2f} seconds![/black]' )
238
+ console .print (f" [black]\t Finished in { total_time :.2f} seconds![/black]" )
0 commit comments