gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 7b8861d4: Fits: new --pixareaonwcs option to v


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 7b8861d4: Fits: new --pixareaonwcs option to visualize distortion
Date: Sun, 16 Oct 2022 18:53:32 -0400 (EDT)

branch: master
commit 7b8861d4aeaf72252fcee5ce1123057aa9761d72
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Fits: new --pixareaonwcs option to visualize distortion
    
    Until now, the users could read the pixel area value determined by the WCS
    keywords using the '--pixelarea' option. However they had no way of knowing
    how much of an area (in degrees squared) each input image pixel has over
    the whole image (which can be different due to distortion). Knowing this
    can help with better understanding the distortion equations.
    
    Although the pixel area value does not vary too much in small distances,
    this difference will create a gradient in images when taking the "accurate"
    pixel area (i.e. each pixel calculated individually from its corners in
    World Coordinates).
    
    With this commit, the Fits program has been given a new '--pixelareaonwcs'
    option which serves the purpose to show the users the most accurate pixel
    area calculated completely based on pixels corners in its given WCS. Since
    this option uses the newly added Warp library of Gnuastro, Fits now also
    has the '--edgesampling' option to get even more accurate.
    
    During the process, many small issues were also implemented:
    
    - Change the 'warp_wcsalign_init_vertices' output from 'gal_data_t' to
      'void' since we have already defined its output (vertices) in
      'gal_warp_wcsalign_t' as the 'vertices' internal variable; Hence, we
      don't need to pass the pointer anymore.
    
    - Added the 'warp_check_basic_params' and 'warp_wcsalign_init_internals' to
      prevent repeating these initializations in the newly defined
      'gal_warp_pixelarea_onwcs' function.
    
    - The 'keyword.h' file of the Fits program held the boilerplate 'HEADER_H'
      value. This commit fixes it to the correct 'KEYWORD_H' value.
    
    - Fixed the typo in the comments of 'bin/fits/main.c' file.
    
    - In the gnuastro manual, now the typo in the library linked lists of
      strings section for the 'gal_list_str_last' which returns a
      'gal_list_str_t *' and not a 'size_t' is fixed.
    
    - Print timing reports if program is not in '--quiet' mode.
    
    - Write the configuration parameters in HDU '1' of the output image.
    
    - Write the documentation updating both Fits and Warp, with examples.
    
    - Update my name in previous text with a hyphen and place the missing 'h'
      in a few cases. So the correct form would be "Pedram Ashofteh-Ardakani"
---
 NEWS                              |  12 ++-
 bin/completion.bash.in            |   2 +-
 bin/fits/Makefile.am              |   5 +-
 bin/fits/args.h                   |  38 ++++++-
 bin/fits/astfits.conf             |   6 ++
 bin/fits/fits.c                   |  10 +-
 bin/fits/keywords.h               |   5 +-
 bin/fits/main.c                   |   3 +-
 bin/fits/main.h                   |   4 +
 bin/fits/meta.c                   | 163 ++++++++++++++++++++++++++++
 bin/fits/{keywords.h => meta.h}   |  13 +--
 bin/fits/ui.c                     |  81 ++++++++++++--
 bin/fits/ui.h                     |   4 +
 bin/table/asttable-complete.bash  |   2 +-
 bin/warp/args.h                   |   2 +-
 bin/warp/main.h                   |   2 +-
 bin/warp/ui.c                     |   2 +-
 bin/warp/ui.h                     |   2 +-
 bin/warp/warp.c                   |   2 +-
 configure.ac                      |   2 +-
 developer-build                   |   2 +-
 doc/gnuastro.texi                 |  87 +++++++++++++--
 lib/arithmetic.c                  |   2 +-
 lib/ds9.c                         |   2 +-
 lib/gnuastro-internal/config.h.in |   2 +-
 lib/gnuastro/warp.h               |   7 +-
 lib/polygon.c                     |   2 +-
 lib/units.c                       |   2 +-
 lib/warp.c                        | 221 ++++++++++++++++++++++++++++----------
 29 files changed, 579 insertions(+), 108 deletions(-)

diff --git a/NEWS b/NEWS
index 99a1db09..7f3b16a1 100644
--- a/NEWS
+++ b/NEWS
@@ -76,6 +76,13 @@ See the end of the file for license conditions.
     standard output. Among other things, this is useful in creating a
     surface brightness image using the new 'counts-to-sb' operator of
     Arithmetic.
+  --pixelareaonwcs: Ouput an image with the same number of pixels as the
+    input. But each pixel's value shows its area on the sky (in
+    degrees-squared). This area is calculated after accounting for
+    distortion, projection or rotation. Implemented by Pedram
+    Ashofteh-Ardakani.
+  --edgesampling: extra sampling along each pixel's edge used to configure
+    the output of '--pixelareaonwcs', similar to Warp.
 
   Statistics:
   - Linear and Polynomial least squares fitting are now available and very
@@ -210,6 +217,7 @@ See the end of the file for license conditions.
   - gal_units_mag_to_sb: surface brightness (SB) from magnitude and area.
   - gal_units_sb_to_counts: counts from SB, zeropoint and area.
   - gal_units_sb_to_mag: magnitude from SB and area.
+  - gal_warp_pixelarea: return image of same size, but with area on sky.
   - gal_warp_wcsalign_init: initialize the WCS aligning structure.
   - gal_warp_wcsalign_onpix: Per-pixel filling of output.
   - gal_warp_wcsalign_onthread: function to give to pthreads.
@@ -475,7 +483,7 @@ See the end of the file for license conditions.
               profile. Found and fixed by Sepideh Eskandarlou.
   bug #62253: Arithmetic: segmentation fault when invalid input given for
               'ra-to-degree' or 'deg-to-degree' operators. Found by Pedram
-              Ashofte-Ardakani.
+              Ashofteh-Ardakani.
   bug #62305: Not reading the 'MemFree' keyword in '/proc/meminfo' to find
               the available RAM (and thus printing an annoying
               warning). Reported by Juan Miro.
@@ -594,7 +602,7 @@ See the end of the file for license conditions.
      as a measure of skewness and why its a very important factor when
      understanding how NoiseChisel works. It was originally written by
      Sepideh Eskandarlou, with edits by Elham Saremi and Pedram
-     Ashofte-Ardakani.
+     Ashofteh-Ardakani.
    - New section called "Integer benefits and pitfalls" added under the
      Arithmetic program's documentation. It describes the running time,
      storage and RAM consumption benefits if you use integers (where
diff --git a/bin/completion.bash.in b/bin/completion.bash.in
index dde81319..2c0fea6f 100644
--- a/bin/completion.bash.in
+++ b/bin/completion.bash.in
@@ -36,7 +36,7 @@
 #       it from anywhere, just correct the locatation).
 #
 # Original author:
-#     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+#     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 # Contributing author(s):
 #     Mohammad Akhlaghi <mohammad@akhlaghi.org>
 # Copyright (C) 2021-2022 Free Software Foundation, Inc.
diff --git a/bin/fits/Makefile.am b/bin/fits/Makefile.am
index b647d2ad..c66f85fe 100644
--- a/bin/fits/Makefile.am
+++ b/bin/fits/Makefile.am
@@ -3,6 +3,7 @@
 ## Original author:
 ##     Mohammad Akhlaghi <mohammad@akhlaghi.org>
 ## Contributing author(s):
+##     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 ## Copyright (C) 2015-2022 Free Software Foundation, Inc.
 ##
 ## Gnuastro is free software: you can redistribute it and/or modify it
@@ -34,10 +35,10 @@ bin_PROGRAMS = astfits
 astfits_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la \
                 -lgnuastro $(CONFIG_LDADD)
 
-astfits_SOURCES = main.c ui.c extension.c fits.c keywords.c
+astfits_SOURCES = main.c ui.c extension.c fits.c keywords.c meta.c
 
 EXTRA_DIST = main.h authors-cite.h args.h ui.h extension.c fits.h \
-             keywords.h astfits-complete.bash
+             keywords.h meta.h astfits-complete.bash
 
 
 
diff --git a/bin/fits/args.h b/bin/fits/args.h
index 2da61f2b..ec9d4cc6 100644
--- a/bin/fits/args.h
+++ b/bin/fits/args.h
@@ -5,6 +5,7 @@ Fits is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -399,7 +400,7 @@ struct argp_option program_options[] =
       UI_KEY_COPYKEYS,
       "INT:INT/STR,STR",
       0,
-      "Range/Names of keywords to copy to output HDU.",
+      "Range/Names of keywords to copy in output.",
       UI_GROUP_KEYWORD,
       &p->copykeys,
       GAL_TYPE_STRING,
@@ -450,6 +451,41 @@ struct argp_option program_options[] =
 
 
 
+    {
+      0, 0, 0, 0,
+      "Meta-image creation:",
+      UI_GROUP_META
+    },
+    {
+      "pixelareaonwcs",
+      UI_KEY_PIXELAREAONWCS,
+      0,
+      0,
+      "Image where pixels show their area in sky (WCS).",
+      UI_GROUP_META,
+      &p->pixelareaonwcs,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_0_OR_1,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+    {
+      "edgesampling",
+      UI_KEY_EDGESAMPLING,
+      "INT",
+      0,
+      "Number of extra samplings in pixel sides.",
+      UI_GROUP_META,
+      &p->edgesampling,
+      GAL_TYPE_SIZE_T,
+      GAL_OPTIONS_RANGE_GE_0,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+
+
+
+
 
     /* Output options. */
     {
diff --git a/bin/fits/astfits.conf b/bin/fits/astfits.conf
index 508be2d2..346cdf46 100644
--- a/bin/fits/astfits.conf
+++ b/bin/fits/astfits.conf
@@ -18,3 +18,9 @@
 # permitted in any medium without royalty provided the copyright notice and
 # this notice are preserved.  This file is offered as-is, without any
 # warranty.
+
+# Output:
+ type            float32
+
+# Meta-image creation:
+ edgesampling    0
diff --git a/bin/fits/fits.c b/bin/fits/fits.c
index 976666b7..3abe3d2e 100644
--- a/bin/fits/fits.c
+++ b/bin/fits/fits.c
@@ -5,6 +5,7 @@ Fits is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2017-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -40,6 +41,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include "main.h"
 
 #include "fits.h"
+#include "meta.h"
 #include "keywords.h"
 
 
@@ -863,10 +865,12 @@ fits(struct fitsparams *p)
 
   switch(p->mode)
     {
+    /* Functions creating meta-images, in other words, images conveying
+       information about the given image. */
+    case FITS_MODE_META: meta_pixelareaonwcs(p); break;
+
     /* Keywords, we have a separate set of functions in 'keywords.c'. */
-    case FITS_MODE_KEY:
-      r=keywords(p);
-      break;
+    case FITS_MODE_KEY: r=keywords(p); break;
 
     /* HDU, functions defined here. */
     case FITS_MODE_HDU:
diff --git a/bin/fits/keywords.h b/bin/fits/keywords.h
index 7f76c579..2e1038df 100644
--- a/bin/fits/keywords.h
+++ b/bin/fits/keywords.h
@@ -5,6 +5,7 @@ Fits is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -20,8 +21,8 @@ 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 HEADER_H
-#define HEADER_H
+#ifndef KEYWORDS_H
+#define KEYWORDS_H
 
 int
 keywords(struct fitsparams *p);
diff --git a/bin/fits/main.c b/bin/fits/main.c
index 932083fe..19effbed 100644
--- a/bin/fits/main.c
+++ b/bin/fits/main.c
@@ -5,6 +5,7 @@ Fits is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -44,7 +45,7 @@ main (int argc, char *argv[])
   /* Read the input parameters. */
   ui_read_check_inputs_setup(argc, argv, &p);
 
-  /* Run MakeProfiles */
+  /* Run Fits. */
   r=fits(&p);
 
   /* Free all non-freed allocations. */
diff --git a/bin/fits/main.h b/bin/fits/main.h
index 0cd60c29..cd1e3175 100644
--- a/bin/fits/main.h
+++ b/bin/fits/main.h
@@ -5,6 +5,7 @@ Fits is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -43,6 +44,7 @@ enum fits_mode
 
     FITS_MODE_HDU,
     FITS_MODE_KEY,
+    FITS_MODE_META,
   };
 
 
@@ -89,6 +91,8 @@ struct fitsparams
   char       *wcsdistortion;   /* WCS distortion to write in output.    */
   uint8_t       quitonerror;   /* Quit if an error occurs.              */
   uint8_t   colinfoinstdout;   /* Print column info in output.          */
+  uint8_t    pixelareaonwcs;   /* Get pixel area by warp edgesampling.  */
+  size_t       edgesampling;   /* Sampling of edges in '--pixelareaonwcs'*/
 
   /* Internal: */
   int                         mode;  /* Operating on HDUs or keywords.  */
diff --git a/bin/fits/meta.c b/bin/fits/meta.c
new file mode 100644
index 00000000..3a445f89
--- /dev/null
+++ b/bin/fits/meta.c
@@ -0,0 +1,163 @@
+/*********************************************************************
+Fits - View and manipulate FITS extensions and/or headers.
+Fits is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Corresponding author:
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
+Contributing author(s):
+     Mohammad Akhlaghi <mohammad@akhlaghi.org>
+Copyright (C) 2022 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 <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <gnuastro/wcs.h>
+#include <gnuastro/fits.h>
+#include <gnuastro/warp.h>
+#include <gnuastro/array.h>
+
+#include <gnuastro-internal/timing.h>
+#include <gnuastro-internal/checkset.h>
+
+#include "main.h"
+
+#include "meta.h"
+
+
+
+
+
+/* Prepare the 'wcsalign' structure based on given options. */
+static void
+meta_initialize(struct fitsparams *p, gal_warp_wcsalign_t *wa)
+{
+  /* Low-level variables. */
+  gal_data_t *input=NULL;
+  struct gal_options_common_params *cp=&p->cp;
+
+  /* High-level variables. */
+  char *hdu=cp->hdu;
+  char *inputname=p->input->v;
+  char *suffix="_pixarea.fits";
+
+  /* Set automatic output filename if nothing is given. */
+  if(!cp->output)
+    cp->output=gal_checkset_automatic_output(cp, inputname, suffix);
+
+  /* Check if we're allowed to delete the output image. If not, fail FAST
+     before any CPU-intensive process. */
+  gal_checkset_writable_remove(cp->output, 0, cp->dontdelete);
+
+  /* Read the input image and its WCS, must free it when done. */
+  input=gal_array_read_one_ch_to_type(inputname, hdu, NULL,
+                                      GAL_TYPE_FLOAT64, -1,  0);
+  input->wcs=gal_wcs_read(inputname, hdu, 0, 0, 0, &input->nwcs);
+
+  /* Prepare the essential warping variables. */
+  wa->input=input;
+  wa->numthreads=cp->numthreads;
+  wa->edgesampling=p->edgesampling;
+
+  /* We're using the same grid so only 'coveredfrac=1.0f' is sensible. In
+     other words, there are no overlaps between the two grids where one
+     pixel might encounter neighboring NaN values which then 'coveredfrac'
+     takes care of. */
+  wa->coveredfrac=1;
+
+  /* Done with initializations, notify the user and start. */
+  if(!p->cp.quiet)
+    {
+      printf(PROGRAM_NAME" "PACKAGE_VERSION" started on %s",
+             ctime(&p->rawtime));
+      printf(" Using %zu CPU thread%s\n", p->cp.numthreads,
+             p->cp.numthreads==1 ? "." : "s.");
+      printf(" Input: %s (hdu: %s)\n", inputname, hdu);
+      printf(" Output: %s (size: %zux%zu, type: %s)\n", cp->output,
+             input->dsize[0], input->dsize[1],
+             gal_type_name(p->cp.type, 1));
+    }
+}
+
+
+
+
+
+/* Write the configuration keywords and the created image to output. */
+static void
+meta_write_to_file(struct fitsparams *p, gal_warp_wcsalign_t *wa)
+{
+  gal_data_t *output=wa->output;
+  gal_fits_list_key_t *headers=NULL;
+
+  /* Add configuration headers. */
+  gal_fits_key_list_add_end(&headers, GAL_TYPE_STRING,
+                            "input", 0, p->input->v, 0,
+                            "File given to astfits", 0, NULL, 0);
+  gal_fits_key_list_add_end(&headers, GAL_TYPE_SIZE_T,
+                            "edgesampling", 0, &p->edgesampling, 0,
+                            "Extra sampling along pixel edges.", 0, NULL, 0);
+  gal_fits_key_list_add_end(&headers, GAL_TYPE_FLOAT64,
+                            "Coveredfrac", 0, &wa->coveredfrac, 0,
+                            "Fraction of pixel that is covered by input",
+                            0, NULL, 0);
+
+  /* Convert to type and write to file. */
+  if(p->cp.type!=output->type)
+    output=gal_data_copy_to_new_type_free(output, p->cp.type);
+  gal_fits_img_write(output, p->cp.output, headers, PROGRAM_NAME);
+
+  /* Clean up. */
+  wa->output=NULL; /* Must be here to prevent double freeing. */
+  gal_data_free(output);
+  gal_data_free(wa->input);
+}
+
+
+
+
+
+/* Calculate input pixel area on WCS and write as pixel values on the a
+   copy of the input. */
+void
+meta_pixelareaonwcs(struct fitsparams *p)
+{
+  struct timeval t1;
+
+  /* Store program start time, and the epoch for further timing reports. */
+  time(&p->rawtime);
+  gettimeofday(&t1, NULL);
+
+  /* Call for an empty wcsalign structure. */
+  gal_warp_wcsalign_t wa=gal_warp_wcsalign_template();
+
+  /* Initialize the warping variables based on commandline arguments. */
+  meta_initialize(p, &wa);
+
+  /* Execute the warping and fill the data-structure with results. */
+  gal_warp_pixelarea(&wa);
+
+  /* Done with calculations, write to file and finish. */
+  meta_write_to_file(p, &wa);
+
+  /* Report how long the operation took. */
+  if(!p->cp.quiet)
+    gal_timing_report(&t1, PROGRAM_NAME" finished in: ", 0);
+}
diff --git a/bin/fits/keywords.h b/bin/fits/meta.h
similarity index 83%
copy from bin/fits/keywords.h
copy to bin/fits/meta.h
index 7f76c579..10767ae7 100644
--- a/bin/fits/keywords.h
+++ b/bin/fits/meta.h
@@ -3,9 +3,10 @@ Fits - View and manipulate FITS extensions and/or headers.
 Fits is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Original author:
-     Mohammad Akhlaghi <mohammad@akhlaghi.org>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Contributing author(s):
-Copyright (C) 2015-2022 Free Software Foundation, Inc.
+     Mohammad Akhlaghi <mohammad@akhlaghi.org>
+Copyright (C) 2022      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,10 +21,10 @@ 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 HEADER_H
-#define HEADER_H
+#ifndef META_H
+#define META_H
 
-int
-keywords(struct fitsparams *p);
+void
+meta_pixelareaonwcs(struct fitsparams *p);
 
 #endif
diff --git a/bin/fits/ui.c b/bin/fits/ui.c
index 20007689..a35e7c54 100644
--- a/bin/fits/ui.c
+++ b/bin/fits/ui.c
@@ -5,6 +5,7 @@ Fits is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -110,6 +111,7 @@ ui_initialize_options(struct fitsparams *p,
 
   /* For clarity and non-zero initializations. */
   p->mode                = FITS_MODE_INVALID;
+  p->edgesampling        = GAL_BLANK_SIZE_T;
 
   /* Modify common options. */
   for(i=0; !gal_options_is_last(&cp->coptions[i]); ++i)
@@ -119,7 +121,6 @@ ui_initialize_options(struct fitsparams *p,
         {
         case GAL_OPTIONS_KEY_SEARCHIN:
         case GAL_OPTIONS_KEY_IGNORECASE:
-        case GAL_OPTIONS_KEY_TYPE:
         case GAL_OPTIONS_KEY_WCSLINEARMATRIX:
         case GAL_OPTIONS_KEY_DONTDELETE:
         case GAL_OPTIONS_KEY_LOG:
@@ -129,7 +130,7 @@ ui_initialize_options(struct fitsparams *p,
           break;
 
         case GAL_OPTIONS_KEY_OUTPUT:
-          cp->coptions[i].doc="Output file name (only for writing HDUs).";
+          cp->coptions[i].doc="Output file name (not for keywords).";
           break;
         }
 
@@ -359,17 +360,55 @@ ui_check_copykeys(struct fitsparams *p)
 
 
 
+/* If any of the META related keywords are given, set mode accordingly. */
+static void
+ui_read_check_mode_meta(struct fitsparams *p)
+{
+  /* Make sure no other type of operation is requested. */
+  if(p->mode!=FITS_MODE_INVALID)
+    error(EXIT_FAILURE, 0, "meta image options (like '--pixelareaonwcs' "
+          "cannot be called with HDU or keyword manipulation options");
+
+  /* If '--type' is not given, inform the user. */
+  if(p->cp.type==0)
+    error(EXIT_FAILURE, 0, "no '--type' specified! This is necessary "
+          "to determine the numerical data type of the output image. "
+          "In most cases, '--type=float32' is sufficient");
+
+  /* If '--edgesampling' isn't given, inform the user. */
+  if(p->edgesampling==GAL_BLANK_SIZE_T)
+    error(EXIT_FAILURE, 0, "no '--edgesampling'! Please specify a "
+          "value to the '--edgesampling' option (usually '0' is "
+          "fine). This specifies the extra samplings along a pixel's "
+          "edge in options like '--pixelareaonwcs' in case "
+          "distortions are significant. Just note that non-zero "
+          "values will significantly slow down the program");
+
+  /* Check if a HDU is given. */
+  if(p->cp.hdu==NULL)
+    error(EXIT_FAILURE, 0, "a HDU (extension) is necessary for meta "
+          "image outputs (e.g., with '--pixelareaonwcs') but none "
+          "was defined. Please use the '--hdu' (or '-h') option to "
+          "select one of your input's HDUs. You can use the "
+          "'astfits input.fits' command to see the list of "
+          "available HDUs in 'input.fits'");
+
+  /* Set the mode. */
+  p->mode=FITS_MODE_META;
 
-/* Read and check ONLY the options. When arguments are involved, do the
-   check in 'ui_check_options_and_arguments'. */
+}
+
+
+
+
+
+/* If any of the keyword manipulation options are requested, then set the
+   mode flag to keyword-mode. */
 static void
-ui_read_check_only_options(struct fitsparams *p)
+ui_read_check_mode_keyword(struct fitsparams *p)
 {
   int checkkeys;
-  uint8_t stdoutcheck=0;
 
-  /* If any of the keyword manipulation options are requested, then set the
-     mode flag to keyword-mode. */
   if( p->date || p->comment || p->history || p->asis || p->keyvalue
       || p->delete || p->rename || p->update || p->write || p->verify
       || p->printallkeys || p->printkeynames || p->copykeys || p->datetosec
@@ -418,8 +457,17 @@ ui_read_check_only_options(struct fitsparams *p)
       /* Set the operating mode. */
       p->mode=FITS_MODE_KEY;
     }
+}
+
+
+
+
+/* Same for the extension-related options */
+static void
+ui_read_check_mode_extension(struct fitsparams *p)
+{
+  uint8_t stdoutcheck=0;
 
-  /* Same for the extension-related options */
   if( p->remove || p->copy || p->cut || p->numhdus || p->datasum
       || p->pixelscale || p->pixelareaarcsec2 || p->skycoverage
       || p->hastablehdu || p->hasimagehdu || p->listtablehdus
@@ -475,6 +523,21 @@ ui_read_check_only_options(struct fitsparams *p)
       /* Set the operating mode. */
       p->mode=FITS_MODE_HDU;
     }
+}
+
+
+
+
+
+/* Read and check ONLY the options. When arguments are involved, do the
+   check in 'ui_check_options_and_arguments'. */
+static void
+ui_read_check_only_options(struct fitsparams *p)
+{
+  /* Check the given optinos and set the operating mode accordingly. */
+  ui_read_check_mode_keyword(p);
+  ui_read_check_mode_extension(p);
+  if( p->pixelareaonwcs) ui_read_check_mode_meta(p);
 
   /* If no options are given, go into HDU mode, which will print the HDU
      information when nothing is asked. */
diff --git a/bin/fits/ui.h b/bin/fits/ui.h
index f74237d5..8e53a4f4 100644
--- a/bin/fits/ui.h
+++ b/bin/fits/ui.h
@@ -5,6 +5,7 @@ Fits is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -36,6 +37,7 @@ enum program_args_groups
   UI_GROUP_EXTENSION_INFORMATION = GAL_OPTIONS_GROUP_AFTER_COMMON,
   UI_GROUP_EXTENSION_MANIPULATION,
   UI_GROUP_KEYWORD,
+  UI_GROUP_META,
 };
 
 
@@ -74,6 +76,7 @@ enum option_keys_enum
   UI_KEY_TITLE        = 1000,
   UI_KEY_DATASUM,
   UI_KEY_PIXELSCALE,
+  UI_KEY_PIXELAREAONWCS,
   UI_KEY_PIXELAREAARCSEC2,
   UI_KEY_SKYCOVERAGE,
   UI_KEY_HASTABLEHDU,
@@ -87,6 +90,7 @@ enum option_keys_enum
   UI_KEY_WCSCOORDSYS,
   UI_KEY_PRIMARYIMGHDU,
   UI_KEY_WCSDISTORTION,
+  UI_KEY_EDGESAMPLING,
 };
 
 
diff --git a/bin/table/asttable-complete.bash b/bin/table/asttable-complete.bash
index 260307fb..87218b02 100644
--- a/bin/table/asttable-complete.bash
+++ b/bin/table/asttable-complete.bash
@@ -2,7 +2,7 @@
 # 'bin/completion.bash.in' for more.
 #
 # Original author:
-#     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+#     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 # Contributing author(s):
 #     Mohammad Akhlaghi <mohammad@akhlaghi.org>
 # Copyright (C) 2021-2022 Free Software Foundation, Inc.
diff --git a/bin/warp/args.h b/bin/warp/args.h
index bfc17bd1..acf790c5 100644
--- a/bin/warp/args.h
+++ b/bin/warp/args.h
@@ -5,7 +5,7 @@ Warp is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/bin/warp/main.h b/bin/warp/main.h
index db2d5195..e558ab64 100644
--- a/bin/warp/main.h
+++ b/bin/warp/main.h
@@ -5,7 +5,7 @@ Warp is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/bin/warp/ui.c b/bin/warp/ui.c
index 6d958e97..8533c1dc 100644
--- a/bin/warp/ui.c
+++ b/bin/warp/ui.c
@@ -5,7 +5,7 @@ Warp is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/bin/warp/ui.h b/bin/warp/ui.h
index 89f08fd0..4cd00a0b 100644
--- a/bin/warp/ui.h
+++ b/bin/warp/ui.h
@@ -5,7 +5,7 @@ Warp is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/bin/warp/warp.c b/bin/warp/warp.c
index 896af1ed..228f155d 100644
--- a/bin/warp/warp.c
+++ b/bin/warp/warp.c
@@ -5,7 +5,7 @@ Warp is part of GNU Astronomy Utilities (Gnuastro) package.
 Corresponding author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/configure.ac b/configure.ac
index bac0e33d..8173a6c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,7 +12,7 @@
 # Original author:
 #     Mohammad Akhlaghi <mohammad@akhlaghi.org>
 # Contributing author(s):
-#     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+#     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 #     Jash Shah <jash28582@gmail.com>
 # Copyright (C) 2015-2022 Free Software Foundation, Inc.
 #
diff --git a/developer-build b/developer-build
index 8162c9d6..e4a665b2 100755
--- a/developer-build
+++ b/developer-build
@@ -10,7 +10,7 @@
 # Contributing author(s):
 #   Mosè Giordano <mose@gnu.org>
 #   Raul Infante-Sainz <infantesainz@gmail.com>
-#   Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+#   Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 # Copyright (C) 2016-2022 Free Software Foundation, Inc.
 #
 # Gnuastro is free software: you can redistribute it and/or modify it under
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 53b27cff..51a85e60 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -438,7 +438,8 @@ Fits
 Invoking Fits
 
 * HDU information and manipulation::  Learn about the HDUs and move them.
-* Keyword inspection and manipulation::  Manipulate metadata keywords in a HDU
+* Keyword inspection and manipulation::  Manipulate metadata keywords in a HDU.
+* Pixel information images::    Pixel values contain information on the pixels.
 
 ConvertType
 
@@ -11789,6 +11790,11 @@ $ astfits --delete=COMMENT --comment="Anything you 
like ;-)."
 
 ## Write two new keywords with different values and comments:
 $ astfits --write=MYKEY1,20.00,"An example keyword" --write=MYKEY2,fd
+
+## Inspect individual pixel area taken based on its WCS (in degree^2).
+## Then convert the area to arcsec^2 with the Arithmetic program.
+$ astfits input.fits --pixareaonwcs -o pixarea.fits
+$ astarithmetic pixarea.fits 3600 3600 x x -o pixarea_arcsec2.fits
 @end example
 
 @cindex HDU
@@ -11826,14 +11832,16 @@ The @option{--hdu} value given in a configuration 
file will only be used when a
 Therefore as described in the paragraphs above, when no explicit call to the 
@option{--hdu} option is made on the command-line and no operation is requested 
(on the command-line or configuration files), the basic information of each 
HDU/extension is printed.
 
 The operating mode and input/output options to Fits are similar to the other 
programs and fully described in @ref{Common options}.
-The options particular to Fits can be divided into two groups:
+The options particular to Fits can be divided into three groups:
 1) those related to modifying HDUs or extensions (see @ref{HDU information and 
manipulation}), and
 2) those related to viewing/modifying meta-data keywords (see @ref{Keyword 
inspection and manipulation}).
-These two classes of options cannot be called together in one run: you can 
either work on the extensions or meta-data keywords in any instance of Fits.
+3) those related to creating meta-images where each pixel shows values for a 
specific property of the image (see @ref{Pixel information images}).
+These three classes of options cannot be called together in one run: you can 
either work on the extensions, meta-data keywords in any instance of Fits, or 
create meta-images where each pixel shows a particular information about the 
image itself.
 
 @menu
 * HDU information and manipulation::  Learn about the HDUs and move them.
-* Keyword inspection and manipulation::  Manipulate metadata keywords in a HDU
+* Keyword inspection and manipulation::  Manipulate metadata keywords in a HDU.
+* Pixel information images::    Pixel values contain information on the pixels.
 @end menu
 
 
@@ -12000,7 +12008,7 @@ If we had not used @option{--primaryimghdu}, then the 
zero-th extension of @file
 @end table
 
 
-@node Keyword inspection and manipulation,  , HDU information and 
manipulation, Invoking astfits
+@node Keyword inspection and manipulation, Pixel information images, HDU 
information and manipulation, Invoking astfits
 @subsubsection Keyword inspection and manipulation
 The meta-data in each header data unit, or HDU (also known as extension, see 
@ref{Fits}) is stored as ``keyword''s.
 Each keyword consists of a name, value, unit, and comments.
@@ -12426,7 +12434,8 @@ However, the WCS coordinate system of 
@file{img-eq.fits} will be the equatorial
 Fits will automatically extract the current coordinate system of 
@file{image.fits} and as long as it is one of the recognized coordinate systems 
listed below, it will do the conversion.
 
 @example
-$ astfits image.fits --wcscoordsys=eq-j2000 --output=img-eq.fits
+$ astfits image.fits --wcscoordsys=eq-j2000 \
+          --output=img-eq.fits
 @end example
 
 The currently recognized coordinate systems are listed below (the most common 
one today is @code{eq-j2000}):
@@ -12474,6 +12483,61 @@ $ astfits in.fits --wcsdistortion=SIP --output=out.fits
 @end table
 
 
+@node Pixel information images,  , Keyword inspection and manipulation, 
Invoking astfits
+@subsubsection Pixel information images
+In @ref{Keyword inspection and manipulation} options like 
@option{--pixelscale} were introduced for information on the pixels from the 
keywords.
+But that only provides a single value for all the pixels!
+This will not be sufficient in some scenarios; for example due to distortion, 
different regions of the image will have different pixel areas when projected 
onto the sky.
+
+@cindex Meta image
+The options in this section provide such ``meta'' images: images where the 
pixel values are information about the pixel itself.
+Such images can be useful in understanding the underlying pixel grid with the 
same tools that you study the astronomical objects within the image (like 
@ref{SAO DS9}).
+After all, nothing beats visual inspection with tools you are familiar with.
+
+@table @code
+@item --pixareaonwcs
+Create a meta-image where each pixel's value shows its area in the WCS units 
(usually degrees squared).
+The output is therefore the same size as the input.
+
+@cindex Pixel mixing
+@cindex Area resampling
+@cindex Resampling by area
+This option uses the same ``pixel mixing'' or ``area resampling'' concept that 
is described in @ref{Resampling} (as part of the Warp program).
+Similar to Warp, its sampling can be tuned with the @option{--edgesampling} 
that is described below.
+
+@cindex Distortion
+@cindex Area of pixel on sky
+One scenario where this option becomes handy is when you are debugging aligned 
images using the Warp program (see @ref{Warp}).
+You may observe gradients after warping and can check if they caused by the 
distortion of the instrument or not.
+Such gradients can happen due to distortions because the detectors pixels are 
measuring photons from different areas on the sky (or the type of projection 
you're seeing).
+This effect is more pronounced in images covering larger portions of the sky, 
for instance, the TESS 
images@footnote{@url{https://www.nasa.gov/tess-transiting-exoplanet-survey-satellite}}.
+
+Here is an example usage of the @option{--pixareaonwcs} option:
+
+@example
+# Check the area each 'input.fits' pixel takes in sky
+$ astfits input.fits -h1 --pixareaonwcs -o pixarea.fits
+
+# Convert each pixel's area to arcsec^2
+$ astarithmetic pixarea.fits 3600 3600 x x \
+                --output=pixarea_arcsec2.fits
+
+# Compare area relative to the actual reported pixel scale
+$ pixarea=$(astfits input.fits --pixelscale -q \
+                    | awk '@{print $3@}')
+$ astarithmetic pixarea.fits $pixarea / -o pixarea_rel.fits
+@end example
+
+@item --edgesampling=INT
+Extra sampling along the pixel edges for @option{--pixareaonwcs}.
+The default value is 0, meaning that only the pixel vertices are used.
+Values greater than zero improve the accuracy in the expense of greater time 
and memory consumption.
+With that said, the default value of zero usually has a good precision unless 
the given image has extreme distortions that produce irregular pixel shapes.
+For more, see @ref{Align pixels with WCS account for distortions}).
+@end table
+
+
+
 
 
 
@@ -12547,7 +12611,7 @@ for example, in @ref{Circles and the complex plane} or 
@ref{Distance on a 2D cur
 The most common vector graphics format is PDF for document sharing or SVG for 
web-based applications.
 
 The pixels of a raster image can be shown as vector-based squares with 
different shades, so vector graphics can generally also support raster graphics.
-This is very useful when you want to add some graphics over an image to help 
your discussion (for examle a @mymath{+} over your object of interest).
+This is very useful when you want to add some graphics over an image to help 
your discussion (for example a @mymath{+} over your object of interest).
 However, vector graphics is not optimized for rasterized data (which are 
usually also noisy!), and can ither not display nicely, or result in much 
larger file volumns (in bytes).
 Therefore, if it is not necessary to add any marks over a FITS image, for 
example, it may be better to store it in a rasterized format.
 
@@ -19788,6 +19852,8 @@ To account for this possible curvature due to 
distortion, you can use this optio
 For example, @option{--edgesampling=1} will add one extra vertice in the 
middle of each edge of the output pixel, producing an 8-vertice polygon.
 Similarly, @option{--edgesampling=5} will put 5 extra vertices along each 
edge, thus sampling the shape (and possible curvature) of the output pixel over 
an input pixel with @mymath{4+5\times4=24} vertice polygon.
 Since the polygon clipping will happen for every output pixel, a higher value 
to this option can significantly reduce the running speed and increase the RAM 
usage of Warp; so use it with caution: in most cases the default 
@option{--edgesampling=0} is sufficient.
+
+To visually inspect the curvature effect on pixel area of the input image, see 
option @option{--pixareaonwcs} in @ref{Pixel information images}.
 @end table
 
 
@@ -31376,7 +31442,7 @@ If @code{*list==NULL}, then this function will also 
return a @code{NULL} pointer
 Return the number of nodes in @code{list}.
 @end deftypefun
 
-@deftypefun size_t gal_list_str_last (gal_list_str_t @code{*list})
+@deftypefun {gal_list_str_t *} gal_list_str_last (gal_list_str_t @code{*list})
 Return a pointer to the last node in @code{list}.
 @end deftypefun
 
@@ -37087,6 +37153,11 @@ Low-level function to free the internal variables 
inside @code{wa} only.
 The caller must free the input pointers themselves, this function will not 
free them (they may be necessary in other parts of the caller's higher-level 
architecture).
 @end deftypefun
 
+@deftypefun void gal_warp_pixelarea (gal_warp_wcsalign_t *wa)
+Calculate each input pixel's area based on its WCS and save it to a copy of 
the input image with only one difference: the pixel values now show pixel area.
+For examples on itse usage, see @ref{Pixel information images}.
+@end deftypefun
+
 
 
 
diff --git a/lib/arithmetic.c b/lib/arithmetic.c
index 6abac87d..fa2b36e5 100644
--- a/lib/arithmetic.c
+++ b/lib/arithmetic.c
@@ -5,7 +5,7 @@ This is part of GNU Astronomy Utilities (Gnuastro) package.
 Corresponding author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/lib/ds9.c b/lib/ds9.c
index 9f855786..64303416 100644
--- a/lib/ds9.c
+++ b/lib/ds9.c
@@ -5,7 +5,7 @@ This is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/lib/gnuastro-internal/config.h.in 
b/lib/gnuastro-internal/config.h.in
index 55be577b..ac0d97e1 100644
--- a/lib/gnuastro-internal/config.h.in
+++ b/lib/gnuastro-internal/config.h.in
@@ -4,7 +4,7 @@ Functions dealing with general aspects of all Gnuastro.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2016-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/lib/gnuastro/warp.h b/lib/gnuastro/warp.h
index 0ca9742a..f0c098f8 100644
--- a/lib/gnuastro/warp.h
+++ b/lib/gnuastro/warp.h
@@ -3,7 +3,7 @@ Warp -- Warp pixels of one dataset to another pixel grid.
 This is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Corresponding author:
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Contributing author(s):
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Copyright (C) 2022 Free Software Foundation, Inc.
@@ -95,6 +95,7 @@ void
 gal_warp_wcsalign_onpix(gal_warp_wcsalign_t *wa, size_t ind);
 
 
+/* Worker function to align per pixel. */
 void *
 gal_warp_wcsalign_onthread(void *inparam);
 
@@ -111,6 +112,10 @@ void
 gal_warp_wcsalign_free(gal_warp_wcsalign_t *wa);
 
 
+/* Return an image where each pixel shows its own area on the sky. */
+void
+gal_warp_pixelarea(gal_warp_wcsalign_t *wa);
+
 
 __END_C_DECLS    /* From C++ preparations */
 
diff --git a/lib/polygon.c b/lib/polygon.c
index 939ef18d..bf646ed2 100644
--- a/lib/polygon.c
+++ b/lib/polygon.c
@@ -6,7 +6,7 @@ Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
      Sachin Kumar Singh <sachinkumarsingh092@gmail.com>
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/lib/units.c b/lib/units.c
index a280506a..2732ee7b 100644
--- a/lib/units.c
+++ b/lib/units.c
@@ -6,7 +6,7 @@ Original author:
      Kartik Ohri <kartikohri13@gmail.com>
 Contributing author(s):
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Copyright (C) 2020-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
diff --git a/lib/warp.c b/lib/warp.c
index 8b8bae87..d0d68e24 100644
--- a/lib/warp.c
+++ b/lib/warp.c
@@ -3,7 +3,7 @@ Warp -- Warp pixels of one dataset to another pixel grid.
 This is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Corresponding author:
-     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
+     Pedram Ashofteh-Ardakani <pedramardakani@pm.me>
 Contributing author(s):
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Copyright (C) 2022 Free Software Foundation, Inc.
@@ -256,7 +256,7 @@ warp_wcsalign_init_output_from_params(gal_warp_wcsalign_t 
*wa)
 
 
 
-static gal_data_t *
+static void
 warp_wcsalign_init_vertices(gal_warp_wcsalign_t *wa)
 {
   size_t es=wa->edgesampling;
@@ -338,7 +338,7 @@ warp_wcsalign_init_vertices(gal_warp_wcsalign_t *wa)
         }
     }
 
-  return vertices;
+  wa->vertices=vertices;
 }
 
 
@@ -579,11 +579,11 @@ warp_wcsalign_init_output_from_wcs(gal_warp_wcsalign_t 
*wa,
 
 
 
-static void *
-warp_wcsalign_init_params(gal_warp_wcsalign_t *wa, const char *func)
+/* Check parameters shared between the wcsalign procedure and the other
+   library functions such as pixelarea_onwcs. */
+static void
+warp_check_basic_params(gal_warp_wcsalign_t *wa, const char *func)
 {
-  size_t *tmp=NULL;
-
   /* Check if input and 'wa' are not NULL! */
   if(wa==NULL) error(EXIT_FAILURE, 0, "%s: 'wa' structure is NULL", func);
   if(wa->input==NULL) error(EXIT_FAILURE, 0, "%s: input is NULL", func);
@@ -596,15 +596,6 @@ warp_wcsalign_init_params(gal_warp_wcsalign_t *wa, const 
char *func)
           "'gal_data_copy_to_new_type_free' for the conversion", func,
           gal_type_name(wa->input->type, 1));
 
-  /* Check 'coveredfrac'. */
-  if(isnan( wa->coveredfrac ))
-    error(EXIT_FAILURE, 0, "%s: no 'coveredfrac' specified. This is the "
-          "acceptable fraction of output covered", func);
-  if(wa->coveredfrac<0.0f || wa->coveredfrac>1.0f)
-    error(EXIT_FAILURE, 0, "%s: coveredfrac takes exactly on positive "
-          "value less than or equal to 1.0, but it is given a value "
-          "of %f", func, wa->coveredfrac);
-
   /* Check 'edgesampling', can't compare to '0' since it has meaning, can't
      check if negative since it is an unsigned type */
   if(wa->edgesampling==GAL_BLANK_SIZE_T)
@@ -627,6 +618,51 @@ warp_wcsalign_init_params(gal_warp_wcsalign_t *wa, const 
char *func)
   wa->nhor=GAL_BLANK_SIZE_T;
   wa->ncrn=GAL_BLANK_SIZE_T;
   wa->gcrn=GAL_BLANK_SIZE_T;
+}
+
+
+
+
+
+static void
+warp_wcsalign_init_internals(gal_warp_wcsalign_t *wa)
+{
+  size_t es, os0, os1;
+
+  es=wa->edgesampling;
+  os0=wa->output->dsize[0];
+  os1=wa->output->dsize[1];
+
+  /* Pickle variables so other functions can access them. */
+  wa->ncrn=4*es+4;
+  wa->gcrn=1+os1*(es+1);
+  wa->v0=WARP_WCSALIGN_V0(es, os0, os1);
+
+  /* Determine the output image rotation direction so we can sort the
+     indices in counter clockwise order. This is necessary for the
+     'gal_polygon_clip' function to work. */
+  warp_check_output_orientation(wa);
+}
+
+
+
+
+
+static void *
+warp_wcsalign_init_params(gal_warp_wcsalign_t *wa, const char *func)
+{
+  size_t *tmp=NULL;
+
+  warp_check_basic_params(wa, func);
+
+  /* Check 'coveredfrac'. */
+  if(isnan( wa->coveredfrac ))
+    error(EXIT_FAILURE, 0, "%s: no 'coveredfrac' specified. This is the "
+          "acceptable fraction of output covered", func);
+  if(wa->coveredfrac<0.0f || wa->coveredfrac>1.0f)
+    error(EXIT_FAILURE, 0, "%s: coveredfrac takes exactly on positive "
+          "value less than or equal to 1.0, but it is given a value "
+          "of %f", func, wa->coveredfrac);
 
   /* If a target WCS is given ignore other variables and initialize the
      output image. */
@@ -813,37 +849,23 @@ warp_wcsalign_init_convert(void *in_prm)
 void
 gal_warp_wcsalign_init(gal_warp_wcsalign_t *wa)
 {
-  size_t os0, os1, gcrn;
-  gal_data_t *input=wa ? wa->input  : NULL;
-  size_t es = wa ? wa->edgesampling : GAL_BLANK_SIZE_T;
-
   /* Run a sanity check on the input parameters and initialize the output
      image. */
   warp_wcsalign_init_params(wa, __func__);
-  os0=wa->output->dsize[0];
-  os1=wa->output->dsize[1];
-  gcrn=1+os1*(es+1);
 
   /* Set up the output image corners in pixel coords */
-  wa->vertices=warp_wcsalign_init_vertices(wa);
+  warp_wcsalign_init_vertices(wa);
 
   /* Project the output image corners to the input image pixel coords. We
      only want one job per thread, so the number of jobs and the number of
      threads are the same. */
-  gal_threads_spin_off(warp_wcsalign_init_convert, wa, wa->numthreads,
-                       wa->numthreads, input->minmapsize,
-                       input->quietmmap);
-
-  /* Pickle variables so other functions can access them */
-  wa->gcrn=gcrn;
-  wa->input=input;
-  wa->ncrn=4*es+4;
-  wa->v0=WARP_WCSALIGN_V0(es, os0, os1);
+  gal_threads_spin_off(warp_wcsalign_init_convert, wa, wa->output->size,
+                       wa->numthreads, wa->input->minmapsize,
+                       wa->input->quietmmap);
 
-  /* Determine the output image rotation direction so we can sort the
-     indices in counter clockwise order. This is necessary for the
-     'gal_polygon_clip' function to work */
-  warp_check_output_orientation(wa);
+  /* Now that the output image is ready, initialize the helper internal
+     variables for future processing. */
+  warp_wcsalign_init_internals(wa);
 }
 
 
@@ -923,28 +945,26 @@ gal_warp_wcsalign_onpix(gal_warp_wcsalign_t *wa, size_t 
ind)
           v=inputarr[(y-1)*is1+x-1];
 
           /* Find the overlapping (clipped) polygon: */
-          {
-            numcrn=0; /* initialize it. */
-            gal_polygon_clip(ocrn, ncrn, pcrn, 4, ccrn, &numcrn);
-            area=gal_polygon_area(ccrn, numcrn);
-
-            /* Add1 the fractional value of this pixel. If this output
-               pixel covers a NaN pixel in the input grid, then
-               calculate the area of this NaN pixel to account for it
-               later. */
-            if( !isnan(v) )
-              {
-                numinput+=1;
-                filledarea+=area;
-                outputarr[ind]+=v*area;
-
-                /* Check
-                   printf("Check: numinput %zu filledarea %f "
-                          "outputarr[%zu]=%f\n",
-                   filledarea, ind, outputarr[ind]);
-                */
-              }
-          }
+          numcrn=0; /* initialize it. */
+          gal_polygon_clip(ocrn, ncrn, pcrn, 4, ccrn, &numcrn);
+          area=gal_polygon_area(ccrn, numcrn);
+
+          /* Add the fractional value of this pixel. If this output
+             pixel covers a NaN pixel in the input grid, then
+             calculate the area of this NaN pixel to account for it
+             later. */
+          if( !isnan(v) )
+            {
+              numinput+=1;
+              filledarea+=area;
+              outputarr[ind]+=v*area;
+
+              /* Check
+                 printf("Check: numinput %zu filledarea %f "
+                 "outputarr[%zu]=%f\n",
+                 filledarea, ind, outputarr[ind]);
+              */
+            }
         }
     }
 
@@ -1049,3 +1069,86 @@ gal_warp_wcsalign(gal_warp_wcsalign_t *wa)
   /* Clean up the internally allocated variables */
   gal_warp_wcsalign_free(wa);
 }
+
+
+
+
+
+static void *
+warp_pixelarea_onthread(void *inparam)
+{
+  /* Thread variables. */
+  struct gal_threads_params *tprm=(struct gal_threads_params *)inparam;
+  gal_warp_wcsalign_t *wa=(gal_warp_wcsalign_t *)tprm->params;
+
+  /* Low-level variables. */
+  size_t i, ind;
+  double area, *ocrn, *outputarr=wa->output->array;
+  double *(*warp_pixel_perimeter)(gal_warp_wcsalign_t *, size_t);
+
+  /* Call the correct function based on the output image orientation. */
+  if( wa->isccw==1 )
+    warp_pixel_perimeter=warp_pixel_perimeter_cw;
+  else if( wa->isccw==0 )
+    warp_pixel_perimeter=warp_pixel_perimeter_ccw;
+  else
+    error(EXIT_FAILURE, 0, "a bug! the code %d is not recognized as "
+          "a valid rotation orientation in "
+          "'gal_polygon_is_counterclockwise', this is not your fault, "
+          "something in the programming has gone wrong. Please contact "
+          "us at %s so we can correct it", wa->isccw, PACKAGE_BUGREPORT);
+
+  /* Loop over pixels given from the 'warp' function */
+  for(i=0; tprm->indexs[i] != GAL_BLANK_SIZE_T; ++i)
+    {
+      ind=tprm->indexs[i];
+
+      /* Fix the vertice ordering, crucial for calculating the area. */
+      ocrn=warp_pixel_perimeter(wa, ind);
+
+      /* Now that the vertices are in CCW order, calculate the area. */
+      area=gal_polygon_area(ocrn, wa->ncrn);
+      outputarr[ind]=area;
+
+      /* Clean up the allocated array. */
+      free(ocrn);
+    }
+
+  /* Wait for all the other threads to finish, then return. */
+  if(tprm->b) { pthread_barrier_wait(tprm->b); }
+  return NULL;
+}
+
+
+
+
+
+/* Calculate input pixel area covering the sky and write it to output. This
+   function has a debugging nature and is not used through the aligning
+   process. */
+void
+gal_warp_pixelarea(gal_warp_wcsalign_t *wa)
+{
+  gal_data_t *input=wa->input;
+
+  warp_check_basic_params(wa, __func__);
+
+  /* Create the output dataset. */
+  wa->output=gal_data_alloc(NULL, GAL_TYPE_FLOAT64, input->ndim,
+                            input->dsize, input->wcs, 0,
+                            input->minmapsize, input->quietmmap,
+                            "PIX-AREA", NULL, NULL);
+
+  /* Create the vertices based on the edgesampling value. */
+  warp_wcsalign_init_vertices(wa);
+  warp_wcsalign_init_internals(wa);
+  gal_wcs_img_to_world(wa->vertices, input->wcs, 1);
+
+  /* Calculate pixel area on WCS and write to output. */
+  gal_threads_spin_off(warp_pixelarea_onthread, wa, wa->output->size,
+                       wa->numthreads, input->minmapsize,
+                       input->quietmmap);
+
+  /* Clean up. */
+  gal_warp_wcsalign_free(wa);
+}



reply via email to

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