Skip to content

Instantly share code, notes, and snippets.

View MatthewJA's full-sized avatar

Matthew Alger MatthewJA

View GitHub Profile
@MatthewJA
MatthewJA / radon_transform.py
Created November 24, 2017 00:51
Fast(ish) approximation to a radon transform.
import numpy
import scipy.ndimage.interpolation
def radon_transform(ims):
"""Radon transform a batch of images.
Parameters
----------
ims : numpy.ndarray
(N x W x H) NumPy array of N images.
@MatthewJA
MatthewJA / matplotlib-latex.py
Created October 11, 2017 04:30
Fix for Matplotlib text output for inclusion in LaTeX documents
import matplotlib
# http://bkanuka.com/articles/native-latex-plots/
def figsize(scale):
fig_width_pt = 240.0
inches_per_pt = 1.0/72.27
golden_mean = (numpy.sqrt(5.0)-1.0)/2.0
fig_width = fig_width_pt*inches_per_pt*scale
fig_height = fig_width*golden_mean
fig_size = [fig_width,fig_height]
@MatthewJA
MatthewJA / first-cutout.py
Created September 27, 2017 07:51
Get FIRST cutouts.
import io
import warnings
import requests
def get_first(coord: 'SkyCoord', size: 'arcmin'=5) -> 'FITS image':
data = {
'RA': coord.to_string(style='hmsdms', sep=' '),
'Dec': '',
'Equinox': 'J2000',
@MatthewJA
MatthewJA / cyclic_viridis.py
Created September 7, 2017 04:27
Simple cyclic matplotlib colourmap based on viridis.
import matplotlib.cm
import matplotlib.colors
cyclic_viridis = matplotlib.colors.LinearSegmentedColormap.from_list(
'cyclic_viridis',
[(0, matplotlib.cm.viridis.colors[0]),
(0.25, matplotlib.cm.viridis.colors[256 // 3]),
(0.5, matplotlib.cm.viridis.colors[2 * 256 // 3]),
(0.75, matplotlib.cm.viridis.colors[-1]),
(1.0, matplotlib.cm.viridis.colors[0])])
@MatthewJA
MatthewJA / sa-baby-names-1944-2013.txt
Created January 24, 2017 07:30
List of South Australian baby names, 1944-2013.
# List of South Australian baby names, 1944-2013.
# Derived from:
# Attorney-General's Dept, SA,
# Most popular Baby Names (1944-2013),
# viewed 24/01/17,
# https://data.sa.gov.au/data/dataset/popular-baby-names/resource/534d13f2-237c-4448-a6a3-93c07b1bb614
# License: CC BY 4.0
A
A'AFF
A'ARON
@MatthewJA
MatthewJA / font-fallback.tex
Created November 5, 2016 03:06
Hack to get cross-platform fallback fonts with XeLaTeX.
\suppressfontnotfounderror1
\def\myfont{Palatino} % Or whatever your primary font choice is.
\def\myfallback{Palatino Linotype} % Or whatever your fallback font is.
\count255=\interactionmode
\batchmode
\font\foo="\myfont"\space at 10pt
\ifx\foo\nullfont
\font\foo = "\myfallback"\space at 10pt
\ifx\foo\nullfont
\errorstopmode

Love Hansard but wish it was somehow represented on a map? So do we. That's why we created Question Time.

We love political banter, and we wanted to visualise how political debate occurs over time. For each day of the 2015 -- 2016 NSW Parliament, Question Time visualises mentions of NSW suburbs found in the NSW Parliament Hansard with a heatmap of how unusually often each suburb was mentioned.

We also analyse the top five location mentions in NSW on each sitting day and plot them on the same map. Clicking one of these locations opens data in the sidebar about why it was interesting on that day. We're going to start out with snippets of mentions in Hansard, but plan to include more interesting record information via NLP.

We made extensive use of Python's Flask and also the OpenLayers 3 mapping library that gives us heatmaps overlaid onto regular maps for free.

@MatthewJA
MatthewJA / cases.hs
Created May 3, 2016 07:23
Haskell case pattern matching example
data Colour = Red | Green | Blue | Yellow
data Shape = Skinny | Round | Triangular
data Fruit = Apple | Banana | Strawberry
data Appearance = Appearance { colour :: Colour, shape :: Shape }
defruitify :: Fruit -> Appearance
defruitify fruit = case fruit of
Apple -> Appearance { colour = Red, shape = Round }
Banana -> Appearance { colour = Yellow, shape = Skinny }
@MatthewJA
MatthewJA / run.py
Created May 15, 2015 10:18
Basic bulk script running.
#!/usr/bin/env python
from subprocess import call
from os import devnull
values = set([
# ("par1", "par2", "par3", "par4"),
# ...,
@MatthewJA
MatthewJA / pygame-beginner-template-light.py
Last active March 12, 2024 16:08
PyGame templates for beginners and for very, very beginners. PyGame template/tutorial script for beginners to PyGame (but not to Python).
import sys
import pygame
from pygame.locals import *
pygame.init()
fps = 60
fpsClock = pygame.time.Clock()