Last active
July 23, 2024 18:07
-
-
Save g4brielvs/80859c21ca0017e4b2e417b4665c58c0 to your computer and use it in GitHub Desktop.
BlackMarblePy Example
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
import pandas as pd | |
from blackmarble.extract import bm_extract | |
from blackmarble.raster import bm_raster | |
# Set NASA EarthData Token (envvar or alternative recommended) | |
bearer = "<NASA-EARTHDATA-TOKEN>" | |
# Retrieve GADM polygon of Lebanon | |
gdf = geopandas.read_file( | |
"https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_GHA_1.json.zip" | |
) | |
# Create NTL raster | |
ntl_r = bm_raster( | |
gdf, | |
product_id="VNP46A4", | |
date_range=pd.date_range("2019-01-01", "2022-01-01", freq="YS"), | |
bearer=bearer | |
) | |
# Create NTL dataset from 2012 to 2022 | |
ntl_df = bm_extract( | |
gdf, | |
product_id="VNP46A4", | |
date_range=pd.date_range("2012-01-01", "2022-01-01", freq="YS"), | |
bearer=bearer, | |
aggfunc = ["sum"], | |
) |
@Abdulazizbek Thank you for reaching out! When invoking bm_raster, the result will be a xrray.Dataset, so you may use leverage its plotting features.
You may try:
r["Gap_Filled_DNB_BRDF-Corrected_NTL"].sel(time="2022-01-01").plot.pcolormesh(
robust=True,
)
Alternatively, you may also use rioxarray to export a raster.
r["Gap_Filled_DNB_BRDF-Corrected_NTL"].sel(time="2021-02-05").rio.to_raster('output.tif')
Finally, please see also this example on the BlackMarblePy's documentation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I save a downloaded file (
geotif
) as an image (ex: intif
or some other format).For example:
I want to save this range of data as an image file:
date_range = pd.date_range("2022-01-01", "2022-03-31", freq="D")
Thank you beforehand