The Chloris Platform

The Chloris Platform is a cloud-based SaaS platform which empowers decision-makers to gain access to reliable, cost-efficient, and repeatable measurements of carbon stocks stored in woody vegetation and its changes at the global scale. It gives access to our premium on-demand data product of annual above-ground carbon stock and change, and forest cover and change.

The site you are currently viewing documents the premium on-demand dataset, both for users of the web interface and for developers who wish to use the API in their own applications.

For more information, see the Chloris website or try it out now at app.chloris.earth.

How it works

Here is how our premium on-demand product works:

  1. You provide a polygon of interest (e.g. a forest concession, a protected area, or a country) and a time period of interest (e.g. 2010-2020).
  2. Optionally, you provide a control polygon (e.g. a neighboring area).
  3. We use our proprietary machine learning algorithms to analyze satellite imagery from several sources and produce annual maps of forest carbon stock, gains, and losses for your area of interest. This is available from 2000 (23+ years) at 30m resolution or from 2017 at 10m resolution (6+ years).
  4. We provide you with a report that includes maps of the results. The report for your site is available via API, and interactively at app.chloris.earth, where you can explore the results, download summary data, or print a PDF report. If your licensing includes it, you can also download the geospatial data outputs.

User guide

You can view the Chloris Platform's web interface user guide here. Contents include:

API documentation

The rest of this documentation is for the Chloris Platform API. This is the API that powers the Chloris Platform web interface, and is available for you to use in your own applications. For a detailed walk-through, see Getting Started. Alternatively, you can view the API reference. Keep up with all API changes by checking the Changelog.

Chloris Platform User Guide

The Chloris Platform is a cloud-based SaaS platform which empowers decision-makers to gain access to reliable, cost-efficient, and repeatable measurements of carbon stocks stored in woody vegetation and its changes at the global scale. It gives access to two datasets: a) a new on-demand operational-scale data product of biomass stock, change and associated uncertainty, and b) a global freely available non-commercial coarser resolution biomass data product that Chloris released in early 2022 (also available through Microsoft’s Planetary Computer).

This guide explains the platform’s functionality, and walks through the process of uploading a site and the outcome of the analysis.

We officially support the latest versions of Chrome and Firefox. For other browsers, some features may not work as expected.

Creating an account

To access the Chloris data, you need to create an account. The global 5 km data is freely available for all users. For premium users, you will receive an invitation email with specific instructions to access your organization’s high resolution biomass data.

sign up

If you have any problems related to your account, please contact us at help@chloris.earth.

Organization overview page

If your account already has sites uploaded, you will see them on your organization’s overview page. You can choose sites directly on the map at the top of the page, or from the list below. organization overview If you want more information about many sites, the "table" button will take you to a table view where you can sort, filter, and aggregate your sites.

Uploading a site

If you have a premium account and have manager or owner’s permissions you can request operational-scale biomass stock and change for your chosen area of interest. To do so, you can either upload a vector file containing a polygon with boundaries of your site of choice, or draw your site’s boundaries using our map tools. If you have not previously uploaded any sites, the options for uploading a new site are the first thing you will see after clicking on your organization. Otherwise, they are on the right side of your organization's home page.

new site button location

To upload a site, click the "New site" button, which will take you to the site upload page.

basic info page

Fill in the basic information about your site. You can specify the range of years you would like to have data available. Add tags about your site for easier navigation, sorting and summary analytics. Later, you can customize your tags and toggle the summary analytics option in the Manage Organization tab in the top right of the screen. When you are ready, click Next.

Uploading a file with your site’s boundaries

Upload a file containing the polygon with boundaries of your site. A site can be uploaded with the majority of vector-based spatial data formats, including ESRI shapefile, GeoJSON files, .gpkg, .kml, and more. Our recommended formats are shapefiles and GeoJSON. If you are uploading an ESRI shapefile, please select all the files (including files with extensions .shp, .shx and .dbf) or a zipped shapefile. After a successful upload, you will see your site on a map on the right-hand side. Please make sure the location of your site is correct and click Next.

If your site is not in the correct location, please try re-projecting the file to EPSG 4326 (WGS84) and uploading again. If you are still having problems, please contact us at help@chloris.earth.

Drawing your site’s boundaries by hand

If you don’t have the file containing your site’s boundaries, you can draw it yourself. First, zoom in to where your site is located and click the Polygon tool. Click on the map to draw a polygon, each click adds one vertex. Double click closes the polygon. If you’re unhappy with the shape you just drew you can change it by clicking and dragging the vertices or in the middle of an edge to add a new vertex. Once you’re satisfied with the shape, click Save on top of the map. You can add new polygons, or delete ones you don't want anymore. Once you're happy with the shape, click "Save", confirm the saved shape matches what you drew, then click "Next".

boundary drawing example

Uploading a control area

An (optional) control area is a secondary site to which your main area of interest will be compared. Adding a control area enables you to observe how the carbon dynamics within your project differ to its surroundings or an area of your choice. You can choose to upload another file with the control area, draw it yourself using our map tools, or auto-generate a buffered area around your site. The upload and drawing process is similar to uploading a site. If you would like to auto generate a buffered control area, click the Auto Generate button.

control page example

Site review

Once you upload your site and a control area, you get a chance to review your project and go back and edit if necessary. The summary at the bottom of the page tells you the total site area, which will be counted toward your account limit. When ready, click Submit.

Confirmation

Congratulations! You have just uploaded your first site. The results of the analysis should be available soon (as little as a few hours, but more often several business days). You can close the page and your new site will appear in your list of sites. It will show ‘Analysis in progress’ until the data is ready, and our team has reviewed it for quality assurance purposes. You will get an email notification when it is ready for you to view.

Results report

Clicking on your site from your organizations home page or the table view will take you to the report page for that site. The report page is divided into several subpages, starting with site summary statistics. You can switch between pages by clicking the arrows at the top of the page.

site summary example

The first page gives a summary of the site’s carbon dynamics and control area, if provided. Here you can find the information about the biomass stock within your site at the beginning and the end of the time period, overall net, gains and losses.

Graphs

The second page displays carbon dynamics plots. As of 2023, the standard graphs show annual stock, annual change, the distribution of stock values, forest cover, forest cover change, and an annual loss allocation which differentiates losses due to deforestation, degradation, and other changes.

site graph example

Each graph has a title in the top left, some options in the top right, and a legend at the bottom. Hovering your cursor over the "i" icon next to the title provides details of what the graph is showing. Clicking on the legend elements switches them on and off. Hovering your cursor the graph will reveal the exact values for each data point. Data shown in the plots is also available to download in tabular form by clicking the download button to the top right of each plot to get a .csv file, or by click the name of your site in the top left, then clicking "downloads".

Exploring the maps

The final page of the site report is the map view. The Chloris platform enables you to explore the location of stock density, change, and forest cover within your site.

site map example

You can change the background map (or "basemap") by clicking on the last button in the top-left of the map. By clicking on the legend in the top-right you can turn the data layer on and off. Hovering your mouse over the legend and scrolling allows you to change the opacity of the data layer. For annual datasets, the time slider at the bottom enables you to explore the data for each year of the time period. The "home" button takes you back to your site if you get lost while exploring. You can change layers either by clicking the buttons in the top left of the map or using the "layers" menu in the bottom left. Clicking the play button next to the year slider will animate the map through the years (note that requires a fast internet connection).

If you find a point of interest that you would like to save for later or share with someone else, you can copy the permalink from your browser's url bar. This will take you back to the same view when you paste it into your browser.

The format of the url when viewing the map page is .../map/{layer}/{longitude}/{latitude}/{zoom}/{year} where the layer is one of stock, change, or forest, the longitude and latitude are the coordinates of the center of the map, the zoom is the zoom level of the map (between 0 and 20), and the year is the year of the data shown on the map.

Exploring forest cover and change

The Chloris platform also enables you to explore forest cover and change within your site in both charts and maps. Forest cover classifies the land into two categories (forest, and non-forest) based on a dynamic threshold of biomass. Non-forest therefore includes impermanent water.

Other site tools

Several additional tools are available when viewing a site report by clicking the name of your site in the top left of the page.

site tools menu

You can export results as a printable PDF report by clicking the name of your site in the top left, then clicking "print".

print page example

Site Downloads

You can download the data shown in the graphs and maps by clicking the name of your site in the top left, then clicking "downloads". Tabular products are available for all sites for all customers. Geospatial products are subject to additional licensing terms and therefore may not be available for all the sites you have access to. If you want to download data for many sites, see bulk downloading.

downloads page example

Comparing sites

You can compare your site to other sites in your organization by clicking the name of your site in the top left, then clicking "compare". This will open a search dialog for you to select a second site to compare to.

Below are some examples of what it looks like when you compare two sites. Note that the first site always appears on the left, and the second on the right.

site comparison example

Units

You can change the units you would like to explore the data with by opening your preference in the top right of the page. If you have manager or owner’s permissions, you can also choose the defaults units for anyone in your organization. Simply go to your "Organization Options" panel in the top right of the page to manage unit options.

unit options menu

On-the-fly site aggregation

In some cases, you might be interested in summary values for your sites - you can view them in the table by selecting multiple sites while holding the Ctrl button (⌘ on Mac) on your keyboard or by holding shift to select a range of sites. The summary values appear at the top, and clicking "view report" will take you to a report page with more details. This can be slow if you are trying to aggregate more than 50 sites, so as an alternative you may tag all the sites you are interested in using a single tag (such as "project1") and then view the summary values for that tag.

aggregation example

Bulk downloading

If you want to download data for many sites at once, you can use the bulk download tool. To access it, click the "Downloads" button on the right of the organization home page.

downloads page example

Select one or more sites from the first list, optionally change the selected products and years of interest, then click "Begin download". Tabular products are available for all sites for all customers. Geospatial products are subject to additional licensing terms and therefore may not be available for all the sites you have access to. For best results, we recommend using the Chrome browser when using this feature.

While your download is processing, you can continue to use the platform, but navigating away or closing your browser will interrupt the download.

If you only want to download data for a single site, or to see exactly what data is available before downloading, you can do so from the site report page. See site downloads for more information.

Managing users

Within your organization, there are different user access permissions:

  • Viewers can access operational-scale data that has already been processed and explore our interactive graphs, maps, and more.
  • Managers can submit new sites, manage organization preferences, and invite others to view the organization.
  • The Owner can do everything above and promote viewers to manager, they are also included on all email notifications.

If you are an owner or manager and would like to change your users' permissions, you can do so in the "Organization Options" panel, which you can get to using the icon in the top right of the screen. Non-managers/owners cannot see this panel.

Conclusion

We hope this guide helped you to navigate our application, if you have any questions please feel free to reach out and email us at help@chloris.earth.

Getting started with the Chloris Platform API

The Chloris Platform API is a RESTful API that allows you to interact with the Chloris Platform. It is designed to be used by both humans and machines, but if you are a human you may find it easier to use the Chloris Platform web interface. Note that the API is only available for use with premium organizations, please contact us if you are interested in using the API.

Unless otherwise stated, all requests and responses are in JSON format.

Examples in this documentation show how to interact with the API using both the chloris-app-sdk in Python (recommended) and using the REST API directly in Javascript (using node-fetch).

Authentication

The Chloris Platform API uses OAuth 2.0 provided by AWS Cognito for authentication. This means that you will need to register an account with the Chloris Platform and then use your Chloris Platform username (email) and password to obtain your API credentials. We provide both a refresh_token (valid for up to 3 years) and an id_token (valid for 3 hours). The refresh_token can then be used to obtain an id_token (via the Oauth2.0 client credentials grant), which can then be used to authenticate all requests to the API. It is best practice to store your credentials securely and not expose them to the public. If your credentials are compromised, you can change your password to revoke them.

Obtaining your credentials

You can view your credentials at any time by logging into the Chloris Platform, opening your profile settings, and clicking "api credentials" at the bottom of the panel.

api credentials

You can use the id_token directly for authentication, but it is recommended to use the refresh_token to obtain a new id_token when the old one expires. The refresh_token is also useful for long-running scripts or services.

Getting started with chloris-app-sdk (Python)

To get started, you'll need to install the chloris-app-sdk package:

pip install chloris_app_sdk

Then instantiate the client with your credentials. To confirm it is working you can call the list_active_sites function to list the sites in your organization.

from chloris_app_sdk import ChlorisAppClient
# create the client
client = ChlorisAppClient(
    organization_id="your-organization-id",
    refresh_token="your-refresh-token", # env: CHLORIS_REFRESH_TOKEN
    # or
    # id_token="your-id-token" # env: CHLORIS_ID_TOKEN
)

reporting_units = client.list_active_sites()

The result is a list of python dicts like this:

[
  {
    organizationId: "your-organization-id",
    reportingUnitId: "123e4567-e89b-12d3-a456-426614174000",
    label: "Site 1",
    description: "Site 1 description",
    createdAt: "2021-01-01T00:00:00Z",
    updatedAt: "2021-01-01T00:00:00Z",
    tags: ["ARR"],
    // stats...
  },
  // other sites...
]

That's it! If you'd like to submit sites to the Chloris Platform, see Submitting sites.

See the Python API reference for the full list of functions and classes available in the SDK.

Getting started with the REST API (JavaScript)

Below are a series of examples that will walk you through the process of listing the sites in your organization. You can run these examples in a node.js environment by creating a file with the .mjs extension and running it with node <filename>.mjs. See the API Reference for more details on the API endpoints.

Listing sites

Now that you have authenticated successfully, you can interact with the API. We'll try this out by listing the sites in your organization.

However, first we need to mention something about the Chloris Platform data model: Your organization can contain multiple sites. Individual sites can be organized into collections. Collections are then aggregated versions of the sites they contain. For example, you might have a collection sites in a single project, or a collection for each region. You might even combine collections into collections. So, internally we treat sites and collections as the same thing, called "reporting units". Additionally, when you apply tags to a site, their aggregated results are also available as reporting units. So, in order to list sites, we'll actually be listing all reporting units.

To do this, we'll use the POST https://app.chloris.earth/api/reportingUnit/ endpoint which returns a list of sites in your organization.

// listReportingUnits.mjs

import fetch from "node-fetch";

const idToken = "your-id-token";
const organizationId = "your-organization-id";

async function listReportingUnits() {
  const url = "https://app.chloris.earth/api/reportingUnit/";

  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: "Bearer " + idToken,
    },
    body: JSON.stringify({
      organizationId: organizationId,
    }),
  });
  const json = await response.json();
  return json?.reportingUnits || [];
}

const reportingUnits = await listReportingUnits();

The response will look something like this (note we're using JSON5 for readability, but the response is actually normal JSON):

{
  reportingUnits: [
    {
      organizationId: "your-organization-id",
      reportingUnitId: "123e4567-e89b-12d3-a456-426614174000",
      label: "Site 1",
      description: "Site 1 description",
      createdAt: "2021-01-01T00:00:00Z",
      updatedAt: "2021-01-01T00:00:00Z",
      tags: ["ARR"],
      // stats...
    },
    {
      organizationId: "your-organization-id",
      reportingUnitId: "123e4567-e89b-12d3-a456-426614174001",
      label: "Site 2",
      description: "Site 2 description",
      createdAt: "2021-01-01T00:00:00Z",
      updatedAt: "2021-01-01T00:00:00Z",
      tags: ["ARR", "ProjectA"],
      // stats...
    },
    {
      organizationId: "your-organization-id",
      reportingUnitId: "ARR",
      branchId: "ARR",
      label: "Site 2",
      description: "Site 2 description",
      createdAt: "2021-01-01T00:00:00Z",
      updatedAt: "2021-01-01T00:00:00Z",
    },
  ],
  nextToken: "asdf123",
}

Now, this is fine if you only have a few reporting units, but at some point the results from this endpoint will be paginated. To get the next page of results, you can use the nextToken field from the response to make another request. To get all reporting units, you can use the listReportingUnits function like this:

/// ...

async function listReportingUnits() {
  const url = "https://app.chloris.earth/api/reportingUnit/";
  // this will be used to store the reporting units as they are retrieved
  let reportingUnits = [];
  // this will be used to store the nextToken after the first page of results
  let nextToken = {};
  while (true) {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: "Bearer " + idToken,
      },
      body: JSON.stringify({
        organizationId: organizationId,
        ...nextToken,
      }),
    });
    const json = await response.json();
    // add the reporting units from this page to the list
    reportingUnits = reportingUnits.concat(json?.reportingUnits || []);

    // if there is a nextToken, store it and repeat the loop, otherwise break out of the loop
    if (json?.nextToken) {
      nextToken = { nextToken: json.nextToken };
    } else {
      break;
    }
  }
  return reportingUnits;
}

const reportingUnits = await listReportingUnits();

As mentioned in the data model, reporting unit entries can be sites, collections, or tags. To filter for just active sites, we have to perform a couple additional steps after retrieving the list of reporting units.

/// ...

async function listReportingUnits() {
  // ...
  return reportingUnits;
}

function filterActiveSites(reportingUnits) {
  // Remove aggregated entries from collections and tags (which have the key `branchId`),
  // control sites (which have `hidden: true`), and sites with now > deletedAt
  const now = new Date().toISOString(); // e.g. 2021-01-01T00:00:00Z
  return reportingUnits.filter(
    (reportingUnit) =>
      !reportingUnit?.branchId &&
      !reportingUnit?.hidden &&
      (!reportingUnit?.deletedAt || reportingUnit.deletedAt < now),
  );
}

const reportingUnits = await listReportingUnits();
const activeSites = filterActiveSites(reportingUnits);

The Chloris Platform Data Model

The Chloris Platform data model is organized around a handful of key concepts:

  • Everything belongs to an organization
  • An organization can contain multiple sites
  • Individual sites are defined by geospatial (multi)polygon boundaries
  • Sites can be organized using one or more tags
  • Sites and aggregated tag summaries are both referred to as "reporting units"
  • A site may have a single "control reporting unit" for display purposes

Conceptual entity relationship map

Chloris Platform data model

Shown here are the things that make up the data model, and how they relate to each other. Each node represents an entity. Arrows indicate the direction of the relationship. For example, a site belongs to an organization. Solid lines indicate "materialized" elements which are queryable and can be returned in a response. Dashed lines indicate elements which exist conceptually, but require additional processing to materialize. For example, several sites can be tagged "ARR", but the tag is materialized by aggregating the results of all unique sites with the tag and storing the results as a new reporting unit entry with the branchId set to the tag name.

See also Output datasets.

The reporting unit

When requesting reporting units from the API, the reporting unit status and a few key summary statistics. This initial result is referred to the "reporting unit entry".

Each reporting unit may also have the following additional data files associated with it, each located under the dataPath attribute*:

  • The boundary file, which the reporting unit entry refers to by boundaryPath*
  • The stats file, which contains additional summary statistics, both for the entire period of interest, and annually. The stats file is always located at :dataPath/stats.json
  • The layers config file, which contains the configuration for the layers displayed in the Chloris Platform web interface. The layers config file is always located at :dataPath/layers.json. See Pre-computed webtiles.
  • The downloads index file, which contains a list of all the downloadable files associated with the reporting unit. The downloads index file is always located at :dataPath/downloads.json. See Geotiff raster file downloads.

* dataPath and boundaryPath may refer to s3://chloris-app-data/, which is a private bucket. Replace s3://chloris-app-data/ with https://app.chloris.earth/ to download the files.

Submitting sites

For submitting sites through the web interface, see the user guide. This page is for submitting sites via the API.

Using chloris-app-sdk (Python)

You can submit a site in the chloris-app-sdk by using the client.submit_site function. This function will upload the boundary, wait for it to be normalized, and then submit the site for processing.

Here is an example which will upload a new site from a geoJSON file:

from chloris_app_sdk import ChlorisAppClient

# create the client
client = ChlorisAppClient(
    organization_id="your-organization-id",
    refresh_token="your-refresh-token", # env: CHLORIS_REFRESH_TOKEN
    # or
    # id_token="your-id-token" # env: CHLORIS_ID_TOKEN
)

# submit the site
reporting_unit = client.submit_site(
    label="Site 1",
    description="Site 1 description",
    tags=["ARR"],
    boundary_path="path/to/boundary.geojson",
    # or boundary_path="https://example.com/path/to/boundary.geojson",

    # optional control site
    control_boundary_path="path/to/control.geojson",
    # or control_boundary_path="https://example.com/path/to/control.geojson",

    # optionally disable email notifications for this site, recommended if using webhooks
    # notify=False,
)

# the new reporting unit entry
print(reporting_unit)
# {
#   organizationId: "...",
#   reportingUnitId: "...",
#   createdAt: "...", # now, ISO 8601
#   updatedAt: "...", # now, ISO 8601
#   controlReportingUnitId: "..."
# }

If you are using webhooks, you will be notified when the site is ready. Otherwise, you can poll the API to check the status of the site:

import time

# ...

reporting_unit_id = reporting_unit["reportingUnitId"]

i = 0
while True:
    # get the reporting unit and check if it is ready
    reporting_unit = client.get_reporting_unit(reporting_unit_id)
    if reporting_unit.get("qualityControlledAt"):
        break
    # sites are ready in hours to days, so we recommend waiting an initial 15 minutes, then exponentially backing off. This is also why we recommend using webhooks.
    time.sleep((60 * 15) * (2 ** i))
    i += 1

Here is an example which submits a local shapefile:


from chloris_app_sdk import ChlorisAppClient

# create the client
client = ChlorisAppClient(
    organization_id="your-organization-id",
    refresh_token="your-refresh-token", # env: CHLORIS_REFRESH_TOKEN
    # or
    # id_token="your-id-token" # env: CHLORIS_ID_TOKEN
)

# submit the site
site = client.submit_site(
    label="Site 1",
    description="Site 1 description",
    tags=["ARR"],
    boundary_path="path/to/boundary.shp",
)

Using the REST API (JavaScript)

Submitting sites via the API is a two-step process. First, you must upload the boundary (and optionally a control boundary) for normalization. Then, you can submit the site using the normalized boundary(s).

Here is an example of submitting a site using the aws-sdk in JavaScript:

// submitSite.mjs
// 1. use the aws-sdk to get temporary sts credentials
// 2. upload the file to S3
// 3. request it be normalized
// 4. wait for the normalized file to be available,
// 5. submit the reporting unit to the API

// node-specific imports
import fetch from "node-fetch";
import fs from "fs";
import crypto from "crypto";
import { extname, resolve } from "path";

// aws-sdk imports
// install via `npm install @aws-sdk/client-cognito-identity @aws-sdk/credential-provider-cognito-identity @aws-sdk/client-s3 @aws-sdk/credential-provider-cognito-identity`
import { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity";
import {
  HeadObjectCommand,
  PutObjectCommand,
  S3Client,
} from "@aws-sdk/client-s3";
import {
  CognitoIdentityProviderClient,
  InitiateAuthCommand,
} from "@aws-sdk/client-cognito-identity-provider";
import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity";

let idToken;

idToken = "your-id-token";
// or
// const refreshToken = "your-refresh-token";

const organizationId = "your-organization-id";
const filePath = resolve("/path/to/local/file.geojson");
const controlFilePath = resolve("/path/to/local/control-file.geojson");

const fileExt = extname(filePath);

const uploadId = crypto.randomUUID();

// Get info about the AWS resources used by the Chloris API
const apiInfo = await (
  await fetch("https://app.chloris.earth/api/info", {
    method: "GET",
  })
).json();

// Create a CognitoIdentityClient
const cognitoClient = new CognitoIdentityClient({
  region: apiInfo.awsRegion,
  credentials: fromCognitoIdentityPool({
    identityPoolId: apiInfo.awsCognitoIdentityPoolId,
    logins: {
      [`cognito-idp.${apiInfo.awsRegion}.amazonaws.com/${apiInfo.awsUserPoolId}`]:
        idToken,
    },
  }),
});
// get temporary credentials
const credentials = await cognitoClient.config.credentials();

const identityId = credentials.identityId;

const uploadKey = `private/${identityId}/apiUploads/${uploadId}${fileExt}`;
const boundaryKey = `protected/${identityId}/uploads/${uploadId}.geojson`;
const boundaryPath = `s3://${apiInfo.awsUserFilesS3Bucket}/${boundaryKey}`;

// Create S3 client with Cognito credentials
const s3 = new S3Client({
  region: apiInfo.awsRegion,
  credentials: credentials,
});

// Upload the boundary
const s3Upload = new PutObjectCommand({
  Bucket: apiInfo.awsUserFilesS3Bucket,
  Key: uploadKey,
  Body: fs.createReadStream(filePath),
});
await s3.send(s3Upload);

// request the boundary be normalized
const boundaryResponse = await (
  await fetch("https://app.chloris.earth/api/boundary", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${idToken}`,
    },
    body: JSON.stringify({
      organizationId,
      uploadId,
      uploadPath: `s3://${apiInfo.awsUserFilesS3Bucket}/${uploadKey}`,
    }),
  })
).json();

if (boundaryResponse?.message) {
  throw new Error(
    "Failed to submit boundary for normalization: " + boundaryResponse.message,
  );
}
console.log("boundaryResponse: ", boundaryResponse);

await wait_for_boundary_normalization(
  apiInfo.awsUserFilesS3Bucket,
  boundaryKey,
);

// optionally download the normalized boundary to inspect it
// const normalizedBoundary = await s3.send(new GetObjectCommand({
//   Bucket: apiInfo.awsUserFilesS3Bucket,
//   Key: boundaryKey,
// }));
// const normalizedBoundaryData = await streamToBuffer(normalizedBoundary.Body);

// begin optional control boundary upload

const controlFileExt = extname(controlFilePath);
// generate a separate id for the control boundary upload
const controlUploadId = crypto.randomUUID();
const controlUploadKey = `private/${identityId}/apiUploads/${controlUploadId}${controlFileExt}`;
const controlBoundaryKey = `protected/${identityId}/uploads/${controlUploadId}.geojson`;
const controlBoundaryPath = `s3://${apiInfo.awsUserFilesS3Bucket}/${controlBoundaryKey}`;

// Upload the control boundary
const controlS3Upload = new PutObjectCommand({
  Bucket: apiInfo.awsUserFilesS3Bucket,
  Key: controlUploadKey,
  Body: fs.createReadStream(controlFilePath),
});
await s3.send(controlS3Upload);

// request the control boundary be normalized
const controlBoundaryResponse = await (
  await fetch("https://app.chloris.earth/api/boundary", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${idToken}`,
    },
    body: JSON.stringify({
      organizationId,
      uploadId: controlUploadId,
      uploadPath: `s3://${apiInfo.awsUserFilesS3Bucket}/${controlUploadKey}`,
      excludeGeojsonPath: boundaryPath,
    }),
  })
).json();

if (controlBoundaryResponse?.message) {
  throw new Error(
    "Failed to submit control boundary for normalization: " +
      controlBoundaryResponse.message,
  );
}

await wait_for_boundary_normalization(
  apiInfo.awsUserFilesS3Bucket,
  controlBoundaryKey,
);

// end optional control boundary upload

// Submit the reporting unit
const reportingUnit = await (
  await fetch("https://app.chloris.earth/api/reportingUnit", {
    method: "PUT",
    headers: await get_headers(),
    body: JSON.stringify({
      organizationId: organizationId,
      boundaryPath: boundaryPath,
      controlBoundaryPath: controlBoundaryPath,
      // dryrun: true, // may be used for testing, deletedAt will be set to 3 hours in the future
    }),
  })
).json();

if (reportingUnit?.message) {
  throw new Error("Failed to submit reporting unit: " + reportingUnit.message);
}

console.log(
  `Reporting unit submitted successfully: ${reportingUnit.reportingUnitId}`,
);

/// Helper functions ///

/**
 * Get the headers for the API requests, refreshing the idToken if necessary
 *
 * @returns {Promise<{}>}
 */
async function get_headers() {
  // check that the idToken JWT is not expired
  const idTokenDecoded = JSON.parse(
    Buffer.from(idToken.split(".")[1], "base64").toString(),
  );
  if (idTokenDecoded.exp * 1000 < Date.now()) {
    idToken = await refreshTokens(refreshToken, apiInfo);
  }

  return {
    "Content-Type": "application/json",
    Accept: "application/json",
    Authorization: `Bearer ${idToken}`,
  };
}

/**
 * Wait for the boundary to be normalized (long poll S3 for the boundary to be processed)
 * @param {string} bucket
 * @param {string} boundaryKey
 *
 * @returns {Promise<void>}
 */
async function wait_for_boundary_normalization(bucket, boundaryKey) {
  // 15 minute timeout with exponential backoff (note that most boundaries will be normalized in a few minutes)
  console.log("waiting for normalization: ", boundaryKey);
  const timeout = Date.now() + 15 * 60 * 1000;
  let i = 0;
  while (true) {
    try {
      const headObjectCommand = new HeadObjectCommand({
        Bucket: bucket,
        Key: boundaryKey,
      });
      const headResult = await s3.send(headObjectCommand);
      if (headResult?.Metadata?.error) {
        throw new Error(headResult.Metadata.error);
      }
      break;
    } catch (e) {
      if (e.name !== "NotFound") {
        throw e;
      }
    }
    if (Date.now() > timeout) {
      throw new Error("Timeout waiting for boundary to be normalized");
    }
    const delay = 5 * Math.pow(1.5, i);
    i++;
    await new Promise((resolve) => setTimeout(resolve, delay * 1000));
  }
}

/**
 * Exchange a refresh token for an idToken
 *
 * @returns {Promise<string>}
 */
async function refreshTokens() {
  if (typeof refreshToken === "undefined") {
    throw new Error("idToken is expired and no refresh token is available");
  }

  try {
    const client = new CognitoIdentityProviderClient({
      region: apiInfo.awsRegion,
    });
    const command = new InitiateAuthCommand({
      AuthFlow: "REFRESH_TOKEN_AUTH",
      ClientId: apiInfo.awsUserPoolWebClientId,
      AuthParameters: {
        REFRESH_TOKEN: refreshToken,
      },
    });
    const response = await client.send(command);

    // Extract and return the ID token from the response
    return response.AuthenticationResult?.IdToken;
  } catch (error) {
    console.error("Error refreshing tokens:", error);
    throw error; // Rethrow the error for handling by the caller
  }
}

Supported file types

When uploading boundaries, GeoJSON is recommended. However, the following file types are also supported:

  • GeoJSON (.geojson)
  • Zipped Shapefile (.shp.zip)*
  • Multi-file Shapefile (.shp, .shx, .dbf, .prj, .cpg)
  • GeoPackage (.gpkg)**
  • FlatGeobuf (.fgb)
  • KML (.kml)***

* Zipped shapefiles may have only contain one shapefile.

** Only the first layer of the GeoPackage will be used.

*** KML files are not recommended, as they often contain invalid geometries (such as unclosed line strings when you would expect a polygon). We recommend using QGIS to convert KML files to GeoJSON before uploading.

When submitting sites to the platform, we recommend using EPSG 4326 (WGS84) as the coordinate reference system (CRS) for your boundary. However, our system can support most CRSs, including UTM zones. Incorrect outputs due to projection issues are solely your responsibility.

Geospatial data

This section describes the geospatial data that is generated by the Chloris Platform and how to access it. Because geospatial data can be confusing, we'll start with a brief introduction to the concepts and terminology. Then cover input datasets, output datasets, and how to access them.

Geospatial data concepts

Geospatial data is any data that has a location component, specifically on Earth. It is separated into two distinct classes: vector and raster. Vector datasets are composed of points (such as longitude and latitude), lines, and polygons. Raster datasets are composed of pixels, possibly with multiple bands, which store more than one value for a single grid cell.

The Chloris Platform consumes vector datasets in the form of site boundaries, and produces raster output datasets. One special thing about geospatial datasets that is not immediately obvious is that every geospatial dataset must have a Coordinate Reference System (CRS), sometimes called a "projection", which describes where the data is located on Earth. The CRS is usually specified in the metadata of the dataset, but certain formats (such as GeoJSON) assume a CRS of WGS84 (EPSG:4326) if one is not specified. Without the correct CRS, the data will not be located in the correct place on Earth.

The Chloris Platform also produces tabular data (i.e. CSV files), but this is not generally considered to be geospatial data. There is one notable exception, which is when the tabular data contains a location component (e.g. longitude and latitude) as we sometimes see with field plots around a central point. Currently, the Chloris Platform does not consume field data, so within the platform interface, you will only see tabular data in the form of graphical tables or CSV files.

Additional beginner geospatial resources:

Input datasets

Site boundaries

Site boundaries are the primary input dataset that the Chloris Platform consumes. Site boundaries are vector datasets that describe the location and shape of a site. The Chloris Platform accepts site boundaries in most single-file formats, plus Shapefiles which have been zipped. Additionally, in the platform interface, you can draw your own site boundaries using the interactive map.

In order to assure the quality of our results, we enforce limits on the minimum size of sites and individual polygons (for statistical accuracy), how sparse the site may be (especially when given multi-polygons), and maximum precision of the vertices. If your site boundaries do not meet these requirements, you will receive a detailed error message explaining why.

Output datasets

For each site, the following datasets are produced:

Normalized boundary polygon

For your review and convenience, the Chloris Platform will return the normalized site boundary that was used for analysis with any invalid geometries (i.e. points and lines) removed, and all polygons flattened into a single multi polygon. Curve geometries are not supported in the platform and are approximated using linear segments. After a site has been submitted, you can retrieve the normalized boundary polygon using the boundaryPath field in the reporting unit entry.

Representative point

For map navigation purposes, the Chloris Platform will return a point (X,Y) that is representative of the reporting unit in WGS84 lon/lat when listing reporting units in the fields pointX and pointY. This point is guaranteed to be inside the reporting unit boundary geometry, so it is safe to perform spatial joins with (but may not be the exact centroid). If the same site is submitted multiple times, the representative points will be identical.

GeoTiff raster file downloads

If your licensing agreement includes data download, the data products (listed below) are available for download as GeoTiff files. Annual data products have one file per year. Difference data products are relative to the previous year, so change from 2000 to 2001 is reported in the 2001 file and there is no 2000 change file. Note that "t" refers to metric tonnes and "ha" refers to hectares.

Available datasets:

  • stock: Annual above-ground biomass stock in the given year (t/ha).
  • change: Annual above-ground biomass change (t/ha/yr).
  • se: Standard error of the annual above-ground biomass stock estimates (t/ha)*.
  • change_se: Standard error of the annual above-ground biomass change estimates (t/ha/yr)*.
  • forest: Area which is forest in the selected year. Boolean (0 or 1) mask.
  • forest_area_gain: Area which is forest in the given year, but not the previous year.
  • forest_area_loss: Area which is not forest in the given year, but was forest in the previous year.
  • forest_area_degradation: Area which remained forest in the given year, but experienced statistically significant losses in biomass.

* Introduced 2024-01-17.

An index of the files available to download is available at {dataPath}/downloads.json where dataPath is specified on the reporting unit entry.

The contents of the downloads index follow this schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "downloads": {
      "type": "array",
      "items": {
        "description": "An entry for a single downloadable file.",
        "type": "object",
        "properties": {
          "format": {
            "type": "string",
            "enum": ["tif", "geojson", "zip"]
          },
          "date": {
            "description": "The date of the data in the file.",
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "urlFormat": {
            "type": "string",
            "description": "The key in the urlFormats object which this url conforms to. Optional, as not all urls will conform to a urlFormat (e.g. a project-level summary pdf report)."
          }
        },
        "required": ["format", "date", "url"]
      }
    },
    "urlFormats": {
      "description": "A map of url formats which may be used to parse variables out of urls.",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "required": ["stock", "change", "boundary"]
    },
    "formatVersion": {
      "type": "string",
      "enum": ["0.1"]
    }
  },
  "required": ["formatVersion", "downloads", "urlFormats"]
}

Example downloads index:

{
  "formatVersion": "0.1",
  "downloads": [
    {
      "format": "tif",
      "date": "2023-01-01",
      "url": "s3://chloris-app-data/data/abc01234/efg56789/downloads/merged_2000_95a.tif",
      "urlFormat": "stock"
    },
    {
      "format": "tif",
      "date": "2023-01-01",
      "url": "s3://chloris-app-data/data/abc01234/efg56789/downloads/merged_2001_ch95a.tif",
      "urlFormat": "change"
    },
    {
      "format": "geojson",
      "date": "2023-01-01",
      "url": "s3://chloris-app-data/data/abc01234/efg56789/downloads/efg56789_boundary.geojson",
      "urlFormat": "boundary"
    }
  ],
  "urlFormats": {
    "stock": "s3://chloris-app-data/data/{organizationId}/{reportingUnitId}/downloads/merged_{year}_95a.tif",
    "change": "s3://chloris-app-data/data/{organizationId}/{reportingUnitId}/downloads/merged_{year}_ch95a.tif",
    "boundary": "s3://chloris-app-data/data/{organizationId}/{reportingUnitId}/downloads/{reportingUnitId}_boundary.geojson"
  }
}

This means you can directly iterate the list for urls, or parse out arbitrary variables for your own processing needs. Note that chloris-app-data is a private bucket accessible only through app.chloris.earth, so you will need to replace the s3://chloris-app-data/ prefix with https://app.chloris.earth/ to download the files.

Here is an example of how to download all the stock rasters for a site using the chloris-app-sdk in Python:

# download_stock_rasters.py
import urllib3
from chloris_app_sdk import ChlorisAppClient

http = urllib3.PoolManager()

# create the client
client = ChlorisAppClient(
    organization_id="your-organization-id",
    refresh_token="your-refresh-token", # env: CHLORIS_REFRESH_TOKEN
    # or
    # id_token="your-id-token" # env: CHLORIS_ID_TOKEN
)

reporting_unit_id = 'abcd1234'

# get the reporting unit entry with downloads (if available)
reporting_unit_entry = client.get_reporting_unit(reporting_unit_id, include_downloads=True)

if not reporting_unit_entry.get('downloads'):
    raise Exception('No downloads available for this reporting unit')

downloads_index = reporting_unit_entry['downloads']

# Filter for stock rasters
stock_urls = [d['url'] for d in downloads_index['downloads'] if d['urlFormat'] == 'stock']

print(f'Downloading {len(stock_urls)} stock rasters for reporting unit {reporting_unit_id}')
for url in stock_urls:
    r = http.request('GET', url.replace('s3://chloris-app-data/', 'https://app.chloris.earth/'))
    fname = url.split('/')[-1]
    with open(fname, 'wb') as f:
        f.write(r.data)
    print(f'Downloaded {fname}')

Here is an example of how to download all the stock rasters for a site in Javascript (node):

// downloadStockRasters.mjs
import fetch from "node-fetch";

const organizationId = "your-organization-id";
const reportingUnitId = "abcd1234";

const reporting_unit_entry_response = await fetch(
  `https://app.chloris.earth/api/reportingUnit/`,
  {
    headers: {
      Authorization: `Bearer ${idToken}`,
    },
    body: JSON.stringify({
      organizationId,
      reportingUnitId,
    }),
  },
);
const reporting_unit_entry = await reporting_unit_entry_response.json();

const dataPath = reporting_unit_entry.dataPath.replace(
  "s3://chloris-app-data/",
  "https://app.chloris.earth/",
);

const url = `${dataPath}/downloads.json`;

const downloads_response = await fetch(url);
const json = await downloads_response.json();

const stockUrls = json.downloads
  .filter((d) => d.urlFormat === "stock")
  .map((d) => d.url);

for (const url of stockUrls) {
  const response = await fetch(url);
  const buffer = await response.buffer();
  const fname = url.split("/").pop();
  await fs.promises.writeFile(fname, buffer);
  console.log(`Downloaded ${fname}`);
}

Pre-computed webtiles

The Chloris Platform produces TMS tiles for a number of the aforementioned raster datasets. The exact symbology information for each is available at :dataPath/layers.json and tiles themselves are available at :dataPath/:layerName/:year?/:z/:x/:y.webp for authenticated users. If you are used to XYZ tiles, the y coordinate in TMS is flipped (i.e. y = 2^z - 1 - y). In general, zoom levels 0-13 are produced in 512px by 512px resolution tiles (effective 9.555m / pixel on the equator). However, the layers config file(layers.json) contains the exact zoom levels for each layer so there is no guesswork. The :year? parameter is omitted for non-annual products.

The following layers are available:

  • stock
  • change
  • cumulative_change
  • forest
  • nonforest (only the non-forest pixels from the forest layer)
  • forest_area_gain
  • forest_area_loss
  • forest_area_degradation

Webhooks

To be notified when sites are ready, you can register a webhook URL for your organization via your organization options panel in the Chloris Platform web interface.

You will be asked to provide an HTTPS publicly-accessible URL for the webhook and a signing secret (a random string of your choosing).

This URL will be called when the site is ready. The webhook will be called with a POST request with the following JSON body:

{
  type: "reportingUnit",
  data: {
    organizationId: "your-organization-id",
    reportingUnitId: "your-reporting-unit-id",
    analysisCompletedAt: "2024-01-01T00:00:00.000Z",
    // ISO 8601
    exportCompletedAt: "2024-01-01T00:00:00.000Z",
    // ISO 8601, omitted if geospatial outputs are not yet available
  },
}

If the request fails, the webhook will be retried once after a random delay of 10-30 seconds. If the request fails again, the webhook will not be retried. In the future, we may add further retry logic, so please let us know if you have a specific use case that requires this.

The analysisCompletedAt timestamp is included to help you determine if the analysis results have been updated since the last time you checked. In the event that a site is reprocessed, the analysisCompletedAt timestamp will be updated. This can happen if the site is reprocessed due to a bug fix or as new data becomes available. If your system is caching the results of the site, you can use this timestamp to determine if you need to update your cache.

If you have licensed geospatial outputs, the webhook will also be invoked a second time with an additional exportCompletedAt timestamp in the payload. This timestamp indicates when the geospatial outputs are ready to be downloaded. If you are using the webhook to download the geospatial outputs, you can use this timestamp to determine when to download the outputs. As of 1.5.0 exportCompletedAt is deprecated and will be removed in a future version. Downloads are now always available when the webhook is called. For backwards compatibility, the field will continue to be included in webhook calls using the same value as analysisCompletedAt, but will be removed in a future version.

Control sites (or any site marked hidden: true) will not trigger a webhook, but will delay the primary site's webhook notification until the control site is ready.

Because there are several scenarios where the webhook will be called multiple times, you should ensure that your webhook endpoint is idempotent. This means that if the webhook is called multiple times, the final state of the site in your system will be both valid and up to date.

Signature validation

When our system calls your webhook endpoint, we will include a signature in the X-Signature http header. We recommend that you verify this signature to ensure that the request is actually from us.

The X-Signature header is a hash made up of the signing secret you specified when creating the webhook in your Chloris Platform account plus the request body. To verify each request to your webhook, you should re-create the hash and compare it to the signature in the header.

Here is an example of validating the signature in Node / Javascript:

import crypto from "crypto";
// the signing secret you specified when creating the webhook
const secret = "";
const body = ""; // the raw request body

const hmac = crypto.createHmac("sha256", secret);
const digest = Buffer.from(hmac.update(request.rawBody).digest("hex"), "utf8");
const signature = Buffer.from(request.get("X-Signature") || "", "utf8");

if (!crypto.timingSafeEqual(digest, signature)) {
  throw new Error("Invalid signature.");
}

And here is an example of validating the signature in Python:

import hmac
import hashlib

# the signing secret you specified when creating the webhook
secret = ''
# the signature in the X-Signature header
signature = ''
# the raw request body (depending on your http library, you may need to encode this.)
body = ''

digest = hmac.new(secret.encode(), body, hashlib.sha256).hexdigest()

if not hmac.compare_digest(digest, signature):
    raise Exception('Invalid signature.')

Testing your webhook endpoint

Here is a curl command that will simulate a webhook call with the signing secret "secret1234" so you can test your endpoint:

curl -X POST \
  -H "Content-Type: application/json" \
  -H "X-Signature: 211eee254e5bab5761e82452a9cf37e1396329cadc9957a99ea64197bd1c25a0" \
  -d '{"type": "reportingUnit", "data": {"organizationId": "your-organization-id", "reportingUnitId": "your-reporting-unit-id", "analysisCompletedAt": "2024-01-01T00:00:00.000Z"}}' \
  http://localhost:8080/webhook

Python API reference »

This page requires JavaScript to be enabled. Alternatively, you can view the [raw OpenAPI specification](./openapi.yml).

Changelog

All notable changes to the API will be documented here. This project adheres to Semantic Versioning.

The API is actively maintained and developed but does not have a regular release schedule.

[v1.5.0] - April 9, 2024

Added

Fixed

Changed

  • The source of truth for where data is located for all new reporting units is reportingUnit.dataPath, instead of the templated format /data/{organizationId}/{reportingUnitId}. This is non-breaking for previously generated data, as all existing data will remain in place. reportingUnit.dataPath is available for all reporting units, and we recommend migrating usage entirely to this.

Deprecated

  • Usage of exportCompletedAt in webhook calls is no longer necessary and will be removed in a future version. Downloads are now always available when the webhook is called. See the webhook documentation for more information.

Security

[1.4.1] - Original release