def loadSingle(sou, line): recs = loadFromFiles('.', 's') recs = select(recs, 'object', sou) recs = select2(recs, 'line', line) recs = select2(recs, 'OBSMODE', 'DSW SIG') ra, deg = [], [] for r in recs: w = WCS(r[0].header) coord = w.wcs_pix2world(np.array([[0, 0, 0]]), 0, ra_dec_order=True) ra.append(coord[0][0]) deg.append(coord[0][1]) axr = np.unique(np.array(ra)) axd = np.unique(np.array(deg)) axr.sort() axd.sort() arr = [[[] for i in range(len(axd))] for i in range(len(axr))] for i in range(len(ra)): arr[np.where(axr == ra[i])[0][0]][np.where( axd == deg[i])[0][0]].append(recs[i]) arr = np.array(arr) import numpy.ma as ma spec = 32768 cube = ma.array(np.zeros((arr.shape[0], arr.shape[1], spec))) systemp = [] spec = 32768 systemp = [] x = 0 y = 0 val = arr[x, y] d, w = [], [] d, w = [], [] for dat in val: d.append(dat[0].data) w.append(dat[0].header['tsys'] * dat[0].header['inttime']) systemp.append(w[-1]) d = np.array(d) w = np.array(w) cube[x, y] = np.average(d, axis=0, weights=w) spec = cube[0, 0] return spec