Commit 268c0fca authored by Carlo Ferrigno's avatar Carlo Ferrigno
Browse files

Correct light curve fits output to make it OGIP compliant.

Avoid stitching or summing if only one product is present.

Adapt to new format of catalog without FLUX.

Corrected bug in plot_lc.

Removed TODO.
parent 5afda893
......@@ -104,6 +104,7 @@ class INTEGRALwrapper(object):
if ys not in disp_by_call:
disp_by_call[ys] = oda_api.api.DispatcherAPI(url=self.disp.url, wait=False)
#This is just a submission
_disp = disp_by_call[ys]
data = data_by_call.get(ys, None)
......@@ -143,7 +144,7 @@ class INTEGRALwrapper(object):
break
self.__log.debug("not done")
n_poll += 1
#TODO test this option
if not wait:
return None
time.sleep(sleep_time)
......@@ -184,6 +185,9 @@ class INTEGRALwrapper(object):
from astropy import table
import oda_api.data_products
if len(self.all_data) == 1:
self.__log.info("We have one mosaic, returning it.")
return self.all_data[0]
list_hdus = [dd.mosaic_image_0_mosaic.to_fits_hdu_list() for dd in self.all_data]
summed_mosaic = mosaic.mosaic_list(list_hdus, pixels=projection, mock=False)
......@@ -311,6 +315,8 @@ class INTEGRALwrapper(object):
if not 'lc' in combined_data._p_list[0].name:
raise ValueError('This is not a light curve and you try to stitch them')
if len(self.all_data) == 1:
return combined_data
sources = self.get_sources()
# gets indexes of source and lc in combined data
......@@ -475,7 +481,7 @@ class INTEGRALwrapper(object):
_ = plt.xlabel('Time [IJD]')
_ = plt.ylabel('Rate')
if ng_sigma_limit >= 1:
if ng_sig_limit >= 1:
ndof = len(y) - 1
prob_limit = stats.norm().sf(ng_sig_limit)
chi2_limit = stats.chi2(ndof).isf(prob_limit)
......@@ -587,7 +593,12 @@ class INTEGRALwrapper(object):
clean_sources['ISGRI_FLAG'][ind] = isgri_flag
else:
INTEGRALwrapper.__log.info('Adding ' + ooi + ' to catalog')
clean_sources.add_row((0, ooi, 0, ra, dec, 0, isgri_flag, flag, 1e-3, 0, 0))
try:
INTEGRALwrapper.__log.debug('Flux is present')
clean_sources.add_row((0, ooi, 0, ra, dec, 0, isgri_flag, flag, 1e-3, 0, 0))
except:
INTEGRALwrapper.__log.debug('Flux is NOT present')
clean_sources.add_row((0, ooi, 0, ra, dec, 0, isgri_flag, flag, 1e-3))
unique_sources = table.unique(clean_sources, keys=['src_names'])
......@@ -601,7 +612,6 @@ class INTEGRALwrapper(object):
@staticmethod
def sum_spectral_products(spectrum_results, source_name):
d = spectrum_results[0]
ID_spec = -1
......@@ -620,7 +630,7 @@ class INTEGRALwrapper(object):
break
INTEGRALwrapper.__log.info('Initialize with IDs for spe, arf and rmf %d %d %d' % (ID_spec, ID_arf, ID_rmf))
d = spectrum_results[0]
#d = spectrum_results[0]
spec = d._p_list[ID_spec].data_unit[1].data
arf = d._p_list[ID_arf].data_unit[1].data
rmf = d._p_list[ID_rmf].data_unit[2].data
......@@ -719,6 +729,9 @@ class INTEGRALwrapper(object):
if not 'spectrum' in summed_data._p_list[0].meta_data['product']:
raise ValueError('This is not a spectrum and you try to sum spectra')
if len(self.all_data) == 1:
return summed_data
sources = self.get_sources()
self.__log.debug(sources)
for source in sources:
......@@ -785,6 +798,23 @@ class INTEGRALwrapper(object):
lc_fn = output_dir + "/%s_lc_%s_%s.fits" % (instrument, source_name.replace(' ', '_'), subcases_pattern)
hdu = lcprod[0].data_unit[ind_extension].to_fits_hdu()
timedel = hdu.header['TIMEDEL']
timepixr = hdu.header['TIMEPIXR']
dt = timedel * timepixr
hdu.header['TSTART'] = hdu.data['TIME'][0] - dt
hdu.header['TSTOP'] = hdu.data['TIME'][-1] + dt
hdu.header['TFIRST'] = hdu.data['TIME'][0] - dt
hdu.header['TLAST'] = hdu.data['TIME'][-1] + dt
hdu.header['TELAPSE'] = hdu.header['TLAST'] - hdu.header['TFIRST']
ontime=0
for x in hdu.data['FRACEXP']:
ontime += x * timedel
hdu.header['ONTIME'] = ontime
fits.writeto(lc_fn, hdu.data, header=hdu.header, overwrite=True)
mjdref = float(hdu.header['MJDREF'])
......@@ -1017,13 +1047,13 @@ class INTEGRALwrapper(object):
INTEGRALwrapper.__log.debug("object:", ooi, c)
plt.scatter(c.ra.deg, c.dec.deg, marker="o", facecolors='none',
edgecolors='white',
plt.scatter(c.ra.deg, c.dec.deg, marker="o", facecolors='none', s=100,
edgecolors='green',
lw=3, label="Added", zorder=5)
# for i in range(len(c)):
plt.text(c.ra.deg,
c.dec.deg + 0.5,
str(ooi), color="white", size=15)
str(ooi), color="green", size=15)
# m = m_new & m_offaxis
# p.scatter(self.coord[m].ra.deg, self.coord[m].dec.deg, s=100, marker="o", facecolors='none', edgecolors='red',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment