{'fraction_non_alphanumeric': 0.03458834202767067, 'fraction_numerical': 0.020866409616693126, 'mean_word_length': 4.290041991601679, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Avoiding the Geometric Boundary Effect in Shear Measurement

In image processing, source detections are inevitably affected by the presence of the geometric boundaries in the images, including the physical boundaries of the CCD, and the boundaries of masked regions due to column defects, bright diffraction spikes, etc.. These boundary conditions make the source detection process not statistically isotropic. It can lead to additive shear bias near the boundaries. We build a phenomenological model to understand the bias, and propose a simple method to effectively eliminate the influence of geometric boundaries on shear measurement. We demonstrate the accuracy and efficiency of this method using both simulations and the z-band imaging data from the third data release of the DECam Legacy Survey.


INTRODUCTION
For better understanding the physical origin of dark matter and dark energy, a number of ongoing and planned surveys are focusing on precisely measuring the weak lensing effect (Abell et al. 2009;Laureijs et al. 2011;Hildebrandt et al. 2016;Troxel et al. 2018;Hikage et al. 2019). Accurate measurement of the cosmic shear signals remains to be a challenge (Hoekstra & Jain 2008;Kilbinger 2015;Mandelbaum et al. 2015a). An important reason is that shear signals contain a wide range of systematic errors, leading to biased cosmological constraints. Currently, the study of systematic errors in shear measurement is still an important direction (Hirata & Seljak 2003;Bernstein 2010;Bridle et al. 2010;Voigt & Bridle 2010;Refregier et al. 2012;Kacprzak et al. 2014;Mandelbaum et al. 2014Mandelbaum et al. , 2015bMartinet et al. 2019;Sheldon et al. 2019;Pujol et al. 2020). Some of the systematic errors are specific to the shear measurement method (e.g., model bias), and others are general problems for any weak lensing pipeline. In this work, we study the shear bias caused by the geomet-ric boundaries in the images, a problem that we believe belongs to the second category.
There are several different kinds of geometric boundaries existing in a typical CCD image, including the physical CCD boundaries, column defects due to the failure of charge transfer along the readout direction, and masked areas due to, e.g., the diffraction spikes of bright stars. For example, fig.1 shows a part of a typical CCD image with column defects from CFHTLenS (Erben et al. 2009;Heymans et al. 2012;Erben et al. 2013). As such boundary condition is locally anisotropic, it breaks the statistical isotropy of source detection/selection, leading to shear biases that are most significant near the boundaries. The purpose of this work is to give a phenomenological model for understanding this effect, and to propose a simple solution to avoid this type of bias. This is done in §2. We then give a brief conclusion and discuss related issues in §3.

BOUNDARY PROBLEM AND ITS SOLUTION
Near the boundary, a galaxy is more likely to be detected as a valid source if its orientation is parallel to the boundary. This is demonstrated in fig.2, in which there are two groups of galaxies at two different distances from the boundary (marked by the dark thick line). The four galaxies of each distance group have the same size and shape, but different pointing directions. For the group  that is closer to the boundary, it can be seen that the galaxy pointing perpendicular to the boundary (marked red) is not likely a valid source for shear measurement, as part of its shape information is missing 1 . Only the other three sources of the same group survive. Statistically, this effect breaks the isotropy of the intrinsic galaxy shape, potentially leading to an additive bias in shear measurement. The more vertical bad columns an image has, the worse the problem is. Similarly, horizontal boundaries also lead to additive shear biases locally, but with an opposite sign. The effect is localized near the boundary, within a distance that is about the typical size of the galaxies. This type of error can in principle cause B-mode (Schneider et al. 2002;Crittenden et al. 2002) in the shear field.

A simple model
To understand the problem further, we build a model to analyze the boundary effect. Since the boundaries are mostly in the horizontal and vertical directions, this effect mainly affects the g 1 component. The area of the affected region is determined by the length of the boundary as well as the typical size of the galaxies. Let us assume that the total number of the observed galaxies on a CCD chip is N , among which N + and N − are sufficiently close to the horizontal and vertical bound-1 In the model fitting methods, either on single exposure or multiple ones, images with missing parts are often used. We argue in §3 that in this case, there are still related anisotropic effects. Figure 3. The upper row: Galsim galaxies with regular shapes; the lower row: RW galaxies with irregular shapes.
aries respectively. On average, we expect a positive (or negative) additive shear bias c (or −c) associated with every galaxy that is close enough to the horizontal (or vertical) boundaries. Thus we can get: For simplicity, let us consider the case of a rectangular CCD chip of size l x × l y , without any bad columns in the middle. Let us also assume that the typical width of the affected regions along the boundaries is s, which should be comparable to the typical galaxy size. We also assume that the average galaxy number density is n. Then we have: N +/− ≈ 2n · s · l x/y and N ≈ n · l x · l y , and therefore:

Simulations
To demonstrate Eq.
(2), we use two types of mock galaxies: 1) each galaxy is made of point sources whose positions are generated with the random walk algorithm proposed in Zhang (2008) (called RW galaxy hereafter); 2) galaxies generated with the Galsim toolkit (Rowe et al. 2015) (called Galsim galaxy hereafter). Galsim galaxies usually have more regular shapes than RW galaxies, as shown in fig.3.
In RW galaxy simulation, each galaxy consists of 60 point sources generated by 60 steps within a circular region of radius r s (9 pixels). The positions of these point sources are generated by the following algorithm: • The size of a single step is fixed at 1 pixel. The direction of each step is completely random. • The first step starts from the center of the circular region. Steps that are about to go beyond the region should restart from the center.
• Each point source is assigned the same flux and convolved with the moffat-type PSF effect (Bridle et al. 2009). The pixel size of our simulations is set at 0.2 arcsec, and the FWHM of the PSF for the RW galaxies is 0.8 arcsec.
Our Galsim galaxies contain two kinds of profiles (Simard et al. 2011): the de Vaucouleurs profile and the exponential profile. For the buldge-dominated galaxies, which accounts for 10% of the total galaxies, we adopt only the de Vaucouleurs profile. The rest discdominated galaxies are made as a combination of these two profiles. The probability distribution of the disc scale length is set as : where α = 4/3, a = r s /0.833, and r s (arcsec) is decided by the i-band magnitude m via ln(r s ) = −1.145−0.269× (m−23). The magnitude distribution is assumed to obey P (m) ∝ 10 0.295m−1.08 , and within the range of [20,24]. We limit the radius r of the galaxy in the range of [0.1, 0.4](arcsec). Each Galsim galaxy is also convolved with the moffat-type PSF, with the FWHM of 0.6 arcsec.
To study the boundary effect, we randomly place 2500 simulated galaxy imagies on a 5000 × 5000 grid, with a very low background noise added. The central 4000 × 4000 region is cut out to mimic a CCD chip. Each chip is divided into many sub-regions of a certain size (e.g., 200 × 400, 400 × 800), separated by masks, so that each sub-region can represent a geometrical boundary structure. For each boundary structure, we generate more than 30000 such CCD chips (each of which contains about 1600 randomly distributed galaxies). Five sets of shear values are applied to sources in these CCDs: (0.02, -0.02), (0.01, -0.01), (0.00,0.00), (-0.01, 0.01), (-0.02, 0.02). Each set of shear values therefore covers 6000 CCDs, containing around 10 7 galaxies. We adopt the commonly used m and c to denote the shear bias as: We use the Fourier Quad pipeline for shear measurement (Zhang et al. 2015(Zhang et al. , 2016(Zhang et al. , 2019. The results for the RW galaxies are shown in fig.4, in which we list the values of additive bias c 1 as a function of the sub-region sizes along the x and y directions (i.e., l x and l y ) 2 . For symmetry reason, we only show the results for cases with l x ≥ l y . We can see from the figure that for a fixed l y , c 1 becomes larger when l x increases, and when l x is fixed, c 1 increases with a decreasing l y . When l x = l y , c 1 is consistent with zero. These properties are all consistent with the prediction of our model in eq.(2). Note however that even in the case of l x = l y , there are still local 2 c 2 is not shown, as it is consistent with zero in every case additive shear biases near the boundaries. The overall null results are just due to cancellation globally.
The parameter 2cs defined in eq.
(2) has a best-fit value of 408 ± 12 in the current simulation. To further check the validity of the relation in the equation, one can quantitatively check the change of the bias c 1 with the ratio of the axis sizes l x /l y for a fixed image area l x l y , or the other way around. The results are shown in fig.5, which are quite consistent with eq.(2).
Another prediction of the model is that the boundary effect should be more significant for galaxies of larger average sizes. To observe this phenomenon, we generate another set of simulations with RW galaxies that are larger by 50% than those in the previous set of simulations. The results are shown in fig.6, from which we can clearly see that c 1 is larger than those reported in fig.4 under the same condition of (l x , l y ).
We also expect the boundary effect to be more significant for more elliptical galaxies. To observe this, we repeat the simulations twice with the Galsim galaxies, with the galaxy ellipticities set at e = 0.2 and e = 0.8 respectively. The results are shown in fig.7 and fig.8 accordingly. One can see that the c 1 's of the more elliptical cases are ten times larger than their counterparts with less elliptical sources.
Overall, we can draw a conclusion that the additive bias due to the boundary is also influenced by the galaxy morphologies, such as their radii, ellipticities, etc.. The results in this section only represents the bias levels for several special cases.   As we have shown, source selection is a statistically anisotropic process near the image boundaries. The resulting shear bias cannot be treated as a universal additive bias, as it is significant only in the neighbourhood of the boundaries. To avoid such a bias, a natural solu-   fig.7, but with more elliptical Galsim galaxies. The ellipticity of the galaxies are set at 0.8. All c1 values are in unit of 10 −3 . The variances are about 1 × 10 −5 . Figure 9. A way of avoiding the anisotropic source selection effect near the boundary is to remove the sources whose stamps are intercepted by the boundary.

The solution and its application on real data
tion is to require all selected sources to be at a certain distance away from the boundaries. It turns out that this condition can be easily realized by requiring that the boundaries do not intercept the image stamp. For example, in the case shown in fig.2, we would need to remove another three stamps that are close enough to the boundary, as shown in red in fig.9, although they are originally valid source images.
We find that this additional requirement is quite effective in removing the additive bias due to the existence of boundaries. For example, fig.10 shows the new results of the simulations used in fig.4 with the additional selection rule. The bias c 1 drops significantly from the level of 10 −3 to 10 −5 . The validity of this solution can also be tested in real data. A direct way to do so is to adopt the idea recently proposed by Zhang et al. (2019), which shows that one can use the galaxy shear estimators to restore the field distortion signal as a way of testing the shear recovery accuracy. It can be done within the observational data itself, without requiring simulations. As in Zhang et al. (2019), here we again perform such a test with the Fourier Quad pipeline. Our imaging data is from the third data release of Dark Energy Camera Legacy Survey(DECaLS) (Dey et al. 2019). We use about 7400 calibrated z-band single exposures to do the test. Our source catalog is from Zou et al. (2019) (also see Zou et al. (2017)).
In fig.11, we show the comparison between the galaxy shear and the signal induced by field distortion. The solid black line is "y=x", shown as a reference. The red square data points are the results from all valid sources confirmed by the Fourier Quad pipeline on single exposures. In this case, one can clearly see a positive additive bias. This is due to the fact that there are many more boundary effects acting along the x-axis (defined to be the direction of RA, which almost coincides with the direction of the longer sides of the CCD chip) than on the y-axis. The green circular points are the results achieved after adopting the new selection criterion regarding the boundary effect. This procedure remove about 5 -10% of the sources. We can see that by removing sources that are close enough to the boundaries, the additive bias in g 1 can indeed be suppressed, and the results of g 2 are hardly affected.

CONCLUSION AND DISCUSSIONS
In this paper, we have specifically studied the geometric boundary effect on the accuracy of shear measurement. The existence of boundaries due to either the CCD edges or bad columns within the images can cause locally anisotropic source detection, thereby biasing the shear measurement. This is simply because sources are more likely to be detected/selected when its orientation is parallel to the boundary. It is a selection effect related to source detection. It causes local additive shear biases that are hard to remove globally. We propose a model to parameterize the shear bias as a function of the side lengths of the bounded region, and find a good agreement between the model predictions and the simulation results. In our simulations, we use a large number of mock galaxies of different morphological types, including both RW galaxies and Galsim galaxies.
The results of the test as well as the model prediction agree with our intuition: the boundary effects are more serious when: 1. the area of the bounded region is small; 2. The ratio of the side lengths is large; 3. the galaxies have large sizes on average; 4. the galaxies are more elliptical. In all the above cases, the boundaries have more impact on the selection of the galaxy sample, and on the resulting shear bias.
We find that a simple way of removing such a bias is to remove the sources that are too close to the boundaries even though their isophotes of the detection threshold (e.g., 2 -4σ above the background) do not yet touch the boundaries. This is done by requiring that no boundary marks (e.g., CCD edges, bad columns, etc.) cross the source stamp (of a predetermined fixed size). We use simulations to show that this simple procedure can indeed remove the additive shear bias related to the boundaries. We further demonstrate the existence of the boundary effect in real data, the DECaLS z-band imaging data, using the field-distortion test method proposed in Zhang et al. (2019). The results also show that our treatment can accurately remove the bias from the boundary effect.
We note that the isotropy of the source selection algorithm is also affected by the shear signal itself: two neighbouring sources are prone to overlap with each other when shear is along the line connecting them (Sheldon et al. 2019). This type of effect leads to multiplicative shear biases, in contrast to the additive biases addressed in this paper. We plan to study this effect in a future work.
Since the Fourier Quad pipeline processes shear measurement on individual exposures independently, our discussion regarding the boundary effect in this paper is quite straightforward and specific. In other shear measurement methods, e.g., model-fitting algorithms, it is often the case that multiple exposures are used together to construct the shear estimator for each galaxy. Images with missing pixels (due to boundaries for example) are often tolerated, and included in the fitting. If the images intercepted by the boundary marks are included in the  Figure 11. Test of shear recovery with the field-distortion signals using the z-band data of the third DECaLS Data Release. The left and right panels are the results of g1 and g2 respectively. The green and red points with 1σ error bars are the results with and without removing boundary effect respectively.
fitting, their anisotropic missing-pixel distribution can still bias the shear estimators in principle. On the other hand, if such contaminated images are discarded in the fitting, the survived ones on the same exposure would tend to lie along the boundaries when they are near the boundaries, thereby causing shear bias as well. In the second case, one can consider adopting the treatment in this paper: discarding the image according to whether the boundary marks cross its stamp, i.e., a domain of a fixed size, instead of the isophote of the detection threshold. A detailed study of this topic is however beyond the scope of this work.