pysepal.planetapi.planet_model.PlanetModel#

class pysepal.planetapi.planet_model.PlanetModel(*args, **kwargs)[source]#

Planet model helper to connect planet API client and perform requests.

It can be instantiated whether itself or linked with a PlanetView input helper. All the methods are aimed to be used without the need of a view.

Parameters:

credentials (str | List[str]) – planet API key or tuple of username and password of planet explorer.

Attributes

SUBS_URL

The url of the planet API subscription

active

Value to determine if at least one subscription has the active true state

authenticated

Value to determine if the credentials are valid and authentication was successful

session

planet session.

subscriptions

All the dictionary info from the available subscriptions

Methods

__init__

Planet model helper to connect planet API client and perform requests.

get_items

Request imagery items from the planet API for the requested dates.

get_mosaics

Get all the mosaics available in a client without pagination limitations.

get_quad

Get a quad response for a specific mosaic and quad.

get_subscriptions

Load the user subscriptions.

init_session

Initialize planet client with api key or credentials.

search_status

Get the status of a specific subscription.

PlanetModel.__init__(credentials='')[source]#

Planet model helper to connect planet API client and perform requests.

It can be instantiated whether itself or linked with a PlanetView input helper. All the methods are aimed to be used without the need of a view.

Parameters:

credentials (str | List[str]) – planet API key or tuple of username and password of planet explorer.

Return type:

None

PlanetModel.get_items(aoi, start, end, cloud_cover, limit=0)[source]#

Request imagery items from the planet API for the requested dates.

Parameters:
  • aoi (dict) – geojson clipping geometry

  • start (str | datetime) – the start of the request (YYYY-mm-dd))

  • end (str | datetime) – the end of the request (YYYY-mm-dd))

  • cloud_cover (float) – maximum cloud coverage.

  • limit (int) – number of items to constrain the search. Defaults to 0 to use all of them.

Returns:

items found using the search query

Return type:

list

PlanetModel.get_mosaics()[source]#

Get all the mosaics available in a client without pagination limitations.

Returns:

The mosaics contained in the API request.

Return type:

dict

Note

The output format is the following:

{
    "_links": {
        "_self": "<mosaic_url>",
        "quads": "<quad_url>",
        "tiles": "<xyz_tiles_url>"
    },
    "bbox": ["<4_corners_coordinates>"],
    "coordinate_system": "<projection_system>",
    "datatype": "uint16",
    "first_acquired": "<date_of_aquisition>",
    "grid": {
        "quad_size": 4096,
        "resolution": 4.77731426716
    },
    "id": "<mposaic_hashed_id>",
    "interval": "<acquisition_interval>",
    "item_types": ["<types_of_imagery"],
    "last_acquired": "<last_image_timestamp>",
    "level": "<max_zoom_level>",
    "name": "<mosaic_name>",
    "product_type": "timelapse",
    "quad_download": true
}
PlanetModel.get_quad(mosaic, quad_id)[source]#

Get a quad response for a specific mosaic and quad.

Parameters:
  • mosaic (dict) – A dict representing a mosaic in the format of list_mosaic

  • quad_id (str) – A quad id (typically <xcoord>-<ycoord>)

Returns:

The quad information as a dict.

Return type:

dict

Note

The output format is the following:

{
    "_links": {
        "_self": "<quad_url>",
        "download": "<download_url>",
        "items": "<items_url>",
        "thumbnail": "<thumbnail_url>"
    },
    "bbox": ["<corner_coordinates>"],
    "id": "<quad_id>",
    "percent_covered": 100
}
PlanetModel.get_subscriptions()[source]#

Load the user subscriptions.

Returns:

the dictionary of user subscription or empty list if nothing found

Return type:

dict

PlanetModel.init_session(credentials, write_secrets=False)[source]#

Initialize planet client with api key or credentials. It will handle errors.

Parameters:
  • credentials (str | List[str]) – planet API key, username and password pair or a secrets planet.json file.

  • write_secrets (bool) – either to write the credentials in the secret file or not. Defaults to True.

Return type:

None

Deprecated since version 3.0: credentials member is deprecated, use self.auth._key instead

static PlanetModel.search_status(d)[source]#

Get the status of a specific subscription.

Parameters:

d (dict) – dictionary of subscription object

Returns:

status) pairs

Return type:

the (sub.name