diff --git a/heracles/catalog/fits.py b/heracles/catalog/fits.py index 5d611aa..ecd0fcf 100644 --- a/heracles/catalog/fits.py +++ b/heracles/catalog/fits.py @@ -38,32 +38,37 @@ def rowfilter(array, expr): class FitsCatalog(CatalogBase): """flexible reader for catalogues from FITS files""" - def __init__(self, filename, *, columns=None, ext=None): + def __init__(self, path, *, columns=None, ext=None): """create a new FITS catalogue reader Neither opens the FITS file nor reads the catalogue immediately. """ super().__init__() - self._filename = filename + self._path = path self._columns = columns self._ext = ext def __copy__(self): """return a copy of this catalog""" other = super().__copy__() - other._filename = self._filename + other._path = self._path other._columns = self._columns other._ext = self._ext return other def __repr__(self): """string representation of FitsCatalog""" - s = self._filename + s = self._path if self._ext is not None: s = s + f"[{self._ext!r}]" return s + @property + def path(self): + """path of the FITS file""" + return self._path + def hdu(self): """HDU for catalogue data""" @@ -77,7 +82,7 @@ def hdu(self): if hdu is None: # need to open the fits file explicitly, not via context manager # we will not close it, to keep the HDU alive - fits = fitsio.FITS(self._filename) + fits = fitsio.FITS(self._path) # but ensure fits gets closed in case of error try: diff --git a/tests/test_catalog.py b/tests/test_catalog.py index ab04d4e..bfccb6a 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -392,13 +392,13 @@ def test_fits_catalog(rng, tmp_path): ra = rng.uniform(-180, 180, size=size) dec = rng.uniform(-90, 90, size=size) - filename = str(tmp_path / "catalog.fits") + path = tmp_path / "catalog.fits" - with fitsio.FITS(filename, "rw") as fits: + with fitsio.FITS(path, "rw") as fits: fits.write(None) fits.write_table([ra, dec], names=["RA", "DEC"], extname="MYEXT") - catalog = FitsCatalog(filename) + catalog = FitsCatalog(path) assert isinstance(catalog, Catalog) @@ -441,7 +441,7 @@ def test_fits_catalog(rng, tmp_path): assert isinstance(copied, FitsCatalog) assert copied is not catalog - assert copied._filename == catalog._filename + assert copied._path == catalog._path assert copied._columns == catalog._columns assert copied._ext == catalog._ext @@ -457,13 +457,13 @@ def test_fits_catalog_caching(rng, tmp_path): ra = rng.uniform(-180, 180, size=size) dec = rng.uniform(-90, 90, size=size) - filename = str(tmp_path / "cached.fits") + path = tmp_path / "cached.fits" - with fitsio.FITS(filename, "rw") as fits: + with fitsio.FITS(path, "rw") as fits: fits.write(None) fits.write_table([ra, dec], names=["RA", "DEC"], extname="MYEXT") - catalog = FitsCatalog(filename) + catalog = FitsCatalog(path) hdu = catalog.hdu() assert catalog.hdu() is hdu @@ -472,7 +472,7 @@ def test_fits_catalog_caching(rng, tmp_path): _fits = hdu._FITS - assert _fits.filename() == filename + assert _fits.filename() == str(path) del hdu gc.collect()