Skip to content

Instantly share code, notes, and snippets.

View andycasey's full-sized avatar

Andy Casey andycasey

View GitHub Profile
@andycasey
andycasey / normalised_citations.py
Last active September 17, 2015 20:28
Top-ranked astronomers by normalised citations
import os
import cPickle as pickle
import matplotlib.pyplot as plt
import ads
max_retries = 5
N_top_papers = 1000
@andycasey
andycasey / stromlo.py
Last active October 12, 2015 00:06
Query articles published last month by ANU RSAA researchers
"""
Retrieve all articles authored by ANU RSAA researchers in the previous month.
"""
__author__ = 'Andy Casey <arc@ast.cam.ac.uk>'
# You will also need PyPDF2 (use `pip install pypdf2`) for this example in order
# to manipulate PDFs.
# Example usage: python stromlo.py (to run previous month)
import numpy as np
from astropy.table import Table
import thecannon as tc
# The Ness et al. (2015) data is accessible from [URL]
labelled_set = Table.read("Ness_2015_labelled.csv")
normalized_flux = np.memmap("Ness_2015_normalized_flux.memmap",
mode="r", dtype=float)
normalized_ivar = np.memmap("Ness_2015_normalized_ivar.memmap",
@andycasey
andycasey / gist:7f322bec408da5d80106
Created January 12, 2016 17:25
finite_abundances.py
In [30]: ok = image[1].data["physical"]
In [31]: elements = [_ for _ in image[1].data.dtype.names if _.endswith("_H") and _ not in ("SRC_H", "PARAM_M_H")]
In [32]: for element in elements:
print(element, np.sum(np.isfinite(image[1].data[element][ok])))
....:
('AL_H', 99127)
('CA_H', 99127)
('C_H', 99127)
@andycasey
andycasey / jason_example.py
Created September 20, 2016 14:21
Cao example
import os
import numpy as np
from astropy.table import Table
from astropy.io import fits
import AnniesLasso as tc
training_set_path = "example_DR10/reference_labels.csv"
import numpy as np
def distance_to_nearest_major_city(database, postcodes,
major_city_postcodes=None):
"""
Calculate the estimate distance between a postcode and the nearest major
city.
# Script to monitor and restart wireless access point when needed
maxPloss=10 #Maximum percent packet loss before a restart
restart_networking() {
# Add any commands need to get network back up and running
/etc/init.d/networking restart
#only needed if your running a wireless ap
wget https://data.sdss.org/sas/dr14/apogee/spectro/redux/r8/stars/l31c/l31c.2/cannon/allStarCannon-l31c.2.fits
wget https://data.sdss.org/sas/dr14/apogee/spectro/redux/r8/stars/l31c/l31c.2/allStar-l31c.2.fits
import numpy as np
from scipy.spatial import Delaunay
training_set_labels = #.... from somewhere else
test_set_labels = np.atleast_2d(test_set_labels)
# construct convex hull of the training set using all labels
hull = Delaunay(training_set_labels)
import numpy as np
from astroquery.gaia import Gaia
import matplotlib.pyplot as plt
def astrometry_covariance_matrix(source):
"""
Construct a covariance matrix for a 5-parameter astrometric solution
measured by Gaia for a single source.