def text_write(spec: Spectrum, path: str, filename: str) -> None: """ Writes an ASCII formatted spec file with appropriate header information. Format can be read in by spec_load_write.text_load() method :param spec: spectrum to be written :param path: /path/to/write/ :param filename: filename to write in path :type spec: Spectrum :type path: str :type filename: str :return: None :rtype: None """ dirCheck(path) with open(join(path, filename), 'w') as outfile: header = "namestring=%s,z=%f,gmag=%f%s" % (spec.getNS(), spec.getRS(), spec.getGmag(), os.linesep) outfile.writelines(header) fieldnames = ["wavelength", "flux density", "error"] writer = DictWriter(outfile, fieldnames=fieldnames) writer.writeheader() writer.writerows(spec.lineDictList())
def binned_source_to_rest(spec: Spectrum, z: float = None) -> Spectrum: """ Takes in a binned source spectrum and shifts it to rest frame. WARNING: Assumes desired wavelengths will be integer values and called (int) on them as a result. If integer wavelengths are NOT desired, this method will need to be modified. :param spec: Binned source spectrum :type spec: Spectrum :param z: Original redshift. If not passed, it will call spec.getRS() and use that value. :type z: float :return: Rest frame spectrum :rtype: Spectrum """ spec = spec.cpy() z = z or spec.getRS() wls = spec.getWavelengths() n = len(wls) for wl in wls: spec[int(wl / (1 + z))] = spec[wl] del spec[wl] return spec