A Simple but Powerful Method to Reduce Background Noise in Celestial Gamma-Ray Images

Reducing background noise is essential for clear data analysis and signal detection. In this study, we introduce a novel denoising algorithm tailored for gamma-ray astronomical data, utilizing local density sampling techniques. The proposed algorithm preferentially amplifies regions of high local density, which are indicative of potential sources, while diminishing the influence of low-density areas. This selective enhancement significantly bolsters the performance of clustering algorithms in pinpointing point sources, effectively minimizing the interference of high-density noise that could be mistaken for genuine sources. We have implemented this algorithm on Fermi Large Area Telescope data, and our results showcase a marked advancement in the clustering algorithm's capacity to discard false sources.


Introduction
Let us consider a set of points scattered throughout space, distributed randomly.Some regions of space may exhibit clustering of these points, either randomly or due to systematic effects.These clustered regions could potentially represent sources of gamma rays amidst scattered gamma photons or members of a star cluster among various celestial bodies, etc.
There are different methods to find these patterns, which are called clustering methods.From the traditional maximum likelihood method (Mattox et al. 1996), wavelet transform analysis (Damiani et al. 1997) to the clustering methods such as DBSCAN (Ester et al. 1996), the minimum spanning tree (MST; Di Gesù & Sacco 1983), and k-means (Lloyd 1982), etc.
One of the applications of scattered point clustering methods is the detection of point sources of gamma rays.High-energy gamma rays are detected by detectors on satellites outside the Earth's atmosphere.The gamma ray produces a pair in a material with a high atomic mass, then the produced pair is traced in a hodoscope detector and thus, we can estimate the direction of the gamma ray.Of course, the stages of this detection have many complications, such as discarding the cosmic rays with the anticoincidence detector, measuring the direction of the satellite, etc., which are omitted in this simple description.This technique has been used in gamma radiation space observatories such as Cos-B (Bignami et al. 1974), Egret (Kanbach et al. 1989), Fermi (Atwood et al. 2009), etc.The obtained image is a number of points corresponding to gamma photons; the location of each photon on this image shows a specific direction on the celestial sphere.In this image, the point sources correspond to the local increase in the concentration of photons.
Usually, one of the common clustering methods is used to detect the location of the photon concentrations.The primary challenge in pinpointing foci locations lies in dealing with background noise, primarily caused by the diffuse gamma-ray background in celestial gamma-ray images.The higher the background noise, the harder it is to detect the location of foci and point sources.In this paper, our main goal is to present an algorithm that can reduce the background noise as much as possible so that the cluster detection algorithms can better detect the source location.
Before describing the basic principles of this algorithm, it should be noted that the main idea of this paper came from several papers that we have already published about determining the core location of extensive air showers (Hedayati Kh. et al. 2011aKh. et al. , 2011bKh. et al. , 2015)).In those papers, the main goal was to detect the location of the shower's core without using the lateral distribution function.In fact, we could identify the location of the shower core using local particle densities.A matrix was formed from the distances of the stimulated detectors and the number of their detected particles, using which we could statistically introduce a weight for each of the stimulated detectors.The weighted center of gravity of the detectors could accurately determine the location of the core (see, e.g., Hedayati Kh. et al. 2015 for details).We named the core determination method in those papers SIMEFIC.In the same manner, an algorithm presented here is called SIME-FIC III.

Analytical Principles of Background Noise Reduction
In order to find the locations of concentrations related to point sources or clusters, we should pay attention that the density of points is higher in the areas near the sources and is lower in the regions far from the sources.Therefore, to find the location of sources, it is enough to statistically check the increase in the density of the points.The increase in the density of points means that near the sources the points are statistically closer to each other and in the areas far from the sources the points are on average far from each other.
In Figure 1, we randomly distributed 150 points on a 10 × 10 screen to demonstrate this. 1 In part (a) of this figure, Original content from this work may be used under the terms of the Creative Commons Attribution 4.0 licence.Any further distribution of this work must maintain attribution to the author(s) and the title of the work, journal citation and DOI.
these 150 points are distributed with a uniform distribution, but in part (b), 120 points have a uniform distribution, and 30 points are generated with a normal radial distribution with σ r = 1 and uniform angular distribution around the point indicated by the plus mark on the figure.
To show the proximity of the points near the source compared to the uniform field, we proceed as follows: First, we identify the pair of points with the closest distance2 among all points and remove both from the list.Then we find another pair with the closest distance in the list of remaining points and remove them from the list.We continue this process until all points have been processed, resulting in a list of pairs of points.The result will be like Figure 2.For the sake of clarity, we remove all pairs of points with a distance of more than half of the average distance of the pairs.The results are shown in parts (c) and (d) of Figure 2. In this manner, in a field with a source, statistically, the pairs with the smallest distance are near the source.But in a uniform field, small pairs are uniformly scattered throughout the field.Another interesting point is that in the presence of a source, the standard deviation of the length of the pairs of points is greater than the standard deviation of their length in the absence of the source.
According to the above analysis, consider a pair of points (i, j) with distance d ij .Suppose we want to consider the distance d ij as a measure of density in one of the two points i or j.The question that arises is which of these two points should we attribute this distance to?One of the answers that may come to mind is to find another point that is closest to these two points.Then, if this point is closer to point i, we should attribute the distance d ij to the point i, otherwise to the point j.
It is worth noting by paying attention to Figure 2, it is clear that sometimes two points far from the source may be close to each other, but the probability that three points close to each other are also far from the source is greatly reduced.Therefore, if one of the points is removed in a pair far from the source, the second point will no longer find a point close to it to pair with, so it will be paired with another point that is farther away from it than the removed point.

SIMEFIC III Algorithm
Based on the analysis of the previous section, the following algorithm is proposed to remove the background noises and pronounces locations of the point sources in a field of points.
Suppose we have N points on a plane.First, we obtain the distances of all pairs of points and form the following matrix: where d ij is the distance between point i and j.The matrix is symmetric whose principal diagonal elements are zero and therefore are omitted.
1. First, we find the two points with the smallest distance between the points, that is, the smallest element of the above matrix.Suppose that element d ij = d ji is the smallest element of this matrix.2. Then we find another point k in the list of points whose sum of the distance from two points i and j is the smallest value:  near the source and consider the distance d ij as its index distance (ID), a i = d ij .Now we remove the ith row and ith column of matrix D. If d ik > d jk , instead we choose the point j with d ij as its ID, a j = d ij .Then we remove the jth row and jth column of matrix D. 4. After performing the above steps, a row and a column of matrix D is removed.For the list of remaining points, we repeat steps 1-3 until all the points in the list are removed.We set the ID of the last point of the list equal to the point before it.In this way, we have a list of points, and each of them has an ID, a.
Now, to remove the noise, it is enough to remove the points that have large IDs from the list of points.In the following, we will use this algorithm for a simulated field and for real data.
When dealing with a small number of points, the first step employs the brute force method to identify the closest pair.However, as the number of points increases, the efficiency of this method deteriorates due to its quadratic time complexity of O n 2 ( ).Consequently, for larger data sets, more efficient algorithms are preferred, such as divide and conquer, which boasts a time complexity of O n n log ( ).In the subsequent step, the divide and conquer approach is also utilized.Here, the algorithm involves considering the middle point between two points (x m , y m ) = ((x i + x j )/2, (y i + y j )/2).Subsequently, the point closest to the midpoint among the other points is determined.By employing this strategy in both the initial and subsequent steps, efficient processing is guaranteed even for large data sets.

Noise Reduction Using SIMEFIC III Algorithm
In the same field of 10 × 10 as in Section 3, we generate 10 sources with normal distribution and sigma σ r = 0.5.The number of points of these sources is 10, 20, ..., up to 100 points, respectively.We add a background noise with uniform distribution and 1000 points to this field.The result will be like part (a) of Figure 3. Now we remove all the points whose ID is more than a fraction of the average value of the ID.As is evident from parts (b) to (d) of Figure 3, a large number of points far from the sources have been removed, but the points near the sources remain.Therefore, the background noise is greatly reduced.
One thing to note is that if the number of deleted points is large, weak sources will be deleted, and conversely if the number of removed points is small, spurious sources may remain in the image.

The Relationship with Clustering Methods
In order to test the capability of this denoising method, it is better to use common clustering techniques and check the noise reduction results.For this purpose, we apply a clustering technique once on the primary field with some sources and once on the same field but denoised.

The MST Algorithm for Cluster Search
An MST connects all the points together without any cycles and with the minimum possible total weight λ of the edges (see, e.g., Cormen et al. 2022).MST-based clustering methods can be used to find locations of sources.The edge weight λ is the distance between a pair of nodes.For finding the candidate sources in this tree, first edges with a weight greater than a selected separation value Λ cut should be removed, and then subtrees with a number of nodes less than a threshold value N cut should be eliminated (see Campana et al. 2008Campana et al. , 2013 for the details).
In order to reveal the advantage of using the SIMEFIC III algorithm, we use the MST algorithm once for part (a) and once for part (c) of Figure 3.We utilize the MST algorithm with two criteria: initially, we prune edges longer than the average edge  length of the entire cluster, followed by the removal of clusters with fewer than three nodes, as determined to be optimal by Campana et al. (2013).
The results are shown in Figure 4. Evidently, the implementation of the SIMEFIC III algorithm has proven highly effective in eliminating spurious clusters.Although it is Figure 6.A Fermi region in galactic coordinates with energy above 3 GeV.Red and blue circles represent 4FGL-DR3 sources with > TS 5 and < TS 5, respectively.Clusters with S > 2.5, identified by DBSCAN, are depicted in various colors.DBSCAN clustering with ε = 0.17 and MinPts = 5 was applied in each part of the figure, and clusters with S < 2.5 were subsequently removed.For sources with > TS 5 in this figure, detailed specifications are provided in Table 1.
evident that the clusters around the sources are relatively smaller compared to the initial field, which poses a risk of removing weak sources; it also offers the advantage of determining the source locations more accurately.Additionally, after denoising, false sources are rarely created at far distances from the real sources.

The DBSCAN Algorithm for Cluster Search
The Density-Based Spatial Clustering of Applications with Noise algorithm (DBSCAN; Ester et al. 1996) is one of the most common clustering algorithms.In the following, we use the DBSCAN algorithm for finding sources.For this purpose, we use a modified version of the DBSCAN algorithm introduced in Tran et al. (2013).
According to their notation, we take the value of neighborhood radius ε = 0.2 and the minimum number of points in the neighborhood, MinPts = 3.As before, we apply the DBSCAN algorithm to the field of Figure 3, first for part (a) and then for part (c).The results are shown in Figure 5. Evidently, while the original field processed with the DBSCAN algorithm generates a significant number of spurious clusters, the reduced noise field shows no false clusters.Additionally, although sources 80 and 100 are mixed in the initial field, they are completely resolved in the denoised field.However, source 10 is removed in the denoised field after applying DBSCAN.

Fermi Gamma-Ray Data Selection for SIMEFIC III Algorithm
After successfully testing our denoising algorithm on stochastic data, we are now poised to apply it to real-world observations from the Fermi gamma-ray sky survey.This transition presents an exciting opportunity to validate the algorithm's effectiveness in practical astrophysical contexts.
The Large Area Telescope (LAT), onboard the Fermi satellite, is a high-energy gamma-ray telescope covering the energy range from above 20 MeV to 300 GeV (Atwood et al. 2009).We conducted analysis on the Pass 8, Release 3 LAT data covering a span of 15 yr, from 2008 August 4 to 2023 August 4 using Fermitools 2.2.0 and Fermipy 1.2.0.All data are available on the LAT data server.It contains photons above 3 GeV and is filtered by applying the standard selection, source class events, evclsss = 128, and both front and back converting, evtype = 3, up to a maximum zenith angle of 90°.
The chosen sky region encompasses a defined area in galactic coordinates (170°< l < 240°and 40°< b < 60°), excluding the galactic plane and poles.A total of 44,211 high-quality photons were gathered.Sources within this region were identified using the LAT 12 yr Source Catalog (4FGL-DR3).The specifications of these sources are detailed in Table 1.

Assessing Clustering Method Performance Using Data
We now test the SIMEFIC III algorithm on real data by applying it to Fermi Large Area Telescope (Fermi-LAT) data and utilizing DBSCAN to find point sources.First, we apply the DBSCAN algorithm to the data without denoising, and then to the denoised data.It is important to note that, unlike the previous sections, the distance between points is no longer the Euclidean distance; instead, it is an angular distance (γ) defined by the following relationship: where b and l represent the galactic latitude and longitude, respectively.
To quantitatively compare the results of cluster search with the DBSCAN algorithm before and after denoising the data, we follow Tramacere & Vecchio (2013) and employ the likelihood ratio proposed by Li & Ma (1983) to calculate the cluster significance, S: where N on represents the number of points within the cluster area, and N off denotes the number of background points within the same area under the assumption of no source presence.
In the 4FGL catalog, the significance of a source emerging from the background is determined by the square root of the test statistic (TS), defined as ), where  is the maximum likelihood value with the source included, and 0 is the maximum likelihood value without the source in the model, calculated over the region of interest.
In the study by Tramacere & Vecchio (2013), the relationship between the square root of the test statistic and cluster significance, S, was established as  S 0.5 TS .Consequently, we set the threshold at S > 2.5 and eliminate all clusters with S < 2.5.Subsequently, we applied the DBSCAN algorithm to the Fermi-LAT data, both before (Figure 6 part (a)) and after denoising (Figure 6 parts (b) and (c)), using the parameter values ε = 0.17 and MinPts = 5, as indicated in the cited paper.
The results of this figure are summarized in Table 2.As depicted, a considerable number of spurious sources are identified before denoising.However, after denoising, the incidence of fake sources notably decreases.It is worth noting that as illustrated in Figure 6 and Table 2, also eliminates weaker sources.By adjusting the denoising parameter, sources with TS less than 5 are also filtered out.Notably, sources with TS greater than 5 either remain unaffected (under the condition of removing IDs greater than a) or are minimally impacted by the condition of removing IDs greater than a 2.
We now assess cluster significance, S. In part (a) of Figure 7, the TS bar chart for sources with > TS 5 from Figure 6 is displayed in descending order of TS.In part (b), the photon counts of clusters related to these sources are shown before and after denoising with a 2. Unresolved sources before denoising are depicted by green bars of equal height, indicating that all green bars of the same height belong to the same cluster.
Yellow bars adjacent to them indicate the photon counts after denoising.With the exception of sources numbered 12 and 27, as well as 47 and 51 (indicated by yellow bars of equal height), the remaining unresolved sources were resolved after denoising.
In part (c) of this figure, a bar graph illustrates the difference in cluster significance before and after denoising.For unresolved sources before denoising that are subsequently resolved after denoising, their cluster significance before denoising is divided among them based on the TS of the sources.This divided cluster significance is then subtracted from their individual significance S after denoising.The cluster significance difference for these sources is represented by red bars.
For instance, consider sources 1 and 33.Initially, they were grouped together in a single cluster with a significance S of 10.11.Denoising separated them into two distinct clusters, each with its own significance S: 19.24 for source 1 and 3.56 for source 33.The shared significance S of 10.11 (before denoising) is apportioned between them based on their square root of TS values: 8.24 for source 1 and 1.86 for source 33.Note.In this field, according to the Fermi-LAT 4FGL-DR3 catalog, there are 54 sources with square TS values greater than 5 and 54 sources with square values less than 5.The table displays number of associated with clusters.Its important to note that some may be linked with two or more sources.It's crucial to highlight that only clusters with S > 2.5 are included, except for row 4, which lacks any cut on S. For further details about row 4, please refer to Figure 9 and its description in the text.
This apportionment is then subtracted from their individual S after denoising, resulting in 10.99 for source 1 and 1.69 for source 33, representing their significance S differences after and before denoising.Upon examining this figure, it becomes clear that the significance (S) of certain clusters has increased while others have decreased.On average, there has been a rise in cluster significance by approximately 1 unit.However, despite this slight increase in the average significance (S) of clusters shown in the figure, it is not significant enough to definitively claim that the denoising algorithm consistently enhances the average cluster significance.
In the field depicted in Figure 6 part (a), unresolved closely spaced sources are identified as bridged clusters.Bridged clusters refer to clusters located in close proximity, connected by a distinctive structure formed by background photons at angular distances below the ε threshold (Campana & Massaro 2021).One effective approach to differentiate these clusters involves denoising techniques, in addition to adjusting clustering parameters and conducting analyses on smaller fields.Figure 8 provides a detailed view of a bridged cluster in Figure 6 part (a), serving as a representative example.Following denoising procedures, this feature resolves into three distinct clusters: two clusters, each associated with one source, and one cluster associated with two sources.This illustrates the benefits of employing denoising methods.
In the subsequent phase, our objective is to eliminate the cluster significance cutoff criterion and notably refine the denoising parameter by imposing a stringent denoising criterion.Figure 9 corresponds to Figure 6 with a denoising parameter < a a 3.Under these conditions, a total of 57 clusters were detected, consisting of 49 sources with TS exceeding 5 and 10 sources with TS below 5.No spurious sources were identified.
The suggestion from this figure, indicating that denoising can proceed without a precise estimate of cluster significance, seems somewhat speculative.Considering the variability in background conditions, such as with galactic latitude, the optimal denoising threshold could fluctuate.Therefore, it is advisable to utilize cross-validation in conjunction with cluster significance assessment.

Conclusion
In various data clustering applications, the presence of random data can lead to false source detection or the emergence of spurious clusters within clustering algorithms.In this paper, a novel method has been introduced to minimize the presence of random data unrelated to any genuine source, thereby enhancing the ability of clustering algorithms to identify true sources.
In its current (2D) form, this algorithm is employed to cluster random points a plane.Initially, among all pairs of points on the screen, the pair with the smallest distance from each other is selected.Subsequently, from this pair, the point with a higher density is chosen.This point is then removed from the list of points as a point proximal to the source.Additionally, the distance between two points is designated as the ID of this point.Similarly, characteristic lengths are assigned to all points within the field following this procedure.Now, we eliminate the points whose characteristic length exceeds a certain threshold.This process effectively removes a statistically significant number of points that are not associated with any source on the plane.
After applying this denoising algorithm to the points on the plane, the effectiveness of clustering algorithms in detecting point sources significantly improves.In this paper, we utilized two common clustering algorithms: MST and DBSCAN.It was observed that following denoising, these algorithms exhibit notably enhanced capabilities in pinpointing the locations of sources, even without altering their parameters.
Applying the denoising algorithm to the Fermi telescope gamma-ray data, we observed a significant decrease in the likelihood of detecting spurious sources.However, it is important to note that this process may also result in the removal of some weak sources.Additionally, another capability of this algorithm is its capacity to fragment bridge clusters into smaller ones, uncovering additional sources in the process.
While nonparametric methods like DBSCAN and MST have been utilized for denoising, the paramount advantage of our method over these denoising techniques is its reliance on only one control parameter, as opposed to methods necessitating two control parameters for operation.Moreover, our method notably enhances the effectiveness of these approaches in detecting and removing spurious sources.
This paper was solely dedicated to introducing the denoising method and its core concept.Further detailed investigations are warranted for this method.For instance, exploring the potential of generalizing this algorithm for 3D or multidimensional data is crucial.Additionally, investigating whether a better parameter than distances between points can be introduced as a criterion for removing noise points is essential.The algorithm should also account for the effects of borders, and efforts should be made to enhance its speed for fields with a large number of points, potentially by utilizing a list of nearest neighbor points.
we compare the two elements d ik and d jk with each other.If d ik < d jk , then we choose the point i as a point

Figure 1 .
Figure 1. 150 points are randomly distributed in a 10 × 10 plane.(a) All points are distributed with uniform random distribution.(b) 120 points are distributed with uniform random distribution.30 points are distributed with normal random distribution around the point indicated by the plus mark.The radial standard deviation of this distribution, σ r is 1, but its angular distribution is uniform.

Figure 2 .
Figure 2. Separation of the points of Figure 1 into pairs of points with the smallest distance.(a) Pair of points of part (a) of Figure 1 (field without source).(b) Pair of points of part (b) of Figure 1 (field with a source).(c) The same as part (a), with removed pairs that have distances more than half of the average distance of all pairs.(d) The same as part (b), with removed pairs that have distances more than half of the average distance of all pairs.The inset figure shows the magnified region of the source.

Figure 3 .
Figure 3. SIMEFIC III application in noise reduction of a field of random points.(a) A field of random points with 10 sources.The total number of points is 1550.(b) Removing points with an ID greater than the average ID ( > a a ¯).The total number of remaining points is 1096.(c) Removing points with > a a 3 ¯.The total number of remaining points is 504.(d) Removing points with > a a 5 ¯.The total number of remaining points is 320.The initial number of points of each source on the image is specified in part (d), where the number of points is fewer.

Figure 4 .
Figure 4. Application of MST algorithm on the field with 10 sources in Figure 3.The sources are marked with red circles in each field.(a) The initial field of Figure 3; (b) denoised field of part (c) of Figure 3.

Figure 5 .
Figure 5. Application of DBSCAN algorithm on the field with 10 sources in Figure 3.The sources are marked with + signs in each field.(a) The initial field of Figure 3; (b) the denoised field corresponding to part (c) of Figure 3.

Figure 7 .
Figure7.Characteristics of sources with TS greater than 5 and their corresponding clusters before and after denoising with a 2.

Figure 8 .
Figure 8.This figure presents a segment of the photon map within context of Figure 6.

Figure 9 .
Figure9.The same field as depicted in Figure6, utilizing a denoising criterion of retaining sources with < a a 3.

Table 2
Summary of Cluster Search Results Within the Field Depicted in Figure 6, Obtained Using the DBSCAN Algorithm