20
20
from descarteslabs .client .services .places import Places
21
21
from descarteslabs .client .auth import Auth
22
22
from descarteslabs .client .services .raster import Raster
23
- from descarteslabs .client .services .metadata .metadata_filtering import AndExpression
23
+ from descarteslabs .client .services .metadata .metadata_filtering import \
24
+ AndExpression , GLOBAL_PROPERTIES
25
+ from descarteslabs .common .dotdict import DotDict , DotList
24
26
25
27
26
28
OFFSET_DEPRECATION_MESSAGE = (
27
29
"Keyword arg `offset` has been deprecated and will be removed in "
28
30
"future versions of the library. "
29
31
)
30
32
33
+ SAT_ID_DEPRECATION_MESSAGE = (
34
+ "Keyword arg `sat_id` has been deprecated and will be removed in "
35
+ "future versions of the library. "
36
+ )
37
+
38
+ SOURCES_DEPRECATION_MESSAGE = (
39
+ "Metadata.sources() has been deprecated and will be removed in "
40
+ "future versions of the library. Please use "
41
+ "Metadata.available_products() or Metadata.products() instead. "
42
+ )
43
+
31
44
32
45
class Metadata (Service ):
33
46
"""
@@ -41,32 +54,29 @@ class Metadata(Service):
41
54
42
55
TIMEOUT = (9.5 , 120 )
43
56
44
- def __init__ (self , url = None , token = None , auth = Auth ()):
57
+ properties = GLOBAL_PROPERTIES
58
+
59
+ def __init__ (self , url = None , auth = None ):
45
60
"""The parent Service class implements authentication and exponential
46
61
backoff/retry. Override the url parameter to use a different instance
47
62
of the backing service.
48
63
"""
64
+ if auth is None :
65
+ auth = Auth ()
66
+
49
67
simplefilter ('always' , DeprecationWarning )
50
68
if url is None :
51
69
url = os .environ .get ("DESCARTESLABS_METADATA_URL" ,
52
70
"https://platform.descarteslabs.com/metadata/v1" )
53
71
54
- Service . __init__ ( self , url , token , auth )
72
+ super ( Metadata , self ). __init__ ( url , auth )
55
73
self ._raster = Raster (auth = self .auth )
56
74
57
75
def sources (self ):
58
- """Get a list of image sources.
76
+ warn ( SOURCES_DEPRECATION_MESSAGE , DeprecationWarning )
59
77
60
- Example::
61
- >>> from descarteslabs.client.services import Metadata
62
- >>> from pprint import pprint
63
- >>> sources = Metadata().sources()
64
- >>> pprint(sources)
65
- [{'product': 'landsat:LC08:PRE:TOAR', 'sat_id': 'LANDSAT_8'}]
66
-
67
- """
68
78
r = self .session .get ('/sources' )
69
- return r .json ()
79
+ return DotList ( r .json () )
70
80
71
81
def bands (
72
82
self ,
@@ -101,7 +111,7 @@ def bands(
101
111
})
102
112
103
113
r = self .session .post ('/bands/search' , json = kwargs )
104
- return r .json ()
114
+ return DotList ( r .json () )
105
115
106
116
def derived_bands (self , bands = None , require_bands = None , limit = None , offset = None , ** kwargs ):
107
117
"""Search for predefined derived bands that you have access to.
@@ -125,7 +135,7 @@ def derived_bands(self, bands=None, require_bands=None, limit=None, offset=None,
125
135
})
126
136
127
137
r = self .session .post ('/bands/derived/search' , json = kwargs )
128
- return r .json ()
138
+ return DotList ( r .json () )
129
139
130
140
def get_bands_by_key (self , key ):
131
141
"""
@@ -137,7 +147,7 @@ def get_bands_by_key(self, key):
137
147
"""
138
148
r = self .session .get ('/bands/key/%s' % key )
139
149
140
- return r .json ()
150
+ return DotDict ( r .json () )
141
151
142
152
def products (self , bands = None , limit = None , offset = None , owner = None , text = None , ** kwargs ):
143
153
"""Search products that are available on the platform.
@@ -161,22 +171,21 @@ def products(self, bands=None, limit=None, offset=None, owner=None, text=None, *
161
171
162
172
r = self .session .post ('/products/search' , json = kwargs )
163
173
164
- return r .json ()
174
+ return DotList ( r .json () )
165
175
166
176
def available_products (self ):
167
177
"""Get the list of product identifiers you have access to.
168
178
169
179
Example::
170
180
>>> from descarteslabs.client.services import Metadata
171
- >>> from pprint import pprint
172
181
>>> products = Metadata().available_products()
173
- >>> pprint( products)
182
+ >>> products
174
183
['landsat:LC08:PRE:TOAR']
175
184
176
185
"""
177
186
r = self .session .get ('/products' )
178
187
179
- return r .json ()
188
+ return DotList ( r .json () )
180
189
181
190
def summary (self , products = None , sat_id = None , date = 'acquired' , part = None ,
182
191
place = None , geom = None , start_time = None , end_time = None , cloud_fraction = None ,
@@ -185,7 +194,7 @@ def summary(self, products=None, sat_id=None, date='acquired', part=None,
185
194
"""Get a summary of the results for the specified spatio-temporal query.
186
195
187
196
:param list(str) products: Product identifier(s).
188
- :param list(str) sat_id: Satellite identifier(s).
197
+ :param list(str) sat_id: Satellite identifier(s). *Deprecated*
189
198
:param str date: The date field to use for search (e.g. `acquired`).
190
199
:param str part: Part of the date to aggregate over (e.g. `day`).
191
200
:param str place: A slug identifier to be used as a region of interest.
@@ -202,19 +211,24 @@ def summary(self, products=None, sat_id=None, date='acquired', part=None,
202
211
Example usage::
203
212
204
213
>>> from descarteslabs.client.services import Metadata
205
- >>> from pprint import pprint
206
- >>> pprint(Metadata().summary(place='north-america_united-states_iowa', \
214
+ >>> Metadata().summary(place='north-america_united-states_iowa', \
207
215
products=['landsat:LC08:PRE:TOAR'], start_time='2016-07-06', \
208
- end_time='2016-07-07', part='hour', pixels=True))
209
- {'bytes': 93298309,
210
- 'count': 1,
211
- 'items': [{'bytes': 93298309,
212
- 'count': 1,
213
- 'date': '2016-07-06T16:00:00',
214
- 'pixels': 250508160,
215
- 'timestamp': 1467820800}],
216
- 'pixels': 250508160,
217
- 'products': ['landsat:LC08:PRE:TOAR']}
216
+ end_time='2016-07-07', part='hour', pixels=True)
217
+ {
218
+ 'bytes': 93298309,
219
+ 'count': 1,
220
+ 'items': [
221
+ {
222
+ 'bytes': 93298309,
223
+ 'count': 1,
224
+ 'date': '2016-07-06T16:00:00',
225
+ 'pixels': 250508160,
226
+ 'timestamp': 1467820800
227
+ }
228
+ ],
229
+ 'pixels': 250508160,
230
+ 'products': ['landsat:LC08:PRE:TOAR']
231
+ }
218
232
"""
219
233
if place :
220
234
places = Places ()
@@ -234,6 +248,8 @@ def summary(self, products=None, sat_id=None, date='acquired', part=None,
234
248
kwargs = {}
235
249
236
250
if sat_id :
251
+ warn (SAT_ID_DEPRECATION_MESSAGE , DeprecationWarning )
252
+
237
253
if isinstance (sat_id , string_types ):
238
254
sat_id = [sat_id ]
239
255
@@ -278,7 +294,7 @@ def summary(self, products=None, sat_id=None, date='acquired', part=None,
278
294
kwargs ['pixels' ] = pixels
279
295
280
296
r = self .session .post ('/summary' , json = kwargs )
281
- return r .json ()
297
+ return DotDict ( r .json () )
282
298
283
299
def search (self , products = None , sat_id = None , date = 'acquired' , place = None ,
284
300
geom = None , start_time = None , end_time = None , cloud_fraction = None ,
@@ -341,6 +357,8 @@ def search(self, products=None, sat_id=None, date='acquired', place=None,
341
357
kwargs ['offset' ] = offset
342
358
343
359
if sat_id :
360
+ warn (SAT_ID_DEPRECATION_MESSAGE , DeprecationWarning )
361
+
344
362
if isinstance (sat_id , string_types ):
345
363
sat_id = [sat_id ]
346
364
@@ -398,7 +416,7 @@ def search(self, products=None, sat_id=None, date='acquired', place=None,
398
416
fc ['properties' ] = {
399
417
'continuation_token' : r .headers ['x-continuation-token' ]}
400
418
401
- return fc
419
+ return DotDict ( fc )
402
420
403
421
def ids (self , products = None , sat_id = None , date = 'acquired' , place = None ,
404
422
geom = None , start_time = None , end_time = None , cloud_fraction = None ,
@@ -448,7 +466,7 @@ def ids(self, products=None, sat_id=None, date='acquired', place=None,
448
466
q = q , limit = limit , offset = offset , fields = [], dltile = dltile ,
449
467
sort_field = sort_field , sort_order = sort_order , randomize = randomize )
450
468
451
- return [ feature ['id' ] for feature in result ['features' ]]
469
+ return DotList ( feature ['id' ] for feature in result ['features' ])
452
470
453
471
def keys (self , products = None , sat_id = None , date = 'acquired' , place = None ,
454
472
geom = None , start_time = None , end_time = None , cloud_fraction = None ,
@@ -499,7 +517,7 @@ def keys(self, products=None, sat_id=None, date='acquired', place=None,
499
517
dltile = dltile , sort_field = sort_field ,
500
518
sort_order = sort_order , randomize = randomize )
501
519
502
- return [ feature ['key' ] for feature in result ['features' ]]
520
+ return DotList ( feature ['key' ] for feature in result ['features' ])
503
521
504
522
def features (self , products = None , sat_id = None , date = 'acquired' , place = None ,
505
523
geom = None , start_time = None , end_time = None , cloud_fraction = None ,
@@ -569,7 +587,7 @@ def get(self, key):
569
587
'tile_id']
570
588
"""
571
589
r = self .session .get ('/get/%s' % key )
572
- return r .json ()
590
+ return DotDict ( r .json () )
573
591
574
592
def get_by_ids (self , ids ):
575
593
"""Get metadata for multiple images by id. The response contains found images in the
@@ -579,7 +597,7 @@ def get_by_ids(self, ids):
579
597
:return: List of image metadata.
580
598
"""
581
599
r = self .session .post ('/batch/images' , json = {'ids' : ids })
582
- return r .json ()
600
+ return DotList ( r .json () )
583
601
584
602
def get_product (self , product_id ):
585
603
"""Get information about a single product.
@@ -588,7 +606,7 @@ def get_product(self, product_id):
588
606
589
607
"""
590
608
r = self .session .get ('/products/%s' % product_id )
591
- return r .json ()
609
+ return DotDict ( r .json () )
592
610
593
611
def get_band (self , band_id ):
594
612
"""Get information about a single product.
@@ -597,7 +615,7 @@ def get_band(self, band_id):
597
615
598
616
"""
599
617
r = self .session .get ('/bands/%s' % band_id )
600
- return r .json ()
618
+ return DotDict ( r .json () )
601
619
602
620
def get_derived_band (self , derived_band_id ):
603
621
"""Get information about a single product.
@@ -606,4 +624,4 @@ def get_derived_band(self, derived_band_id):
606
624
607
625
"""
608
626
r = self .session .get ('/bands/derived/%s' % derived_band_id )
609
- return r .json ()
627
+ return DotDict ( r .json () )
0 commit comments