Commit fe66ff60 authored by Carlo Ferrigno's avatar Carlo Ferrigno
Browse files

Correct bug in logging

Correct bug in summing images
Treated case of empty source catalog and add source of interest
v 1.3.25
parent 7543d607
......@@ -274,7 +274,7 @@ class INTEGRALwrapper(object):
summed_mosaic.to_hdu_list()[1:]
if hh.header['IMATYPE'] != 'NIMAGE']
self.summed_data.dispatcher_catalog_1.table = INTEGRALwrapper.compute_fluxes(summed_data, detection_threshold)
summed_data.dispatcher_catalog_1.table = INTEGRALwrapper.compute_fluxes(summed_data, detection_threshold)
INTEGRALwrapper.display_sources(summed_data.dispatcher_catalog_1.table, detection_threshold)
self.summed_data=summed_data
......@@ -282,6 +282,9 @@ class INTEGRALwrapper(object):
@staticmethod
def display_sources(stacked_table, min_sigma):
if stacked_table is None:
INTEGRALwrapper.__log.info("No sources to be displayed")
return
out_str = 'source_name RA DEC Flux Flux_err\n-----------------------------------'
INTEGRALwrapper.__log.info(out_str)
......@@ -307,7 +310,7 @@ class INTEGRALwrapper(object):
#
stacked_table = summed_data.dispatcher_catalog_1.table
if len(stacked_table) == 0:
self.__log.warning("No sources in the catalog, impossible to compute fluxes")
INTEGRALwrapper.__log.warning("No sources in the catalog, impossible to compute fluxes")
return
#Filter sources by significance
......@@ -603,12 +606,23 @@ class INTEGRALwrapper(object):
# objects_of_interest=[('Her X-1', Simbad.query )]
# objects_of_interest=[('Her X-1', Skycoord )]
# objects_of_interest=[ Skycoord(....) ]
if image.dispatcher_catalog_1.table is None:
INTEGRALwrapper.__log.warning("No sources in the catalog")
if objects_of_interest != []:
return INTEGRALwrapper.add_objects_of_interest(None, objects_of_interest,
flag, isgri_flag)
else:
return 'none'
sources = image.dispatcher_catalog_1.table[image.dispatcher_catalog_1.table['significance'] >= det_sigma]
if len(sources) == 0:
INTEGRALwrapper.__log.warning('No sources in the catalog with det_sigma > %.1f' % det_sigma)
return 'none'
if objects_of_interest != []:
return INTEGRALwrapper.add_objects_of_interest(None, objects_of_interest,
flag, isgri_flag)
else:
return 'none'
if not include_new_sources:
ind = [not 'NEW' in ss for ss in sources['src_names']]
......@@ -630,6 +644,11 @@ class INTEGRALwrapper(object):
return copied_image.dispatcher_catalog_1.get_api_dictionary()
@staticmethod
def make_one_source_catalog_string(name, ra, dec, isgri_flag, flag):
out_str_templ ='{"cat_frame": "fk5", "cat_coord_units": "deg", "cat_column_list": [[1], ["%s"], [0.0], [%f], [%f], [-32768], [%d], [%d], [0.001]], "cat_column_names": ["meta_ID", "src_names", "significance", "ra", "dec", "NEW_SOURCE", "ISGRI_FLAG", "FLAG", "ERR_RAD"], "cat_column_descr": [["meta_ID", "<i8"], ["src_names", "<U7"], ["significance", "<f8"], ["ra", "<f8"], ["dec", "<f8"], ["NEW_SOURCE", "<i8"], ["ISGRI_FLAG", "<i8"], ["FLAG", "<i8"], ["ERR_RAD", "<f8"]], "cat_lat_name": "dec", "cat_lon_name": "ra"}'
return out_str_templ % (name, ra, dec, isgri_flag, flag)
@staticmethod
def add_objects_of_interest(clean_sources, objects_of_interest, flag=1, isgri_flag=2, tolerance = 1./60.):
for ooi in objects_of_interest:
......@@ -653,37 +672,40 @@ class INTEGRALwrapper(object):
dec = source_coord.dec.deg
INTEGRALwrapper.__log.info("RA=%g Dec=%g" % (ra, dec))
#Look for the source of interest in NEW sources by coordinates
for ss in clean_sources:
if 'NEW' in ss['src_names']:
if np.abs(ra - ss['ra']) <= tolerance and np.abs(dec - ss['dec']) <= tolerance:
INTEGRALwrapper.__log.info('Found ' + ooi + ' in catalog as ' + ss['src_names'])
ind = clean_sources['src_names'] == ss['src_names']
clean_sources['FLAG'][ind] = flag
clean_sources['ISGRI_FLAG'][ind] = isgri_flag
clean_sources['src_names'][ind] = ooi
#Look for the source of interest in
ind = clean_sources['src_names'] == ooi
if np.count_nonzero(ind) > 0:
INTEGRALwrapper.__log.info('Found ' + ooi + ' in catalog')
clean_sources['FLAG'][ind] = flag
if 'ISGRI_FLAG' in clean_sources.keys():
clean_sources['ISGRI_FLAG'][ind] = isgri_flag
if 'JEMX_FLAG' in clean_sources.keys():
clean_sources['JEMX_FLAG'][ind] = isgri_flag
else:
INTEGRALwrapper.__log.info('Adding ' + ooi + ' to catalog')
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))
if clean_sources is not None:
#Look for the source of interest in NEW sources by coordinates
for ss in clean_sources:
if 'NEW' in ss['src_names']:
if np.abs(ra - ss['ra']) <= tolerance and np.abs(dec - ss['dec']) <= tolerance:
INTEGRALwrapper.__log.info('Found ' + ooi + ' in catalog as ' + ss['src_names'])
ind = clean_sources['src_names'] == ss['src_names']
clean_sources['FLAG'][ind] = flag
clean_sources['ISGRI_FLAG'][ind] = isgri_flag
clean_sources['src_names'][ind] = ooi
#Look for the source of interest in
ind = clean_sources['src_names'] == ooi
if np.count_nonzero(ind) > 0:
INTEGRALwrapper.__log.info('Found ' + ooi + ' in catalog')
clean_sources['FLAG'][ind] = flag
if 'ISGRI_FLAG' in clean_sources.keys():
clean_sources['ISGRI_FLAG'][ind] = isgri_flag
if 'JEMX_FLAG' in clean_sources.keys():
clean_sources['JEMX_FLAG'][ind] = isgri_flag
else:
INTEGRALwrapper.__log.info('Adding ' + ooi + ' to catalog')
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'])
unique_sources = table.unique(clean_sources, keys=['src_names'])
return unique_sources
return unique_sources
else:
return INTEGRALwrapper.make_one_source_catalog_string(ooi, ra, dec, isgri_flag, flag)
@staticmethod
def sum_spectral_products(spectrum_results, source_name):
......@@ -1066,46 +1088,46 @@ class INTEGRALwrapper(object):
# plt.ylim([dec[np.transpose(m_on)].min(), dec[np.transpose(m_on)].max()])
plt.xlim([ra.max(), ra.min()])
plt.ylim([dec.min(), dec.max()])
if sources is not None:
if len(sources) > 0:
ras = np.array([x for x in sources['ra']])
decs = np.array([x for x in sources['dec']])
names = np.array([x for x in sources['src_names']])
sigmas = np.array([x for x in sources['significance']])
# Defines relevant indexes for plotting regions
if len(sources) > 0:
ras = np.array([x for x in sources['ra']])
decs = np.array([x for x in sources['dec']])
names = np.array([x for x in sources['src_names']])
sigmas = np.array([x for x in sources['significance']])
# Defines relevant indexes for plotting regions
m_new = np.array(['NEW' in name for name in names])
m_new = np.array(['NEW' in name for name in names])
# m_offaxis = self.source_results.MEAN_VAR > 5
# m_noisy = self.source_results.DETSIG_CORR < 5
m_noisy = sigmas < 5
# m_offaxis = self.source_results.MEAN_VAR > 5
# m_noisy = self.source_results.DETSIG_CORR < 5
m_noisy = sigmas < 5
# plot new sources as pink circles
# plot new sources as pink circles
try:
m = m_new & (sigmas > det_sigma)
ra_coord = ras[m]
dec_coord = decs[m]
new_names = names[m]
if zero_crossing:
ind_ra = ra_coord > 180.
try:
ra_coord[ind_ra] -= 360.
except:
pass
except:
ra_coord = []
dec_coord = []
new_names = []
plt.scatter(ra_coord, dec_coord, s=100, marker="o", facecolors='none',
edgecolors='pink',
lw=3, label="NEW any", zorder=5)
for i in range(len(ra_coord)):
# print("%f %f %s\n"%(ra_coord[i], dec_coord[i], names[i]))
plt.text(ra_coord[i],
dec_coord[i] + 0.5,
new_names[i], color="pink", size=15)
try:
m = m_new & (sigmas > det_sigma)
ra_coord = ras[m]
dec_coord = decs[m]
new_names = names[m]
if zero_crossing:
ind_ra = ra_coord > 180.
try:
ra_coord[ind_ra] -= 360.
except:
pass
except:
ra_coord = []
dec_coord = []
new_names = []
plt.scatter(ra_coord, dec_coord, s=100, marker="o", facecolors='none',
edgecolors='pink',
lw=3, label="NEW any", zorder=5)
for i in range(len(ra_coord)):
# print("%f %f %s\n"%(ra_coord[i], dec_coord[i], names[i]))
plt.text(ra_coord[i],
dec_coord[i] + 0.5,
new_names[i], color="pink", size=15)
# CF Plots object of interest as green
for ooi in objects_of_interest:
......
......@@ -15,7 +15,7 @@ include_package_data=True
scripts_list = glob.glob('./bin/*')
setup(name='oda_integral_wrapper',
version="1.3.24",
version="1.3.25",
description='wrapper for INTEGRAL analysis using the API plugin for CDCI online data analysis',
author='Carlo Ferrigno',
author_email='carlo.ferrigno@unige.ch',
......
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