Skip to content

Instantly share code, notes, and snippets.

@acrosby
acrosby / get_ct_images.py
Created December 7, 2023 18:19
Scrape CT Images from Scan of the Month Website
import base64
import requests
import os
from io import StringIO
output_path = "output"
default_url = "https://www.scanofthemonth.com/scans/game-boy-compendium"
source = requests.get(default_url)
ujson = set([x.strip().replace('"', "").split("=")[-1] for x in source.text.split("\n") if "data-src=" in x])
@acrosby
acrosby / generic_nws13_example.py
Created January 18, 2023 22:18
A Generic Example of Code to Convert Regular Gridded NetCDF with Winds/Pressures to NWS13 NetCDF, and also the structure of the code that does the same for sets of ascii NWS12 OWI WIN/PRE domains
import netCDF4
import xarray as xr
import numpy as np
from glob import glob
params = ["U10", "V10", "PSFC", "lon", "lat", "time"]
def xrreaddumb(fpathpattern, ilatdim="lati", ilondim="long",
ilatcoord="latitude", iloncoord="longitude",
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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
@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 / 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 / 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:
;; 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)
# 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
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 ..