from_file

astrodata.from_file(*args, **kwargs)[source]

Return an AstroData object from a file.

Parameters:

source (str, os.PathLike or HDUList) – The path to the file or the HDUList object. If a string is passed, it will be treated as a path to a file.

Returns:

An instantiated object. It will be a subclass of AstroData.

Return type:

AstroData

Notes

For implementation details, see get_astro_data().

This function is a wrapper around the factory method get_astro_data(), and uses the default factory instance at factory. If you want to override the default factory, you can create a new instance of AstroDataFactory and use its methods directly, or assign it to factory.

Example

>>> from astrodata import from_file
>>> ad = from_file("path/to/file.fits")

Alternatively, you can use an HDUList object:

>>> from astropy.io import fits
>>> hdulist = fits.open("path/to/file.fits")
>>> ad = from_file(hdulist)

Which can be useful for inspecting input before creating the AstroData object. This will not use the normal AstroData lazy-loading mechanism, however.