Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
header, header_comments = get_header(hdulist, hduname)
# Closes the FITS file, further file data reads will be done via Stingray
hdulist.close()
# Prepares additional_columns
additional_columns = []
for i in range(len(columns)):
if columns[i] != column:
if len(extra_colums) == 0 or columns[i] in extra_colums:
additional_columns.append(columns[i])
# Reads fits data
logging.debug("Reading Events Fits columns's data")
fits_data = load_events_and_gtis(destination,
additional_columns=additional_columns,
gtistring=gtistring,
hduname=hduname, column=column)
event_list, events_start_time = substract_tstart_from_events(fits_data, time_offset)
# Gets PI column data from eventlist if requiered and PHA not in additional_data
if "PI" in additional_columns \
and "PI" not in fits_data.additional_data \
and "PHA" not in fits_data.additional_data:
fits_data.additional_data["PI"] = event_list.pi
dataset = DataSet.get_dataset_applying_gtis(dsId, header, header_comments,
fits_data.additional_data, [],
event_list.time, [],
event_list.gti[:, 0], event_list.gti[:, 1],
if not destination:
return None
filename = os.path.splitext(destination)[0]
file_extension = magic.from_file(destination)
logging.debug("File extension: %s" % file_extension)
if file_extension.find("FITS") == 0:
# Opening Fits
hdulist = fits.open(destination, memmap=True)
if 'EVENTS' in hdulist:
# If EVENTS extension found, consider the Fits as EVENTS Fits
fits_data = load_events_and_gtis(destination,
additional_columns=['PI', "PHA"],
gtistring=CONFIG.GTI_STRING,
hduname='EVENTS', column=CONFIG.TIME_COLUMN)
return substract_tstart_from_events(fits_data, time_offset)
elif 'RATE' in hdulist:
# If RATE extension found, consider the Fits as LIGHTCURVE Fits
# Reads the lightcurve with hendrics
outfile = lcurve_from_fits(destination, gtistring=get_hdu_string_from_hdulist(CONFIG.GTI_STRING, hdulist),
timecolumn=CONFIG.TIME_COLUMN, ratecolumn=None, ratehdu=1,
fracexp_limit=CONFIG.FRACEXP_LIMIT)[0]
return substract_tstart_from_lcurve(load_lcurve(outfile), time_offset)
else:
logging.error("Unsupported FITS type!")