gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master f47a4c2 072/125: MakeProfiles now reads the co


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master f47a4c2 072/125: MakeProfiles now reads the columns
Date: Sun, 23 Apr 2017 22:36:40 -0400 (EDT)

branch: master
commit f47a4c2ebedcda7a406dc5fb5fe515551bc013b5
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    MakeProfiles now reads the columns
    
    The columns are now read into MakeProfiles easily with the infra-structure
    that has been built. One great feature of having the new `gal_data_t' is
    that we can now accept the profile function using string and integer
    constants. This is very convenient for the users making a small set of
    profiles and also in readability. The profile codes (when giving them in
    numerical format) have also been incremented by one.
    
    Some other minor changes were made:
    
     - The new function `gal_data_copy_to_new_type_free' will change the type
       and free the input data, which is very convenient.
    
     - A sanity check was added to `gal_fits_read_hdu', so when the `hdu' value
       is NULL, it reports an error.
    
     - The unsinged and signed integers were missing in
       `gal_data_copy_to_new_type'.
---
 bin/mkprof/args.h         |   4 +-
 bin/mkprof/astmkprof.conf |  18 ++---
 bin/mkprof/main.h         |  12 +++-
 bin/mkprof/mkprof.c       |  10 +--
 bin/mkprof/ui.c           | 168 +++++++++++++++++++++++++++++++++++++++++++---
 doc/gnuastro.texi         |  27 ++++----
 lib/data.c                |  39 ++++++++++-
 lib/fits.c                |   4 ++
 lib/gnuastro/data.h       |   3 +
 lib/options.c             |   2 +-
 lib/table.c               |   2 +-
 11 files changed, 246 insertions(+), 43 deletions(-)

diff --git a/bin/mkprof/args.h b/bin/mkprof/args.h
index 3d85351..860c8f3 100644
--- a/bin/mkprof/args.h
+++ b/bin/mkprof/args.h
@@ -372,8 +372,8 @@ struct argp_option program_options[] =
       ARGS_OPTION_KEY_FCOL,
       "STR/INT",
       0,
-      "Sersic (0), Moffat (1), Gaussian (2), Point (3), "
-      "Flat (4), Circumference (5).",
+      "Sersic (1), Moffat (2), Gaussian (3), Point (4), "
+      "Flat (5), Circumference (6).",
       ARGS_GROUP_CATALOG,
       &p->fcol,
       GAL_DATA_TYPE_STRING,
diff --git a/bin/mkprof/astmkprof.conf b/bin/mkprof/astmkprof.conf
index 66cb031..37a2930 100644
--- a/bin/mkprof/astmkprof.conf
+++ b/bin/mkprof/astmkprof.conf
@@ -39,15 +39,15 @@
  yshift                0
 
 # Catalog:
- xcol                  1
- ycol                  2
- fcol                  3
- rcol                  4
- ncol                  5
- pcol                  6
- qcol                  7
- mcol                  8
- tcol                  9
+ xcol                  2
+ ycol                  3
+ fcol                  4
+ rcol                  5
+ ncol                  6
+ pcol                  7
+ qcol                  8
+ mcol                  9
+ tcol                 10
 
 # WCS:
  crpix1                1
diff --git a/bin/mkprof/main.h b/bin/mkprof/main.h
index 3a8ca74..2031a75 100644
--- a/bin/mkprof/main.h
+++ b/bin/mkprof/main.h
@@ -150,12 +150,20 @@ struct mkprofparams
 
 
   /* Processing parameters: */
+  size_t                num;  /* The number of profiles.                  */
+  double                 *x;  /* X axis position of profile center.       */
+  double                 *y;  /* Y axis position of profile center.       */
+  int                    *f;  /* Profile function code.                   */
+  float                  *r;  /* Radius of profile.                       */
+  float                  *n;  /* Index of profile.                        */
+  float                  *p;  /* Position angle of profile                */
+  float                  *q;  /* Axis ratio of profile.                   */
+  float                  *m;  /* Magnitude of profile.                    */
+  float                  *t;  /* Truncation distance.                     */
   gsl_rng              *rng;  /* Main instance of random number generator.*/
   time_t            rawtime;  /* Starting time of the program.            */
   gal_data_t           *out;  /* Output image.                            */
   double               *cat;  /* Input catalog.                           */
-  size_t                cs0;  /* Number of rows in input catalog.         */
-  size_t                cs1;  /* Number of columns in input catalog.      */
   double               *log;  /* Log data to be printed.                  */
   struct builtqueue     *bq;  /* Top (last) elem of build queue.          */
   pthread_cond_t     qready;  /* bq is ready to be written.               */
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index e482a74..edbe56e 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -413,7 +413,7 @@ write(struct mkprofparams *p)
   long os=p->oversample;
   int replace=p->replace;
   gal_data_t *out, *towrite;
-  size_t complete=0, cs0=p->cs0;
+  size_t complete=0, num=p->num;
   struct builtqueue *ibq=NULL, *tbq;
   float *to, *from, *colend, *rowend;
   size_t i, j, iw, jw, ii, jj, w=p->naxes[0], ow;
@@ -435,7 +435,7 @@ write(struct mkprofparams *p)
 
 
   /* Write each image into the output array. */
-  while(complete<p->cs0)
+  while(complete<p->num)
     {
       /* Set ibq. */
       if(ibq==NULL)
@@ -528,7 +528,7 @@ write(struct mkprofparams *p)
           if(jobname==NULL)
             error(EXIT_FAILURE, errno, "jobname in mkprof.c");
           sprintf(jobname, "row %zu complete, %zu left to go",
-                  ibq->id, cs0-complete);
+                  ibq->id, num-complete);
           gal_timing_report(NULL, jobname, 2);
           free(jobname);
         }
@@ -621,7 +621,7 @@ mkprof(struct mkprofparams *p)
   /* Distribute the different profiles for different threads. Note
      that one thread is left out for writing, while nt-1 are left
      for building. */
-  gal_threads_dist_in_threads(p->cs0, nt, &indexs, &thrdcols);
+  gal_threads_dist_in_threads(p->num, nt, &indexs, &thrdcols);
 
   /* onaxes are sides of the image without over-sampling. */
   onaxes[0] = (p->naxes[0]-2*p->shift[0])/os + 2*p->shift[0]/os;
@@ -641,7 +641,7 @@ mkprof(struct mkprofparams *p)
       /* Initialize the attributes. Note that this main thread will
          also have to be kept behind the barrier, so we need nt+1
          barrier stops. */
-      if(p->cs0<nt) nb=p->cs0+1;
+      if(p->num<nt) nb=p->num+1;
       else nb=nt+1;
       gal_threads_attr_barrier_init(&attr, &b, nb);
 
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index 690abba..8540475 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -26,6 +26,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <errno.h>
 #include <error.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <gnuastro/fits.h>
 #include <gnuastro/table.h>
@@ -314,8 +315,8 @@ ui_read_check_only_options(struct mkprofparams *p)
 static void
 ui_check_options_and_arguments(struct mkprofparams *p)
 {
-  /* Make sure an input table is given, and if it is FITS, that the HDU is
-     also provided. */
+  /* Make sure an input catalog is given, and if it is FITS, that the HDU
+     is also provided. */
   if(p->catname)
     {
       if( gal_fits_name_is_fits(p->catname) && p->cp.hdu==NULL)
@@ -353,22 +354,171 @@ ui_check_options_and_arguments(struct mkprofparams *p)
 /***************       Preparations         *******************/
 /**************************************************************/
 static void
-ui_preparations(struct mkprofparams *p)
+ui_read_profile_function(struct mkprofparams *p, char **strarr)
+{
+  size_t i;
+
+  p->f=gal_data_malloc_array(GAL_DATA_TYPE_INT, p->num);
+  for(i=0;i<p->num;++i)
+    {
+      if( !strcmp("sersic", strarr[i]) )
+        p->f[i]=PROFILE_SERSIC;
+      else if ( !strcmp("moffat", strarr[i]) )
+        p->f[i]=PROFILE_MOFFAT;
+      else if ( !strcmp("gaussian", strarr[i]) )
+        p->f[i]=PROFILE_GAUSSIAN;
+      else if ( !strcmp("point", strarr[i]) )
+        p->f[i]=PROFILE_POINT;
+      else if ( !strcmp("flat", strarr[i]) )
+        p->f[i]=PROFILE_FLAT;
+      else if ( !strcmp("circumference", strarr[i]) )
+        p->f[i]=PROFILE_CIRCUMFERENCE;
+      else
+        error(EXIT_FAILURE, 0, "`%s' not recognized as a profile function "
+              "name in row %zu", strarr[i], i);
+    }
+}
+
+
+
+
+
+static void
+ui_read_cols(struct mkprofparams *p)
 {
-  struct gal_linkedlist_stll *cols=NULL;
+  size_t counter=0;
+  gal_data_t *cols, *tmp, *corrtype;
   char *ax1col=p->racol?p->racol:p->xcol;
   char *ax2col=p->deccol?p->deccol:p->ycol;
+  struct gal_linkedlist_stll *colstrs=NULL;
+
+  /* Specify the order of columns. */
+  gal_linkedlist_add_to_stll(&colstrs, ax1col, 0);
+  gal_linkedlist_add_to_stll(&colstrs, ax2col, 0);
+  gal_linkedlist_add_to_stll(&colstrs, p->fcol, 0);
+  gal_linkedlist_add_to_stll(&colstrs, p->rcol, 0);
+  gal_linkedlist_add_to_stll(&colstrs, p->ncol, 0);
+  gal_linkedlist_add_to_stll(&colstrs, p->pcol, 0);
+  gal_linkedlist_add_to_stll(&colstrs, p->qcol, 0);
+  gal_linkedlist_add_to_stll(&colstrs, p->mcol, 0);
+  gal_linkedlist_add_to_stll(&colstrs, p->tcol, 0);
+
+  /* Read the desired columns from the file. */
+  cols=gal_table_read(p->catname, p->cp.hdu, colstrs, p->cp.searchin,
+                      p->cp.ignorecase, p->cp.minmapsize);
+
+  /* Set the number of objects. */
+  p->num=cols->size;
+
+  /* For a sanity check, make sure that the total number of columns read is
+     the same as those that were wanted (it might be more). */
+  while(cols!=NULL)
+    {
+      /* Increment the column counter. */
+      ++counter;
+
+      /* Pop out the top node. */
+      tmp=gal_data_pop_from_ll(&cols);
+
+      /* Note that the input was a linked list, so the output order is the
+         inverse of the input order. For the position, we will store the
+         values into the `x' and `y' arrays even if they are RA/Dec. */
+      switch(counter)
+        {
+        case 9:
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_DOUBLE);
+          p->x=corrtype->array;
+          corrtype->array=NULL;
+          break;
+
+        case 8:
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_DOUBLE);
+          p->y=corrtype->array;
+          corrtype->array=NULL;
+          break;
+
+        case 7:
+          if(tmp->type==GAL_DATA_TYPE_STRING)
+            ui_read_profile_function(p, tmp->array);
+          else
+            {
+              corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_INT);
+              p->f=corrtype->array;
+              corrtype->array=NULL;
+            }
+          break;
+
+        case 6:
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_FLOAT);
+          p->r=corrtype->array;
+          corrtype->array=NULL;
+          break;
+
+        case 5:
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_FLOAT);
+          p->n=corrtype->array;
+          corrtype->array=NULL;
+          break;
+
+        case 4:
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_FLOAT);
+          p->p=corrtype->array;
+          corrtype->array=NULL;
+          break;
+
+        case 3:
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_FLOAT);
+          p->q=corrtype->array;
+          corrtype->array=NULL;
+          break;
+
+        case 2:
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_FLOAT);
+          p->m=corrtype->array;
+          corrtype->array=NULL;
+          break;
+
+        case 1:
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_FLOAT);
+          p->t=corrtype->array;
+          corrtype->array=NULL;
+          break;
+
+        /* If the index isn't recognized, then it is larger, showing that
+           there was more than one match for the given criteria */
+        default:
+          error(EXIT_FAILURE, 0, "there was more than one match for at "
+                "least one of the input columns from `%s'. You can check "
+                "the column information with the following command, and "
+                "correct the options ending with `col' appropriately.\n\n"
+                "   $ asttable --information %s\n\n"
+                "The current values to all options can be checked by calling "
+                "the `--printparams' (or `-P') option. To learn more about "
+                "how the columns are selected, please try the following "
+                "command:\n\n"
+                "   $ info gnuastro \"Selecting table columns\" ",
+                p->catname, p->catname);
+        }
+
+    }
+}
+
+
+
+
+
+static void
+ui_preparations(struct mkprofparams *p)
+{
 
   /* Correct/set based on the given oversampling. */
   p->naxes[0] *= p->oversample;
   p->naxes[1] *= p->oversample;
   p->halfpixel = 0.5f/p->oversample;
 
-  /* Read the columns.
-  gal_linkedlist_add_to_stll(cols, ax1col, 0);
-  gal_table_read(char *filename, char *hdu, struct gal_linkedlist_stll *cols,
-                 int searchin, int ignorecase, int minmapsize);
-  */
+  /* Read in all the columns. */
+  ui_read_cols(p);
+
 }
 
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 0374b33..6633eef 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -14056,26 +14056,29 @@ column number, where counting starts from zero.
 @table @option
 
 @item --fcol=INT/STR
-The functional form of the profile with one of the values below. Note that
-this value will be converted to an integer before analysis using the
-internal type conversion of C. So for example 2.80 will be converted to 2.
+The functional form of the profile with one of the values below. The column
+can contain both string characters (for example address@hidden') and the
+numeric codes (address@hidden'). The string format can be easier when the
+catalog is to be read, or written by hand. For ways to benefit from string
+columns in a plain text table/catalog, see @ref{Gnuastro text table
+format}.
 
 @itemize
 @item
-0: S@'ersic.
+S@'ersic profile with address@hidden' or address@hidden'.
 @item
-1: Moffat.
+Moffat profile with address@hidden' or address@hidden'.
 @item
-2: Gaussian.
+Gaussian profile with address@hidden' or address@hidden'.
 @item
-3: Point source (a star).
+Point source with address@hidden' or address@hidden'.
 @item
-4: Flat profile: all pixels have same value.
+Flat profile with address@hidden' or address@hidden'.
 @item
-5: Circumference: same value for all pixels between the truncation
-radius (@mymath{r_t}) and @mymath{r_t-w} where @mymath{w} is the value
-to the @option{--circumwidth}. Currently this is only intended to be
-used for making an elliptical annulus (with a width of 1 or 2 pixels).
+Circumference profile with address@hidden' or address@hidden'. A fixed
+value will be used for all pixels between the truncation radius
+(@mymath{r_t}) and @mymath{r_t-w} (@mymath{w} is the value to the
address@hidden).
 @end itemize
 
 @item --xcol=STR/INT
diff --git a/lib/data.c b/lib/data.c
index 297ec3a..f853412 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -1881,6 +1881,14 @@ gal_data_flag_blank(gal_data_t *data)
       COPY_OTYPE_ITYPE_SET(otype, short);                               \
       break;                                                            \
                                                                         \
+    case GAL_DATA_TYPE_UINT:                                            \
+      COPY_OTYPE_ITYPE_SET(otype, unsigned int);                        \
+      break;                                                            \
+                                                                        \
+    case GAL_DATA_TYPE_INT:                                             \
+      COPY_OTYPE_ITYPE_SET(otype, int);                                 \
+      break;                                                            \
+                                                                        \
     case GAL_DATA_TYPE_ULONG:                                           \
       COPY_OTYPE_ITYPE_SET(otype, unsigned long);                       \
       break;                                                            \
@@ -1902,8 +1910,8 @@ gal_data_flag_blank(gal_data_t *data)
       break;                                                            \
                                                                         \
     default:                                                            \
-      error(EXIT_FAILURE, 0, "type %d not recognized for "              \
-            "for newtype in COPY_OTYPE_SET", in->type);                 \
+      error(EXIT_FAILURE, 0, "type code %d not recognized for "         \
+            "`in->type' in COPY_OTYPE_SET", in->type);                  \
     }
 
 
@@ -1920,6 +1928,12 @@ gal_data_copy_to_new_type(gal_data_t *in, int newtype)
   out=gal_data_alloc(NULL, newtype, in->ndim, in->dsize, in->wcs,
                      0, in->minmapsize, in->name, in->unit, in->comment);
 
+  /* For debugging.
+  printf("in: %d (%s)\nout: %d (%s)\n\n", in->type,
+         gal_data_type_as_string(in->type, 1), out->type,
+         gal_data_type_as_string(out->type, 1));
+  */
+
   /* Fill in the output array: */
   switch(newtype)
     {
@@ -1939,6 +1953,14 @@ gal_data_copy_to_new_type(gal_data_t *in, int newtype)
       COPY_OTYPE_SET(short);
       break;
 
+    case GAL_DATA_TYPE_UINT:
+      COPY_OTYPE_SET(unsigned int);
+      break;
+
+    case GAL_DATA_TYPE_INT:
+      COPY_OTYPE_SET(int);
+      break;
+
     case GAL_DATA_TYPE_ULONG:
       COPY_OTYPE_SET(unsigned long);
       break;
@@ -1973,6 +1995,19 @@ gal_data_copy_to_new_type(gal_data_t *in, int newtype)
 
 
 gal_data_t *
+gal_data_copy_to_new_type_free(gal_data_t *in, int type)
+{
+  gal_data_t *out;
+  out=gal_data_copy_to_new_type(in, type);
+  gal_data_free(in);
+  return out;
+}
+
+
+
+
+
+gal_data_t *
 gal_data_copy(gal_data_t *in)
 {
   return gal_data_copy_to_new_type(in, in->type);
diff --git a/lib/fits.c b/lib/fits.c
index c3b35eb..ff9f9f1 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -497,6 +497,10 @@ gal_fits_read_hdu(char *filename, char *hdu, unsigned char 
img0_tab1)
   fitsfile *fptr;
   int status=0, hdutype;
 
+  /* A small sanity check. */
+  if(hdu==NULL)
+    error(EXIT_FAILURE, 0, "no HDU specified for %s", filename);
+
   /* Add hdu to filename: */
   asprintf(&ffname, "%s[%s#]", filename, hdu);
 
diff --git a/lib/gnuastro/data.h b/lib/gnuastro/data.h
index 6e4928e..f58d71b 100644
--- a/lib/gnuastro/data.h
+++ b/lib/gnuastro/data.h
@@ -289,6 +289,9 @@ gal_data_t *
 gal_data_copy_to_new_type(gal_data_t *in, int newtype);
 
 gal_data_t *
+gal_data_copy_to_new_type_free(gal_data_t *in, int type);
+
+gal_data_t *
 gal_data_copy(gal_data_t *in);
 
 int
diff --git a/lib/options.c b/lib/options.c
index 0bb7404..954364c 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -1183,7 +1183,7 @@ options_set_lengths(struct argp_option *poptions,
    multiple lines and without the `#', the start of the line will be read
    as an option. */
 static void
-options_print_doc(FILE *fp, char *doc, int nvwidth)
+options_print_doc(FILE *fp, const char *doc, int nvwidth)
 {
   size_t len=strlen(doc);
 
diff --git a/lib/table.c b/lib/table.c
index a4c5b10..f012414 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -716,7 +716,7 @@ make_list_of_indexs(struct gal_linkedlist_stll *cols, 
gal_data_t *allcols,
    columns should be specified by the `cols' linked list as string values
    in each node of the list, the strings in each node can be a number, an
    exact match to a column name, or a regular expression (in GNU AWK
-   format) enclosed in `/ /'. The `tosearch' value comes from the
+   format) enclosed in `/ /'. The `searchin' value comes from the
    `gal_table_where_to_search' enumerator and has to be one of its given
    types. If `cols' is NULL, then this function will read the full table.
 



reply via email to

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