Manipulating objects#

This capter aims to guide you in the all the objects you can find in pygeodes.

Working with STAC objects#

With STAC objects (pygeodes.utils.stac.Item and pygeodes.utils.stac.Collection), you can get the info using method find associated to the name of a column.

Working with dataframes#

A way to work in pygeodes is to work with geopandas.GeoDataFrame, which can get from an items research or from a list of STAC objects.

From STAC objects to dataframes#

To create you first dataframe from STAC objects, you can use pygeodes.utils.formatting.format_collections() and pygeodes.utils.formatting.format_items(). For example from a list of pygeodes.utils.stac.Item, if I want to create a dataframe and add the column spaceborne:cloudCover :

from pygeodes.utils.formatting import format_items
items = [item1,item2,...]

dataframe = format_items(items,columns_to_add={"spaceborne:cloudCover"})

But if I put a dataframe instead of a list of items in format_items, the columns will be added to the ones already in the dataframe.

Hint

To explore the available columns you can build dataframes with, use method list_available_keys on an Item or a Collection object.

Filtering in the dataframes#

After having added the columns you want, you can filter your data using the dataframes, let’s say we want a cloud cover inferior to 10%.

dataframe = format_items(items,columns_to_add={"spaceborne:cloudCover"})
filtered = dataframe[dataframe["spaceborne:cloudCover"] <= 10]

See also

To explore dataframe filtering options, see pandas docs on the subject.

From dataframes to STAC objects#

Once we filtered our dataframe of items, we could want to download them, so we need to get back our items objects.

items = filtered['item'].values # with 'filtered' being any items dataframe
for item in items:
    item.download_archive()

Serialization of dataframes#

You could want to serialize a dataframe to work with it later, it’s possible using pygeodes.utils.formatting.export_dataframe()

from pygeodes.utils.formatting import export_dataframe

export_dataframe(dataframe,"df.json")

and you can load it later using pygeodes.utils.formatting.load_dataframe() :

from pygeodes.utils.formatting import export_dataframe

dataframe = load_dataframe("df.json")

Plotting and exploring data using dataframes#

You can see where your data is located on a map using dataframe.explore :

dataframe.explore()

Note

The default EPSG used to plot is 4326, but you can change it, see geopandas docs.

For more examples on using dataframes to explore your data and plot, see Using dataframes to explore data and make plots.