Skip to content

Commit

Permalink
[PT-5138] Drop get blocks, get block details and block coverage (#593)
Browse files Browse the repository at this point in the history
* Drop get blocks, get block details and block coverage

* Bump version and update CHANGELOG.md
  • Loading branch information
javidq authored Apr 17, 2024
1 parent 3ce74a3 commit d64636b
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 253 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ You can check your current version with the following command:
```

For more information, see [UP42 Python package description](https://pypi.org/project/up42-py/).
## 1.0.0a7

**Apr 16, 2024**
- Dropped `get_blocks`, `get_block_details` and `get_block_coverage` from `main.py`

## 1.0.0a6

**Apr 16, 2024**
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "up42-py"
version = "1.0.0a6"
version = "1.0.0a7"
description = "Python SDK for UP42, the geospatial marketplace and developer platform."
authors = ["UP42 GmbH <[email protected]>"]
license = "https://github.com/up42/up42-py/blob/master/LICENSE"
Expand Down
6 changes: 0 additions & 6 deletions tests/fixtures/fixtures_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ def auth_mock(requests_mock: req_mock.Mocker) -> up42_auth.Auth:
url="https://api.up42.com/users/me",
json={"data": {"id": constants.WORKSPACE_ID}},
)
# get_blocks
url_get_blocks = f"{constants.API_HOST}/blocks"
requests_mock.get(
url=url_get_blocks,
json=constants.JSON_BLOCKS,
)
# get_credits_balance
url_get_credits_balance = f"{constants.API_HOST}/accounts/me/credits/balance"
requests_mock.get(
Expand Down
55 changes: 0 additions & 55 deletions tests/fixtures/fixtures_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,61 +51,6 @@

WEBHOOK_ID = "123"


JSON_BLOCKS = {
"data": [
{
"id": "4ed70368-d4e1-4462-bef6-14e768049471",
"name": "tiling",
"displayName": "Raster Tiling",
"type": "PROCESSING",
},
{
"id": "c0d04ec3-98d7-4183-902f-5bcb2a176d89",
"name": "sharpening",
"displayName": "Sharpening Filter",
"type": "PROCESSING",
},
{
"id": "c4cb8913-2ef3-4e82-a426-65ea8faacd9a",
"name": "esa-s2-l2a-gtiff-visual",
"displayName": "Sentinel-2 L2A Visual (GeoTIFF)",
"type": "DATA",
},
],
"error": {},
}

JSON_WORKFLOW_ESTIMATION = {
"data": {
"esa-s2-l2a-gtiff-visual:1": {
"blockConsumption": {
"credit": {"max": 0, "min": 0},
"resources": {"max": 0, "min": 0, "unit": "SQUARE_KM"},
},
"machineConsumption": {
"credit": {"max": 1, "min": 1},
"duration": {"max": 0, "min": 0},
},
},
"tiling:1": {
"blockConsumption": {
"credit": {"max": 0, "min": 0},
"resources": {
"max": 3.145728,
"min": 3.145728,
"unit": "MEGABYTE",
},
},
"machineConsumption": {
"credit": {"max": 9, "min": 2},
"duration": {"max": 428927, "min": 80930},
},
},
},
"error": {},
}

JSON_ASSET = {
"accountId": "69353acb-f942-423f-8f32-11d6d67caa77",
"createdAt": "2022-12-07T14:25:34.968Z",
Expand Down
84 changes: 0 additions & 84 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pandas
import pytest

from up42 import main
Expand All @@ -12,89 +11,6 @@ def setup_auth_mock(auth_mock):
yield


def test_get_blocks(requests_mock):
url_get_blocks = f"{constants.API_HOST}/blocks"
requests_mock.get(
url=url_get_blocks,
json={
"data": [
{"id": "789-2736-212", "name": "tiling"},
{"id": "789-2736-212", "name": "sharpening"},
],
"error": {},
},
)
blocks = main.get_blocks()
assert isinstance(blocks, dict)
assert "tiling" in list(blocks.keys())


def test_get_blocks_not_basic_dataframe(requests_mock):
url_get_blocks = f"{constants.API_HOST}/blocks"
json_get_blocks = {
"data": [
{"id": "789-2736-212", "name": "tiling"},
{"id": "789-2736-212", "name": "sharpening"},
],
"error": {},
}
requests_mock.get(url=url_get_blocks, json=json_get_blocks)

blocks_df = main.get_blocks(basic=False, as_dataframe=True)
assert isinstance(blocks_df, pandas.DataFrame)
assert "tiling" in blocks_df["name"].to_list()


def test_get_block_details(requests_mock):
block_id = "273612-13"
url_get_blocks_details = f"{constants.API_HOST}/blocks/{block_id}"
requests_mock.get(
url=url_get_blocks_details,
json={
"data": {"id": "273612-13", "name": "tiling", "createdAt": "123"},
"error": {},
},
)
details = main.get_block_details(block_id=block_id)
assert isinstance(details, dict)
assert details["id"] == block_id
assert "createdAt" in details


def test_get_block_coverage(requests_mock):
block_id = "273612-13"
url_get_blocks_coverage = f"{constants.API_HOST}/blocks/{block_id}/coverage"
requests_mock.get(
url=url_get_blocks_coverage,
json={
"data": {"url": "https://storage.googleapis.com/coverage-area-interstellar-prod/coverage.json"},
"error": {},
},
)
url_geojson_response = "https://storage.googleapis.com/coverage-area-interstellar-prod/coverage.json"
requests_mock.get(
url=url_geojson_response,
json={
"type": "FeatureCollection",
"name": "bundle6m",
"crs": {
"type": "name",
"properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"},
},
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {"type": "MultiPolygon", "coordinates": []},
}
],
},
)
coverage = main.get_block_coverage(block_id=block_id)
assert isinstance(coverage, dict)
assert "features" in coverage


def test_get_credits_balance():
balance = main.get_credits_balance()
assert isinstance(balance, dict)
Expand Down
14 changes: 1 addition & 13 deletions up42/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@
initialize_tasking,
initialize_webhook,
)
from up42.main import (
authenticate,
create_webhook,
get_block_coverage,
get_block_details,
get_blocks,
get_credits_balance,
get_webhook_events,
get_webhooks,
)
from up42.main import authenticate, create_webhook, get_credits_balance, get_webhook_events, get_webhooks
from up42.order import Order
from up42.storage import Storage
from up42.tasking import Tasking
Expand Down Expand Up @@ -70,9 +61,6 @@
get_webhooks,
create_webhook,
get_webhook_events,
get_blocks,
get_block_details,
get_block_coverage,
get_credits_balance,
]
]
95 changes: 1 addition & 94 deletions up42/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import logging
import pathlib
import warnings
from typing import Dict, List, Optional, Union

import pandas
import requests
from typing import List, Optional, Union

from up42 import auth as up42_auth
from up42 import host, utils, webhooks
Expand Down Expand Up @@ -110,96 +107,6 @@ def get_webhook_events() -> dict:
return webhooks.Webhooks(auth=get_auth_safely()).get_webhook_events()


@check_auth
def get_blocks(
block_type: Optional[str] = None,
basic: bool = True,
as_dataframe: bool = False,
) -> Union[List[Dict], dict, pandas.DataFrame]:
"""
Gets a list of all public blocks on the marketplace. Can not access custom blocks.
Args:
block_type: Optionally filters to "data" or "processing" blocks, default None.
basic: Optionally returns simple version {block_id : block_name}
as_dataframe: Returns a dataframe instead of JSON (default).
Returns:
A list of the public blocks and their metadata. Optional a simpler version
dict.
"""
if block_type:
block_type = block_type.lower()
url = host.endpoint("/blocks")
response_json = get_auth_safely().request(request_type="GET", url=url)
public_blocks_json = response_json["data"]

if block_type == "data":
logger.info("Getting only data blocks.")
blocks_json = [block for block in public_blocks_json if block["type"] == "DATA"]
elif block_type == "processing":
logger.info("Getting only processing blocks.")
blocks_json = [block for block in public_blocks_json if block["type"] == "PROCESSING"]
else:
blocks_json = public_blocks_json

if basic:
logger.info("Getting blocks name and id, use basic=False for all block details.")
blocks_basic = {block["name"]: block["id"] for block in blocks_json}
if as_dataframe:
return pandas.DataFrame.from_dict(blocks_basic, orient="index")
else:
return blocks_basic

else:
if as_dataframe:
return pandas.DataFrame(blocks_json)
else:
return blocks_json


@check_auth
def get_block_details(block_id: str, as_dataframe: bool = False) -> Union[dict, pandas.DataFrame]:
"""
Gets the detailed information about a specific public block from
the server, includes all manifest.json and marketplace.json contents.
Can not access custom blocks.
Args:
block_id: The block id.
as_dataframe: Returns a dataframe instead of JSON (default).
Returns:
A dict of the block details metadata for the specific block.
"""
url = host.endpoint(f"/blocks/{block_id}") # public blocks
response_json = get_auth_safely().request(request_type="GET", url=url)
details_json = response_json["data"]

if as_dataframe:
return pandas.DataFrame.from_dict(details_json, orient="index").transpose()
else:
return details_json


@check_auth
def get_block_coverage(block_id: str) -> dict:
"""
Gets the spatial coverage of a data/processing block as
url or GeoJson Feature Collection.
Args:
block_id: The block id.
Returns:
A dict of the spatial coverage for the specific block.
"""
url = host.endpoint(f"/blocks/{block_id}/coverage")
response_json = get_auth_safely().request(request_type="GET", url=url)
details_json = response_json["data"]
return requests.get(details_json["url"], timeout=utils.TIMEOUT).json()


@check_auth
def get_credits_balance() -> dict:
"""
Expand Down

0 comments on commit d64636b

Please sign in to comment.