Skip to content

Instantly share code, notes, and snippets.

View barentsen's full-sized avatar

Geert Barentsen barentsen

View GitHub Profile
@barentsen
barentsen / gist:46a4b44223ae05377702
Created January 28, 2015 18:37
Silly hack to read the WCS of a Kepler target file into astropy.wcs
"""Reads the WCS for the raw pixel counts into astropy.wcs"""
from astropy.io import fits
from astropy.wcs import WCS
f = fits.open('tpf_dstn.fits.gz')
funny_keywords = {'1CTYP4': 'CTYPE1',
'2CTYP4': 'CTYPE2',
'1CRPX4': 'CRPIX1',
'2CRPX4': 'CRPIX2',
'1CRVL4': 'CRVAL1',
@barentsen
barentsen / coalesce.py
Created April 13, 2015 23:21
Example coalesce() function for use with astropy's MaskedColumn objects
def coalesce(columns):
"""Coalesces masked columns.
Parameters
----------
columns : iterable of type `MaskedColumn`
Returns
-------
column : coalesced result
@barentsen
barentsen / plot-k2-centroids.py
Created December 10, 2015 23:27
Creates a plot of a K2 target's centroids, with and without mid-campaign offset.
"""Creates a plot of a K2 target's centroids, with and without mid-campaign offset.
"""
import numpy as np
import matplotlib.pyplot as pl
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import seaborn
from astropy.io import fits
@barentsen
barentsen / gist:5488680
Created April 30, 2013 13:27
Numpy: speed of np.ptp() vs np.max()-np.min()
In [1]: import numpy as np
In [2]: a = np.random.random(1e2)
In [3]: timeit a.ptp()
100000 loops, best of 3: 8.3 us per loop
In [4]: timeit a.max()-a.min()
100000 loops, best of 3: 9.31 us per loop
@barentsen
barentsen / 2015-apj-papers-not-on-arxiv.txt
Created March 4, 2016 16:40
Bibcodes and titles of ApJ papers published in 2015 that have not been uploaded to arXiv (yet?)
2015ApJ...803...27P Prognosis of Gles of Relativistic Solar Protons
2015ApJ...803L...7L Radial and Azimuthal Oscillations of Halo Coronal Mass Ejections in the Sun
2015ApJS..217...10M A Laboratory Study of C<SUB>3</SUB>H<SUP>+</SUP> and the C<SUB>3</SUB>H Radical in Three New Vibrationally Excited <SUP>2</SUP>Σ States Using a Pin-Hole Nozzle Discharge Source
2015ApJ...799...31F Modulation of Galactic Cosmic Rays Observed at L1 in Solar Cycle 23
2015ApJ...800...32L Hercules X-1: Using Eclipse to Measure the X-Ray Corona
2015ApJ...798...72S Benzene Formation on Interstellar Icy Mantles Containing Propargyl Alcohol
2015ApJ...798...36S Observations of Warm Carbon Chain Chemistry in NGC 3576
2015ApJ...799...80G Diffusive Shock Acceleration of High-energy Charged Particles at Fast Interplanetary Shocks: A Parameter Survey
2015ApJ...800...87C Whistler Turbulence Forward Cascade versus Inverse Cascade: Three-dimensional Particle-in-cell Simulations
2015ApJ...807..164N Properties of Cyclotron Lines in a Line-forming R
@barentsen
barentsen / median-radius-of-kepler-exoplanets.py
Created April 1, 2016 18:53
Compute the median radius of all confirmed Kepler planets using Python and the NASA Exoplanet Archive.
"""Compute the median radius of all confirmed Kepler planets."""
import pandas as pd
# Fetch the table of confirmed exoplanets from NExSci
planets = pd.read_csv('http://exoplanetarchive.ipac.caltech.edu/cgi-bin/nstedAPI/nph-nstedAPI?table=exoplanets&select=*')
# Select the Kepler planets
kepler_planets = planets[planets.pl_kepflag == 1]
# Do your statistics
print(kepler_planets.pl_rade.median())
@barentsen
barentsen / compute-arxiv-usage-rates-by-journal.py
Created March 4, 2016 18:12
Computes the fraction of astronomical papers that are uploaded to arXiv as a function of their journal.
"""Computes the arXiv usage rates as a function of journal.
This is a rough script used for the sake of providing the numbers for one tweet:
https://twitter.com/GeertHub/status/705788341531201537
I may turn this into a webservice that reports on the use of arXiv every month?
What do you think?
"""
import ads
import json
@barentsen
barentsen / get-exoplanet-discovery-dates.py
Created September 15, 2016 17:32
Obtain discovery dates for all confirmed exoplanets in the NASA Exoplanet Archive
"""Obtain discovery dates for all confirmed exoplanets.
This script combines the NASA Exoplanet Archive and ADS API to obtain the
publication date for the discovery paper of all the confirmed exoplanets.
Author: Geert Barentsen
"""
import requests
import pandas as pd
@barentsen
barentsen / c9-superstamp-polygons.json
Created September 16, 2016 20:50
c9-superstamp-polygons.json
{
"channels": {
"31": {
"dec": [
-28.031356156487746,
-27.755350022942594,
-28.854298809320532,
-29.131659330859346,
-28.031356156487746
],
@barentsen
barentsen / First-try-at-PSF-fitting-of-TESS-data-using-Astropy-Photutils.ipynb
Last active November 2, 2016 16:29
First try at PSF fitting of TESS data using Astropy Photutils
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.