Skip to content

Commit d965ee1

Browse files
authored
Fix skymap reading on Windows (#571)
* Fix reading skymap windows * Use unlink instead of remove * Satisfy pylint
1 parent ad6afef commit d965ee1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/hats/io/file_io/file_io.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
import tempfile
45
from collections.abc import Generator
56
from io import BytesIO
@@ -255,11 +256,14 @@ def read_fits_image(map_file_pointer: str | Path | UPath) -> np.ndarray:
255256
value at each index corresponds to the number of objects found at the healpix pixel.
256257
"""
257258
map_file_pointer = get_upath(map_file_pointer)
258-
with tempfile.NamedTemporaryFile() as _tmp_file:
259+
with tempfile.NamedTemporaryFile(delete=False) as _tmp_file:
259260
with map_file_pointer.open("rb") as _map_file:
260-
map_data = _map_file.read()
261-
_tmp_file.write(map_data)
262-
return Skymap.from_fits(_tmp_file.name).values
261+
_tmp_file.write(_map_file.read())
262+
tmp_path = _tmp_file.name
263+
try:
264+
return Skymap.from_fits(tmp_path).values
265+
finally:
266+
os.unlink(tmp_path)
263267

264268

265269
def write_fits_image(histogram: np.ndarray, map_file_pointer: str | Path | UPath):

0 commit comments

Comments
 (0)