Skip to content

Instantly share code, notes, and snippets.

View joferkington's full-sized avatar
🏠
Working from home

Joe Kington joferkington

🏠
Working from home
View GitHub Profile
@joferkington
joferkington / download_mosaic_assets.py
Last active August 11, 2023 15:54
Download provenance or UDM data for a Planet mosaic
#! /usr/bin/env python3
# Copyright 2023 Planet Labs, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@joferkington
joferkington / mpl_contour_clipping_example.py
Last active December 10, 2020 23:10
Using a masked array for contour clipping
# There are two ways to clip data to irregular boundaries.
# One uses a masked array (and is most useful for "real" data)
# The other uses set_clip_path (and is most useful for graphics)
# This demonstrates the first (masked array)
import matplotlib.pyplot as plt
import scipy.ndimage
import numpy as np
import skimage.draw
#!/usr/bin/env python
"""
# Copyright 2019 Planet Labs, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@joferkington
joferkington / mold_spores.py
Created February 24, 2020 16:43
Some auto-generated mold-like art in matplotlib.
"""
Silly auto-generated art. Meant to look like some sort of mold spores.
Deliberately slow to render -- meant to look good at high-res.
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib.collections import LineCollection
"""
Converts one or more zmap grids to ascii x,y,z tab-delimited files. Exported
files will be saved to the current directory with a ".xyz" extension and the
same file name as the original. Null grid values will not be included unless
the "--with_nulls" option is specified.
Usage:
zmap2xyz.py [options] INPUT_FILES...
Options:
@joferkington
joferkington / cards_that_do_not_fit_future_sight.py
Created November 30, 2018 16:27
How many MTG cards would not fit on a future sight border?
import json
# https://mtgjson.com/v4/json/AllCards.json.zip
with open('AllCards.json', 'r') as infile:
data = json.load(infile)
for name in data:
card = data[name]
cost = card.get('manaCost', '')
if cost.count('{') > 6:
import numpy as np
from scipy.interpolate import Rbf
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from mpl_toolkits.axes_grid1 import inset_locator
from matplotlib.projections.polar import PolarAxes
np.random.seed(1977)
def main():
x, y, z = generate_surface()
import Tkinter as tk
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
def main():
root = tk.Tk()
app = Application(root)
tk.mainloop()
@joferkington
joferkington / struct_vs_numpy_example.py
Last active December 7, 2015 18:52
Writing an arbitrary, pre-existing numpy array to a hetergenous binary format
import numpy as np
# Our input data...
x = np.random.randint(0, 3200, (1000,1000))
# We're replacing something like
# struct.pack(">"+"hB"*x.size)
# Note that that's a 2-byte signed int followed by 1-byte unsigned
# We'll need to create the output 1D array and assign manually:
import numpy as np
import scipy.sparse
import scipy.ndimage
import scipy.stats
import scipy.signal
import matplotlib.pyplot as plt
def main():
x, y = generate_data(int(1e7))