[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 32e14e6: MakeCatalog: object ID mapping now ap
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 32e14e6: MakeCatalog: object ID mapping now applied to corrected clump labels |
Date: |
Tue, 27 Oct 2020 14:00:15 -0400 (EDT) |
branch: master
commit 32e14e6fbc76028b86ec19743b0e4ee07caf9ea9
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
MakeCatalog: object ID mapping now applied to corrected clump labels
Until now, When MakeCatalog is run on an objects labeled image that has
non-contiguous labels (for example 23, 25, 800: usually happens when making
crops of labeled images), it applies an internal mapping of the actual
labels/IDs with a contiguous set of IDs. But this scenario (of
non-contiguous IDs) was only tested on generating object catalogs. While
working on a cropped clumps image (that was accompanied with a cropped
label and values image), I noticed that MakeCatalog crashes with a
segmentation fault.
With this commit this issue has been fixed: I noticed that the mapping the
object IDs wasn't being used in the part where we are identifying the
clumps, so they were trying to associate themselves with regions far
outside the allocated number of objects in memory.
This fixes bug #59371.
---
NEWS | 1 +
bin/mkcatalog/main.h | 1 +
bin/mkcatalog/mkcatalog.c | 6 ++++--
bin/mkcatalog/ui.c | 28 +++++++++++++++++++++++++---
4 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index 60a7367..146f103 100644
--- a/NEWS
+++ b/NEWS
@@ -134,6 +134,7 @@ See the end of the file for license conditions.
bug #59105: Column arithmetic operator degree-to-ra, returning to dec.
bug #59136: Makeprofiles with --replace is not thread-safe.
bug #59155: Match cannot find the proper row when coordinates have NaN.
+ bug #59371: MakeCatalog crash with clumps on non-contiguous object labels.
diff --git a/bin/mkcatalog/main.h b/bin/mkcatalog/main.h
index d4c9547..7074161 100644
--- a/bin/mkcatalog/main.h
+++ b/bin/mkcatalog/main.h
@@ -253,6 +253,7 @@ struct mkcatalogparams
float medstd; /* Median standard deviation value. */
float cpscorr; /* Counts-per-second correction. */
int32_t *outlabs; /* Labels in output catalog (when necessary) */
+ int32_t *outlabsinv; /* Inverse of the 'outlabs' array. */
size_t numobjects; /* Number of object labels in image. */
float clumpsn; /* Clump S/N threshold. */
size_t numclumps; /* Number of clumps in image. */
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index c8186ec..34d7dac 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -150,7 +150,7 @@ mkcatalog_single_object(void *in_prm)
the array positions start from 0. */
pp.ci = NULL;
pp.object = ( p->outlabs
- ? p->outlabs[tprm->indexs[i]]
+ ? p->outlabs[ tprm->indexs[i] ]
: tprm->indexs[i] + 1 );
pp.tile = &p->tiles[ tprm->indexs[i] ];
pp.spectrum = &p->spectra[ tprm->indexs[i] ];
@@ -621,7 +621,9 @@ sort_clumps_by_objid(struct mkcatalogparams *p)
i=0;
while(i<p->numclumps)
{
- o=p->hostobjid_c[i]-1;
+ o = ( p->outlabsinv
+ ? (p->outlabsinv[ p->hostobjid_c[i] ] + 1)
+ : p->hostobjid_c[i] ) - 1;
for(j=0; j<p->numclumps_c[o]; ++j)
permute[i++] = rowstart[o] + j;
}
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 4dbe04a..51aad7b 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -572,6 +572,7 @@ ui_wcs_info(struct mkcatalogparams *p)
static size_t
ui_num_clumps(struct mkcatalogparams *p)
{
+ int32_t olab;
char *basename;
int keepinputdir;
size_t i, counter, numclumps=0;
@@ -593,13 +594,14 @@ ui_num_clumps(struct mkcatalogparams *p)
if(*o>0 && *c>0)
{
/* See if the label has already been found. */
- for(tmp=labsinobj[*o];tmp!=NULL;tmp=tmp->next) if(tmp->v==*c) break;
+ olab = p->outlabsinv ? p->outlabsinv[*o] : *o;
+ for(tmp=labsinobj[olab];tmp!=NULL;tmp=tmp->next) if(tmp->v==*c)
break;
/* When it wasn't found, 'tmp==NULL'. */
if(tmp==NULL)
{
++numclumps;
- gal_list_i32_add(&labsinobj[*o], *c);
+ gal_list_i32_add(&labsinobj[olab], *c);
}
}
@@ -618,7 +620,8 @@ ui_num_clumps(struct mkcatalogparams *p)
if(*o>0 && *c>0)
{
counter=0;
- for(tmp=labsinobj[*o];tmp!=NULL;tmp=tmp->next)
+ olab = p->outlabsinv ? p->outlabsinv[*o] : *o;
+ for(tmp=labsinobj[olab];tmp!=NULL;tmp=tmp->next)
{ counter++; if(tmp->v==*c) {*c=counter; break;} }
}
@@ -763,9 +766,25 @@ ui_one_tile_per_object_correct_numobjects(struct
mkcatalogparams *p)
"p->outlabs");
for(i=0;i<p->numobjects;++i) if(rarray[i]==0) p->outlabs[j++]=i+1;
+ /* Allocate an array for easy finding of the proper label and fill it
+ with the new labels. This array should have an element for each of
+ the original labels (that are not contiguous). */
+ if(p->clumpscat)
+ {
+ p->outlabsinv=gal_pointer_allocate(GAL_TYPE_UINT32,
+ p->numobjects+1, 1,
+ __func__, "p->outlabsinv");
+ for(i=0;i<no;++i) p->outlabsinv[ p->outlabs[i] ] = i;
+ }
+
/* Correct numobjects and clean up. */
p->numobjects=no;
gal_data_free(rowsremove);
+
+ /* For a check:
+ for(i=0;i<p->numobjects;++i)
+ printf("outlabs[%zu]: %d\n", i, p->outlabs[i]);
+ */
}
/* For a check.
@@ -821,6 +840,7 @@ ui_read_labels(struct mkcatalogparams *p)
"is currently only defined on 3D datasets", p->objectsfile,
p->cp.hdu, p->objects->ndim);
+
/* See if the total number of objects is given in the header keywords. */
keys[0].name="NUMLABS";
keys[0].type=GAL_TYPE_SIZE_T;
@@ -833,6 +853,7 @@ ui_read_labels(struct mkcatalogparams *p)
gal_data_free(tmp);
}
+
/* If there were no objects in the input, then inform the user with an
error (it is pointless to build a catalog). */
if(p->numobjects==0)
@@ -1985,6 +2006,7 @@ ui_free_report(struct mkcatalogparams *p, struct timeval
*t1)
gal_list_data_free(p->clumpcols);
gal_list_data_free(p->objectcols);
gal_list_data_free(p->specsliceinfo);
+ if(p->outlabsinv) free(p->outlabsinv);
if(p->upcheckout) free(p->upcheckout);
gal_data_array_free(p->tiles, p->numobjects, 0);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 32e14e6: MakeCatalog: object ID mapping now applied to corrected clump labels,
Mohammad Akhlaghi <=