This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Color wheel for matplotlib plots.""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.axes_grid1 import inset_locator | |
def add_cwheel(ax_parent, rect, label, cmap=None, half=True, nticks=4): | |
"""Add color wheel to a matplotlib axes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""GMT tutorial using GMT.jl | |
1. In the Julia shell, do `]add GMT` | |
2. Download GSHHG data: <http://www.soest.hawaii.edu/wessel/gshhg/> | |
3. Unpack GSHHG data to a predictable directory | |
4. Create the `.gmt` folder in your HOME directory | |
5. In the command line shell, run `gmt defaults -Ds > .gmt/gmt.conf` | |
6. Change the assignment of `DIR_GSHHG` to point to the directory from step 3 | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Read columns of a delimited file into a namedtuple. | |
Supports column type parsers, e.g. | |
def parser(colname, data): | |
if colname == "foo": | |
return map(float, data) | |
return data | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import Fraction | |
def fspread(count, start, end=None, step=None, mode=1): | |
"""Generate evenly-spaced floats. | |
Yields a sequence of evenly-spaced numbers. Optional `mode` controls | |
endpoint behaviour. Requires the stdlib class `fraction.Fraction`. Source: | |
http://code.activestate.com/recipes/577881-equally-spaced-floats-part-2/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Copy or link this script into .git/hooks/ | |
# It runs automatically in the project root directory (parent of .git/). | |
# Code formatting | |
if black --check src/pydrex; then | |
exit 0 | |
else | |
black src/pydrex | |
git add -u |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using TOML | |
using HTTP | |
""" | |
get_ref(key) | |
Get HTML-formatted reference text for the given referernce key. | |
The key must match either a key in the `_assets/refcache.toml` | |
or the `_assets/doilist.toml` file. The text will be formatted with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LinearAlgebra | |
function inverse(a::AbstractMatrix{BigInt}, modulus) | |
m, n = size(a) | |
if m - n != 0 | |
error("cannot find modular inverse of non-square matrix") | |
end | |
det_inv = invmod(BigInt(det(a)), modulus) | |
if det_inv == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src := $(wildcard *.tex) | |
bib := $(wildcard *.bib) | |
all: $(src:%.tex=%.pdf) | |
%.pdf: $(src) out/%.bbl | |
@ 1>/dev/null lualatex --output-directory=out --interaction=batchmode --halt-on-error --file-line-error $< \ | |
|| echo "LuaLaTeX run 2/3 failed, check log files in out/ for details" | |
@ lualatex --output-directory=out --halt-on-error --file-line-error $<|rg -v '/usr/share/' | |
@ mv out/$@ $@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Pkg | |
using TerminalPager | |
using UnicodePlots | |
# Reduce color space of most REPL components from 16 to 8. | |
# Line numbers is stacktraces are still unreadable in dark themes... | |
Base.text_colors[:white] = Base.text_colors[:yellow] | |
Base.text_colors[:light_cyan] = Base.text_colors[:cyan] | |
Base.text_colors[:light_red] = Base.text_colors[:red] | |
Base.text_colors[:light_magenta] = Base.text_colors[:magenta] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import csv | |
import pdfplumber | |
# Create a list of minerals as classified by the IMA. | |
# Get PDF from http://cnmnc.main.jp/ | |
pdf = pdfplumber.open("IMA_MineralList_202207.pdf") |
OlderNewer