Created
October 31, 2025 14:13
-
-
Save ovolve/9b86c54891ff1c097cd3c78bbbd131b3 to your computer and use it in GitHub Desktop.
Public forestcast demo colab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "provenance": [], | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "name": "python3", | |
| "display_name": "Python 3" | |
| }, | |
| "language_info": { | |
| "name": "python" | |
| } | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/ovolve/9b86c54891ff1c097cd3c78bbbd131b3/public-forestcast-demo-colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "Copyright 2025 Google LLC.\n", | |
| "\n", | |
| "SPDX-License-Identifier: Apache-2.0" | |
| ], | |
| "metadata": { | |
| "id": "F5JqLWusf15a" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "id": "ZQDSP3xMAfQR" | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import datetime\n", | |
| "import tensorflow_datasets as tfds" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "DATA_DIR = \"gs://nature-trace/datasets/tfds\"\n", | |
| "ds_all, info = tfds.load(\n", | |
| " \"forestcast/southeast_asia:1.0.0\",\n", | |
| " data_dir=DATA_DIR,\n", | |
| " download=False,\n", | |
| " try_gcs=True,\n", | |
| " with_info=True,\n", | |
| ")\n", | |
| "\n", | |
| "info" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "olHeMGbgAom5", | |
| "outputId": "93baa082-90ca-47d1-8e68-b19ff00dbb00" | |
| }, | |
| "execution_count": null, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "tfds.core.DatasetInfo(\n", | |
| " name='forestcast',\n", | |
| " full_name='forestcast/southeast_asia/1.0.0',\n", | |
| " description=\"\"\"\n", | |
| " Forestcast dataset.\n", | |
| " \"\"\",\n", | |
| " homepage='https://www.tensorflow.org/datasets/catalog/forestcast',\n", | |
| " data_dir='gs://nature-trace/datasets/tfds/forestcast/southeast_asia/1.0.0',\n", | |
| " file_format=tfrecord,\n", | |
| " download_size=Unknown size,\n", | |
| " dataset_size=7.52 TiB,\n", | |
| " features=FeaturesDict({\n", | |
| " 'ccdc/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'ccdc/pixels': Tensor(shape=(None, 256, 256, 3), dtype=float32),\n", | |
| " 'ccdc/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'fdap_palm/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'fdap_palm/pixels': Tensor(shape=(None, 256, 256, 1), dtype=float32),\n", | |
| " 'fdap_palm/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'gfw_forest_change/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'gfw_forest_change/pixels': Tensor(shape=(None, 256, 256, 3), dtype=float32),\n", | |
| " 'gfw_forest_change/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'gfw_forest_change_imagery/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'gfw_forest_change_imagery/pixels': Tensor(shape=(None, 256, 256, 4), dtype=float32),\n", | |
| " 'gfw_forest_change_imagery/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'gmd_mangrove/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'gmd_mangrove/pixels': Tensor(shape=(None, 256, 256, 1), dtype=float32),\n", | |
| " 'gmd_mangrove/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'gpw/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'gpw/pixels': Tensor(shape=(None, 256, 256, 1), dtype=float32),\n", | |
| " 'gpw/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'grip/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'grip/pixels': Tensor(shape=(None, 256, 256, 2), dtype=float32),\n", | |
| " 'grip/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'gwl_wetland/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'gwl_wetland/pixels': Tensor(shape=(None, 256, 256, 1), dtype=float32),\n", | |
| " 'gwl_wetland/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'metadata/end_time': string,\n", | |
| " 'metadata/start_time': string,\n", | |
| " 'sentinel_2/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'sentinel_2/pixels': Tensor(shape=(None, 256, 256, 6), dtype=float32),\n", | |
| " 'sentinel_2/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " 'srtm/band_names': Tensor(shape=(None,), dtype=string),\n", | |
| " 'srtm/pixels': Tensor(shape=(None, 256, 256, 1), dtype=float32),\n", | |
| " 'srtm/timestamp_ms': Tensor(shape=(None,), dtype=int64),\n", | |
| " }),\n", | |
| " supervised_keys=None,\n", | |
| " disable_shuffling=False,\n", | |
| " nondeterministic_order=False,\n", | |
| " splits={\n", | |
| " '2017-00': <SplitInfo num_examples=11052, num_shards=3818>,\n", | |
| " '2018-00': <SplitInfo num_examples=10889, num_shards=3790>,\n", | |
| " '2019-00': <SplitInfo num_examples=10829, num_shards=3798>,\n", | |
| " '2020-00': <SplitInfo num_examples=11057, num_shards=3824>,\n", | |
| " '2021-00': <SplitInfo num_examples=10969, num_shards=3791>,\n", | |
| " '2022-00': <SplitInfo num_examples=10970, num_shards=3843>,\n", | |
| " '2023-00': <SplitInfo num_examples=10895, num_shards=3791>,\n", | |
| " },\n", | |
| " citation=\"\"\"\"\"\",\n", | |
| ")" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 2 | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "# Get a batch of 4 examples for a selected split.\n", | |
| "split = \"2023-00\"\n", | |
| "batch = next(ds_all[split].batch(4).as_numpy_iterator())\n", | |
| "\n", | |
| "for k, v in batch.items():\n", | |
| " print(k, v.shape, v.dtype)" | |
| ], | |
| "metadata": { | |
| "id": "NpSTCZPrAt4u" | |
| }, | |
| "execution_count": null, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "def to_datetime(encoded_timestamp: bytes):\n", | |
| " timestamp_ms = int(encoded_timestamp) // 1000\n", | |
| " return datetime.datetime.fromtimestamp(\n", | |
| " timestamp_ms, tz=datetime.timezone.utc)\n", | |
| "\n", | |
| "print(to_datetime(batch[\"metadata/start_time\"][0]))\n", | |
| "print(to_datetime(batch[\"metadata/end_time\"][0]))" | |
| ], | |
| "metadata": { | |
| "id": "ohm8TFW5pHYK" | |
| }, | |
| "execution_count": null, | |
| "outputs": [] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment