Skip to content

Instantly share code, notes, and snippets.

@drdavella
drdavella / Dockerfile
Created March 6, 2019 14:41
Dockerfile for provisioning my Python development environment (with conda) on Centos7
FROM centos:centos7
RUN yum -y update; yum clean all
RUN yum -y install epel-release sudo
RUN yum -y install zsh vim tmux git git-gui bzip2
RUN yum -y install gcc cscope valgrind freeglut-devel
RUN yum -y install python36 python36-pip
RUN pip3.6 install pip --upgrade
RUN pip3.6 install ipython
@drdavella
drdavella / sudoku.py
Created December 12, 2018 20:24
Fun little sudoku solver that shows progress as it works
#!/usr/bin/env python
import sys
import time
import curses
sudoku = """
0 0 0 0 0 0 0 0 0
0 0 8 0 0 0 0 4 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 6 0 0 0
@drdavella
drdavella / cherry.sh
Created November 28, 2018 02:20
Script used to help assist with a semi-automated release process
#!/bin/bash
set -eu
if [ $# != 2 ]; then
echo "USAGE: $(basename $0) <file> <number>"
exit 1
fi
args=("$@")
@drdavella
drdavella / ping.py
Created September 25, 2018 21:05
WIP implementation of ping in Python
#!/usr/bin/env python3
import struct
from argparse import ArgumentParser
from socket import socket, AF_INET, SOCK_DGRAM, IPPROTO_ICMP
ICMP_ECHO_REQUEST = 8
def ip_checksum(databuf, s=0):
@drdavella
drdavella / gwcs_pipeline.py
Last active September 19, 2018 20:02
Add custom step to WCS pipeline and serialize with ASDF
#!/usr/bin/env python
import os
import sys
import copy
import asdf
from astropy import modeling
@drdavella
drdavella / spectrum1d.py
Created September 5, 2018 19:51
Quick demo of constructing a Spectrum1D object
import numpy as np
from astropy import units as u
from astropy.modeling import models
from specutils import Spectrum1D
mean = 5
frequencies = np.linspace(1, mean*2, 100) * u.GHz
g1 = models.Gaussian1D(amplitude=5*u.Jy, mean=mean*u.GHz, stddev=0.8*u.GHz)
spectrum = Spectrum1D(spectral_axis=frequencies, flux=g1(frequencies))
@drdavella
drdavella / create_asdf.py
Created May 10, 2018 16:05
Script to create an ASDF file useful for testing asdf-cpp implementation
#!/usr/bin/env python3
import asdf
import numpy as np
tree = dict()
tree['top'] = dict(foo=42, bar='hello', nums=np.array([x for x in range(100)]))
with asdf.AsdfFile(tree) as af:
af.write_to('test.asdf')
@drdavella
drdavella / override_compound.py
Created April 4, 2018 13:32
Override extension type in ASDF
#!/usr/bin/env python3
"""A simple example demonstrating how a compound model can be overridden"""
import sys
from astropy.modeling.models import Polynomial1D
from astropy.modeling.core import _CompoundModel
import asdf
from asdf import CustomType
@drdavella
drdavella / asdf_in_fits.py
Created March 19, 2018 19:24
Easily reproduce ASDF-in-FITS object for testing
# coding: utf-8
from astropy.io import fits
from astropy.io.fits import HDUList, ImageHDU
from asdf.fits_embed import AsdfInFits
import numpy as np
get_ipython().run_line_magic('rm', '-f asdf.fits')
image = ImageHDU(np.random.random(1000))
hdulist = HDUList()
@drdavella
drdavella / asdf_test_case.py
Last active January 25, 2018 22:29
Simple reproducer for transient ASDF bug
#!/usr/bin/env python
import asdf
from astropy import units as u
from astropy.coordinates.representation import SphericalRepresentation
tree = {'coord': SphericalRepresentation(10*u.deg, 10*u.deg, 1*u.m)}
print('distance:', tree['coord'].distance)
with asdf.AsdfFile(tree=tree) as ff:
ff.write_to("test.asdf")