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.1.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.1-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: blackmarble_ntl_toolkit-0.1.1.tar.gz
  • Upload date:
  • Size: 2.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","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.1.tar.gz
Algorithm Hash digest
SHA256 497e8b56cb640ce24a24026774012c1008d1e77fdd5b701b91b007641388d270
MD5 5ab6476de37c0c80f0e0bece0fc6c444
BLAKE2b-256 c43a889260d3b4ce6e426c941a4fd89a9533916b78b38fc182eadc68d3af83c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blackmarble_ntl_toolkit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b64497135982f31898b9d1f489f78a5eb1a7f64b4aabbe63503f7c28867066e1
MD5 47065228b370bc5b91e7f95ca3c737bf
BLAKE2b-256 4f33855b688b2a0d1398712d7942086431428a2e773bd8f5cf3db3b9dbe9e3b1

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