Skip to content

Instantly share code, notes, and snippets.

# coding: utf-8
""" Astropy modeling demo against leastsq """
from __future__ import division, print_function
__author__ = "adrn <adrn@astro.columbia.edu>"
# Standard library
import os, sys
@adrn
adrn / unit_plot_api.py
Created July 17, 2013 16:12
API for astropy.units aware plotting
# API for unit-aware plotting
theta1 = np.random.uniform(0., 360., size=100)*u.degree
phi1 = np.random.uniform(-90., 90., size=100)*u.degree
theta2 = np.random.uniform(0., 24., size=50)*u.hourangle
phi2 = np.random.uniform(-90., 90, size=50)*u.degree
ax = fig.add_subplot(111)
ax.plot(theta1, phi1)
ax.plot(theta2, phi2)
@adrn
adrn / matplotlibrc
Last active December 23, 2015 05:58
Test matplotlibrc file
axes.facecolor : adeade
@adrn
adrn / cmd-line-function.py
Created September 24, 2013 20:40
Specify which function to run in a module from the command line
import sys
def some_name():
print("function 1")
def some_other_name():
print("function 2")
if __name__ == "__main__":
func = getattr(sys.modules[__name__], sys.argv[1])
@adrn
adrn / astropy_coordinates_api.py
Last active December 27, 2015 21:18
sketching out some thoughts on representing coordinates in Python
position = np.array([15, 18.5, -0.7]) * u.kpc
c = Cartesian(position, frame=None)
c.transform_system(Spherical)
c.transform_frame(Heliocentric) # raises error - no input frame specified
# the system/representation classes -- e.g. Cartesian, Spherical,
# Cylindrical, Bispherical, etc. -- accept any Quantity object
velocity = np.array([10.4, 57.134, -81.124]) * u.km/u.s
v = Cartesian(velocity, frame=None)
v.transform_system(Cylindrical)
@adrn
adrn / data.csv
Last active December 31, 2015 11:09
M-dwarf example
J-K H-K J-H Spectral Type EW NA EW Ca H2OK2 Index [Fe/H]
0.8120003 0.2609997 0.5510006 M4V 4.1302047 2.5678225 0.8856874 -0.1703601
0.8410001 0.2430000 0.5980000 M5V 4.4665532 2.2672496 0.8618297 -0.0832374
0.8839998 0.3260002 0.5579996 M5V 5.9497361 3.4705281 0.8493133 0.1951554
0.8350000 0.2869997 0.5480003 M3V 4.9369497 4.1303015 0.9326374 0.0237309
0.8550005 0.2890005 0.5660000 M5V 4.7328906 2.0805767 0.8393655 -0.0205419
0.8449993 0.2779999 0.5669994 M4V 5.9279079 3.9511623 0.8810213 0.1923087
0.8930001 0.2960000 0.5970001 M5V 6.6394548 3.2767606 0.8216949 0.2658672
0.9359999 0.3309994 0.6050005 M6V 6.1195040 1.8434182 0.8068823 0.2160206
0.8599997 0.2539997 0.6059999 M4V 6.1938062 3.6349468 0.8940281 0.2244418
@adrn
adrn / data.csv
Last active January 1, 2016 08:19
kepler data set
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 21 columns, instead of 6. in line 7.
Kepler ID,KOI Name,Discovery Quarter,Kepler Disposition,RA (J2000),Dec (J2000),Period,Transit Depth,Duration,Semi-major Axis,Eccentricity,r/R,a/R,Planet Radius,Teq,Teff,log(g),Stellar Radius,Stellar Mass,KOI count,Binary Discrimination
11446443,K00001.01,1,CANDIDATE,19 07 14.033,+49 18 59.04,2.47,14284,1.72,0.04,0,0.12,8.45,14.4,1394,5814,4.38,1.06,1,1,3.78
10666592,K00002.01,1,CANDIDATE,19 28 59.348,+47 58 10.28,2.2,6713,3.88,0.04,0,0.08,4.68,22.3,2303,6264,3.79,2.71,1.66,1,3.91
10748390,K00003.01,1,CANDIDATE,19 50 50.244,+48 04 51.07,4.89,4323,2.37,0.05,0,0.06,16.68,4.68,794,4766,4.59,0.74,0.79,1,1.27
8554498,K00005.01,1,CANDIDATE,19 18 57.532,+44 38 50.71,4.78,966,2.01,0.06,0,0.04,7.56,5.66,1279,5861,4.19,1.42,1.15,2,2.20E-004
8554498,K00005.02,1,CANDIDATE,19 18 57.532,+44 38 50.71,7.05,18,3.69,0.08,0,0,9.8,0.66,1124,5861,4.19,1.42,1.15,2,0.99
11853905,K00007.01,1,CANDIDATE,19 02 27.678,+50 08 08.70,3.21,735,4.11,0.04,0,0.03,4.49,3.72,1386,5858,4.28,1.27,1.12,1,0
6922244,K00010.01,1,CANDIDATE,18 45 09.148,
@adrn
adrn / data.csv
Last active April 18, 2019 16:46
Jupiter's moons dataset
Name log mass (log kg) Semi-major axis (km) Orbital period (days) Inclination (deg) Eccentricity Discovery year Group
Metis 16.5563025007673 127690 7.07 0.06 0 1979 Inner
Adrastea 15.301029995664 128690 7.17 0.03 0.0015 1979 Inner
Amalthea 18.3180633349628 181366 11.95 0.374 0.0032 1892 Inner
Thebe 17.6334684555796 221889 16.16 1.076 0.0175 1979 Inner
Io 22.9509438521411 421700 1.769 0.05 0.0041 1610 Galilean
Europa 22.6812412373756 671034 3.551 0.471 0.0094 1610 Galilean
Ganymede 23.1708188980337 1070412 7.154 0.204 0.0011 1610 Galilean
Callisto 23.031771907514 1882709 16.689 0.205 0.0074 1610 Galilean
Themisto 14.8388490907373 7393216 129.87 45.762 0.2115 1975 *Themisto*
@adrn
adrn / fixaudio
Last active January 4, 2016 15:08
OS X Mavericks has some audio issues on sleep/wake.
#!/bin/bash
# see: https://discussions.apple.com/thread/5482053?start=45&tstart=0
#
# 1) Create a bin path in your home directory (mkdir ~/bin)
# 2) Add this bin to your path in your rc or shell profile (e.g., export PATH=$PATH:${HOME}/bin)
# 3) Copy and paste this gist into a file in ~/bin (e.g., curl -vs https://gist.github.com/adrn/8638334/raw 2>&1 > ~/bin/fixaudio)
# 4) If your audio ever stops working, just execute 'fixaudio' at the command line.
sudo kextunload /System/Library/Extensions/AppleHDA.kext
sudo kextload /System/Library/Extensions/AppleHDA.kext
@adrn
adrn / data.csv
Last active August 29, 2015 13:57
Data for hack day exercise.
# x y sigma_y
0.1029224715 6.1523941226 0.1816047467
0.1719426056 6.1203735252 0.2797154059
0.2261364446 6.0386732469 0.1232469666
0.2322520636 6.0468432274 0.4025523066
0.2904180608 6.2151388619 0.0880203776
0.3252579649 5.7345903217 0.6583423380
0.4424625103 6.2595326795 0.3846405824
0.4883605700 6.4047751371 0.1488420104
0.6101911742 6.4503687020 0.0235317241