Skip to content

Instantly share code, notes, and snippets.

View asjohnston-asf's full-sized avatar

Andrew Johnston asjohnston-asf

View GitHub Profile
@asjohnston-asf
asjohnston-asf / nisar_gcov_to_geotiff.py
Created March 20, 2026 00:03
Convert backscatter data to geotiffs for each NISAR GCOV product in a given directory
import os
from concurrent.futures import ProcessPoolExecutor
from pathlib import Path
from osgeo import gdal
gdal.UseExceptions()
os.environ['GDAL_NUM_THREADS'] = 'ALL_CPUS'
os.environ['GDAL_DISABLE_READDIR_ON_OPEN'] = 'TRUE'
@asjohnston-asf
asjohnston-asf / cnm_generator.py
Created March 18, 2026 17:16
NISAR GCOV CNM Generator
import datetime
import hashlib
import json
import os
import requests
session = requests.Session()
from osgeo import gdal, osr
from nisar.products.readers import open_product
# get the data bands
gcov = open_product('NISAR_L2_PR_GCOV_045_107_A_031_4005_DHDH_A_20240621T144514_20240621T144551_T00410_N_F_J_001.h5')
hhhh = gcov.getImageDataset(frequency='A', polarization='HHHH')
hvhv = gcov.getImageDataset(frequency='A', polarization='HVHV')
# compute your RGB pixel values here
red = hhhh[:,:]
@asjohnston-asf
asjohnston-asf / find_opera_disp_products.py
Last active February 6, 2025 18:01
Find download URLs for OPERA DISP products in ASF non-production archive by product version and frame id
import requests
def get_download_url(product: dict, protocol: str) -> str:
if protocol not in ['https', 's3']:
raise ValueError(f'Unknown protocol {protocol}; must be https or s3')
for url in product['umm']['RelatedUrls']:
if url['Type'].startswith('GET DATA') and url['URL'].startswith(protocol):
return url['URL']
@asjohnston-asf
asjohnston-asf / coherence-notebook.ipynb
Created December 2, 2022 21:41
"Search the GSSICB STAC Catalog" notebook for AGU 2022
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@asjohnston-asf
asjohnston-asf / gist:c252f6e393299bc4e0079f133de1ebbc
Last active August 31, 2020 20:34
cmr query for average s1 ingest lag time
from statistics import mean
from datetime import timedelta, datetime
import requests
from dateutil.parser import parse
SESSION = requests.Session()
def get_granules(day):
from requests import Session
search_url = 'https://cmr.earthdata.nasa.gov/search/granules'
parameters = {
'scroll': 'true',
'provider': 'ASF',
'page_size': 2000,
# set any search criteria here
#'short_name': ['SENTINEL-1A_SP_GRD_HIGH','SENTINEL-1B_SP_GRD_HIGH','SENTINEL-1A_DP_GRD_HIGH','SENTINEL-1B_DP_GRD_HIGH'],
@app.route(....)
def list_zip_contents():
try:
return do_it()
except RemoteIoError as e:
status_code = get_status_code(e)
abort(status_code)
except KeyError as e:
return 'no such file...', 400
{
"zip_url": "https://datapool.asf.alaska.edu/SLC/SA/S1A_IW_SLC__1SDV_20200127T193344_20200127T193411_030990_038F2E_9EF2.zip",
"zip_filename": "S1A_IW_SLC__1SDV_20200127T193344_20200127T193411_030990_038F2E_9EF2.zip",
"zip_size": 3799270867,
"list_url": "https://unzip-test.asf.alaska.edu/SLC/SA/S1A_IW_SLC__1SDV_20200127T193344_20200127T193411_030990_038F2E_9EF2.zip/",
"contents": [{
"filename": "S1A_IW_SLC__1SDV_20200127T193344_20200127T193411_030990_038F2E_9EF2.SAFE/",
"size": 0,
"url": "https://unzip-test.asf.alaska.edu/SLC/SA/S1A_IW_SLC__1SDV_20200127T193344_20200127T193411_030990_038F2E_9EF2.zip/S1A_IW_SLC__1SDV_20200127T193344_20200127T193411_030990_038F2E_9EF2.SAFE/"
}, {