Skip to content

Instantly share code, notes, and snippets.

@acrosby
acrosby / rtree_large_test.py
Last active December 9, 2020 15:50
Sample code for python rtree bulk loading of 10,000,000 points and a nearest neighbor query.
from rtree import index
from random import random
from datetime import datetime
timer = datetime.now()
# Create 10,000,000 random numbers between 0 and 1
rands = [random() for i in range(10000000)]
# Function required to bulk load the random points into the index
'''
Only slighted modified from code provided by Laura De Cicco (USGS).
Laura De Cicco, A. Crosby
http://nwisvaws02.er.usgs.gov/ogc-swie/wml2/uv/sos?request=GetObservation&featureID=01446500&offering=UNIT&observedProperty=00060&beginPosition=2013-02-15
'''
from xml.dom import minidom, Node
import datetime
@acrosby
acrosby / hdf5_build
Last active December 17, 2015 09:08
# Make sure g++ compiler is installed for hdf5
sudo apt-get install g++ dpkg-dev
# Download HDF5 source unpack and cd to directory
wget http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.8.10.tar.gz
tar -xzvf hdf5-1.8.10.tar.gz
cd hdf5-1.8.10
./configure --prefix=/usr/local --enable-shared --enable-hl
make -j 2
sudo make install
sudo apt-get install dpkg-dev libcurl4-gnutls-dev
# Download netCDF4 source unpack and cd to directory
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.2.1.1.zip
unzip netcdf-4.2.1.1.zip
cd netcdf-4.2.1.1
LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include ./configure --enable-netcdf-4 --enable-dap --enable-shared --prefix=/usr/local --disable-doxygen
make -j 2
sudo make install
cd ..
# Install spatialindex 1.7.0+
wget http://download.osgeo.org/libspatialindex/spatialindex-src-1.7.1.tar.gz
tar zxvf spatialindex-src-1.7.1.tar.gz
cd spatialindex-src-1.7.1
./configure
make -j 2
sudo make install
sudo ldconfig
;; this location is "~/.pudb-bp" in older versions of pudb
(setq pudb-bp-file (expand-file-name "~/.config/pudb/saved-breakpoints"))
(defun pudb-add-breakpoint ()
(interactive)
(append-to-file
(concat "b " buffer-file-name ":"
(nth 1 (split-string (what-line))) "\n")
nil pudb-bp-file))
(define-key py-mode-map (kbd "C-c C-t") 'pudb-add-breakpoint)
@acrosby
acrosby / optitry
Last active September 27, 2021 16:29
Python alias script for retrying "optirun" if fallback fails.
#!/usr/bin/python
import subprocess, sys, shlex
#command = shlex.split(sys.argv[1])
command = "optirun " + sys.argv[1]
test = True
c = 0
while test:
@acrosby
acrosby / calc_volume.py
Last active February 12, 2024 12:18
This code demonstrates how to read a binary STL file and calculate its volume in python.
import numpy as np
import struct
def read_stl(filename):
with open(filename) as f:
Header = f.read(80)
nn = f.read(4)
Numtri = struct.unpack('i', nn)[0]
record_dtype = np.dtype([
@acrosby
acrosby / Julia Cartopy Examples.md
Created June 5, 2017 17:20 — forked from jpwspicer/Julia Cartopy Examples.md
Examples of using Cartopy with Julia
@acrosby
acrosby / look_at_ugrid_netcdf_files.py
Created May 17, 2022 20:56
Validating netcdf ugrid meshes with `pyugrid` and `netCDF4` in Python
import pyugrid
import netCDF4
# Default ADCIRC output (from OWI)
adcirc = "fort.63.nc"
nc = netCDF4.Dataset(adcirc)
ugobj = pyugrid.UGrid.from_nc_dataset(nc)
pyugrid.read_netcdf.is_valid_mesh(nc, "adcirc_mesh")
# SELFE sample