Skip to content

Instantly share code, notes, and snippets.

View PBarmby's full-sized avatar

Pauline Barmby PBarmby

View GitHub Profile
@PBarmby
PBarmby / LocalGalaxyVisualizer.ipynb
Created July 13, 2017 14:22
Galaxy visualization example
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import astropy.wcs as wcs
import astropy.io.fits as fits
import matplotlib.pyplot as plt
from matplotlib import cm
import scipy.stats as sps
from astropy.table import Table, Column, vstack
from astropy.coordinates import SkyCoord, Distance, Angle
from astropy import units as u
from matplotlib.ticker import NullFormatter
@PBarmby
PBarmby / histogram_with_sidecars.py
Created July 29, 2015 19:37
Uses numpy.histogram2d to make 2-D and associated 1-D histograms. Also useful for explicating numpy axis behaviour.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import NullFormatter
# based on http://www.astrobetter.com/blog/2014/02/10/visualization-fun-with-python-2d-histogram-with-1d-histograms-on-axes/
def fancy_2d_plot(xvals, yvals):
'''makes a histogran with sidecars:
2D histogram shown as an image in center, with
1D histograms corresponding to the 2 axes along each side
@PBarmby
PBarmby / make_latex_unc_tab.py
Created January 5, 2015 00:28
Deals with making a LaTeX table with uncertainties and correct number of significant figures
from astropy.table import Table, Column, join, vstack
from uncertainties import ufloat
import astropy.units as u
def uncert_str(tab_row, col_name, value_fmt):
''' format tab_row[col_name] single table row in LaTeX $num \pm unc$ format
input: tab_row: single row from an astropy table
col_name: name of column to be extracted and formatted
value_fmt: format for string output
output:
@PBarmby
PBarmby / Class_list_viewer.py
Created August 28, 2014 15:21
Class list viewer
"""
show_student_pix:
Uses a Western University class list file (typically named .rcl
but really .csv) and the accompanying set of jpg student ID
pictures to display a few random pictures/names at a time.
Designed for use in IPython notebook.
2014-08-28, P. Barmby
@PBarmby
PBarmby / tab_trans.py
Created May 1, 2014 15:09
Transpose tables in astropy
import numpy as np
from astropy.table import Table, Column
def transpose_table(tab_before, id_col_name='ID'):
'''Returns a copy of tab_before (an astropy.Table) with rows and columns interchanged
id_col_name: name for optional ID column corresponding to
the column names of tab_before'''
# contents of the first column of the old table provide column names for the new table
# TBD: check for duplicates in new_colnames & resolve
new_colnames=tuple(tab_before[tab_before.colnames[0]])
@PBarmby
PBarmby / Least-squares special cases.ipynb
Created March 17, 2014 16:02
ipython notebook: least-squares special cases
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PBarmby
PBarmby / chi-squared test, confidence intervals.ipynb
Created March 12, 2014 23:58
ipython notebook for demonstrating chi^2 test for goodness of fit, some confidence intervals
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PBarmby
PBarmby / least-squares_chi-squared.ipynb
Created March 12, 2014 23:55
ipython notebook for demonstrating least-squares fitting and chi^2
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PBarmby
PBarmby / gal_radii_pb.py
Created March 4, 2014 21:16
Computes deprojected galactocentric distances
from astropy.coordinates import ICRS, Galactic, Distance, Angle
from astropy import units as u
import math as mt
import numpy as np
from astropy.table import Table, Column
# inspired by
#http://idl-moustakas.googlecode.com/svn-history/r560/trunk/impro/hiiregions/im_hiiregion_deproject.pro
def correct_rgc(coord, glx_ctr=ICRS('00h42m44.33s +41d16m07.5s'), glx_PA=Angle('37d42m54s'), glx_incl=Angle('77.5d'), glx_dist=Distance(783,unit=u.kpc)):
'''computes deprojected galactocentric distance for an object at coord,