from IPython.display import Image Image('question.jpg') %matplotlib inline import numpy as np import matplotlib.pyplot as plt plt.rcParams['figure.figsize'] = (8, 6) from astropy.io import fits help(plt.plot) dir(fits) help(fits.open) %ls data ls data hdus = fits.open('data/mystery-picture.fits') hdus ihdu = hdus[0] ihdu len(hdus) len("Carlos é magnífico") len(ihdu) 2 + 3 "David Hasselhoff en alemán significa impresionante" (-3.4 + 2j) * (4.1 - 0.8j) print(ihdu) print ihdu dir(ihdu) carlos = ihdu.data() carlos = ihdu.data carlos == hdus[0].data np.all(carlos == hdus[0].data) carlos print(carlos) carlos.shape carlos.dtype plt.imshow(carlos) plt.set_cmap('grey') plt.imshow(carlos) plt.set_cmap('gray') mariano = carlos[400:,:] mariano.shape plt.imshow(mariano, cmap='gray') from skimage.filter import canny matteo = canny(mariano) matteo.shape matteo.dtype plt.imshow(matteo) hdus = fits.open("data/evt2.fits") print(hdus) hdus.info() thdu = hdus[1] print(thdu.columns) coldata = thdu.data type(coldata) coldata.size coldata.shape coldata[0] times = coldata.field('time') times.shape times[0] dt = times - times[0] dt[0:10] print(thdu.header['TIMEDEL'], thdu.header['EXPTIME']) print("timedel={} exptime={}".format(thdu.header['TIMEDEL'], thdu.header['EXPTIME'])) print "timedel=%f exptime=%f" % (thdu.header['TIMEDEL'], thdu.header['EXPTIME']) dt[:20] / thdu.header['EXPTIME'] dt[0:20] / thdu.header['TIMEDEL'] (dt[:20] / thdu.header['TIMEDEL']).astype(np.int) Image(filename='wat.jpg') dt[-1] vals = np.histogram(dt, bins=100) vals Image('question.jpg') (y,x) = vals print(y.shape) print(x.shape) plt.plot(x[:-1], y) plt.hist(dt, bins=100) cvals = np.fft.fft(y) print("shape={}".format(cvals.shape)) print("data type={}".format(cvals.dtype)) avals = np.abs(cvals)**2 print("data type={}".format(avals.dtype)) plt.plot(avals) plt.yscale('LOG') plt.xlim(-5, 105) Image('question.jpg') tstep = thdu.header['TIMEDEL'] freqs = np.fft.fftfreq(y.size, tstep) idx = np.argsort(freqs) plt.plot(freqs[idx], avals[idx]) plt.yscale('LOG') def diego(times, tstep): """What Would Diego Do?""" fft = np.fft.fft(times) real = np.abs(fft)**2 freqs = np.fft.fftfreq(times.size, tstep) idx = np.argsort(freqs) return (freqs[idx], real[idx]) (a,b) = diego(y - y.mean(), tstep) plt.plot(a, b) stimes = fits.open("data/swift.evt")[1].data.field('time') Image(filename='wat.jpg') dts = stimes - stimes[0] print(dts[0:10]) print(dts.size) print(dts.dtype) test = fits.open("data/lc.fits") test.info() test[1].columns t = test[1].data.field('time') r = test[1].data.field('count_rate') plt.plot(t, r) t - t[0] (x,y) = diego(r, t[1] - t[0]) plt.plot(x, y) plt.plot(x[x >= 0], y[x >= 0]) idx = x >= 0 plt.plot(x[idx], y[idx]) plt.yscale('log') idx[0:10] idx[-11:-1] np.where((x > 0.003) & (x < 0.004)) i, = np.where((x > 0.003) & (x < 0.004)) for ii in i[0:7]: print("x={:e} y={:8.1f}".format(x[ii], y[ii])) rone = r.copy() rone[r > 0] = 1.0 plt.plot(t, rone) (xone,yone) = diego(rone, t[1] - t[0]) plt.plot(x[x>=0], y[x>=0]) plt.plot(xone[xone>=0], yone[xone>=0]) plt.yscale('log') plt.text(0.001, 5e7, 'data', size=20, color='blue') plt.text(0.003, 5e7, 'gti', size=20, color='green')