Coverage for src/susi/io/multi_hdu_reader.py: 29%
21 statements
« prev ^ index » next coverage.py v7.5.0, created at 2025-08-22 09:20 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2025-08-22 09:20 +0000
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Module provides `MultiHDUReader`
6@author: hoelken
7"""
9from astropy.io import fits
11from src.susi.io import Fits
14class MultiHDUReader:
15 """
16 ## MultiHDUWriter
17 Writes the given datasets / header(s) to individual HDUs in a FITS file
18 """
20 def __init__(self, path):
21 #: path of the fits to read/write
22 self.path = path
23 #: list of the data.
24 self.data = []
25 #: List of headers
26 self.headers = []
28 def read(self, fits_list=False):
29 """
30 Reads the FITS file and populates the data and headers attributes.
32 ### Returns
33 `self` or a list of Fits objects if `fits_list` is True.
34 """
35 hdul = fits.open(self.path)
36 for i in range(0, len(hdul)):
37 self.data.append(hdul[i].data)
38 self.headers.append(hdul[i].header)
40 if fits_list:
41 all_fits = []
42 for f in range(len(self.data)):
43 fits_obj = Fits(self.path)
44 fits_obj.data = self.data[f]
45 fits_obj.header = self.headers[f]
46 all_fits.append(fits_obj)
47 return all_fits