Details
-
Type:
RFC
-
Status: Adopted
-
Resolution: Unresolved
-
Component/s: DM
-
Labels:None
Description
Many of our afw.image FITS I/O methods have many overloads that really only differ (when argument defaults are considered) in the order that arguments are passed. The FITS-reading image constructors have at least 3 overloads, for filename vs. MemFileManager vs afw::fits::Fits. All of the writeFits methods have an extra factor of two for compression options, for a total of 6 writeFits overloads per image type. We also have static readFits methods that duplicate the constructors (in order to provide an consistent interface with the afw::table classes, I suspect), and dedicated FITS-reading helper classes like ImageFitsReader.
Having so many overloads is a problem in its own right, as there's a lot of duplication of both docs and code, but this is a more immediate problem for RFC-817, which would temporarily double the number of most of these overloads (deprecating the existing ones that unnecessarily use shared_ptr while adding new ones that don't).
I'm proposing here that we deprecate and eventually remove all of these from C++, except:
- the FITS-reading helper classes (these are already what we use in Butler)
- a single writeFits method per image class, which would take a afw::fits::Fits instance as its first argument, then image compression arguments (defaulted) and optional header-metadata arguments (defaulted). C++ code that wanted to use a filename or MemFileManager would be expected to (trivially) construct an afw::fits::Fits instance from those.
In Python, we would retain separate writeFits, constructor overloads for filename and afw::fits::Fits (via lambdas in the pybind11 layer), since filename is by far the most common use. All other arguments would be made keyword-only, so their order in the declaration is irrelevant (and incidentally, most calls will get more readable and less error-prone; calls with >3 positional arguments start to worry me). All readFits static methods would be removed.
If this ticket is adopted, I'd want to implement it at the same time as (the rest of) RFC-817, so we'd end up deprecating essentially all of the existing C++ signatures at one time and adding one that replaces all of them (but, I think, breaking very little existing code, especially in Python).
Attachments
Issue Links
- is triggering
-
DM-35062 Fix excessive overloading in afw.image FITS methods
- To Do
- relates to
-
RFC-817 Discourage shared_ptr arguments for functions that can use raw pointers
- Implemented
- mentioned in
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
-
Page Loading...
I do use Exposure.readFits(filename) (and SourceCatalog.readFits(filename)) in python when mucking about with tests, or trying to understand why a given file has particular contents. So long as there is a way to do that (easily discoverable, as Krzysztof says), I'm happy.
If this is just a proposal about the Image class, then I don't think I've ever used those methods directly, myself.