Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tekknolagi
Created March 8, 2018 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekknolagi/03f10b1137917baad3c0e261e9a5e973 to your computer and use it in GitHub Desktop.
Save tekknolagi/03f10b1137917baad3c0e261e9a5e973 to your computer and use it in GitHub Desktop.
import itertools
import math
import matplotlib.pyplot as plt
import numpy as np
import tufte
from collections import namedtuple
SNPoint = namedtuple('SNPoint', ['sn_name', 'z_cmb', 'mu_mag', 'err_mu',
'sample', 'flag'])
def import_data(fname):
with open(fname, 'r') as f:
lines = f.readlines()
def fmt_line(line):
return (line[0], float(line[1]), float(line[2]), float(line[3]),
int(line[4]), line[5])
# Ignore comments
return [SNPoint(*fmt_line(x.split())) for x in lines if x[0] != '#']
if __name__ == '__main__':
print import_data('datafile.txt')[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment