gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 565404c1 2/2: MakeProfiles: point profiles are


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 565404c1 2/2: MakeProfiles: point profiles are built in 3D
Date: Fri, 2 Jun 2023 13:40:12 -0400 (EDT)

branch: master
commit 565404c1e71bc8ecd8455cf3cb5fdf9a72a1c7c0
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    MakeProfiles: point profiles are built in 3D
    
    Until now, when building a point profile on a 3D cube, MakeProfiles would
    crash with an error about a dimension with zero length. This happened
    because point profiles occupy a single element (pixel/voxel), and required
    special attention (as opposed to the rest of the profiles).
    
    With this commit, the necessary check for 3D data has been implemented in
    point profiles. Also, I noticed that '--mforflatpix' was not being used for
    point profiles, which is un-intuitive (after all a point is "flat"!). So
    that was also fixed.
    
    This bug was found by Teet Kuumta.
    
    This fixes bug #64274.
---
 NEWS                         |  1 +
 bin/mkprof/mkprof.c          | 22 +++++++++++++++-------
 bin/mkprof/oneprofile.c      | 20 +++++++++++---------
 doc/announce-acknowledge.txt |  1 +
 doc/gnuastro.texi            |  2 +-
 5 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/NEWS b/NEWS
index 605e3cdd..2ab2a7db 100644
--- a/NEWS
+++ b/NEWS
@@ -88,6 +88,7 @@ See the end of the file for license conditions.
               Sharbaf.
   bug #64250: astscript-fits-view: no message printed when input file did
               not exist. Reported by Ryan Begley.
+  bug #64274: MakeProfiles crash for points in 3D. Found by Teet Kuumta.
 
 
 
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index 0ca5a398..ac4edaaf 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -485,6 +485,7 @@ mkprof_build(void *inparam)
 {
   struct mkonthread *mkp=(struct mkonthread *)inparam;
   struct mkprofparams *p=mkp->p;
+
   size_t i, id, ndim=p->ndim;
   struct builtqueue *ibq, *fbq=NULL;
   double center[3], semiaxes[3], euler_deg[3];
@@ -505,18 +506,23 @@ mkprof_build(void *inparam)
       id=ibq->id=mkp->indexs[i];
       if(fbq==NULL) fbq=ibq;
 
-
       /* Write the necessary parameters for this profile into 'mkp'.*/
       oneprofile_set_prof_params(mkp);
 
-
       /* Find the bounding box size (NOT oversampled). */
       if( p->f[id] == PROFILE_POINT )
-        mkp->width[0]=mkp->width[1]=1;
+        {
+          mkp->width[0]=mkp->width[1]=1;
+          if(ndim==3) mkp->width[2]=1;
+        }
       else if( p->f[id] == PROFILE_CUSTOM_IMG )
         {
           mkp->width[0]=mkp->customimg->dsize[1]; /* 'width' is in */
           mkp->width[1]=mkp->customimg->dsize[0]; /* FITS order not C. */
+          if(ndim==3)
+            error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at "
+                  "'%s' to fix the problem. Custom images are not yet "
+                  "supported for 3D inputs", __func__, PACKAGE_BUGREPORT);
         }
       else
         switch(ndim)
@@ -790,7 +796,8 @@ mkprof(struct mkprofparams *p)
      ignore it. */
   if(p->out)
     {
-      onaxes=gal_pointer_allocate(GAL_TYPE_LONG, ndim, 0, __func__, "onaxes");
+      onaxes=gal_pointer_allocate(GAL_TYPE_LONG, ndim, 0, __func__,
+                                  "onaxes");
       for(fi=0; fi < ndim; ++fi)
         {
           i=ndim-fi-1;
@@ -820,10 +827,11 @@ mkprof(struct mkprofparams *p)
 
       /* Initialize the condition variable and mutex. */
       err=pthread_mutex_init(&p->qlock, NULL);
-      if(err) error(EXIT_FAILURE, 0, "%s: mutex not initialized", __func__);
-      err=pthread_cond_init(&p->qready, NULL);
-      if(err) error(EXIT_FAILURE, 0, "%s: condition variable not initialized",
+      if(err) error(EXIT_FAILURE, 0, "%s: mutex not initialized",
                     __func__);
+      err=pthread_cond_init(&p->qready, NULL);
+      if(err) error(EXIT_FAILURE, 0, "%s: condition variable not "
+                    "initialized", __func__);
 
       /* Spin off the threads: */
       for(i=0;i<nt;++i)
diff --git a/bin/mkprof/oneprofile.c b/bin/mkprof/oneprofile.c
index b2556da3..75c6e30a 100644
--- a/bin/mkprof/oneprofile.c
+++ b/bin/mkprof/oneprofile.c
@@ -377,7 +377,7 @@ oneprofile_pix_by_pix(struct mkonthread *mkp)
   /* If this is a point source, just fill that one pixel and leave this
      function. */
   if(mkp->func==PROFILE_POINT)
-    { array[p]=1; return; }
+    { array[p] = mkp->fixedvalue; return; }
 
   /* Allocate the 'byt' array. It is used as a flag to make sure that we
      don't re-calculate the profile value on a pixel more than once. */
@@ -692,9 +692,17 @@ oneprofile_set_prof_params(struct mkonthread *mkp)
 
 
     case PROFILE_POINT:
-      mkp->correction       = 1;
-      mkp->fixedvalue       = 1.0f;
       mkp->profile          = &profiles_flat;
+      if(p->mforflatpix)
+        {
+          mkp->correction   = 0;
+          mkp->fixedvalue   = p->m[id];
+        }
+      else
+        {
+          mkp->correction   = 1;
+          mkp->fixedvalue   = 1.0f;
+        }
       break;
 
 
@@ -744,8 +752,6 @@ oneprofile_set_prof_params(struct mkonthread *mkp)
 
 
 
-
-
     case PROFILE_AZIMUTH:
       mkp->profile          = profiles_azimuth;
       mkp->truncr           = tp ? p->t[id] : p->t[id]*p->r[id];
@@ -808,12 +814,10 @@ oneprofile_make(struct mkonthread *mkp)
   float *f, *ff;
   size_t i, dsize[3], ndim=p->ndim;
 
-
   /* Find the profile center in the over-sampled image in C
      coordinates. IMPORTANT: width must not be oversampled.*/
   oneprofile_center_oversampled(mkp);
 
-
   /* If a custom image is provided, there is no need to build a new
      dataset. */
   if(mkp->customimg)
@@ -828,14 +832,12 @@ oneprofile_make(struct mkonthread *mkp)
           dsize[ndim-i-1] = mkp->width[i];
         }
 
-
       /* Allocate and clear the array for this one profile. */
       mkp->ibq->image=gal_data_alloc(NULL, GAL_TYPE_FLOAT32, ndim, dsize,
                                      NULL, 1, p->cp.minmapsize,
                                      p->cp.quietmmap, "MOCK",
                                      "counts", NULL);
 
-
       /* Build the profile in the image. */
       oneprofile_pix_by_pix(mkp);
     }
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index e634624f..0d52568f 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -5,6 +5,7 @@ Irene Pintos Castro
 Raul Infante-Sainz
 Ryan Begley
 Sepideh Eskandarlou
+Teet Kuumta
 Zahra Sharbaf
 Zohreh Ghaffari
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 2c0bf508..e9ca4502 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -28727,7 +28727,7 @@ Read it as `t-unit-in-p' for `truncation unit in 
pixels'.
 
 @item -f
 @itemx --mforflatpix
-When making fixed value profiles (flat and circumference, see 
`@option{--fcol}'), do not use the value in the column specified by 
`@option{--mcol}' as the magnitude.
+When making fixed value profiles (``flat'', ``circumference'' or ``point'' 
profiles, see `@option{--fcol}'), do not use the value in the column specified 
by `@option{--mcol}' as the magnitude.
 Instead use it as the exact value that all the pixels of these profiles should 
have.
 This option is irrelevant for other types of profiles.
 This option is very useful for creating masks, or labeled regions in an image.



reply via email to

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