Georeferenced Rasters of Nighttime Lights from NASA Black Marble data
Project description
BlackMarblePy
BlackMarblePy is a Python package that provides a simple way to use nighttime lights data from NASA's Black Marble project. Black Marble is a NASA Earth Science Data Systems (ESDS) project that provides a product suite of daily, monthly and yearly global nighttime lights. This package automates the process of downloading all relevant tiles from the NASA LAADS DAAC to cover a region of interest, converting the raw files (in HDF5 format) to georeferenced rasters, and mosaicking rasters together when needed.
Features
- Download daily, monthly, and yearly nighttime lights data for user-specified region of interest and time.
- Parallel downloading for faster data retrieval and automatic retry mechanism for handling network errors.
- Access NASA Black Marble as a xarray.Dataset
- Integrated data visualization with customization options
- Choose between various plot types, including bar charts, line graphs, and heatmaps.
- Customize plot appearance with color palettes, axes labels, titles, and legends.
- Save visualizations as high-resolution images for presentations or reports.
- Perform time series analysis on nighttime lights data.
- Calculate zonal statistics like mean and sum.
- Plot time series of nighttime lights data.
- Integrated data visualization with customization options
Documentation
The BlackMarblePy library allows you to interact with and manipulate data from NASA's Black Marble, which provides global nighttime lights data. Below is a guide on how to use the key functionalities of the library.
Installation
BlackMarblePy is available on PyPI as blackmarblepy. To install, it is recommended to use a modern Python package manager. While pip is the traditional choice, you can also use uv, which is a fast drop-in replacement for pip that offers improved performance and compatibility with modern workflows.
Using pip
pip install blackmarblepy
Using uv (modern, faster alternative)
uv install blackmarblepy
Usage
BlackMarblePy requires a NASA Earthdata bearer token for authenticated access to the NASA LAADS archive. To obtain a token, log in or register at Earthdata Login and generate a personal access token from your Earthdata profile.
Before downloading or extracting NASA Black Marble data, ensure the following:
- You have a valid and not expired
bearer
token set (retrieved from your Earthdata profile). For convenience and security, we recommend setting your token as anBLACKMARBLE_TOKEN
environment variable. - You have defined a region of interest
gdf
as ageopandas.GeoDataFrame
, which represents the area over which data will be queried and downloaded.
# Option 1: Class-based interface
from blackmarble import BlackMarble, Product
# Create a BlackMarble instance. If no bearer token is passed explicitly,
# it will attempt to read from the BLACKMARBLE_TOKEN environment variable.
bm = BlackMarble() # or: BlackMarble(bearer="YOUR_BLACKMARBLE_TOKEN")
# Define your region of interest as a GeoDataFrame (gdf)
# For example: gdf = gpd.read_file("path_to_shapefile.geojson")
# Retrieve VNP46A2 for date range into a Xarray Dataset
daily = bm.raster(
gdf,
product_id=Product.VNP46A2,
date_range=pd.date_range("2022-01-01", "2022-03-31", freq="D"),
)
Alternatively, use the bm_raster procedural interface to retrieve daily NASA Black Marble data (VNP46A2) as an xarray.Dataset
:
# Option 2: Backward-compatible procedural interface
from blackmarble import bm_raster, Product
# Define your region of interest as a GeoDataFrame (gdf)
# For example: gdf = gpd.read_file("path_to_shapefile.geojson")
# Retrieve VNP46A2 for date range into a Xarray Dataset
daily = bm_raster(
gdf,
product_id=Product.VNP46A2,
date_range=pd.date_range("2022-01-01", "2022-03-31", freq="D"),
bearer=bearer, # optional: can be omitted if BLACKMARBLE_TOKEN is set in the environment
)
Data is sourced from the NASA LAADS archive, specifically from the VNP46 product suite (e.g., VNP46A1, VNP46A4). For more detailed information and examples, please refer to the examples.
Full API Reference
For a full reference of all available functions and their parameters, please refer to the official documentation.
Contributing
We welcome contributions to improve this documentation. If you find errors, have suggestions, or want to add new content, please follow our contribution guidelines.
Feedback and Issues
If you have any feedback, encounter issues, or want to suggest improvements, please open an issue.
Versioning
This project follows the YYYY.0M.MICRO CALVER scheme for versioning. If you have any questions or need more information about our versioning approach, feel free to ask.
Contributors
This project follows the all-contributors specification. Contributions of any kind are welcome!
Gabriel Stefanini VicenteRobert Marty
Citation
When using BlackMarblePy, your support is much appreciated! Please consider using the following citation or download bibliography.bib:
@misc{blackmarblepy,
title = {{BlackMarblePy: Georeferenced Rasters and Statistics of Nighttime Lights from NASA Black Marble}},
author = {Gabriel {Stefanini Vicente} and Robert Marty},
year = {2023},
howpublished = {\url{https://worldbank.github.io/blackmarblepy}},
doi = {10.5281/zenodo.10667907},
url = {https://worldbank.github.io/blackmarblepy},
}
{cite:empty}blackmarblepy
:filter: docname in docnames
:style: plain
Related Projects
Looking for an R implementation? Check out the blackmarbler package, which provides similar functionality for working with NASA Black Marble data in R.
License
This projects is licensed under the Mozilla Public License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file blackmarblepy-2025.6.3.tar.gz
.
File metadata
- Download URL: blackmarblepy-2025.6.3.tar.gz
- Upload date:
- Size: 9.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
fcbf005aa2f43c4eb572250c8fdf399cc4a0e96d69497cc9b1dcabcec9ec8862
|
|
MD5 |
848c7e23397d0453bc27f2ca3dfb0f3c
|
|
BLAKE2b-256 |
6ef8d365d07a03e2c3cde81fcdc8d6c7f89a3b69a1aabba0415c3cb624c28cab
|
Provenance
The following attestation bundles were made for blackmarblepy-2025.6.3.tar.gz
:
Publisher:
release.yml
on worldbank/blackmarblepy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
blackmarblepy-2025.6.3.tar.gz
-
Subject digest:
fcbf005aa2f43c4eb572250c8fdf399cc4a0e96d69497cc9b1dcabcec9ec8862
- Sigstore transparency entry: 234759353
- Sigstore integration time:
-
Permalink:
worldbank/blackmarblepy@96bde4485cf4f359bb6949d9d45dc1d5535a8b17
-
Branch / Tag:
refs/tags/v2025.06.3
- Owner: https://github.com/worldbank
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
release.yml@96bde4485cf4f359bb6949d9d45dc1d5535a8b17
-
Trigger Event:
release
-
Statement type:
File details
Details for the file blackmarblepy-2025.6.3-py3-none-any.whl
.
File metadata
- Download URL: blackmarblepy-2025.6.3-py3-none-any.whl
- Upload date:
- Size: 41.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
00fb84a39e6741413a0d6fdba9fca338d14090b3068a1e4fb20e06a83811af17
|
|
MD5 |
12a04e826bbb160f994426e8210591a9
|
|
BLAKE2b-256 |
2f7bff16e374a8f815296b0c4e0465df69065bdd8c0a5d4962ce2f403e96843d
|
Provenance
The following attestation bundles were made for blackmarblepy-2025.6.3-py3-none-any.whl
:
Publisher:
release.yml
on worldbank/blackmarblepy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
blackmarblepy-2025.6.3-py3-none-any.whl
-
Subject digest:
00fb84a39e6741413a0d6fdba9fca338d14090b3068a1e4fb20e06a83811af17
- Sigstore transparency entry: 234759357
- Sigstore integration time:
-
Permalink:
worldbank/blackmarblepy@96bde4485cf4f359bb6949d9d45dc1d5535a8b17
-
Branch / Tag:
refs/tags/v2025.06.3
- Owner: https://github.com/worldbank
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
release.yml@96bde4485cf4f359bb6949d9d45dc1d5535a8b17
-
Trigger Event:
release
-
Statement type: