Skip to content

Instantly share code, notes, and snippets.

Avatar

Pauline Barmby PBarmby

View GitHub Profile
@PBarmby
PBarmby / LocalGalaxyVisualizer.ipynb
Created Jul 13, 2017
Galaxy visualization example
View LocalGalaxyVisualizer.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View completeness_2d_hist.py
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 Jul 29, 2015
Uses numpy.histogram2d to make 2-D and associated 1-D histograms. Also useful for explicating numpy axis behaviour.
View histogram_with_sidecars.py
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 Jan 5, 2015
Deals with making a LaTeX table with uncertainties and correct number of significant figures
View make_latex_unc_tab.py
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:
View Class_list_viewer.py
"""
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
Transpose tables in astropy
View tab_trans.py
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 Mar 17, 2014
ipython notebook: least-squares special cases
View Least-squares special cases.ipynb
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 Mar 12, 2014
ipython notebook for demonstrating chi^2 test for goodness of fit, some confidence intervals
View chi-squared test, confidence intervals.ipynb
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 Mar 12, 2014
ipython notebook for demonstrating least-squares fitting and chi^2
View least-squares_chi-squared.ipynb
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 Mar 4, 2014
Computes deprojected galactocentric distances
View gal_radii_pb.py
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,