Ejemplo n.º 1
0
def get_newsources_for_dataset(dsid):
    """
    Returns dicts representing all newsources for this dataset.

    Args:
        dsid: Dataset id

    Returns:
        list: (list of dicts) Each dict represents one newsource.
            The dict keys are all the columns in the newsources table, plus
            the 'taustart_ts' from the image table, which represents the
            trigger time.
    """
    qry = """\
    SELECT tr.id
          ,tr.previous_limits_image
          ,rc.id as runcat_id
          ,img.taustart_ts
          ,img.band
          ,ax.v_int
          ,ax.eta_int
          , ((ex.f_peak - limits_image.detection_thresh*limits_image.rms_min)
               / limits_image.rms_min) AS low_thresh_sigma
           , ((ex.f_peak - limits_image.detection_thresh*limits_image.rms_max)
               / limits_image.rms_max) AS high_thresh_sigma
      FROM newsource tr
          ,runningcatalog rc
          ,extractedsource ex
          ,image img
          ,assocxtrsource ax
          ,image limits_image
      WHERE rc.dataset = %(dsid)s
        AND tr.runcat = rc.id
        AND tr.trigger_xtrsrc = ex.id
        AND ex.image = img.id
        AND ax.runcat = rc.id
        AND ax.xtrsrc = ex.id
        AND tr.previous_limits_image = limits_image.id
    """
    cursor = Database().connection.cursor()
    cursor.execute(qry, {'dsid':dsid})
    newsource_rows_for_dataset = get_db_rows_as_dicts(cursor)
    return newsource_rows_for_dataset
Ejemplo n.º 2
0
def get_newsources_for_dataset(dsid):
    """
    Returns dicts representing all newsources for this dataset.

    Args:
        dsid: Dataset id

    Returns:
        list: (list of dicts) Each dict represents one newsource.
            The dict keys are all the columns in the newsources table, plus
            the 'taustart_ts' from the image table, which represents the
            trigger time.
    """
    qry = """\
    SELECT tr.id
          ,tr.previous_limits_image
          ,rc.id as runcat_id
          ,img.taustart_ts
          ,img.band
          ,ax.v_int
          ,ax.eta_int
          , ((ex.f_peak - limits_image.detection_thresh*limits_image.rms_min)
               / limits_image.rms_min) AS low_thresh_sigma
           , ((ex.f_peak - limits_image.detection_thresh*limits_image.rms_max)
               / limits_image.rms_max) AS high_thresh_sigma
      FROM newsource tr
          ,runningcatalog rc
          ,extractedsource ex
          ,image img
          ,assocxtrsource ax
          ,image limits_image
      WHERE rc.dataset = %(dsid)s
        AND tr.runcat = rc.id
        AND tr.trigger_xtrsrc = ex.id
        AND ex.image = img.id
        AND ax.runcat = rc.id
        AND ax.xtrsrc = ex.id
        AND tr.previous_limits_image = limits_image.id
    """
    cursor = Database().cursor
    cursor.execute(qry, {'dsid':dsid})
    newsource_rows_for_dataset = get_db_rows_as_dicts(cursor)
    return newsource_rows_for_dataset
Ejemplo n.º 3
0
def execute(query, parameters={}, commit=False):
    """
    A generic wrapper for doing any query to the database

    :param query: the query string
    :param parameters: The query parameters. These will be converted and escaped.
    :param commit: should a commit be performed afterwards, boolean

    :returns: a database cursor object
    """
    database = Database()
    return database.execute(query, parameters=parameters, commit=commit)
Ejemplo n.º 4
0
def execute(query, parameters={}, commit=False):
    """
    A generic wrapper for doing any query to the database

    :param query: the query string
    :param parameters: The query parameters. These will be converted and escaped.
    :param commit: should a commit be performed afterwards, boolean

    :returns: a database cursor object
    """
    database = Database()
    return database.execute(query, parameters=parameters, commit=commit)