Skip to content

Commit 48c6f95

Browse files
Merge pull request #46 from CosmoStat/fits
read fits file
2 parents 4a3619b + 2876809 commit 48c6f95

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

cs_util/cat.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,39 @@ def write_fits_BinTable_file(
168168
hdu_list.writeto(output_path, overwrite=True)
169169

170170

171+
def read_fits_to_dict(file_path):
172+
"""Read Fits To Dict.
173+
174+
Read FITS file and return dictionary.
175+
176+
Parameters
177+
----------
178+
file_path : str
179+
input file path
180+
181+
Returns
182+
-------
183+
dict
184+
file content
185+
186+
Raises
187+
------
188+
IOError
189+
if input file is not found
190+
"""
191+
if not os.path.exists(file_path):
192+
raise IOError(f"Input file '{file_path}' not found")
193+
194+
hdu_list = fits.open(file_path)
195+
data_input = hdu_list[1].data
196+
col_names = hdu_list[1].data.dtype.names
197+
data = {}
198+
for col_name in col_names:
199+
data[col_name] = data_input[col_name]
200+
201+
return data
202+
203+
171204
def bin_edges2centers(bin_edges):
172205
"""Bin Edges To Centers.
173206

cs_util/plots.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def savefig(fname, close_fig=True):
4343
fname : str
4444
output file name
4545
close_fig : bool, optional
46-
closes figure if True (default)
46+
closes figure if ``True`` (default); chose ``False``
47+
to display figure in a jupyter notebook
4748
4849
"""
4950
plt.savefig(fname, facecolor="w", bbox_inches="tight")

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ authors = ["Martin Kilbinger <[email protected]>"]
66
readme = "README.md"
77

88
[tool.poetry.dependencies]
9-
python = ">=3.9,<3.12"
10-
astropy = "5.2"
9+
python = ">=3.9,<3.13"
10+
astropy = "^5.0"
1111
camb = "1.5.4"
1212
datetime = "^5.5"
1313
numpy = "^1.26.4"

0 commit comments

Comments
 (0)