Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/forge/detect_on_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Demonstrate running a detector on all images within a project
"""

from picterra import APIClient

# Set the PICTERRA_API_KEY environment variable to define your API key
Expand Down
15 changes: 7 additions & 8 deletions examples/forge/raster_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
local_raster_id = client.upload_raster("data/raster1.tif", name="A short-lived raster")
print("Uploaded a second local raster=", local_raster_id)
# Editing the image's band specification. See https://docs.picterra.ch/imagery/#Multispectral
client.edit_raster(local_raster_id, multispectral_band_specification={
"ranges": [
[0, 128], [0, 128], [0, 128]
],
"display_bands": [
{"type": "multiband", "name": "default", "bands": [2, 1, 0]}
]
})
client.edit_raster(
local_raster_id,
multispectral_band_specification={
"ranges": [[0, 128], [0, 128], [0, 128]],
"display_bands": [{"type": "multiband", "name": "default", "bands": [2, 1, 0]}],
},
)
# Deleting the image
client.delete_raster(local_raster_id)
print("Deleted raster=", local_raster_id)
2 changes: 1 addition & 1 deletion examples/tracer/plots_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"New analysis",
["plotid_1", "plotid_2", "plotid_3"],
datetime.date.fromisoformat("2022-01-01"),
datetime.date.fromisoformat("2024-01-01")
datetime.date.fromisoformat("2024-01-01"),
)
url = client.get_plots_analysis(analysis_id, plots_group_id)["url"]

Expand Down
11 changes: 11 additions & 0 deletions src/picterra/forge_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ class ForgeClient(BaseAPIClient):
def __init__(self, **kwargs):
super().__init__("public/api/v2/", **kwargs)

def get_user_info(self) -> dict:
"""
Get information about the current user

This endpoint is in alpha stage and may change without warning.
"""
resp = self.sess.get(self._full_url("users/me/"))
if not resp.ok:
raise APIError(resp.text)
return resp.json()

def upload_raster(
self,
filename: str,
Expand Down
10 changes: 10 additions & 0 deletions src/picterra/tracer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def _upload_plot_ids(self, plot_ids: List[str]) -> str:
_check_resp_is_ok(resp, "Failure uploading plots file")
return upload_id

def get_user_info(self) -> dict:
"""
Get information about the current user

This endpoint is in alpha stage and may change without warning.
"""
resp = self.sess.get(self._full_url("users/me/"))
_check_resp_is_ok(resp, "Failed to get user info")
return resp.json()

def list_methodologies(
self,
search: Optional[str] = None,
Expand Down
24 changes: 18 additions & 6 deletions tests/test_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def request_callback(request, uri, response_headers):
time.sleep(2)
return [200, response_headers, json.dumps([])]

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

@responses.activate
def test_headers_api_key(monkeypatch):
_add_api_response(detector_api_url("detectors/"), responses.POST, json={"id": "foobar"})
_add_api_response(
detector_api_url("detectors/"), responses.POST, json={"id": "foobar"}
)
client = _client(monkeypatch)
client.create_detector()
assert len(responses.calls) == 1
Expand All @@ -88,7 +92,9 @@ def test_headers_api_key(monkeypatch):

@responses.activate
def test_headers_user_agent_version(monkeypatch):
_add_api_response(detector_api_url("detectors/"), responses.POST, json={"id": "foobar"})
_add_api_response(
detector_api_url("detectors/"), responses.POST, json={"id": "foobar"}
)
client = _client(monkeypatch)
client.create_detector()
assert len(responses.calls) == 1
Expand All @@ -99,8 +105,12 @@ def test_headers_user_agent_version(monkeypatch):

@responses.activate
def test_headers_user_agent_version__fallback(monkeypatch):
_add_api_response(detector_api_url("detectors/"), responses.POST, json={"id": "foobar"},)
monkeypatch.setattr(base_client, '_get_distr_name', lambda: 'foobar')
_add_api_response(
detector_api_url("detectors/"),
responses.POST,
json={"id": "foobar"},
)
monkeypatch.setattr(base_client, "_get_distr_name", lambda: "foobar")
client = _client(monkeypatch)
client.create_detector()
assert len(responses.calls) == 1
Expand All @@ -126,7 +136,9 @@ def test_results_page():
method=responses.GET,
url="http://example.com/page/2",
json={
"count": 1, "next": None, "previous": "http://example.com/page/1",
"count": 1,
"next": None,
"previous": "http://example.com/page/1",
"results": ["three"],
},
status=200,
Expand Down
Loading
Loading