Skip to content

Commit 425e41e

Browse files
Merge pull request #47 from CosmoStat/develop
version 0.1.1
2 parents 473deb8 + 20ac590 commit 425e41e

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

cs_util/cat.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@
1010

1111
import os
1212
from datetime import datetime
13+
from importlib.metadata import version
14+
1315
from astropy.io import fits
1416
from astropy.io import ascii
1517
from astropy.table import Table
1618

1719

18-
def write_header_info_sp(primary_header, name="unknown", version="unknown"):
20+
def write_header_info_sp(
21+
primary_header,
22+
software_name="cs_util",
23+
software_version="unknown",
24+
author=None,
25+
):
1926
"""Write Header Info sp_validation.
2027
2128
Write information about software and run to FITS header
@@ -24,27 +31,37 @@ def write_header_info_sp(primary_header, name="unknown", version="unknown"):
2431
----------
2532
primary_header : dict
2633
FITS header information
27-
name : str
28-
software name, default is 'unknown'
29-
version : str
30-
version, default is 'unknown'
34+
software_name : str, optional
35+
software name; default is "cs_util"
36+
software_version : str, optional
37+
version; default is current cs_util version
38+
author : str, optional
39+
author name; if ``None`` (default), read from os.environ["USER"],
40+
or if not set in env, "unknown"
3141
3242
Returns
3343
-------
3444
dict
3545
updated FITS header information
3646
3747
"""
38-
if "USER" in os.environ:
39-
author = os.environ["USER"]
48+
if software_version is None:
49+
software_version = version("cs_util")
50+
51+
if author is None:
52+
if "USER" in os.environ:
53+
author = os.environ["USER"]
54+
else:
55+
author = "unknown"
4056
else:
4157
author = "unknown"
58+
4259
primary_header["AUTHOR"] = (author, "Who ran the software")
43-
primary_header["SOFTNAME"] = (name, "Name of the software")
44-
primary_header["SOFTVERS"] = (version, "Version of the software")
60+
primary_header["SOFTNAME"] = (software_name, "Software name")
61+
primary_header["SOFTVERS"] = (software_version, "software version")
4562
primary_header["DATE"] = (
4663
datetime.now().strftime("%Y-%m-%d_%H-%M-%S"),
47-
"When it was started",
64+
"Creation date",
4865
)
4966

5067
return primary_header

0 commit comments

Comments
 (0)