Coverage for python/lsst/obs/base/formatters/fitsGeneric.py: 91%
17 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-16 02:16 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-16 02:16 -0700
1# This file is part of obs_base.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22__all__ = ("FitsGenericFormatter",)
24import os.path
26from lsst.daf.butler.formatters.file import FileFormatter
29class FitsGenericFormatter(FileFormatter):
30 """Interface for reading and writing objects that support the standard
31 afw I/O readFits/writeFits methods.
32 """
34 supportedExtensions = frozenset({".fits", ".fits.gz", ".fits.fz", ".fz", ".fit"})
35 extension = ".fits"
37 def _readFile(self, path, pytype):
38 """Read a file from the path in FITS format.
40 Parameters
41 ----------
42 path : `str`
43 Path to use to open the file.
44 pytype : `class`
45 Class to use to read the FITS file.
47 Returns
48 -------
49 data : `object`
50 Instance of class `pytype` read from FITS file. None
51 if the file could not be opened.
52 """
53 if not os.path.exists(path): 53 ↛ 54line 53 didn't jump to line 54, because the condition on line 53 was never true
54 return None
55 if self.fileDescriptor.parameters:
56 try:
57 return pytype.readFitsWithOptions(path, options=self.fileDescriptor.parameters)
58 except AttributeError:
59 pass
61 return pytype.readFits(path)
63 def _writeFile(self, inMemoryDataset):
64 """Write the in memory dataset to file on disk.
66 Parameters
67 ----------
68 inMemoryDataset : `object`
69 Object to serialize.
71 Raises
72 ------
73 Exception
74 The file could not be written.
75 """
76 inMemoryDataset.writeFits(self.fileDescriptor.location.path)