Skip to content

Instantly share code, notes, and snippets.

@taldcroft
Last active September 10, 2017 01:28
Show Gist options
  • Save taldcroft/547c0b6e0ae15e0c970d to your computer and use it in GitHub Desktop.
Save taldcroft/547c0b6e0ae15e0c970d to your computer and use it in GitHub Desktop.
IPython startup magic
# ~/.ipython/profile_default/startup/10-mystartup.py
import numpy as np
ip = get_ipython()
def import_astropy(self, arg):
ip.ex('import astropy')
ip.ex('print(astropy.__version__)')
ip.ex('from astropy.io import ascii')
ip.ex('from astropy import table')
ip.ex('from astropy.table import Table, QTable, Column, MaskedColumn')
ip.ex('from astropy.table.table_helpers import TimingTables, simple_table, complex_table')
ip.ex('from astropy.time import Time, TimeDelta')
ip.ex('from astropy.coordinates import SkyCoord, ICRS, FK4, FK5')
ip.ex('import astropy.units as u')
try:
import line_profiler
ip.define_magic('lprun', line_profiler.magic_lprun)
except ImportError:
pass
ip.define_magic('astro', import_astropy)
@keflavich
Copy link

This is great. I keep mine in a profile so that these all get loaded with --profile=astropy automatically. I like this approach, though, as it allows you to have a lightweight startup by default.

@saimn
Copy link

saimn commented Sep 23, 2015

Very useful, thanks for sharing this !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment