Skip to content

Commit c5b8818

Browse files
authored
Merge pull request #55 from descarteslabs/feat/fractions
Adding fraction(s) arguments to metadata
2 parents 40a3cd4 + 3a16c08 commit c5b8818

File tree

5 files changed

+72
-16
lines changed

5 files changed

+72
-16
lines changed

descarteslabs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# flake8: noqa
1616

17-
__version__ = "0.1.6"
17+
__version__ = "0.2.0"
1818
from .auth import Auth
1919
descartes_auth = Auth()
2020

descarteslabs/scripts/places

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if __name__ == "__main__":
2424

2525
parser = argparse.ArgumentParser()
2626

27-
parser.add_argument('command', choices=['find', 'place', 'prefix', 'placetypes'],
27+
parser.add_argument('command', choices=['find', 'shape', 'prefix', 'placetypes'],
2828
help='The action to take.')
2929
parser.add_argument('argument', nargs='?')
3030

descarteslabs/services/metadata.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def sources(self):
4949

5050
return r.json()
5151

52-
def summary(self, const_id=None, sat_id=None, date='acquired', part='day',
53-
place=None, geom=None, start_time=None, end_time=None,
54-
params=None, bbox=False):
52+
def summary(self, const_id=None, sat_id=None, date='acquired', part=None,
53+
place=None, geom=None, start_time=None, end_time=None, cloud_fraction=None,
54+
cloud_fraction_0=None, fill_fraction=None, params=None, bbox=False):
5555
"""Get a summary of the results for the specified spatio-temporal query.
5656
5757
:param list(str) const_id: Constellation identifier(s).
@@ -62,6 +62,9 @@ def summary(self, const_id=None, sat_id=None, date='acquired', part='day',
6262
:param str geom: A GeoJSON or WKT region of interest.
6363
:param str start_time: Desired starting date and time (inclusive).
6464
:param str end_time: Desired ending date and time (inclusive).
65+
:param float cloud_fraction: Maximum cloud fraction, calculated by data provider.
66+
:param float cloud_fraction_0: Maximum cloud fraction, calculated by cloud mask pixels.
67+
:param float fill_fraction: Minimum scene fill fraction, calculated as valid/total pixels.
6568
:param bool bbox: If true, query by the bounding box of the region of interest.
6669
:param str params: JSON of additional query parameters.
6770
@@ -135,6 +138,15 @@ def summary(self, const_id=None, sat_id=None, date='acquired', part='day',
135138
if end_time:
136139
kwargs['end_time'] = end_time
137140

141+
if cloud_fraction:
142+
kwargs['cloud_fraction'] = cloud_fraction
143+
144+
if cloud_fraction_0:
145+
kwargs['cloud_fraction_0'] = cloud_fraction_0
146+
147+
if fill_fraction:
148+
kwargs['fill_fraction'] = fill_fraction
149+
138150
if params:
139151
kwargs['params'] = json.dumps(params)
140152

@@ -149,8 +161,9 @@ def summary(self, const_id=None, sat_id=None, date='acquired', part='day',
149161
return r.json()
150162

151163
def search(self, const_id=None, sat_id=None, date='acquired', place=None,
152-
geom=None, start_time=None, end_time=None, params=None,
153-
limit=100, offset=0, bbox=True):
164+
geom=None, start_time=None, end_time=None, cloud_fraction=None,
165+
cloud_fraction_0=None, fill_fraction=None, params=None,
166+
limit=100, offset=0, bbox=False):
154167
"""Search metadata given a spatio-temporal query. All parameters are
155168
optional. Results are paged using limit/offset.
156169
@@ -161,6 +174,9 @@ def search(self, const_id=None, sat_id=None, date='acquired', place=None,
161174
:param str geom: A GeoJSON or WKT region of interest.
162175
:param str start_time: Desired starting date and time (inclusive).
163176
:param str end_time: Desired ending date and time (inclusive).
177+
:param float cloud_fraction: Maximum cloud fraction, calculated by data provider.
178+
:param float cloud_fraction_0: Maximum cloud fraction, calculated by cloud mask pixels.
179+
:param float fill_fraction: Minimum scene fill fraction, calculated as valid/total pixels.
164180
:param bool bbox: If true, query by the bounding box of the region of interest.
165181
:param str params: JSON of additional query parameters.
166182
:param int limit: Number of items to return.
@@ -213,6 +229,15 @@ def search(self, const_id=None, sat_id=None, date='acquired', place=None,
213229
if end_time:
214230
kwargs['end_time'] = end_time
215231

232+
if cloud_fraction:
233+
kwargs['cloud_fraction'] = cloud_fraction
234+
235+
if cloud_fraction_0:
236+
kwargs['cloud_fraction_0'] = cloud_fraction_0
237+
238+
if fill_fraction:
239+
kwargs['fill_fraction'] = fill_fraction
240+
216241
if params:
217242
kwargs['params'] = json.dumps(params)
218243

@@ -233,7 +258,8 @@ def search(self, const_id=None, sat_id=None, date='acquired', place=None,
233258
return result
234259

235260
def keys(self, const_id=None, sat_id=None, date='acquired', place=None,
236-
geom=None, start_time=None, end_time=None, params=None, limit=100,
261+
geom=None, start_time=None, end_time=None, cloud_fraction=None,
262+
cloud_fraction_0=None, fill_fraction=None, params=None, limit=100,
237263
offset=0, bbox=False):
238264
"""Search metadata given a spatio-temporal query. All parameters are
239265
optional. Results are paged using limit/offset.
@@ -245,6 +271,9 @@ def keys(self, const_id=None, sat_id=None, date='acquired', place=None,
245271
:param str geom: A GeoJSON or WKT region of interest.
246272
:param str start_time: Desired starting date and time (inclusive).
247273
:param str end_time: Desired ending date and time (inclusive).
274+
:param float cloud_fraction: Maximum cloud fraction, calculated by data provider.
275+
:param float cloud_fraction_0: Maximum cloud fraction, calculated by cloud mask pixels.
276+
:param float fill_fraction: Minimum scene fill fraction, calculated as valid/total pixels.
248277
:param bool bbox: If true, query by the bounding box of the region of interest.
249278
:param str params: JSON of additional query parameters.
250279
:param int limit: Number of items to return.
@@ -266,13 +295,15 @@ def keys(self, const_id=None, sat_id=None, date='acquired', place=None,
266295
"""
267296
result = self.search(sat_id=sat_id, const_id=const_id, date=date,
268297
place=place, geom=geom, start_time=start_time,
269-
end_time=end_time, params=params, limit=limit,
270-
offset=offset, bbox=bbox)
298+
end_time=end_time, cloud_fraction=cloud_fraction,
299+
cloud_fraction_0=cloud_fraction_0, fill_fraction=fill_fraction,
300+
params=params, limit=limit, offset=offset, bbox=bbox)
271301

272302
return [feature['id'] for feature in result['features']]
273303

274304
def features(self, const_id=None, sat_id=None, date='acquired', place=None,
275-
geom=None, start_time=None, end_time=None, params=None,
305+
geom=None, start_time=None, end_time=None, cloud_fraction=None,
306+
cloud_fraction_0=None, fill_fraction=None, params=None,
276307
limit=100, bbox=False):
277308
"""Generator that combines summary and search to page through results.
278309
@@ -282,7 +313,9 @@ def features(self, const_id=None, sat_id=None, date='acquired', place=None,
282313
"""
283314
result = self.summary(sat_id=sat_id, const_id=const_id, date=date,
284315
place=place, geom=geom, start_time=start_time,
285-
end_time=end_time, params=params, bbox=bbox)
316+
end_time=end_time, cloud_fraction=cloud_fraction,
317+
cloud_fraction_0=cloud_fraction_0, fill_fraction=fill_fraction,
318+
params=params, bbox=bbox)
286319

287320
for summary in result:
288321

@@ -294,8 +327,10 @@ def features(self, const_id=None, sat_id=None, date='acquired', place=None,
294327

295328
features = self.search(sat_id=sat_id, const_id=const_id,
296329
date=date, place=place, geom=geom,
297-
start_time=start_time,
298-
end_time=end_time, params=params,
330+
start_time=start_time, end_time=end_time,
331+
cloud_fraction=cloud_fraction,
332+
cloud_fraction_0=cloud_fraction_0,
333+
fill_fraction=fill_fraction, params=params,
299334
limit=limit, offset=offset, bbox=bbox)
300335

301336
offset = limit + offset

descarteslabs/tests/test_metadata.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ def test_sat_id(self):
4040
r = self.instance.search(start_time='2016-09-01', end_time='2016-09-02', sat_id='LANDSAT_8')
4141
self.assertEqual(100, len(r['features']))
4242

43+
@unittest.skipIf(is_external_user(), "currently requires internal user")
44+
def test_cloud_fraction(self):
45+
r = self.instance.search(start_time='2016-09-01', end_time='2016-09-02', sat_id='LANDSAT_8',
46+
cloud_fraction=0.5)
47+
for feature in r['features']:
48+
self.assertLess(feature['properties']['cloud_fraction'], 0.5)
49+
4350
@unittest.skipIf(is_external_user(), "currently requires internal user")
4451
def test_const_id(self):
4552
r = self.instance.search(start_time='2016-09-01', end_time='2016-09-02', const_id=['L8'])
@@ -58,7 +65,21 @@ def test_place(self):
5865
@unittest.skipIf(is_external_user(), "currently requires internal user")
5966
def test_summary(self):
6067
r = self.instance.summary(start_time='2016-09-01', end_time='2016-09-02', const_id=['L8'])
61-
self.assertEqual(1, len(list(r['items'])))
68+
self.assertIn('const_id', r)
69+
self.assertIn('count', r)
70+
self.assertIn('pixels', r)
71+
self.assertIn('bytes', r)
72+
self.assertGreater(r['count'], 0)
73+
74+
@unittest.skipIf(is_external_user(), "currently requires internal user")
75+
def test_summary_part(self):
76+
r = self.instance.summary(start_time='2016-09-01', end_time='2016-09-02', const_id=['L8'], part='year')
77+
self.assertIn('const_id', r)
78+
self.assertIn('count', r)
79+
self.assertIn('pixels', r)
80+
self.assertIn('bytes', r)
81+
self.assertIn('items', r)
82+
self.assertEqual(len(r['items']), 1)
6283

6384

6485
if __name__ == '__main__':

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from setuptools import setup, find_packages
2020

2121

22-
__version__ = "0.1.6"
22+
__version__ = "0.2.0"
2323

2424

2525
def do_setup():

0 commit comments

Comments
 (0)