Skip to content

Commit bf0198d

Browse files
committed
[style] Format with black
1 parent 0f53487 commit bf0198d

7 files changed

Lines changed: 347 additions & 202 deletions

File tree

examples/forge/detect_on_project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Demonstrate running a detector on all images within a project
33
"""
4+
45
from picterra import APIClient
56

67
# Set the PICTERRA_API_KEY environment variable to define your API key

examples/forge/raster_management.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
local_raster_id = client.upload_raster("data/raster1.tif", name="A short-lived raster")
2626
print("Uploaded a second local raster=", local_raster_id)
2727
# Editing the image's band specification. See https://docs.picterra.ch/imagery/#Multispectral
28-
client.edit_raster(local_raster_id, multispectral_band_specification={
29-
"ranges": [
30-
[0, 128], [0, 128], [0, 128]
31-
],
32-
"display_bands": [
33-
{"type": "multiband", "name": "default", "bands": [2, 1, 0]}
34-
]
35-
})
28+
client.edit_raster(
29+
local_raster_id,
30+
multispectral_band_specification={
31+
"ranges": [[0, 128], [0, 128], [0, 128]],
32+
"display_bands": [{"type": "multiband", "name": "default", "bands": [2, 1, 0]}],
33+
},
34+
)
3635
# Deleting the image
3736
client.delete_raster(local_raster_id)
3837
print("Deleted raster=", local_raster_id)

examples/tracer/plots_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"New analysis",
1414
["plotid_1", "plotid_2", "plotid_3"],
1515
datetime.date.fromisoformat("2022-01-01"),
16-
datetime.date.fromisoformat("2024-01-01")
16+
datetime.date.fromisoformat("2024-01-01"),
1717
)
1818
url = client.get_plots_analysis(analysis_id, plots_group_id)["url"]
1919

tests/test_base_client.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def request_callback(request, uri, response_headers):
6565
time.sleep(2)
6666
return [200, response_headers, json.dumps([])]
6767

68-
httpretty.register_uri(httpretty.GET, detector_api_url("rasters/"), body=request_callback)
68+
httpretty.register_uri(
69+
httpretty.GET, detector_api_url("rasters/"), body=request_callback
70+
)
6971
timeout = 1
7072
client = _client(monkeypatch, timeout=timeout)
7173
with pytest.raises(requests.exceptions.ConnectionError) as e:
@@ -79,7 +81,9 @@ def request_callback(request, uri, response_headers):
7981

8082
@responses.activate
8183
def test_headers_api_key(monkeypatch):
82-
_add_api_response(detector_api_url("detectors/"), responses.POST, json={"id": "foobar"})
84+
_add_api_response(
85+
detector_api_url("detectors/"), responses.POST, json={"id": "foobar"}
86+
)
8387
client = _client(monkeypatch)
8488
client.create_detector()
8589
assert len(responses.calls) == 1
@@ -88,7 +92,9 @@ def test_headers_api_key(monkeypatch):
8892

8993
@responses.activate
9094
def test_headers_user_agent_version(monkeypatch):
91-
_add_api_response(detector_api_url("detectors/"), responses.POST, json={"id": "foobar"})
95+
_add_api_response(
96+
detector_api_url("detectors/"), responses.POST, json={"id": "foobar"}
97+
)
9298
client = _client(monkeypatch)
9399
client.create_detector()
94100
assert len(responses.calls) == 1
@@ -99,8 +105,12 @@ def test_headers_user_agent_version(monkeypatch):
99105

100106
@responses.activate
101107
def test_headers_user_agent_version__fallback(monkeypatch):
102-
_add_api_response(detector_api_url("detectors/"), responses.POST, json={"id": "foobar"},)
103-
monkeypatch.setattr(base_client, '_get_distr_name', lambda: 'foobar')
108+
_add_api_response(
109+
detector_api_url("detectors/"),
110+
responses.POST,
111+
json={"id": "foobar"},
112+
)
113+
monkeypatch.setattr(base_client, "_get_distr_name", lambda: "foobar")
104114
client = _client(monkeypatch)
105115
client.create_detector()
106116
assert len(responses.calls) == 1
@@ -126,7 +136,9 @@ def test_results_page():
126136
method=responses.GET,
127137
url="http://example.com/page/2",
128138
json={
129-
"count": 1, "next": None, "previous": "http://example.com/page/1",
139+
"count": 1,
140+
"next": None,
141+
"previous": "http://example.com/page/1",
130142
"results": ["three"],
131143
},
132144
status=200,

tests/test_forge_client.py

Lines changed: 87 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def add_mock_rasters_in_folder_list_response(folder_id):
7979
}
8080
qs = {"folder": folder_id, "page_number": "1"}
8181
_add_api_response(
82-
detector_api_url("rasters/"), json=data, match=responses.matchers.query_param_matcher(qs)
82+
detector_api_url("rasters/"),
83+
json=data,
84+
match=responses.matchers.query_param_matcher(qs),
8385
)
8486

8587

@@ -110,7 +112,9 @@ def add_mock_rasters_in_filtered_list_response(
110112
if has_layers is not None:
111113
qs["has_vector_layers"] = bool(has_layers)
112114
_add_api_response(
113-
detector_api_url("rasters/"), match=responses.matchers.query_param_matcher(qs), json=data
115+
detector_api_url("rasters/"),
116+
match=responses.matchers.query_param_matcher(qs),
117+
json=data,
114118
)
115119

116120

@@ -186,21 +190,32 @@ def add_mock_detectors_list_response(string=None, tag=None, shared=None):
186190

187191
def add_mock_detector_creation_response(**kwargs):
188192
match = responses.json_params_matcher({"configuration": kwargs}) if kwargs else None
189-
_add_api_response(detector_api_url("detectors/"), responses.POST, json={"id": "foobar"}, match=match)
193+
_add_api_response(
194+
detector_api_url("detectors/"),
195+
responses.POST,
196+
json={"id": "foobar"},
197+
match=match,
198+
)
190199

191200

192201
def add_mock_detector_edit_response(d_id, **kwargs):
193202
match = responses.json_params_matcher({"configuration": kwargs}) if kwargs else None
194-
_add_api_response(detector_api_url("detectors/%s/" % d_id), responses.PUT, status=204, match=match)
203+
_add_api_response(
204+
detector_api_url("detectors/%s/" % d_id), responses.PUT, status=204, match=match
205+
)
195206

196207

197208
def add_mock_detector_train_responses(detector_id):
198-
_add_api_response(detector_api_url("detectors/%s/train/" % detector_id), responses.POST, OP_RESP)
209+
_add_api_response(
210+
detector_api_url("detectors/%s/train/" % detector_id), responses.POST, OP_RESP
211+
)
199212

200213

201214
def add_mock_run_dataset_recommendation_responses(detector_id):
202215
_add_api_response(
203-
detector_api_url("detectors/%s/dataset_recommendation/" % detector_id), responses.POST, OP_RESP
216+
detector_api_url("detectors/%s/dataset_recommendation/" % detector_id),
217+
responses.POST,
218+
OP_RESP,
204219
)
205220

206221

@@ -287,7 +302,9 @@ def add_mock_raster_upload_responses(identity_key, multispectral, cloud_coverage
287302
# Storage PUT
288303
responses.add(responses.PUT, "http://storage.example.com", status=200)
289304
# Commit
290-
_add_api_response(detector_api_url("rasters/%s/commit/" % raster_id), responses.POST, OP_RESP)
305+
_add_api_response(
306+
detector_api_url("rasters/%s/commit/" % raster_id), responses.POST, OP_RESP
307+
)
291308
# Status, first check
292309
data = {"id": raster_id, "name": "raster1", "status": "processing"}
293310
_add_api_response(detector_api_url("rasters/%s/" % raster_id), json=data)
@@ -302,26 +319,36 @@ def add_mock_detection_areas_upload_responses(raster_id):
302319
# Upload initiation
303320
data = {"upload_url": "http://storage.example.com", "upload_id": upload_id}
304321
_add_api_response(
305-
detector_api_url("rasters/%s/detection_areas/upload/file/" % raster_id), responses.POST, data
322+
detector_api_url("rasters/%s/detection_areas/upload/file/" % raster_id),
323+
responses.POST,
324+
data,
306325
)
307326
# Storage PUT
308327
responses.add(responses.PUT, "http://storage.example.com", status=200)
309328
# Commit
310329
_add_api_response(
311-
detector_api_url("rasters/%s/detection_areas/upload/%s/commit/" % (raster_id, upload_id)),
330+
detector_api_url(
331+
"rasters/%s/detection_areas/upload/%s/commit/" % (raster_id, upload_id)
332+
),
312333
responses.POST,
313334
OP_RESP,
314335
status=200,
315336
)
316337
# Status, first check
317338
data = {"status": "processing"}
318339
_add_api_response(
319-
detector_api_url("rasters/%s/detection_areas/upload/%s/" % (raster_id, upload_id)), json=data
340+
detector_api_url(
341+
"rasters/%s/detection_areas/upload/%s/" % (raster_id, upload_id)
342+
),
343+
json=data,
320344
)
321345
# Status, second check
322346
data = {"status": "ready"}
323347
_add_api_response(
324-
detector_api_url("rasters/%s/detection_areas/upload/%s/" % (raster_id, upload_id)), json=data
348+
detector_api_url(
349+
"rasters/%s/detection_areas/upload/%s/" % (raster_id, upload_id)
350+
),
351+
json=data,
325352
)
326353

327354

@@ -390,7 +417,9 @@ def add_mock_vector_layer_download_responses(layer_id, polygons_num):
390417
}
391418
add_mock_operations_responses("success", results=results)
392419
url = results["download_url"]
393-
polygons_fc = multipolygon_to_polygon_feature_collection(make_geojson_multipolygon(polygons_num))
420+
polygons_fc = multipolygon_to_polygon_feature_collection(
421+
make_geojson_multipolygon(polygons_num)
422+
)
394423
assert len(polygons_fc["features"]) == polygons_num
395424
responses.add(
396425
responses.GET,
@@ -399,13 +428,19 @@ def add_mock_vector_layer_download_responses(layer_id, polygons_num):
399428
)
400429
return polygons_fc
401430

431+
402432
def add_mock_folder_creation_response(id, name):
403433
match = responses.matchers.json_params_matcher({"name": name})
404-
_add_api_response(detector_api_url("folders/"), responses.POST, json={"id": id}, match=match)
434+
_add_api_response(
435+
detector_api_url("folders/"), responses.POST, json={"id": id}, match=match
436+
)
405437

406438

407439
def make_geojson_polygon(base=1):
408-
return {"type": "Polygon", "coordinates": [[[0, 0], [base, 0], [base, base], [0, base], [0, 0]]]}
440+
return {
441+
"type": "Polygon",
442+
"coordinates": [[[0, 0], [base, 0], [base, base], [0, base], [0, 0]]],
443+
}
409444

410445

411446
def make_geojson_multipolygon(npolygons=1):
@@ -424,9 +459,10 @@ def add_mock_download_result_response(op_id, num_classes):
424459
"class": {"name": f"class_{i + 1}"},
425460
"result": {
426461
"url": f"http://storage.example.com/result_for_class_{i + 1}.geojson",
427-
"vector_layer_id": f"layer_{i + 1}"
462+
"vector_layer_id": f"layer_{i + 1}",
428463
},
429-
} for i in range(num_classes)
464+
}
465+
for i in range(num_classes)
430466
],
431467
},
432468
}
@@ -479,15 +515,19 @@ def add_mock_delete_raster_response(raster_id):
479515

480516

481517
def add_mock_delete_detectionarea_response(raster_id):
482-
_add_api_response(detector_api_url("rasters/%s/detection_areas/" % raster_id), responses.DELETE)
518+
_add_api_response(
519+
detector_api_url("rasters/%s/detection_areas/" % raster_id), responses.DELETE
520+
)
483521

484522

485523
def add_mock_delete_detector_response(detector_id):
486524
_add_api_response(detector_api_url("detectors/%s/" % detector_id), responses.DELETE)
487525

488526

489527
def add_mock_delete_vector_layer_response(layer_id):
490-
_add_api_response(detector_api_url("vector_layers/%s/" % layer_id), responses.DELETE)
528+
_add_api_response(
529+
detector_api_url("vector_layers/%s/" % layer_id), responses.DELETE
530+
)
491531

492532

493533
def add_mock_edit_vector_layer_response(layer_id, **kwargs):
@@ -536,7 +576,9 @@ def add_mock_marker_creation_response(marker_id, raster_id, detector_id, coords,
536576
"text": text,
537577
}
538578
match = responses.matchers.json_params_matcher(body)
539-
_add_api_response(detector_api_url(url), responses.POST, json={"id": marker_id}, match=match)
579+
_add_api_response(
580+
detector_api_url(url), responses.POST, json={"id": marker_id}, match=match
581+
)
540582

541583

542584
def add_mock_folder_detector_response(folder_id: str):
@@ -598,27 +640,30 @@ def test_multipolygon_to_polygon_feature_collection():
598640
"type": "MultiPolygon",
599641
"coordinates": [
600642
[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
601-
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
602-
]
643+
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]],
644+
],
603645
}
604646
fc = multipolygon_to_polygon_feature_collection(mp)
605647
assert fc == {
606648
"type": "FeatureCollection",
607-
"features": [{
608-
"type": "Feature",
609-
"properties": {},
610-
"geometry": {
611-
"type": "Polygon",
612-
"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]
613-
}
614-
}, {
615-
"type": "Feature",
616-
"properties": {},
617-
"geometry": {
618-
"type": "Polygon",
619-
"coordinates": [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
620-
}
621-
}]
649+
"features": [
650+
{
651+
"type": "Feature",
652+
"properties": {},
653+
"geometry": {
654+
"type": "Polygon",
655+
"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
656+
},
657+
},
658+
{
659+
"type": "Feature",
660+
"properties": {},
661+
"geometry": {
662+
"type": "Polygon",
663+
"coordinates": [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]],
664+
},
665+
},
666+
],
622667
}
623668

624669

@@ -953,7 +998,9 @@ def test_download_result_to_feature_collection(monkeypatch):
953998
assert len(feat1["geometry"]["coordinates"]) == 10
954999
assert isinstance(feat1["geometry"]["coordinates"][0][0][0][0], (int, float))
9551000
feat2 = fc["features"][(class_1_index + 1) % 2]
956-
assert feat2["type"] == "Feature" and feat2["geometry"]["type"] == "MultiPolygon"
1001+
assert (
1002+
feat2["type"] == "Feature" and feat2["geometry"]["type"] == "MultiPolygon"
1003+
)
9571004
assert feat2["properties"]["class_name"] == "class_2"
9581005
assert len(feat2["geometry"]["coordinates"]) == 20
9591006
assert isinstance(feat2["geometry"]["coordinates"][0][0][0][0], (int, float))
@@ -1060,7 +1107,9 @@ def test_download_vector_layer_to_file(monkeypatch):
10601107
assert fc["type"] == "FeatureCollection"
10611108
assert fc == polygons_fc and len(fc["features"]) == 2
10621109
assert fc["features"][0]["geometry"]["type"] == "Polygon"
1063-
assert isinstance(fc["features"][1]["geometry"]["coordinates"][0][0][0], (int, float))
1110+
assert isinstance(
1111+
fc["features"][1]["geometry"]["coordinates"][0][0][0], (int, float)
1112+
)
10641113
assert len(responses.calls) == 3 # POST /download, GET /operations, GET url
10651114

10661115

0 commit comments

Comments
 (0)