Skip to content

Instantly share code, notes, and snippets.

@AdrianoPereira
Created April 24, 2025 17:14
Show Gist options
  • Select an option

  • Save AdrianoPereira/402ec009ddccfe9d22c799c318330a9f to your computer and use it in GitHub Desktop.

Select an option

Save AdrianoPereira/402ec009ddccfe9d22c799c318330a9f to your computer and use it in GitHub Desktop.
Script for download GOES13 data from STAC
import pystac_client
from tqdm import tqdm
import os
from datetime import datetime
import requests
STAC_API_URL = 'https://data.inpe.br/bdc/stac/v1/'
BASE_DIR = '/storage/goes/goes13'
CHANNEL = 'B04'
START_DATE = '2015-01-01'
END_DATE = '2015-12-31'
DATE_RANGE = f"{START_DATE}/{END_DATE}"
service = pystac_client.Client.open(STAC_API_URL)
def download_file(url, output_dir):
filename = url.split("/")[-1]
output_path = os.path.join(output_dir, filename)
try:
response = requests.get(url, stream=True)
response.raise_for_status()
total = int(response.headers.get('content-length', 0))
with open(output_path, 'wb') as file, tqdm(
desc=filename,
total=total,
unit='B',
unit_scale=True,
unit_divisor=1024,
) as bar:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)
bar.update(len(chunk))
print(f"Downloaded: {filename}")
except requests.exceptions.RequestException as e:
print(f"Failed to download {url}: {e}")
collection = service.get_collection("GOES13-L3-IMAGER-1")
items_search = service.search(
datetime=DATE_RANGE,
collections=["GOES13-L3-IMAGER-1"],
)
for item in items_search.items():
channel_asset = item.assets[CHANNEL]
year = item.datetime.year
month = item.datetime.month
day = item.datetime.day
path = f"{BASE_DIR}/{CHANNEL}/{year:02d}/{month:02d}/{day:02d}"
os.makedirs(path, exist_ok=True)
download_file(channel_asset.href, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment