Skip to content

Tutorial: reading and writing ODP data for my own area

Linda Angulo Lopez, 29 November 2026. ODP Academy, Working with Ocean Data on ODP, Module 3: Code, lesson Pulling your first data (Python).

The course notebook works with Tanzania and Unguja. This tutorial takes the same steps to my own area, the Wild Coast of the Eastern Cape, South Africa, and to my Lab 2 place, the Port St Johns canyons. It ends by writing my Module 2 layers back to ODP as one table.

You need a Small ODP Workspace with odp-sdk installed. If you have not opened one yet, start with Tutorial: from an ODP Workspace to QGIS. The course notebook, WIO_Code_ReadWrite_Python.ipynb, is under Downloads on the lesson page.

Status, 29 November 2026

The code below follows the course notebook and the ODP SDK documentation. Once my Workspace had odp-sdk, the write-back in step 5 ran into my practice dataset, Group 21 - Linda - practice: the screenshot is at the end of step 5.

The rule: let ODP make the data small

Two computers work together. ODP keeps the big tables and can filter them, pick columns and count. The Workspace gets only the result and makes the maps, sums and files. The Allen Coral Atlas has over 40 million rows: nobody should download it to look at one coast.

So every step below asks ODP for as little as possible: (i) the size and the columns first, (ii) only the rows and columns needed, (iii) totals instead of rows when totals are enough.

1. Connect

In a Workspace you are already signed in, so the client needs no key.

from odp.client import Client

cli = Client()

On your own computer, pip install odp-sdk and set the key as an environment variable (export ODP_API_KEY=...), never in the notebook.

2. Look before you load

Each dataset has a UUID, on its page in the ODP Catalog. Two calls tell me how big a table is and what is in it, without downloading a row:

mpas = cli.dataset("a608f54b-75c7-4df9-a3a8-cedbfa391873").table   # ProtectedSeas

mpas.stats().num_rows     # how many rows
mpas.schema().names       # which columns

3. Take only what I need

A select() takes a filter (which rows) and a list of columns. ODP does the search and sends back the result.

South Africa's protected areas, three columns:

south_africa = mpas.select(
    filter="country == 'South Africa'",
    columns=["site_name", "designation", "geometry"],
).all().dataframe()

The country is written as ProtectedSeas writes it, 'South Africa', with the space and the capitals.

A filter can also be a place. My Lab 2 place, written as text: its corners as longitude latitude, going round, with the first corner again at the end.

my_area = "POLYGON((29.4 -31.72, 29.55 -31.6, 30.06 -31.6, 30.06 -32.1, 29.48 -32.1, 29.4 -31.72))"

my_protected = mpas.select(
    filter=f"geometry intersect '{my_area}'",
    columns=["site_name", "designation", "geometry"],
).all().dataframe()

The same filter on the UNEP-WCMC coral reefs (b6d0b072-519a-4e25-82a4-7c7f6a575161) should return few shapes or none: the Wild Coast lies south of the reef-building corals. Here the protected areas and the canyons are the point, not the reefs.

ODP can write the filter for you. On a dataset's page in the Catalog, click Explore table, filter a column, click Apply filters, then Show Code Examples, and copy the code. It returns the first rows; add .all().dataframe() for all of them.

4. Let ODP do the counting

When I only need totals, I do not need the rows. aggregate() counts on ODP and sends back one number per group. The protected areas per country, for the course's countries and South Africa:

counts = mpas.aggregate(
    group_by="country",
    filter=("country == 'Tanzania' OR country == 'Kenya' OR country == 'Mozambique' "
            "OR country == 'Madagascar' OR country == 'Seychelles' OR country == 'South Africa'"),
    aggr={"site_id": "count"},
)

counts["site_id"].sort_values(ascending=False)

Count ProtectedSeas zones with care: one MPA can be split into several zones (on the Wild Coast, Pondoland appears as the MPA plus four zones, inshore and offshore, controlled and restricted: 23 shapes for 15 names), so the count is of zones, not of protected areas as a law names them.

5. Write back: my Wild Coast layers as one table

The course writes the Tanzania result into a practice dataset. I write my own area instead: the five layers that my Module 2 dataset, Wild Coast seafloor and protected areas (Group 21 - Linda), describes.

Practice first, or straight to the real dataset? The course's insert cell adds the rows again each time it runs, which is fine in a practice dataset and not in a real one. I made a practice dataset too, Group 21 - Linda - practice, to test on. In the version for the real dataset, the rows are added only when the table is empty.

(i) Make the table, once. One column says which layer each row comes from, so the table can be filtered by layer in Map Explorer. Each column has a description, and one is marked as the shapes.

import pyarrow as pa

my_ds = cli.dataset("363b2cc8-dcac-4ef8-aed0-44464d365eee")

my_ds.table.create(pa.schema([
    pa.field("layer", pa.string(), metadata={"description": "my_place, protected_areas, seamounts, canyons or shelf"}),
    pa.field("name", pa.string(), metadata={"description": "Name of the place, protected area or feature"}),
    pa.field("detail", pa.string(), metadata={"description": "Designation (protected areas) or depth and size (seafloor features)"}),
    pa.field("note", pa.string(), metadata={"description": "Why I chose it (my place) or the source of the layer"}),
    pa.field("geometry", pa.string(), metadata={"description": "Shape (WGS84)", "isGeometry": "1", "index": "1"}),
]))

(ii) Build the rows. The five layers are the derived files from Module 2, in this repository under outputs/, read straight from GitHub. Each becomes rows with the same five columns, and the shapes become text (WKT) that ODP can read.

import geopandas as gpd
import pandas as pd

RAW = "https://raw.githubusercontent.com/lindangulopez/odp-academy-2026/main/outputs/"
GSFM = "Seafloor Geomorphic Features Map, GRID-Arendal (CC BY 4.0); Harris et al. 2014, Marine Geology 352: 4-24"
PS = "ProtectedSeas Navigator V2 (CC BY 4.0), via ODP"

place = gpd.read_file(RAW + "lab2/my_place.geojson")
pas = gpd.read_file(RAW + "wild_coast_protected_areas.geojson")
seamounts = gpd.read_file(RAW + "qgis/wild_coast_seamounts.geojson")
canyons = gpd.read_file(RAW + "qgis/wild_coast_canyons.geojson")
shelf = gpd.read_file(RAW + "qgis/wild_coast_shelf.geojson")

def part(layer, gdf, name, detail, note):
    return pd.DataFrame({"layer": layer, "name": name, "detail": detail, "note": note,
                         "geometry": gdf.to_crs("EPSG:4326").geometry.to_wkt()})

rows = pd.concat([
    part("my_place", place, place["name"], "Lab 2, ODP Academy 2026", place["why"]),
    part("protected_areas", pas, pas["site_name"], pas["designation"], PS),
    part("seamounts", seamounts, "Seamount " + seamounts["SeamountID"],
         "peak depth " + seamounts["Peak_Depth"].astype(str) + " m, height " + seamounts["Height"].astype(str) + " m", GSFM),
    part("canyons", canyons, "Canyon " + canyons["Canyon_ID"],
         canyons["type"] + ", mean depth " + canyons["Mean_Depth"].round().astype(int).astype(str) + " m", GSFM),
    part("shelf", shelf, "Continental shelf", "clipped to the Wild Coast", GSFM),
], ignore_index=True)

Tested on my computer, this gives 50 rows:

layer rows name detail
my_place 1 Port St Johns canyons Lab 2, ODP Academy 2026
protected_areas 23 e.g. Amathole MPA, Kei Offshore Controlled Zone Marine Protected Area
seamounts 1 Seamount S1403 peak depth 218 m, height 3540 m
canyons 24 e.g. Canyon C1702 blind, mean depth 2585 m
shelf 1 Continental shelf clipped to the Wild Coast

One trap: the GSFM shelf carries an area_km2 of about 14 million km², the global shelf, not the Wild Coast piece. I left it out.

(iii) Add the rows, only into an empty table.

if my_ds.table.stats().num_rows == 0:
    with my_ds.table as tx:
        tx.insert(rows)

my_ds.table.stats().num_rows

(iv) Check it. In My Data the table and its column descriptions show on the dataset page. In Map Explorer, switch on Search in private data, find the dataset and add it to the map.

The result in my practice dataset, 29 November 2026, in the table explorer: the five columns, the rows by layer, and the protected areas and canyons on the map.

ODP table explorer: my Wild Coast table in the practice dataset, with columns layer, name, detail, note and geometry, and the protected areas and canyons on the map Data: ProtectedSeas Navigator V2 (CC BY 4.0); Seafloor Geomorphic Features Map, GRID-Arendal (CC BY 4.0), Harris et al. 2014; via the Ocean Data Platform.

When it goes wrong

What you see Why What to do
No module named 'odp' The server is not Small, or the SDK is missing Restart as Small; ask in Discussions if it persists. Do not pip install odp-sdk in a Workspace
Table already exists The create cell ran twice Fine: the table is there, go on
The row count doubles The course's insert cell ran twice Use the empty-table check above, or a practice dataset
A filter returns nothing A spelling or case difference, e.g. 'South africa' Copy the value from Explore table
Coordinates in the wrong place Latitude written before longitude Write longitude latitude, south as negative

What this shows

The same four calls, stats, schema, select and aggregate, work on any coast; only the filter changes. Writing back is where care is needed: a table on ODP is shared and lasts, and a cell that adds rows on every run belongs in a practice dataset, not in a dataset others will cite.

What would you want ODP to count for your own place before you download a single row?