Ejemplo n.º 1
0
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())