Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions hendrics/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,27 @@ def get_file_type(fname, raw_data=False):
return ftype, contents


def is_lightcurve(hdulist):
"""Determine whether the file is a lightcurve

Returns:
bool: True if the HDU list represents a light curve, False otherwise.
"""
if len(hdulist) < 2:
return False

data_hdu = hdulist[1]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check every extension (not just hdulist[1]).

if not hasattr(data_hdu, "columns"):
return False

colnames = [col.name.upper() for col in data_hdu.columns]

time_col = "TIME" in colnames
lc_like_col = any(x in colnames for x in ["FLUX", "RATE", "COUNTS", "SAP_FLUX", "PDCSAP_FLUX"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for name in [
"ERROR",
"FRACEXP"
])

You may include this also .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accept columns common in NICER data like "ERROR", "FRACEXP" as part of the light curve signature.


return time_col and lc_like_col


# ----- functions to save and load EVENT data
def save_events(eventlist, fname):
"""Save events in a file.
Expand Down
14 changes: 13 additions & 1 deletion hendrics/read_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
)

from astropy import log
from astropy.io import fits

from .base import common_name, hen_root
from .io import HEN_FILE_EXTENSION, load_events, save_events
from .io import HEN_FILE_EXTENSION, load_events, save_events, is_lightcurve


def treat_event_file(
Expand Down Expand Up @@ -643,6 +644,17 @@ def main(args=None):

arglist = [[f, argdict] for f in files]

for fname in files:
if fname.endswith(".fits") or fname.endswith(".fit"):
with fits.open(fname) as hdulist:
hdu_names = [h.name.upper() for h in hdulist]
if "EVENTS" not in hdu_names and is_lightcurve(hdulist):
print(f"\n The file '{fname}' appears to be a light curve.")
ans = input("Do you want to proceed with reading the file? [y/N]: ").strip().lower()
if ans != 'y':
raise ValueError("Aborted reading.")


if os.name == "nt" or args.nproc == 1:
[_wrap_fun(a) for a in arglist]
else:
Expand Down