Client
Geocube-client has three level of access:
Client
is for basic access. TheClient
has CRUD access to most entities. It can also index new images.- Consolidater is for optimization of the database, through consolidation of the datasets. It has CRUD access to
entities.job
. - Admin is for operation that must be done wisely and cautiously.
Source code in geocube/client.py
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
|
__init__(uri, secure=False, api_key='', verbose=True)
Initialise the connexion to the Geocube Server
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
str
|
of the Geocube Server |
required |
secure |
bool
|
True to use a TLS Connexion |
False
|
api_key |
str
|
(optional) API Key if Geocube Server is secured using a bearer authentication |
''
|
verbose |
bool
|
set the default verbose mode |
True
|
Source code in geocube/client.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
add_records_tags(records, tags)
Add or update tags to a list of records
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records |
List[Union[str, entities.Record]]
|
List of records to be updated |
required |
tags |
Dict[str, str]
|
List of new tags or tags to be updated |
required |
Returns:
Type | Description |
---|---|
int
|
the number of updated records |
Source code in geocube/client.py
283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
create_aoi(aoi, exist_ok=False)
Create a new AOI. Raise an error if an AOI with the same coordinates already exists. The id of the AOI can be retrieved from the details of the error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
aoi |
Union[geometry.Polygon, geometry.MultiPolygon]
|
in geographic coordinates |
required |
exist_ok |
bool
|
(optional): if already exists, do not raise an error and return the aoi_id |
False
|
Returns:
Type | Description |
---|---|
str
|
the id of the AOI |
Source code in geocube/client.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
create_grid(grid)
Create a grid in the Geocube
Source code in geocube/client.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
|
create_layout(layout, exist_ok=False)
Create a layout in the Geocube exist_ok: (optional, see warning): if already exists, do not raise an error. !!! WARNING: it does not mean that the layout already stored in the geocube is exactly the same !!!
Source code in geocube/client.py
554 555 556 557 558 559 560 561 562 563 564 |
|
create_palette(name, colors, replace=False)
Create a new palette from [0, 1] to RGBA, providing a list of index from 0 to 1. The intermediate values are linearly interpolated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the palette |
required |
colors |
List[Tuple[float, int, int, int, int]]
|
a list of tuple[index, R, G, B, A] mapping index to the corresponding RGBA value |
required |
replace |
bool
|
if a palette already exists with the same name, replace it else raise an error. |
False
|
Source code in geocube/client.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
create_record(aoi_id, name, tags, date, exist_ok=False)
Create a new record. A record is uniquely identified with the tuple (name, tags, date) Raise an error if a record with the same Name, Tags and Date already exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
aoi_id |
str
|
uuid4 of the AOI. |
required |
name |
str
|
of the records. |
required |
tags |
Dict[str, str]
|
user-defined tags associated to the record. |
required |
date |
datetime
|
date of the data referenced by the record. |
required |
exist_ok |
bool
|
(optional, see warning): if already exists, do not raise an error !!! WARNING: it does not mean that the record in the geocube is the same: its aoi may be different !!! |
False
|
Returns:
Type | Description |
---|---|
str
|
the ID of the record |
Source code in geocube/client.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
create_records(aoi_ids, names, tags, dates)
Create a list of records. All inputs must have the same length. (see create_record for the description of the parameters)
Source code in geocube/client.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
create_variable(name, dformat, bands, unit='', description='', palette='', resampling_alg=entities.Resampling.bilinear, exist_ok=False)
Create a single Variable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the variable |
required |
dformat |
entities.DataFormat
|
data format of the variable (min and max are the theoretical extrema) |
required |
bands |
List[str]
|
Name of the bands |
required |
unit |
str
|
of the data (for user information only) |
''
|
description |
str
|
of the data (for user information only) |
''
|
palette |
str
|
for rendering in png (TileServer). Must be created using create_palette. |
''
|
resampling_alg |
entities.Resampling
|
when reprojection is needed (see entities.Resampling) |
entities.Resampling.bilinear
|
exist_ok |
bool
|
(optional, see warning): if already exists, do not raise an error. !!! WARNING: it does not mean that the variable already stored in the geocube is exactly the same !!! |
False
|
Returns:
Type | Description |
---|---|
entities.Variable
|
the variable |
Source code in geocube/client.py
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 |
|
delete_grid(name='')
Delete a grid by its name
Source code in geocube/client.py
605 606 607 608 |
|
delete_layout(name='')
Delete a layout from the Geocube
Source code in geocube/client.py
575 576 577 578 |
|
delete_records(records)
Delete records iif no dataset are indexed to them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records |
List[Union[str, entities.Record]]
|
List of records to be deleted |
required |
Source code in geocube/client.py
311 312 313 314 315 316 317 318 319 320 |
|
get_cube(params, headers_only=False, compression=0, verbose=None)
Get a cube given a CubeParameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
entities.CubeParams
|
CubeParams (see entities.CubeParams) |
required |
headers_only |
bool
|
Only returns the header of each image (gives an overview of the query) |
False
|
compression |
int
|
define a level of compression to speed up the transfer. (0: no compression, 1 fastest to 9 best, -2: huffman-only) The data is compressed by the server and decompressed by the Client. Compression=0 or -2 is advised if the bandwidth is not limited |
0
|
verbose |
bool
|
display information during the transfer (if None, use the default verbose mode) |
None
|
Returns:
Type | Description |
---|---|
Tuple[List[np.array], List[entities.GroupedRecords]]
|
list of images (np.ndarray) and the list of corresponding records (several records can be returned for each image when they are grouped together, by date or something else. See entities.Record.group_by) |
Source code in geocube/client.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
|
get_cube_it(params, headers_only=False, compression=0, file_format=FileFormatRaw, file_pattern=None)
Returns a cube iterator over the requested images
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
entities.CubeParams
|
CubeParams (see entities.CubeParams) |
required |
headers_only |
returns only the header of the dataset (use this option to control the output of get_cube) |
False
|
|
compression |
define a level of compression to speed up the transfer (0: no compression, 1 fastest to 9 best, -2: huffman-only) The data is compressed by the server and decompressed by the Client. Compression=0 or -2 is advised if the bandwidth is not limited |
0
|
|
file_format |
(optional) currently supported geocube.FileFormatRaw & geocube.FileFormatGTiff |
FileFormatRaw
|
|
file_pattern |
(optional) iif file_format != Raw, pattern of the file name. {#} will be replaced by the number of image, {date} and {id} by the value of the record |
None
|
Returns:
Type | Description |
---|---|
entities.CubeIterator
|
an iterator yielding an image, its associated records, an error (or None) and the size of the image |
client = Client('127.0.0.1:8080', False) cube_params = entities.CubeParams.from_records("+proj=utm +zone=31", ... entities.geo_transform(366162, 4833123, 30), (512, 512), ... client.variable(name="test/rgb").instance("master"), records=client.list_records('france')) affine.Affine.translation(366162, 4833123)*affine.Affine.scale(30, -30)) cube_it = client.get_cube_it(cube_params) from matplotlib import pyplot as plt for image, , _, err in cube_it: ... if not err: ... plt.figure(cube_it.index+1) ... plt.imshow(image)
Source code in geocube/client.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
get_xyz_tile(instance, records, x, y, z, file)
Create a PNG file covering the (X,Y,Z) web-mercator tile, using the palette of the variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance |
Union[str, entities.VariableInstance]
|
instance of the variable |
required |
records |
List[Union[str, entities.Record]]
|
list of records |
required |
x |
int
|
coordinate of the web-mercator XYZ tile |
required |
y |
int
|
coordinate of the web-mercator XYZ tile |
required |
z |
int
|
coordinate of the web-mercator XYZ tile |
required |
file |
str
|
output PNG file |
required |
Source code in geocube/client.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
|
index(containers)
Index a new container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
containers |
List[entities.Container]
|
List of container to index. |
required |
Source code in geocube/client.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
index_dataset(uri, record, instance, dformat, bands=None, min_out=None, max_out=None, exponent=1)
Index the given "bands" of the dataset located at "uri", referenced by a record and an instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
str
|
of the file to index |
required |
record |
Union[str, entities.Record, Tuple[str, Dict[str, str], datetime]]
|
id of the record describing the data-take or a tuple (name, metadata, datetime) to create the record on the fly |
required |
instance |
entities.VariableInstance
|
describing the data |
required |
dformat |
entities.DataFormat
|
describing the internal format (see entities.DataFormat.from_user()) |
required |
bands |
List[int]
|
subset of bands' file (start at 1) that maps to |
None
|
min_out |
float
|
(optional, default: instance.dformat.min_value, instance.dformat.dtype) maps dformat.min_value |
None
|
max_out |
float
|
(optional, default: instance.dformat.max_value, instance.dformat.dtype) maps dformat.max_value |
None
|
exponent |
float
|
(optional, default: 1) non-linear scaling between dformat.min_max_value to min_max_out. |
1
|
Source code in geocube/client.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
list_grids(name_like='')
List grids by name name_like: pattern of the name. * and ? are supported to match all or any character.
Source code in geocube/client.py
596 597 598 599 600 601 602 603 |
|
list_layouts(name_like='')
List available layouts by name name_like: pattern of the name. * and ? are supported to match all or any character.
Source code in geocube/client.py
566 567 568 569 570 571 572 573 |
|
list_records(name='', tags=None, from_time=None, to_time=None, aoi=None, limit=10000, page=0, with_aoi=False)
List records given filters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
pattern of the name. * and ? are supported to match all or any character. (?i) can be added at the end to be insensitive to case |
''
|
tags |
Dict[str, str]
|
list of mandatory tags. Support the same pattern as name. |
None
|
from_time |
datetime
|
filter by date |
None
|
to_time |
datetime
|
filter by date |
None
|
aoi |
geometry.MultiPolygon
|
records that intersect the AOI in geographic coordinates |
None
|
limit |
int
|
the number of records returned (0 to return all records) |
10000
|
page |
int
|
start at 0 |
0
|
with_aoi |
bool
|
also returns the AOI of the record. Otherwise, only the ID of the aoi is returned. load_aoi(record) can be called to retrieve the AOI later. |
False
|
Returns:
Type | Description |
---|---|
List[entities.Record]
|
a list of records |
Source code in geocube/client.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
list_variables(name='', limit=0, page=0)
List all the variables given a pattern
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
pattern of the name. * and ? are supported to match all or any character. (?i) can be added at the end to be insensitive to case |
''
|
limit |
int
|
limit the number of variables returned |
0
|
page |
int
|
number of the page (starting at 0). |
0
|
Returns:
Type | Description |
---|---|
List[entities.Variable]
|
a list of variable |
Source code in geocube/client.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
load_aoi(aoi_id)
Load the geometry of the AOI of the given record
Parameters:
Name | Type | Description | Default |
---|---|---|---|
aoi_id |
Union[str, entities.Record]
|
uuid of the AOI or the record. If the record is provided, its geometry will be updated |
required |
Returns:
Type | Description |
---|---|
geometry.MultiPolygon
|
the geometry of the AOI |
Source code in geocube/client.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
remove_records_tags(records, tag_keys)
Remove tags keys from a list of records
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records |
List[Union[str, entities.Record]]
|
List of records to be updated |
required |
tag_keys |
List[str]
|
List of keys to be deleted |
required |
Returns:
Type | Description |
---|---|
int
|
the number of updated records |
Source code in geocube/client.py
297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
tile_aoi(aoi, layout_name=None, layout=None, resolution=None, crs=None, shape=None)
Tile an AOI
Parameters:
Name | Type | Description | Default |
---|---|---|---|
aoi |
geometry.MultiPolygon
|
AOI to be tiled in geographic coordinates |
required |
crs |
Optional[str]
|
CRS of the tile (not the AOI) |
None
|
resolution |
Optional[float]
|
resolution of the tile |
None
|
shape |
Optional[Tuple[int, int]]
|
shape of each tile |
None
|
layout_name |
Optional[str]
|
use a defined layout. |
None
|
layout |
Optional[entities.Layout]
|
use a customer defined layout |
None
|
Returns:
Type | Description |
---|---|
List[entities.Tile]
|
a list of Tiles covering the AOI in the given CRS at the given resolution |
Source code in geocube/client.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
|
variable(name=None, id_=None, instance_id=None)
Fetch a variable given an id, a name or an instance id (mutually exclusive)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
None
|
|
id_ |
str
|
internal id of the variable (uuid4) |
None
|
instance_id |
str
|
internal id of one instance of the variable (uuid4) |
None
|
Returns:
Type | Description |
---|---|
Union[entities.Variable, entities.VariableInstance]
|
either a Variable (first two cases) or a VariableInstance (specialization of the variable) |
Source code in geocube/client.py
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 |
|
version()
Returns the version of the Geocube Server
Source code in geocube/client.py
49 50 51 52 |
|