Skip to content

Instantly share code, notes, and snippets.

@drdavella
drdavella / mp-benchmark.py
Created December 19, 2017 18:54
Simple benchmark for testing data transfer between processes using Python's multiprocess module
#!/usr/bin/env python
from argparse import ArgumentParser
from multiprocessing import Process, Array, Pipe, Queue
from timeit import default_timer as timer
import numpy as np
def process_with_array(dest, source):
input_data = np.array(source, copy=False, dtype=float)
@drdavella
drdavella / asdf-testenv.yaml
Created January 25, 2018 22:09
A simple Conda environment file for attempting to reproduce ASDF test failures
name: asdf-test-env
channels:
dependencies:
- python=3.5
- ipython
- pytest
- numpy>=1.13
- pip:
- git+https://github.com/cadair/astropy@asdf_tags_coords#egg=astropy
- git+https://github.com/spacetelescope/asdf#egg=asdf
@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")
@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 / 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 / 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 / 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 / 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 / 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 / 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=("$@")