Primary
astropy.io.fits.open() ⚬|Documentation|1st|20251021190715-00-⌔
File Handling and Convenience Functions — Astropy v7.2.0#astropy.io.fits.open
astropy.io.fits.open(name, mode='readonly', memmap=None, save_backup=False, cache=True, lazy_load_hdus=None, ignore_missing_simple=False, ﹡, use_fsspec=None, fsspec_kwargs=None, decompress_in_memory=False, ﹡﹡kwargs)Factory function to open a FITS file and return an
HDUListobject.Parameters:
name:str, file-like object orpathlib.PathFile to be opened.
mode:str, optionalOpen mode, ‘readonly’, ‘update’, ‘append’, ‘denywrite’, or ‘ostream’. Default is ‘readonly’.
If
nameis a file object that is already opened,modemust match the mode the file was opened with, readonly (rb), update (rb+), append (ab+), ostream (w), denywrite (rb)).
memmap: bool, optionalIs memory mapping to be used? This value is obtained from the configuration item
astropy.io.fits.Conf.use_memmap. Default isTrue.
save_backup: bool, optionalIf the file was opened in update or append mode, this ensures that a backup of the original file is saved before any changes are flushed. The backup has the same name as the original file with “.bak” appended. If “file.bak” already exists then “file.bak.1” is used, and so on. Default is
False.
cache: bool, optionalIf the file name is a URL,
download_fileis used to open the file. This specifies whether or not to save the file locally in Astropy’s download cache. Default isTrue.
lazy_load_hdus: bool, optionalTo avoid reading all the HDUs and headers in a FITS file immediately upon opening. This is an optimization especially useful for large files, as FITS has no way of determining the number and offsets of all the HDUs in a file without scanning through the file and reading all the headers. Default is
True.To disable lazy loading and read all HDUs immediately (the old behavior) use
lazy_load_hdus=False. This can lead to fewer surprises–for example with lazy loading enabled,len(hdul)can be slow, as it means the entire FITS file needs to be read in order to determine the number of HDUs.lazy_load_hdus=Falseensures that all HDUs have already been loaded after the file has been opened.Added in version 1.3.
uint: bool, optionalInterpret signed integer data where
BZEROis the central value andBSCALE == 1as unsigned integer data. For example,int16data withBZERO = 32768andBSCALE = 1would be treated asuint16data. Default isTrueso that the pseudo-unsigned integer convention is assumed.
ignore_missing_end: bool, optionalDo not raise an exception when opening a file that is missing an
ENDcard in the last header. Default isFalse.
ignore_missing_simple: bool, optionalDo not raise an exception when the SIMPLE keyword is missing. Note that io.fits will raise a warning if a SIMPLE card is present but written in a way that does not follow the FITS Standard. Default is
False.Added in version 4.2.
checksum: bool,str, optionalIf
True, verifies that bothDATASUMandCHECKSUMcard values (when present in the HDU header) match the header and data of all HDU’s in the file. Updates to a file that already has a checksum will preserve and update the existing checksums unless this argument is given a value of ‘remove’, in which case the CHECKSUM and DATASUM values are not checked, and are removed when saving changes to the file. Default isFalse.
disable_image_compression: bool, optionalIf
True, treats compressed image HDU’s like normal binary table HDU’s. Default isFalse.
do_not_scale_image_data: bool, optionalIf
True, image data is not scaled using BSCALE/BZERO values when read. Default isFalse.
character_as_bytes: bool, optionalWhether to return bytes for string columns, otherwise unicode strings are returned, but this does not respect memory mapping and loads the whole column in memory when accessed. Default is
False.
logical_as_bytes: bool, optionalWhether to return raw bytes for logical columns, otherwise boolean values are returned. When
True, columns with formatLare returned as single-byte string arrays (dtype|S1) whose elements areb'T'for True,b'F'for False, andb'\'for undefined (NULL). This allows distinguishing between False and NULL values in logical columns. Default isFalse.
ignore_blank: bool, optionalIf
True, the BLANK keyword is ignored if present. Default isFalse.
scale_back: bool, optionalIf
True, when saving changes to a file that contained scaled image data, restore the data to the original type and reapply the original BSCALE/BZERO values. This could lead to loss of accuracy if scaling back to integer values after performing floating point operations on the data. Default isFalse.
output_verify:strOutput verification option. Must be one of
"fix","silentfix","ignore","warn", or"exception". May also be any combination of"fix"or"silentfix"with"+ignore",+warn, or+exception"(e.g. ``"fix+warn"). See Verification Options for more info.
use_fsspec: bool, optionalUse
fsspec.opento open the file? Defaults toFalseunlessnamestarts with the Amazon S3 storage prefixs3://or the Google Cloud Storage prefixgs://. Can also be used for paths with other prefixes (e.g.,http://) but in this case you must explicitly passuse_fsspec=True. Use of this feature requires the optionalfsspecpackage. AModuleNotFoundErrorwill be raised if the dependency is missing.Added in version 5.2.
fsspec_kwargs:dict, optionalKeyword arguments passed on to
fsspec.open. This can be used to configure cloud storage credentials and caching behavior. For example, passfsspec_kwargs={"anon": True}to enable anonymous access to Amazon S3 open data buckets. Seefsspec’s documentation for available parameters.Added in version 5.2.
decompress_in_memory: bool, optionalBy default files are decompressed progressively depending on what data is needed. This is good for memory usage, avoiding decompression of the whole file, but it can be slow. With decompress_in_memory=True it is possible to decompress instead the whole file in memory.
Added in version 6.0.
Returns:
hdulist:HDUList
HDUListcontaining all of the header data units in the file.Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •