Skip to main content

The EASIER Data Initiative's Python Client

Features

  • Simple CID Data Retrieval
  • CID CSV To Dataframe Object
  • Querying EASIER STAC API by Bounding Box
    • Single Band Retrieval
    • Multi Band Retrieval

Installation

The client can be installed through pip

$ pip install ipfs-stac

Language Support

The client currently supports Python versions 3+

Usage

Create a client object

from ipfs_stac import client

# Create a new client object without a local node (uses remote gateways)
easier = client.Web3(stac_endpoint="<my_stac_server>/api/v1/pgstac/")

# If you want to use your local IPFS node (preferred), specify the endpoint in the local_gateway argument
easier = client.Web3(local_gateway="127.0.0.1", stac_endpoint="<my_stac_server>/api/v1/pgstac/")

Fetch a CID from IPFS

# Simple hello world example
data = easier.getFromCID("QmZ4tDuvesekSs4qM5ZBKpXiZGun7S2CYtEZRB3DYXkjGx")
print(data)

"""
hello worlds
"""

Get CID CSV Data to Pandas Dataframe

df = easier.getCSVDataframeFromCID("bafybeifw6kcodgxnamtuvhkxgaf4ep2rwscjae3gnzxb3zj5c6zyea2nri")
print(f"Data frame length: {len(df)}")

"""
Data frame length: 3510
"""

Query STAC API By Bounding Box

easier = client.Web3(local_gateway="", stac="<YOUR STAC ENDPOINT GOES HERE>")
"""
Retrieve all items from STAC catalog that are in bounding box with searchSTACByBox method (2 arguments)
1. Coordinates of bounding box
2. Name(s) of STAC collections)
"""
# Use any collection name you want. This is just an example
items = easier.searchSTACByBox([-76.964657, 38.978967, -76.928008, 39.002783], "landsat-c2l1") 

"""
The searchSTACByBoxIndex by method takes 3 arguments
1. Coordinates for the bounding box
2. Name of the STAC collection to query
3. Index of the item you want to retrieve
"""
item = easier.searchSTACByBoxIndex([-76.964657, 38.978967, -76.928008, 39.002783], "landsat-c2l1", 0)
# In this example, 'nir08' is the name of the band (asset) we want to retrieve from a landsat item
band = easier.getAssetFromItem(item, 'nir08')

# Optionally, you can fetch multiple assets by the getAssetsFromItem Method
bands = easier.getAssetsFromItem(item, ["blue", "red"]) # Returns array of assets

The asset object

# This snippet extends the previous under "Query STAC API By Bounding Box"

# The asset object, when printed, will return the CID
print(band) # QmNddx9BvBsQMXgwp6a83D2wiLrmovgCpRKVYKSJoWNNbx

# The asset content (bytes) can be found in asset.data. If this is None, you can call the fetch method to retrieve the data.
band.fetch()
print(band.data) # b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x...

# Alternatively, you can also transform the asset data in different formats such as a numpy array
band_np = band.to_np_ndarray()
print(band_np) # [[0. 0. 0. ... 0. 0. 0.]
               #  [0. 0. 0. ... 0. 0. 0.]
               #  [0. 0. 0. ... 0. 0. 0.]
               #  ...
               #  [0. 0. 0. ... 0. 0. 0.]
               #  [0. 0. 0. ... 0. 0. 0.]
               #  [0. 0. 0. ... 0. 0. 0.]]

Attributions

This project was made possible by the following

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipfs_stac-0.1.12.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipfs_stac-0.1.12-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file ipfs_stac-0.1.12.tar.gz.

File metadata

  • Download URL: ipfs_stac-0.1.12.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ipfs_stac-0.1.12.tar.gz
Algorithm Hash digest
SHA256 b676aa8cbe9834660549127d668b1451ca43aea70017b9ac031a38dc1d50664f
MD5 2f9a86f065c59417539ea4f5113dbb62
BLAKE2b-256 e33f8c0fbe2461a1b3a66a58f2bc42847e91e04ac4c1298425dd9125edb167fc

See more details on using hashes here.

File details

Details for the file ipfs_stac-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: ipfs_stac-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ipfs_stac-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 a665590dba1c0fb8448d37fca0b5c47ddacabaf6fa2642d092e17a94342faf58
MD5 a2cde2cf3c9aad3f50475ed5459d8fa7
BLAKE2b-256 82c706256f3a351203cff14968c3de13c9003b71c96cc3fe1d2abaa1edf02c32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page