def hstfos_readspec(obj, channel): """Read in an HST FOS quasar spectrum """ path = datapath.hstfos_path() subpath = ((obj['NAME'].strip()).replace('+', 'p')).replace('-', 'm') filename = channel + '.fits' infile = join(path, subpath, filename) if not isfile(infile): raise IOError("{0} not found.") # print "Reading {0}.".format(infile) return fitsio.read(infile)
def starburst_filename(): path = datapath.hstfos_path() return join(path, _subpath, _starburstfile)
outstr['flux'] = hstfos_obj['flux'] outstr['error'] = hstfos_obj['error'] # write out output fits = fitsio.FITS(outfile, 'rw', clobber=True) fits.write(outstr) fits.close() # return else: warnings.warn("Can't find the file: " + repr(infile)) return # Main Program # read in qso list catfile = starburst_filename() gal = np.genfromtxt(catfile, dtype=[('gal', 'S15')]) path = datapath.hstfos_path() for thisgal in gal: specfile = thisgal['gal'] + '.txt' infile = join(path, _subpath, specfile) txt2fits(infile) #print "I'm done! Some quick check by looking at the file Numbers." #print "There are ", (subprocess.check_output("ls -l */*.txt | wc -l", shell=True)).split()[0], " .txt files" #print "and ", (subprocess.check_output("ls -l */*.fits | wc -l", shell=True)).split()[0], ".fits files"
def hstfos_qso_filename(): path = datapath.hstfos_path() filename = 'hstfos_master_visual.fits' return join(path, filename)
def rest_allspec(overwrite=False): """Load and interpolate *ALL* HST FOS/GHRS starburst spectra on to the same rest-frame wavelength grid """ path = join(datapath.hstfos_path(), _subpath, 'corrected') # check output files bands = _allinone_rest_bands for thisband in bands: # check outfiles outfile = allinone_rest_filename(thisband) if isfile(outfile) and not overwrite: print "File {0} exists. Use overwrite to overwrite it.".format(outfile) return -1 # print "Will write into these files: {0}".format(outfile) # read in the starburst catalog objs_ori = starburst_readin() nobj = objs_ori.size # make a temporary new catalog objs_dtype = [('RA', 'f8'), ('DEC', 'f8'), ('Z', 'f8'), ('gal', 'S15')] objs = np.zeros(nobj, dtype=objs_dtype) objs['RA'] = 0. objs['DEC'] = 0. objs['Z'] = 0. objs['gal'] = objs_ori['gal'] # read in master wavelength grid master_wave = (aio.allinone_wave_readin())[0]['WAVE'] master_loglam = np.log10(master_wave) nwave = master_wave.size # initialization, nobj second dimension because of NMF traditions rest_allflux = np.zeros((nwave, nobj)) rest_allivar = np.zeros((nwave, nobj)) # Wavelength wave_pos = np.array([1000., 3300.]) rest_loc = np.searchsorted(master_wave, wave_pos) newloglam = master_loglam[rest_loc[0]:rest_loc[1]] flux = np.zeros((objs.size, newloglam.size)) ivar = np.zeros((objs.size, newloglam.size)) pbar = ProgressBar(maxval=nobj).start() # Progress bar for (iobj, thisobj) in zip(np.arange(objs.size), objs): pbar.update(iobj) thisdata = readspec_rest(thisobj) inloglam = np.log10(thisdata['wave']) influx = thisdata['flux'] inivar = 1./np.power(thisdata['error'], 2) (rest_allflux[rest_loc[0]:rest_loc[1], iobj], rest_allivar[rest_loc[0]:rest_loc[1], iobj]) = specutils.interpol_spec(inloglam, influx, inivar, newloglam) #Progress bar pbar.finish() # write out print "Now I am writing everything out..." allinone_rest_writeout(objs, master_wave, rest_allflux, rest_allivar, overwrite=overwrite)
def readspec_obs(obj): obspath = join(datapath.hstfos_path(), _subpath, 'observed') obsfile = join(obspath, obj['gal']+'.fits') return (fitsio.read(obsfile))[0]
def readspec_rest(obj): restpath = join(datapath.hstfos_path(), _subpath, 'corrected') specfile = obj['gal']+'.fits' restfile = join(restpath, specfile) return (fitsio.read(restfile))[0]
def mgii_composite_filename(): path = datapath.hstfos_path() return join(path, _subpath, _mgiicompositefile)