Skip to content

Instantly share code, notes, and snippets.

@selimnairb
selimnairb / hrrr_legend_test.html
Created June 3, 2021 19:46
Use HTML5 Canvas API to draw a legend for NOAA High-Resolution Rapid Refresh (HRRR) simulated radar reflectivity data (https://rapidrefresh.noaa.gov/hrrr/)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HRRR legend test</title>
<!-- Use HTML5 Canvas API to draw a legend for NOAA High-Resolution Rapid Refresh
(HRRR) simulated radar reflectivity data (https://rapidrefresh.noaa.gov/hrrr/)
-->
</head>
<body>
@selimnairb
selimnairb / base36.py
Last active June 25, 2020 02:36 — forked from marcg1968/base36.py
Python convert (encode/decode) base 36
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# http://stackoverflow.com/a/1181922
def base36encode(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
"""Converts an integer to a base36 string."""
if not isinstance(number, int):
raise TypeError('number must be an integer')
@selimnairb
selimnairb / RaspbianShrink.md
Last active December 10, 2021 12:54
Make a custom shrunken Raspbian image

Quickly and efficiently create a custom shrunken SD-card image for Raspberry Pi computers

The following assumes you have an SD card with Raspbian Stretch Lite on it, and that all commands are run on a separate (from your Raspberry Pi) Linux machine (or VM).

Some of this was adapted from here.

1. Resize the SD card

  • Put your SD card in an SD card reader
  • Run gparted: sudo gparted
@selimnairb
selimnairb / tipping_bucket_to_hourly.py
Last active October 13, 2015 01:31
Python/Pandas code for converting an irregular timeseries of tipping bucket rain gage data to hourly rainfall accumulations
#!/usr/bin/env python
import sys
import pandas as pd
df = pd.read_csv(sys.argv[1], delimiter='|', index_col=0, parse_dates=True, header=0,
names=['timestamp', 'tips_in', 'qual', 'interp', 'remarks'])
monthly_precip_in = df.tips_in.resample('H', how='sum')
monthly_precip_mm = monthly_precip_in * 25.4
monthly_precip_mm.name = 'precip_mm'
@selimnairb
selimnairb / tipping_bucket_to_hourly.r
Created October 13, 2015 00:24
Tortured R code to convert irregular timeseries of tipping bucket rain gage data into hourly rainfall accumulations.
rm(list=ls())
library(xts)
IN_TO_M = 0.0254
setwd('path/to/my/tipping/bucket/data')
gage1 = read.table("gage1_tipping.txt", sep="|", header=T)
gage2 = read.table("gage2_tipping.txt", sep="|", header=T)
data = list(gage1, gage2)
@selimnairb
selimnairb / gist:1e25fee5a19ca5fe62f2
Created December 29, 2014 17:05
Calculate the area of a geodesic polygon defined by WGS84 coordinates using Python version of GeographicLib
# See http://geographiclib.sourceforge.net for more information
from geographiclib.polygonarea import PolygonArea
from geographiclib.geodesic import Geodesic
coords = [(-81.684594, 35.725673),
(-80.059151, 35.725673),
(-80.059151, 36.689994),
(-81.684594, 36.689994)]
polyArea = PolygonArea(Geodesic.WGS84, False)
@selimnairb
selimnairb / gist:6d1e6d1dbe0b2ed5ef5e
Created June 26, 2014 02:05
Bare bones script for estimating yearly pan evaporation for a GHCN station using ulmo
import ulmo
print("Downloading GHCN daily data for station USC00311677...")
nc_data = ulmo.ncdc.ghcn_daily.get_data('USC00311677', as_dataframe=True)
nc_evap = nc_data['EVAP'].copy().value # evaporation in 1/10-mm
nc_evap = nc_evap.truncate(before='1950-01-01', after='2009-12-30')
nc_evap = nc_evap.fillna(value=0)
nc_evap_yearly = nc_evap.resample('A', how='sum') # get yearly sum
nc_evap_yearly_filter = nc_evap_yearly[nc_evap_yearly > 1000] # Filter out very low yearly totals
nc_evap_avg_mm = nc_evap_yearly_filter.mean() / 10
@selimnairb
selimnairb / gist:b43beb73a477ea8d9c24
Last active August 29, 2015 14:02
Bare bones tool for writing a UNC-RENCI Hydro-NEXRAD rainfall accumulation data file (in netCDF format) to CSV.
#!/usr/bin/env python
""" Bare bones tool for writing a UNC-RENCI Hydro-NEXRAD rainfall
accumulation data file (in netCDF format) to CSV. Writes output
to standard out.
@author brian_miles@unc.edu
Requires Unidata's netcdf4 Python library: https://github.com/Unidata/netcdf4-python
"""
import os, sys
@selimnairb
selimnairb / gist:652a243fa3086a4ad844
Last active September 15, 2020 09:13
Barebones tool to subset a netCDF grid dataset based on geographic (WGS84) bounding box
/**
Barebones tool to subset a netCDF grid dataset based on geographic bounding box.
Requires NetCDF-Java version 4.3 (may work with 4.5, haven't tested it):
@see http://www.unidata.ucar.edu/software/thredds/current/netcdf-java/documentation.htm
@author brian_miles@unc.edu
To use: