Skip to main content

A Python toolkit for retrieving and preprocessing NASA's Black Marble Nighttime Light (NTL) data using Google Earth Engine, xarray, and Dask.

Project description

Black Marble NTL Toolkit

Documentation Python 3.12+ License

Black Marble NTL Toolkit is a Python package designed to streamline the retrieval, cleaning, aggregation, and visualization of NASA's Nighttime Light (NTL) data.

Deploying NTL data for conflict monitoring or socioeconomic research demands a combination of deep domain expertise and advanced technical proficiency to retrieve, process, and analyze large-scale datasets. Consequently, effective research relies on close collaboration between conflict researchers, machine learning specialists, and data engineers. To lower these technical barriers and facilitate independent experimentation, the codebase contains helper functions designed to streamline the retrieval, cleaning, and visualization of NTL data.

📚 Documentation

Full documentation, tutorials, and API reference can be found here:
🔗 https://jankokla.github.io/blackmarble-ntl-toolkit/


✨ Main Functionality

1. Earth Engine Authentication & Data Retrieval

Before retrieving data, you must authenticate and initialize the Google Earth Engine Python API. Once initialized, you can seamlessly pull down daily and annual NASA Black Marble products.

from blackmarble_toolkit.utils import initialize_ee
from blackmarble_toolkit.retrieval import BlackMarbleRetriever

initialize_ee(project_name="your-gee-project-id")

retriever = BlackMarbleRetriever()

raw_ds = retriever.get_data(
    product="VNP46A2",
    start_date="2022-01-01", 
    end_date="2022-12-31",
    region=geometry
)

2. Preprocessing Pipeline

Create a robust, memory-efficient pipeline leveraging Dask and Xarray to filter out clouds, snow, and background noise, and correct geometric or angular distortions.

from blackmarble_toolkit.pipeline import NTLPipeline
from blackmarble_toolkit.methods import filters, angular, geometric, imputation

steps = [
    filters.CloudSnowFilter(),
    angular.QuadraticVZACorrection(),
    geometric.AveragePooling2D(filter_size=(3, 3)),
    imputation.LinearInterpolationGapFilling()
]

pipeline = NTLPipeline(steps)
processed_ds = pipeline.run(raw_ds, cache_intermediates=True)

3. Spatial Aggregation

Map your pixel-level NTL radiance to custom geometries (like administrative regions) for time-series analysis.

import geopandas as gpd

regions = gpd.read_file("regions.geojson")
regions = regions.reset_index(names="region_id")

aggregated_results = pipeline.aggregate(
    gdf=regions,
    geo_id_col="region_id"
)

4. Exporting to CSV

If you prefer doing downstream analysis and plotting in pandas or R, you can easily export the aggregated results to a CSV file.

df = pipeline.to_csv("ntl_aggregated_results.csv")

🛠️ Installation

You can install the toolkit directly via PyPI:

pip install blackmarble-ntl-toolkit

For more details on setting up your environment and configuring Earth Engine, please consult the Installation Guide.

Project details


Download files

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

Source Distribution

blackmarble_ntl_toolkit-0.1.2.tar.gz (2.9 MB view details)

Uploaded Source

Built Distribution

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

blackmarble_ntl_toolkit-0.1.2-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file blackmarble_ntl_toolkit-0.1.2.tar.gz.

File metadata

  • Download URL: blackmarble_ntl_toolkit-0.1.2.tar.gz
  • Upload date:
  • Size: 2.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for blackmarble_ntl_toolkit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7db9a75284b30580cae6d942c8b1e6defb56e6850f359561f8fb1ff632ccd316
MD5 09cb0eeb207301b4fdd340ef68f8f52a
BLAKE2b-256 b4c4d83db96b8cfb1e739ace23bc1542bae8d554ed302db36e963b4de8eed1c5

See more details on using hashes here.

File details

Details for the file blackmarble_ntl_toolkit-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: blackmarble_ntl_toolkit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for blackmarble_ntl_toolkit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0a68e4b24539d780ec8e5ea8f415f50b2a240acf5505c630e228e86c65457d6a
MD5 fa6a13452accbcd72a8bd5255bbed3e0
BLAKE2b-256 cc7564cb6ea9bf6aab634712789d67315b3a08607f5dd8345640c797ce303848

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