post_processing

trap.post_processing.construct_lightcurves(db_engine: Engine | None = None, attribute: str = 'int_flux', sources: DataFrame | None = None, images: DataFrame | None = None)[source]

Reconstruct a dataframe with lightcurves from the source relations defined in the standard database.

Parameters:
  • db_engine – A sqlalchemy database engine.

  • attribute (str) – The name of the attribute to use as value for the lightcurve. This can be any column name of the extraced_sources table.

  • sources (pandas.DataFrame) – A DataFrame containing the extracted sources. By providing the sources there is no need to read the extracted_sources from the database. If the sources are already in memory, providing them like this is more performant than having to read the data from the database every time this function is called. This is especially relevant when this function is called several times with a different attribute on the same DataFrame with extracted sources.

  • images (pandas.DataFrame) – A DataFrame containing the images and their frequency band. By providing these, there is no need to read them from the database.

Return type:

A pandas DataFrame where each row is a lightcurve and each column is correlated to each image.

trap.post_processing.construct_varmetric(db_engine: Engine, sources: DataFrame | None = None, images: DataFrame | None = None) DataFrame[source]

Calculate lightcurve properties which can be used for filtering and isolating potential transients.

The properties are based on the extracted_sources table. These properties are:

  • newsource

    Reference to the id of the first extracted source in the lightcurve.

  • v_int

    The flux coefficient of variation (V_ν), based on the integrated flux values.

  • eta_int

    The ‘reduced chi-squared’ variability index (η_ν), based on the integrated flux values.

  • sigma_rms_min

    Integrated flux from the from the extracted source that triggered an new source entry, divided by the minimum value of the estimated-RMS-map within the source-extraction region.

  • sigma_rms_max

    Integrated flux from the from the extracted source that triggered an new source entry, divided by the maximum value of the estimated-RMS-map within the source-extraction region.

  • lightcurve_max

    The maximum flux value of the lightcurve based on the integrated flux.

  • lightcurve_avg

    The average flux value of the lightcurve based on the integrated flux.

  • wm_ra

    The weighted mean right ascension of the source, computed across all detections using inverse-squared positional uncertainties (1/ra_err²) as weights. This represents the best-estimate sky position in right ascension.

  • wm_dec

    The weighted mean declination of the source, computed across all detections using inverse-squared positional uncertainties (1/dec_err²) as weights. This represents the best-estimate sky position in declination.

  • avg_ra_err

    The average or mean of the right ascension uncertainties (ra_fir_err) across all detections contributing to the lightcurve. Represents the average measurement uncertainty in RA.

  • avg_dec_err

    The average or mean of the declination uncertainties (dec_fit_err) across all detections contributing to the lightcurve. Represents the average measurement uncertainty in Dec.

  • nr_datapoints

    The number of images that were used to calculate the variablility metrics per source. If a source was not naturally detected in a specific image the flux value is NaN. Such values are not used in the calculation of the variability metrics and do not count towards the total nr_datapoints for that source.

  • first_image

    The id of the first image in which a source was detected

  • first_detection_time

    The acquisition time of the first image in which a source was detected

Parameters:
  • db_engine – A sqlalchemy database engine.

  • sources (pandas.DataFrame (optional)) – A DataFrame containing the extracted sources. By providing the sources there is no need to read the extracted_sources from the database. Since ony the provided sources will be used to calculate the variability metric, this allows for the calculation of the varibility metrics on a subset of extracted sources.

  • images (pandas.DataFrame (optional)) – A DataFrame containing the images and their frequency band. By providing these, there is no need to read them from the database. They do need to match the provided sources, meaning that each im_id that is present in the sources table should be reflected in the images table. It is recommended to leave this empty if the provided sources are all from the specified database. In that case the function defaults to reading all image metadata from the database which should then match the provided sources.

Returns:

A dictionary with the lightcurve properties mentioned above.

Return type:

dict

trap.post_processing.update_varmetrics_iterative(varmetric, source_list, extracted_sources, im_id, images)[source]

Updates the varmetric dataframe using only the new data.