gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 5660940: Query: Enabled access to VizieR


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5660940: Query: Enabled access to VizieR
Date: Tue, 12 Jan 2021 22:50:01 -0500 (EST)

branch: master
commit 5660940f301689142029cc3d25d74287630f31b3
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Query: Enabled access to VizieR
    
    Until now, Query only connected with ESA's Gaia database. But this was only
    for a proof of concept. Therefore with the help of Francois Ochsenbein, I
    learnt the similar 'curl'-based TAP access to VizieR and was able to
    implement it in this commit.
    
    In short, the old 'gaia_query' function is now renamed to 'tap_download'
    which is placed in a new file called 'tap.c'. The initial sanity-checks and
    preparations for Gaia have been kept in 'gaia.c' and a new 'vizier.c' file
    has been added with similar checks for VizieR.
    
    Also, a feature has been added that databases can be accessed through
    various URLs (mirrors): by storing the URLs as a simply-linked list of
    strings. If the 'curl' command is not successful in one URL it will go to
    the next. Gaia only has one URL, but from the 'vizquery' source, I saw that
    VizieR has many mirrors in many countries so they are added for
    Vizier. However, when I tried them, the 'curl' command failed to connect to
    them. So they are commented now. I am in touch with Fancois to see how this
    should be fixed.
---
 bin/query/Makefile.am          |   4 +-
 bin/query/gaia.c               | 126 +++----------------------------------
 bin/query/gaia.h               |   2 +-
 bin/query/main.h               |   3 +
 bin/query/query.c              |  11 +++-
 bin/query/query.h              |   1 +
 bin/query/{gaia.c => tap.c}    | 140 ++++++++++++++++++-----------------------
 bin/query/{gaia.h => tap.h}    |  10 +--
 bin/query/ui.c                 |   3 +-
 bin/query/vizier.c             |  84 +++++++++++++++++++++++++
 bin/query/{gaia.h => vizier.h} |   8 +--
 doc/gnuastro.texi              |  56 ++++++++++++++---
 12 files changed, 228 insertions(+), 220 deletions(-)

diff --git a/bin/query/Makefile.am b/bin/query/Makefile.am
index e95b4a1..0039917 100644
--- a/bin/query/Makefile.am
+++ b/bin/query/Makefile.am
@@ -41,9 +41,9 @@ bin_PROGRAMS = astquery
 astquery_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la -lgnuastro \
                  $(MAYBE_NORPATH)
 
-astquery_SOURCES = main.c ui.c query.c gaia.c
+astquery_SOURCES = main.c ui.c query.c gaia.c tap.c vizier.c
 
-EXTRA_DIST = main.h authors-cite.h args.h ui.h query.h gaia.h
+EXTRA_DIST = main.h authors-cite.h args.h ui.h query.h gaia.h tap.h vizier.h
 
 
 
diff --git a/bin/query/gaia.c b/bin/query/gaia.c
index 7031df2..462d1cb 100644
--- a/bin/query/gaia.c
+++ b/bin/query/gaia.c
@@ -27,7 +27,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <error.h>
 #include <string.h>
 
-#include <gnuastro/wcs.h>
 #include <gnuastro-internal/checkset.h>
 
 #include "main.h"
@@ -38,8 +37,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 
 
-static void
-gaia_sanitycheck(struct queryparams *p)
+void
+gaia_prepare(struct queryparams *p)
 {
   /* Make sure that atleast one type of constraint is specified. */
   if(p->query==NULL && p->center==NULL && p->overlapwith==NULL)
@@ -92,121 +91,12 @@ gaia_sanitycheck(struct queryparams *p)
           gal_checkset_allocate_copy("public.tycho2", &p->datasetstr);
         }
     }
-}
-
-
-
-
-
-void
-gaia_query(struct queryparams *p)
-{
-  size_t ndim;
-  gal_data_t *tmp;
-  double width2, *center, *darray;
-  char *tmpstr, *regionstr, *rangestr=NULL;
-  char *command, *columns, allcols[]="*", *querystr;
-  double *ocenter=NULL, *owidth=NULL, *omin=NULL, *omax=NULL;
-
-  /* Make sure everything is fine. */
-  gaia_sanitycheck(p);
-
-  /* If the raw query has been given, use it. */
-  if(p->query)
-    querystr=p->query;
-  else
-    {
-      /* If certain columns have been requested use them, otherwise
-         download all existing columns.*/
-      columns = p->columns ? ui_strlist_to_str(p->columns) : allcols;
-
-      /* If the user wanted an overlap with an image, then calculate it. */
-      if(p->overlapwith)
-        {
-          /* Calculate the Sky coverage of the overlap dataset. */
-          gal_wcs_coverage(p->overlapwith, p->cp.hdu, &ndim, &ocenter,
-                           &owidth, &omin, &omax);
-
-          /* Make sure a WCS existed in the file. */
-          if(owidth==NULL)
-            error(EXIT_FAILURE, 0, "%s (hdu %s): contains no WCS to "
-                  "derive the sky coverage", p->overlapwith, p->cp.hdu);
-        }
-
-      /* For easy reading. */
-      center = p->overlapwith ? ocenter : p->center->array;
-
-      /* Write the region. */
-      if(p->radius)
-        {
-          darray=p->radius->array;
-          if( asprintf(&regionstr, "CIRCLE('ICRS', %.8f, %.8f, %g)",
-                       center[0], center[1], darray[0])<0 )
-            error(EXIT_FAILURE, 0, "%s: asprintf allocation ('regionstr')",
-                  __func__);
-        }
-      else if(p->width || p->overlapwith)
-        {
-          darray = p->overlapwith ? owidth : p->width->array;
-          width2 = ( (p->overlapwith || p->width->size==2)
-                     ? darray[1] : darray[0] );
-          if( asprintf( &regionstr, "BOX('ICRS', %.8f, %.8f, %.8f, %.8f)",
-                        center[0], center[1], darray[0], width2 )<0 )
-            error(EXIT_FAILURE, 0, "%s: asprintf allocation ('regionstr')",
-                  __func__);
-        }
-
-      /* Set the range criteria on the requested columns. */
-      if(p->range)
-        for(tmp=p->range; tmp!=NULL; tmp=tmp->next)
-          {
-            darray=tmp->array;
-            if( asprintf(&tmpstr, "%s%sAND %s>=%g AND %s<=%g",
-                         rangestr==NULL ? "" : rangestr,
-                         rangestr==NULL ? "" : " ",
-                         tmp->name, darray[0], tmp->name, darray[1]) < 0 )
-              error(EXIT_FAILURE, 0, "%s: asprintf allocation ('tmpstr')",
-                    __func__);
-            free(rangestr);
-            rangestr=tmpstr;
-          }
-
-      /* Write the automatically generated query string. */
-      if( asprintf(&querystr,  "SELECT %s "
-                   "FROM %s "
-                   "WHERE 1=CONTAINS( POINT('ICRS', ra, dec), %s ) %s",
-                   columns, p->datasetstr, regionstr,
-                   rangestr ? rangestr : "")<0 )
-        error(EXIT_FAILURE, 0, "%s: asprintf allocation ('querystr')",
-              __func__);
-
-      /* Clean up. */
-      free(regionstr);
-      if(columns!=allcols) free(columns);
-      if(p->overlapwith)
-        {free(ocenter); free(owidth); free(omin); free(omax);}
-    }
-
-
-  /* Build the calling command. */
-  if( asprintf(&command, "curl -o%s --form LANG=ADQL --form FORMAT=fits "
-               "--form REQUEST=doQuery --form QUERY=\"%s\" "
-               "https://gea.esac.esa.int/tap-server/tap/sync";, p->downloadname,
-               querystr)<0 )
-    error(EXIT_FAILURE, 0, "%s: asprintf allocation ('command')", __func__);
-
-
-  /* Print the calling command for the user to know. */
-  if(p->cp.quiet==0)
-    error(EXIT_SUCCESS, 0, "running: %s", command);
 
-  /* Run the command. */
-  if(system(command))
-    error(EXIT_FAILURE, 0, "the query download command %sfailed%s\n",
-          p->cp.quiet==0 ? "printed above " : "",
-          p->cp.quiet==0 ? "" : " (the command can be printed "
-          "if you don't use the option '--quiet', or '-q')");
+  /* Set the URLs, note that this is a simply-linked list, so we need to
+     reverse it in the end to have the same order here. */
+  gal_list_str_add(&p->urls, "https://gea.esac.esa.int/tap-server/tap/sync";, 
0);
 
-  /* Clean up. */
-  free(command);
+  /* Name of RA Dec columns to use in Gaia. */
+  p->ra_name="ra";
+  p->dec_name="dec";
 }
diff --git a/bin/query/gaia.h b/bin/query/gaia.h
index eaa9e2b..45cb89b 100644
--- a/bin/query/gaia.h
+++ b/bin/query/gaia.h
@@ -26,6 +26,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include "main.h"
 
 void
-gaia_query(struct queryparams *p);
+gaia_prepare(struct queryparams *p);
 
 #endif
diff --git a/bin/query/main.h b/bin/query/main.h
index c18d9df..fd0e427 100644
--- a/bin/query/main.h
+++ b/bin/query/main.h
@@ -59,6 +59,9 @@ struct queryparams
   char            *databasestr;  /* Name of input database.            */
   char           *downloadname;  /* Temporary output name.             */
   size_t       outtableinfo[2];  /* To print in output.                */
+  gal_list_str_t         *urls;  /* List of URLs to use.               */
+  char                *ra_name;  /* Name of RA column.                 */
+  char               *dec_name;  /* Name of Dec columns.               */
 
   /* Output: */
   time_t               rawtime;  /* Starting time of the program.      */
diff --git a/bin/query/query.c b/bin/query/query.c
index 31f7cbe..ead149c 100644
--- a/bin/query/query.c
+++ b/bin/query/query.c
@@ -33,8 +33,10 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <gnuastro-internal/checkset.h>
 
+#include "tap.h"
 #include "gaia.h"
 #include "query.h"
+#include "vizier.h"
 
 
 
@@ -106,13 +108,17 @@ query(struct queryparams *p)
   /* Download the dataset. */
   switch(p->database)
     {
-    case QUERY_DATABASE_GAIA: gaia_query(p); break;
+    case QUERY_DATABASE_GAIA:   gaia_prepare(p);   break;
+    case QUERY_DATABASE_VIZIER: vizier_prepare(p); break;
     default:
       error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to address "
             "the problem. '%d' is not a recognized database code", __func__,
             PACKAGE_BUGREPORT, p->database);
     }
 
+  /* Download the requested query. */
+  tap_download(p);
+
   /* Make sure that the result is a readable FITS file, otherwise, abort
      with an error. */
   query_check_download(p);
@@ -126,4 +132,7 @@ query(struct queryparams *p)
         printf("Query's raw downloaded file: %s\n", p->downloadname);
       printf("Query's final output: %s\n", p->cp.output);
     }
+
+  /* Clean up. */
+  gal_list_str_free(p->urls, 0);
 }
diff --git a/bin/query/query.h b/bin/query/query.h
index 1621494..f95cd88 100644
--- a/bin/query/query.h
+++ b/bin/query/query.h
@@ -29,6 +29,7 @@ enum query_databases
 {
   QUERY_DATABASE_INVALID,
   QUERY_DATABASE_GAIA,
+  QUERY_DATABASE_VIZIER,
 };
 
 
diff --git a/bin/query/gaia.c b/bin/query/tap.c
similarity index 56%
copy from bin/query/gaia.c
copy to bin/query/tap.c
index 7031df2..90e952c 100644
--- a/bin/query/gaia.c
+++ b/bin/query/tap.c
@@ -1,11 +1,11 @@
 /*********************************************************************
-Gaia Query: retrieve tables from Gaia catalog.
+Table Access Protocol (TAP) based download of given query.
 Query is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Original author:
      Mohammad akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-Copyright (C) 2020-2021, Free Software Foundation, Inc.
+Copyright (C) 2021, Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
@@ -25,10 +25,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdio.h>
 #include <errno.h>
 #include <error.h>
-#include <string.h>
+#include <stdlib.h>
 
 #include <gnuastro/wcs.h>
-#include <gnuastro-internal/checkset.h>
 
 #include "main.h"
 
@@ -36,61 +35,28 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 
 
-
-
+/* The database string needs to be quoted if it contains a slash. */
 static void
-gaia_sanitycheck(struct queryparams *p)
+tap_database_quote_if_necessary(struct queryparams *p)
 {
-  /* Make sure that atleast one type of constraint is specified. */
-  if(p->query==NULL && p->center==NULL && p->overlapwith==NULL)
-    error(EXIT_FAILURE, 0, "no '--query', '--center' or '--overlapwith' "
-          "specified. At least one of these options are necessary in the "
-          "Gaia dataset");
-
-  /* If '--center' is given, '--radius' is also necessary. */
-  if(p->center || p->overlapwith)
+  int quote=0;
+  char *c, *new;
+
+  /* Parse the string. */
+  for(c=p->datasetstr; *c!='\0'; ++c)
+    if(*c=='/') { quote=1; break; }
+
+  /* Add quotes around the database string. */
+  if(quote)
     {
-      /* Make sure the radius is given, and that it isn't zero. */
-      if(p->overlapwith==NULL && p->radius==NULL && p->width==NULL)
-        error(EXIT_FAILURE, 0, "the '--radius' ('-r') or '--width' ('-w') "
-              "options are necessary with the '--center' ('-C') option");
-
-      /* If no dataset is explicitly given, then use default one and let
-         the user know. */
-      if( p->datasetstr==NULL)
-        {
-          gal_checkset_allocate_copy("edr3", &p->datasetstr);
-          error(EXIT_SUCCESS, 0, "using '%s' dataset since no dataset "
-                "was explicitly requested (with '--dataset')",
-                p->datasetstr);
-        }
+      /* Allocate the new string with quotes. */
+      if( asprintf(&new, "\"%s\"", p->datasetstr)<0 )
+        error(EXIT_FAILURE, 0, "%s: asprintf allocation ('new')",
+              __func__);
 
-      /* Use simpler names for the commonly used datasets. */
-      if( !strcmp(p->datasetstr, "edr3") )
-        {
-          free(p->datasetstr);
-          gal_checkset_allocate_copy("gaiaedr3.gaia_source", &p->datasetstr);
-        }
-      else if( !strcmp(p->datasetstr, "dr2") )
-        {
-          free(p->datasetstr);
-          gal_checkset_allocate_copy("gaiadr2.gaia_source", &p->datasetstr);
-        }
-      else if( !strcmp(p->datasetstr, "dr1") )
-        {
-          free(p->datasetstr);
-          gal_checkset_allocate_copy("gaiadr1.gaia_source", &p->datasetstr);
-        }
-      else if( !strcmp(p->datasetstr, "hipparcos") )
-        {
-          free(p->datasetstr);
-          gal_checkset_allocate_copy("public.hipparcos", &p->datasetstr);
-        }
-      else if( !strcmp(p->datasetstr, "tycho2") )
-        {
-          free(p->datasetstr);
-          gal_checkset_allocate_copy("public.tycho2", &p->datasetstr);
-        }
+      /* Free the old one, and replace it. */
+      free(p->datasetstr);
+      p->datasetstr=new;
     }
 }
 
@@ -99,18 +65,16 @@ gaia_sanitycheck(struct queryparams *p)
 
 
 void
-gaia_query(struct queryparams *p)
+tap_download(struct queryparams *p)
 {
   size_t ndim;
   gal_data_t *tmp;
+  gal_list_str_t *url;
   double width2, *center, *darray;
   char *tmpstr, *regionstr, *rangestr=NULL;
   char *command, *columns, allcols[]="*", *querystr;
   double *ocenter=NULL, *owidth=NULL, *omin=NULL, *omax=NULL;
 
-  /* Make sure everything is fine. */
-  gaia_sanitycheck(p);
-
   /* If the raw query has been given, use it. */
   if(p->query)
     querystr=p->query;
@@ -171,11 +135,15 @@ gaia_query(struct queryparams *p)
             rangestr=tmpstr;
           }
 
+      /* If the dataset has special characters (like a slash) it needs to
+         be quoted. */
+      tap_database_quote_if_necessary(p);
+
       /* Write the automatically generated query string. */
       if( asprintf(&querystr,  "SELECT %s "
                    "FROM %s "
-                   "WHERE 1=CONTAINS( POINT('ICRS', ra, dec), %s ) %s",
-                   columns, p->datasetstr, regionstr,
+                   "WHERE 1=CONTAINS( POINT('\"'ICRS', %s, %s), %s ) %s",
+                   columns, p->datasetstr, p->ra_name, p->dec_name, regionstr,
                    rangestr ? rangestr : "")<0 )
         error(EXIT_FAILURE, 0, "%s: asprintf allocation ('querystr')",
               __func__);
@@ -187,25 +155,39 @@ gaia_query(struct queryparams *p)
         {free(ocenter); free(owidth); free(omin); free(omax);}
     }
 
+  /* Go over the given URLs for this server. */
+  for(url=p->urls; url!=NULL; url=url->next)
+    {
+      /* Build the calling command. Note the quotations around the value of
+         QUERY: we start the values with a single quote, because in ADQL,
+         we need double quotes to comment dataset names. However, inside
+         'queryst', we finish the single quotes and switch to double quotes
+         because we need the single quotes around 'IRCS'. So here, while we
+         started it with a single quote, we finish with double quotes. */
+      if( asprintf(&command, "curl -o%s --form LANG=ADQL "
+                   "--form FORMAT=fits --form REQUEST=doQuery "
+                   "--form QUERY='%s\" %s", p->downloadname, querystr,
+                   url->v)<0 )
+        error(EXIT_FAILURE, 0, "%s: asprintf allocation ('command')",
+              __func__);
 
-  /* Build the calling command. */
-  if( asprintf(&command, "curl -o%s --form LANG=ADQL --form FORMAT=fits "
-               "--form REQUEST=doQuery --form QUERY=\"%s\" "
-               "https://gea.esac.esa.int/tap-server/tap/sync";, p->downloadname,
-               querystr)<0 )
-    error(EXIT_FAILURE, 0, "%s: asprintf allocation ('command')", __func__);
-
-
-  /* Print the calling command for the user to know. */
-  if(p->cp.quiet==0)
-    error(EXIT_SUCCESS, 0, "running: %s", command);
-
-  /* Run the command. */
-  if(system(command))
-    error(EXIT_FAILURE, 0, "the query download command %sfailed%s\n",
-          p->cp.quiet==0 ? "printed above " : "",
-          p->cp.quiet==0 ? "" : " (the command can be printed "
-          "if you don't use the option '--quiet', or '-q')");
+      /* Print the calling command for the user to know. */
+      if(p->cp.quiet==0)
+        error(EXIT_SUCCESS, 0, "running: %s", command);
+
+      /* Run the command: if it succeeds ('system' returns zero), then stop
+         parsing with a break. If it fails, then see if this is the last
+         URL or not. If its the last one ('url->next' is NULL), then exit
+         with a failure, otherwise, just let the user know that this
+         download failed, but continue with the next URLs. */
+      if(system(command)==EXIT_SUCCESS) break;
+      else
+        error(url->next ? EXIT_SUCCESS : EXIT_FAILURE, 0,
+              "the query download command %sfailed%s\n",
+              p->cp.quiet==0 ? "printed above " : "",
+              p->cp.quiet==0 ? "" : " (the command can be printed "
+              "if you don't use the option '--quiet', or '-q')");
+    }
 
   /* Clean up. */
   free(command);
diff --git a/bin/query/gaia.h b/bin/query/tap.h
similarity index 84%
copy from bin/query/gaia.h
copy to bin/query/tap.h
index eaa9e2b..7f31b73 100644
--- a/bin/query/gaia.h
+++ b/bin/query/tap.h
@@ -1,11 +1,11 @@
 /*********************************************************************
-Gaia Query: retrieve tables from Gaia catalog.
+Table Access Protocol (TAP) based download of given query.
 Query is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Original author:
      Mohammad akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-Copyright (C) 2020-2021, Free Software Foundation, Inc.
+Copyright (C) 2021, Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
@@ -20,12 +20,12 @@ General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/
-#ifndef GAIA_H
-#define GAIA_H
+#ifndef TAP_H
+#define TAP_H
 
 #include "main.h"
 
 void
-gaia_query(struct queryparams *p);
+tap_download(struct queryparams *p);
 
 #endif
diff --git a/bin/query/ui.c b/bin/query/ui.c
index 15d541b..97b23bf 100644
--- a/bin/query/ui.c
+++ b/bin/query/ui.c
@@ -261,7 +261,8 @@ ui_read_check_only_options(struct queryparams *p)
           "command) for the current databases");
 
   /* Convert the given string into a code. */
-  if( !strcmp(p->databasestr, "gaia") ) p->database=QUERY_DATABASE_GAIA;
+  if(      !strcmp(p->databasestr, "gaia") )   p->database=QUERY_DATABASE_GAIA;
+  else if( !strcmp(p->databasestr, "vizier") ) 
p->database=QUERY_DATABASE_VIZIER;
   else
     error(EXIT_FAILURE, 0, "'%s' is not a recognized database.\n\n"
           "For the full list of recognized databases, please see the "
diff --git a/bin/query/vizier.c b/bin/query/vizier.c
new file mode 100644
index 0000000..4bb4b00
--- /dev/null
+++ b/bin/query/vizier.c
@@ -0,0 +1,84 @@
+/*********************************************************************
+Access VizieR servers for query.
+Query is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Mohammad akhlaghi <mohammad@akhlaghi.org>
+Contributing author(s):
+Copyright (C) 2021, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#include <config.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <string.h>
+
+#include <gnuastro-internal/checkset.h>
+
+#include "main.h"
+
+#include "ui.h"
+
+
+
+
+
+void
+vizier_prepare(struct queryparams *p)
+{
+  /* Make sure that atleast one type of constraint is specified. */
+  if(p->query==NULL && p->center==NULL && p->overlapwith==NULL)
+    error(EXIT_FAILURE, 0, "no '--query', '--center' or '--overlapwith' "
+          "specified. At least one of these options are necessary in the "
+          "Gaia dataset");
+
+  /* If '--center' is given, '--radius' is also necessary. */
+  if(p->center || p->overlapwith)
+    {
+      /* Make sure the radius is given, and that it isn't zero. */
+      if(p->overlapwith==NULL && p->radius==NULL && p->width==NULL)
+        error(EXIT_FAILURE, 0, "the '--radius' ('-r') or '--width' ('-w') "
+              "options are necessary with the '--center' ('-C') option");
+
+      /* If no dataset is explicitly given, let the user know that a
+         catalog reference is necessary. */
+      if( p->datasetstr==NULL)
+        error(EXIT_FAILURE, 0, "no '--dataset' specified. You can "
+              "use the URL below to search existing datasets "
+              "(catalogs):\n\n"
+              "   http://cdsarc.u-strasbg.fr/viz-bin/cat";);
+    }
+
+  /* Set the URLs, note that this is a simply-linked list, so we need to
+     reverse it in the end to have the same order here. */
+  gal_list_str_add(&p->urls, 
"http://tapvizier.u-strasbg.fr/TAPVizieR/tap/sync";, 0);
+
+  /* These don't seem to be working as of January 2021.
+  gal_list_str_add(&p->urls, 
"https://vizier.cfa.harvard.edu/TAPVizieR/tap/sync";, 0);
+  gal_list_str_add(&p->urls, "http://vizier.hia.nrc.ca/TAPVizieR/tap/sync";, 0);
+  gal_list_str_add(&p->urls, "http://vizier.nao.ac.jp/TAPVizieR/tap/sync";, 0);
+  gal_list_str_add(&p->urls, "http://data.bao.ac.cn/TAPVizieR/tap/sync";, 0);
+  gal_list_str_add(&p->urls, "http://vizier.ast.cam.ac.uk/TAPVizieR/tap/sync";, 
0);
+  gal_list_str_add(&p->urls, 
"http://www.ukirt.jach.hawaii.edu/TAPVizieR/tap/sync";, 0);
+  gal_list_str_add(&p->urls, "http://vizier.inasan.ru/TAPVizieR/tap/sync";, 0);
+  */
+  gal_list_str_reverse(&p->urls);
+
+  /* Name of RA Dec columns to use in Gaia. */
+  p->ra_name="RAJ2000";
+  p->dec_name="DEJ2000";
+}
diff --git a/bin/query/gaia.h b/bin/query/vizier.h
similarity index 89%
copy from bin/query/gaia.h
copy to bin/query/vizier.h
index eaa9e2b..8d24431 100644
--- a/bin/query/gaia.h
+++ b/bin/query/vizier.h
@@ -1,5 +1,5 @@
 /*********************************************************************
-Gaia Query: retrieve tables from Gaia catalog.
+Access VizieR servers for query.
 Query is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Original author:
@@ -20,12 +20,12 @@ General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/
-#ifndef GAIA_H
-#define GAIA_H
+#ifndef VIZIER_H
+#define VIZIER_H
 
 #include "main.h"
 
 void
-gaia_query(struct queryparams *p);
+vizier_prepare(struct queryparams *p);
 
 #endif
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 6f302be..678c2cc 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -10317,16 +10317,18 @@ One line examples:
 
 @example
 ## Import all the columns of all entries in the Gaia early DR3
+## catalog from VizieR (CDS) within 20 arc-minutes of the center.
+$ astquery --database=vizier --dataset=I/350/gaiaedr3 \
+           --center=113.8729761,31.9027152 --radius=20/60 \
+           --output=gaia-on-vizier.fits
+
+## Import all the columns of all entries in the Gaia early DR3
 ## catalog (default) within 20 arc-minutes of the given coordinate.
 $ astquery --database=gaia --output=my-gaia.fits \
            --center=113.8729761,31.9027152 --radius=20/60
 
-## Similar to above, but return all objects within a square box of
-## 30 arcminutes (can also be rectangular, see '--width').
-$ astquery --database=gaia --dataset=edr3 --output=my-gaia.fits \
-           --center=113.8729761,31.9027152 --width=30/60
-
-## Similar to above, but for objects with magnitude range 10 to 15,
+## Similar to above, but for objects with magnitude range 10 to 15.
+## Note that in Vizier, this column is called 'Gmag'.
 $ astquery --database=gaia --output=my-gaia.fits \
            --center=113.8729761,31.9027152 --width=30/60 \
            --range=phot_g_mean_mag,10:15
@@ -10394,9 +10396,20 @@ Identifer for the database for sending the query.
 The current list of databases are listed here:
 
 @table @code
+@item vizier
+@cindex VizieR
+@cindex CDS, VizieR
+@cindex Catalog, Vizier
+@cindex Database, VizieR
+Vizier (@url{https://vizier.u-strasbg.fr}) is arguably the largest catalog 
database in astronomy: containing more than 20500 catalogs as of mid January 
2021.
+Almost all published catalogs in major projects, and even tables in papers are 
archived and accessible here.
+For example VizieR also has a full copy of the Gaia database mentioned below, 
with some additional standardized columns (like RA and Dec in J2000).
+Just note that because VizieR curates such a diverse set of data from tens of 
thousands of projects and aims for interoperability between them, it is forced 
to rename some columns compared to the original datasets of large projects.
+
 @item gaia
 @cindex Gaia catalog
 @cindex Catalog, Gaia
+@cindex Database, Gaia
 The Gaia project (@url{https://www.cosmos.esa.int/web/gaia}) database which is 
a large collection of star positions on the celestial sphere, as well as 
peculiar velocities, paralloxes and magnitudes in some bands among many others.
 Besides scientific studies (like studying resolved stellar populations in the 
Galaxy and its halo), Gaia is also invaluable for raw data calibrations, like 
astrometry.
 The query given to this database will be submitted to 
@code{https://gea.esac.esa.int/tap-server/tap/sync}.
@@ -10411,21 +10424,46 @@ The queries will generally contain space and other 
meta-characters, so we recomm
 @itemx --dataset=STR
 The dataset to query within the database (not compatible with 
@option{--query}).
 The reason for this is that many databases have different types of datasets, 
for example different data releases (DRs), or various high-level calculations 
on subsets of the database elements.
-If not excplicity given, a particular dataset will be internally set as 
default for each database, and its name will be printed on the command-line.
-The default dataset is highlighted under each database listed below.
+For smaller databases like Gaia that have a clear ``main'' dataset, this 
option is not mandatory: in such cases, the default database mentioned below 
will be used.
+However, for larger databases like VizieR, this option is mandatory.
 
 You can either use the database's official name of the datasets, for example 
@code{gaiaedr3.gaia_source} for the early data release 3 the Gaia database, or 
a simplified version that maps to it (@code{edr3}) for easy typing on the 
command-line.
 Below is a list of the simplified names for the databases that have them.
 
 @table @code
+@item vizier
+As mentioned under @option{--database}, VizieR contains +20000 datasets.
+It is therefore not possible to list them all here!
+The best solutions is to visit its own web-based catalog searching feature:
+
+@itemize
+@item @url{http://cdsarc.u-strasbg.fr/viz-bin/cat}
+@end itemize
+
+For example if you want the VizieR version of Gaia early data release 3, you 
should use @option{--dataset=I/350/gaiaedr3}.
+
+Alternatively, if you want the 80-row table published in Roman and Trujillo 
(2017, @url{http://doi.org/10.1093/mnras/stx438}), you should use 
@option{--dataset=J/MNRAS/468/703/tableb1}.
+Just note that individual paper datasets don't usually cover the whole sky and 
are focused on a unique sub-set of objects, in one region of the sky.
+
+For example the objects in the paper above are all located around an RA and 
Dec (in degrees, epoch 2000) of 18.8 and 0.33 (within a radius of less than 3 
degrees).
+If you don't want a sub-set of the catalog, but the whole thing, you can use 
the command below.
+
+@example
+astquery --database=vizier \
+         --dataset=J/MNRAS/468/703/tableb1 \
+         --center=18,0 --radius=3 \
+         --output=abell168-udgs.fits
+@end example
+
 @item gaia
+Gaia is a single major project with only 5 datasets that are provided with a 
shortcut that you can use.
 @itemize
 @item
 @code{edr3 --> gaiaedr3.gaia_source} (the default dataset)
 @item
 @code{dr2 --> gaiadr2.gaia_source}
 @item
-@code{dr2 --> gaiadr1.gaia_source}
+@code{dr1 --> gaiadr1.gaia_source}
 @item
 @code{tycho2 --> public.tycho2}
 @item



reply via email to

[Prev in Thread] Current Thread [Next in Thread]