AstroDbQueries - EranOfek/AstroPack GitHub Wiki

Background

In the course of astronomical data processing, some the high-level products (e.g., source catalogs or processed image metadata) are saved and stored in dedicated databases. In particular, the AstroDb class functionality is employed to store processed image data and catalogs, produced by the LAST telescope pipeline, in a postgreSQL database.

Database queries

To make a query to a postgreSQL base, one may use either

  1. matlab query functions, provided by the AstroDb class or
  2. UNIX command-line tool psql

Some examples

Shell queries


% Query the table _coadd_images_ from the database _last_operational_ at host _last0_ 
% and save all the records from columns ra, dec, mount, camnum, jd, object 
% into the text file coadd_coo:
> psql -d last_operational -h last0 -p 5432 -U postgres -c "SELECT ra, dec, mount, camnum, jd, object from coadd_images" > coadd_coo

% Query the table _coadd_images_ 
% and get the column _filename_ from all the records where column _object_ is equal to '275-16', 
% save query results in the text file _275-16.txt_ :
> psql -d last_operational -h last0 -p 5432 -U postgres -c "SELECT filename from coadd_images WHERE object='275-16' " > 275-16.txt

Matlab queries

% Make a cone search query around a given point. 
% First, create a DB object to establish a connection:
ADB = db.AstroDb('Host','10.23.1.25','DatabaseName','last_operational');
% Next, query one of the DB tables and save results in the Res structure:
% Search the _'coadd_images'_ table around RA = 34.5 deg and Dec = -4.3 deg 
% with the radius of 600 arcsec, put out only RA and Dec:
Res = ADB.coneSearch('coadd_images',34.5,-4.3, 600);
% Search the _'proc_src_catalog'_ table around RA = 220 deg and Dec = 51 deg with the radius of 5 arcmin,
% selecting records with SN > 10, put out all the table columns:
Res = ADB.coneSearch('proc_src_catalog',220,51,5,'DistUnit','arcmin','AND','sn>10','Columns','*');