Move the management of the name in the read method
@@ -1234,12 +1234,8 @@ class MapDataset(Dataset):
@classmethod
def _read_lazy(cls, name, filename, cache, format=format):
- ds_name = make_name(name)
- # hdulist = fits.open(str(make_path(filename)))
- # if 'NAME' in hdulist[0].header and name is None:
- # ds_name = hdulist[0].header['NAME']
- # hdulist.close()
- kwargs = {"name": ds_name}
+ name = make_name(name)
+ kwargs = {"name": name}
try:
kwargs["gti"] = GTI.read(filename)
except KeyError:
@@ -1299,16 +1295,17 @@ class MapDataset(Dataset):
Map dataset.
"""
+ if name is None:
+ header = fits.getheader(filename)
+ name = header.get("NAME", name)
+ ds_name = make_name(name)
+
if lazy:
return cls._read_lazy(
- name=name, filename=filename, cache=cache, format=format
+ name=ds_name, filename=filename, cache=cache, format=format
)
else:
with fits.open(str(make_path(filename)), memmap=False) as hdulist:
- if name is None:
- header = fits.getheader(filename)
- name = header.get("NAME", name)
- ds_name = make_name(name)
return cls.from_hdulist(hdulist, name=ds_name, format=format)
@classmethod
