Skip to content

Instantly share code, notes, and snippets.

View kapadia's full-sized avatar
💭
eating a pecan bar

Amit Kapadia kapadia

💭
eating a pecan bar
View GitHub Profile
@kapadia
kapadia / main.py
Created February 1, 2023 21:50
Interface with LP DAAC using Earthdata token
import os
import rasterio as rio
url = "https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/HLSS30.020/HLS.S30.T22KDF.2023030T133831.v2.0/HLS.S30.T22KDF.2023030T133831.v2.0.B05.tif"
token = os.environ.get("NASA_EARTHDATA_TOKEN")
gdal_env = {
"GDAL_HTTP_HEADERS": f"Authorization: Bearer {token}",
"GDAL_DISABLE_READDIR_ON_OPEN": "EMPTY_DIR",
}
@kapadia
kapadia / gist:3956486
Created October 26, 2012 01:43
Endianness in JavaScript
// Endian Differences When Interpreting Binary Data in JavaScript
// Let's make a request for a binary file
var xhr = new XMLHttpRequest();
xhr.open('GET', 'data/m101.fits');
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
var buffer = xhr.response;
@kapadia
kapadia / scale-me.sh
Created September 25, 2014 17:42
Scaling Bit Depth with GDAL
# Converting from 16bit to 8bit
gdal_translate -ot Byte -scale 0 65535 0 255 sixteen.tif eight.tif
# Converting from 8bit to 16bit
gdal_translate -ot Uint16 -scale 0 255 0 65535 eight.tif sixteen.tif
@kapadia
kapadia / viirs-resource.md
Created August 4, 2015 16:45
VIIRS Resources
g = sns.pairplot(df[(np.abs(df.wx) < 2) & (np.abs(df.wy) < 2) & (np.abs(df.wz) < 2)], vars=['motion_blur', 'wx', 'wy', 'wz'], plot_kws={'alpha': 0.2})
for ax in g.axes[-1, :]:
ax.set_xticklabels(ax.get_xticks(), rotation=40)
@kapadia
kapadia / go.sh
Created December 11, 2014 23:48
Bash Error Handling
#!/bin/bash
# Use -e to exit the script as soon as anything returns non-zero
set -eou pipefail
function usage() {
echo ""
echo "Template script for bash error handling."
echo ""
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kapadia
kapadia / matcher.py
Created February 13, 2013 21:16
Use OpenCV to match features between two images
import numpy
import cv2
original = "original.tif"
cropped = "cropped.jpeg"
def matcher():
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.