|
7 | 7 | from collections.abc import Iterable |
8 | 8 |
|
9 | 9 | import numpy as np |
10 | | -from astropy.io import fits |
11 | 10 | from astropy.table import Table |
12 | 11 | from astropy.logger import AstropyUserWarning |
13 | 12 | import matplotlib.pyplot as plt |
|
16 | 15 |
|
17 | 16 | import stingray.utils as utils |
18 | 17 | from stingray.loggingconfig import setup_logger |
| 18 | +from stingray.utils import fits_open_including_remote |
19 | 19 |
|
20 | 20 |
|
21 | 21 | from .utils import ( |
@@ -765,7 +765,7 @@ def __init__( |
765 | 765 | additional_columns = [self.detector_key] |
766 | 766 | elif self.detector_key != "NONE": |
767 | 767 | additional_columns.append(self.detector_key) |
768 | | - self.data_hdu = fits.open(self.fname)[self.hduname] |
| 768 | + self.data_hdu = self.data_hdus[self.hduname] |
769 | 769 | self.gti_file = gti_file |
770 | 770 | self._read_gtis(self.gti_file) |
771 | 771 |
|
@@ -914,8 +914,8 @@ def _initialize_header_events(self, fname, force_hduname=None): |
914 | 914 | If not None, the name of the HDU to read. If None, an extension called |
915 | 915 | EVENTS or the first extension. |
916 | 916 | """ |
917 | | - hdulist = fits.open(fname) |
918 | | - |
| 917 | + hdulist = fits_open_including_remote(fname) |
| 918 | + self.data_hdus = hdulist |
919 | 919 | if not force_hduname: |
920 | 920 | for hdu in hdulist: |
921 | 921 | if "TELESCOP" in hdu.header or "MISSION" in hdu.header: |
@@ -1052,11 +1052,11 @@ def _read_gtis(self, gti_file=None, det_numbers=None): |
1052 | 1052 | # So, here I'm reading a bunch of rows hoping that they represent the |
1053 | 1053 | # detector number population |
1054 | 1054 | if self.detector_key is not None: |
1055 | | - with fits.open(self.fname) as hdul: |
1056 | | - data = hdul[self.hduname].data |
1057 | | - if self.detector_key in data.dtype.names: |
1058 | | - probe_vals = data[:100][self.detector_key] |
1059 | | - det_numbers = list(set(probe_vals)) |
| 1055 | + hdul = self.data_hdus |
| 1056 | + data = hdul[self.hduname].data |
| 1057 | + if self.detector_key in data.dtype.names: |
| 1058 | + probe_vals = data[:100][self.detector_key] |
| 1059 | + det_numbers = list(set(probe_vals)) |
1060 | 1060 | del hdul |
1061 | 1061 |
|
1062 | 1062 | accepted_gtistrings = self.gtistring.split(",") |
@@ -1127,7 +1127,7 @@ def _get_idx_from_time_range(self, start, stop): |
1127 | 1127 | time_edges[raw_max_idx] - stop >= 0 |
1128 | 1128 | ), f"Stop: {stop}; {time_edges[raw_max_idx] - stop} < 0" |
1129 | 1129 |
|
1130 | | - with fits.open(self.fname) as hdulist: |
| 1130 | + with fits_open_including_remote(self.fname) as hdulist: |
1131 | 1131 | filtered_times = hdulist[self.hduname].data[self.time_column][ |
1132 | 1132 | raw_lower_edge : raw_upper_edge + 1 |
1133 | 1133 | ] |
@@ -1219,7 +1219,7 @@ def _trace_nphots_in_file(self, nedges=1001): |
1219 | 1219 |
|
1220 | 1220 | fname = self.fname |
1221 | 1221 |
|
1222 | | - with fits.open(fname) as hdul: |
| 1222 | + with fits_open_including_remote(fname) as hdul: |
1223 | 1223 | size = hdul[1].header["NAXIS2"] |
1224 | 1224 | nedges = min(nedges, size // 10 + 2) |
1225 | 1225 |
|
@@ -1335,7 +1335,7 @@ def read_header_key(fits_file, key, hdu=1): |
1335 | 1335 | The value stored under ``key`` in ``fits_file`` |
1336 | 1336 | """ |
1337 | 1337 |
|
1338 | | - hdulist = fits.open(fits_file, ignore_missing_end=True) |
| 1338 | + hdulist = fits_open_including_remote(fits_file, ignore_missing_end=True) |
1339 | 1339 | try: |
1340 | 1340 | value = hdulist[hdu].header[key] |
1341 | 1341 | except KeyError: # pragma: no cover |
@@ -1367,7 +1367,7 @@ def ref_mjd(fits_file, hdu=1): |
1367 | 1367 | fits_file = fits_file[0] |
1368 | 1368 | logger.info("opening %s" % fits_file) |
1369 | 1369 |
|
1370 | | - hdulist = fits.open(fits_file, ignore_missing_end=True) |
| 1370 | + hdulist = fits_open_including_remote(fits_file, ignore_missing_end=True) |
1371 | 1371 |
|
1372 | 1372 | ref_mjd_val = high_precision_keyword_read(hdulist[hdu].header, "MJDREF") |
1373 | 1373 |
|
|
0 commit comments