tkp.db.general – general database functions

A collection of back end subroutines (mostly SQL queries).

In this module we collect together various routines that don’t fit into a more specific collection.


Return a list of distinct bands present in the dataset.


Insert dataset with description as given by argument.

tkp.db.general.insert_extracted_sources(image_id, results, extract_type='blind', ff_runcat_ids=None, ff_monitor_ids=None)[source]

Insert all detections from sourcefinder into the extractedsource table.

Besides the source properties from sourcefinder, we calculate additional attributes that are increase performance in other tasks.

The strict sequence from results (the sourcefinder detections) is given below. Note the units between sourcefinder and database. (0) ra [deg], (1) dec [deg], (2) ra_fit_err [deg], (3) decl_fit_err [deg], (4) peak_flux [Jy], (5) peak_flux_err [Jy], (6) int_flux [Jy], (7) int_flux_err [Jy], (8) significance detection level, (9) beam major width (arcsec), (10) - minor width (arcsec), (11) - parallactic angle [deg], (12) ew_sys_err [arcsec], (13) ns_sys_err [arcsec], (14) error_radius [arcsec] (15) gaussian fit (bool) (16), (17) chisq, reduced_chisq (float)

ra_fit_err and decl_fit_err are the 1-sigma errors from the gaussian fit, in degrees. Note that for a source located towards the poles the ra_fit_err increases with absolute declination. error_radius is a pessimistic on-sky error estimate in arcsec. ew_sys_err and ns_sys_err represent the telescope dependent systematic errors and are in arcsec. An on-sky error (declination independent, and used in de ruiter calculations) is then: uncertainty_ew^2 = ew_sys_err^2 + error_radius^2 uncertainty_ns^2 = ns_sys_err^2 + error_radius^2 The units of uncertainty_ew and uncertainty_ns are in degrees. The error on RA is given by ra_err. For a source with an RA of ra and an error of ra_err, its RA lies in the range [ra-ra_err, ra+ra_err]. ra_err^2 = ra_fit_err^2 + [alpha_inflate(ew_sys_err,decl)]^2 decl_err^2 = decl_fit_err^2 + ns_sys_err^2. The units of ra_err and decl_err are in degrees. Here alpha_inflate() is the RA inflation function, it converts an angular on-sky distance to a ra distance at given declination.

Input argument “extract” tells whether the source detections originate from: ‘blind’: blind source extraction ‘ff_nd’: from forced fits at null detection locations ‘ff_ms’: from forced fits at monitoringlist positions

Input argument ff_runcat is not empty in the case of forced fits from null detections. It contains the runningcatalog ids from which the source positions were derived for the forced fits. In that case the runcat ids will be inserted into the extractedsource table as well, to simplify further null-detection processing. For blind extractions this list is empty (None).

For all extracted sources additional parameters are calculated, and appended to the sourcefinder data. Appended and converted are:

  • the image id to which the extracted sources belong to
  • the zone in which an extracted source falls is calculated, based on its declination. We adopt a zoneheight of 1 degree, so the floor of the declination represents the zone.
  • the positional errors are converted from degrees to arcsecs
  • the Cartesian coordinates of the source position
  • ra * cos(radians(decl)), this is very often being used in source-distance calculations
tkp.db.general.insert_monitor_positions(dataset_id, positions)[source]

Add entries to the monitor table.

  • dataset_id (int) – Positions will only be monitored when processing this dataset.
  • positions (list of tuples) – List of (RA, decl) tuples in decimal degrees.

Obtain a light curve for a specific extractedsource

Parameters:xtrsrcid (int) – the source identifier that corresponds to a point on the light curve. Note that the point does not have to be the start (first) point of the light curve.
a list of tuples, each containing:
  • observation start time as a datetime.datetime object
  • integration time (float)
  • integrated flux (float)
  • integrated flux error (float)
  • database ID of this particular source
  • frequency band ID
  • stokes
Return type:(tuple)
Returns:a list of dictionarys representing rows in runningcatalog, for all sources belonging to this dataset

Column ‘id’ is returned with the key ‘runcat’

Currently only returns 3 columns: [{‘runcat,’xtrsrc’,’datapoints’}]

Return type:(tuple)

Update dataset start-of-processing timestamp.