@@ -16,7 +16,9 @@ def simulate_galaxy(
1616 truncate_ratio = 1.0 ,
1717 maximum_num_grids = 4096 ,
1818 draw_method = "auto" ,
19- force_ngrid = False
19+ force_ngrid = False ,
20+ delta_image_x = 0.0 ,
21+ delta_image_y = 0.0 ,
2022):
2123 """The function samples the surface density field of a galaxy at the grids
2224 This function only conduct sampling; PSF and pixel response are not
@@ -32,14 +34,19 @@ def simulate_galaxy(
3234 truncate at truncate_ratio times good_image_size
3335 maximum_num_grids (int):
3436 maximum number of grids for simulation in real space
35- draw_method (str): method to draw the galaxy image, "auto" will convolve with
36- pixel response, "no_pixel" is as it implies
37- force_ngrid (bool): If True, force the number of grids to be ngrid even if a smaller
38- number of grids is sufficient for the simulation
37+ draw_method (str): method to draw the galaxy image, "auto" will convolve
38+ with pixel response, "no_pixel" is as it implies
39+ force_ngrid (bool): If True, force the number of grids to be ngrid even if
40+ a smaller number of grids is sufficient for the
41+ simulation
3942 Returns:
4043 outcome (ndarray): 2D galaxy image on the grids
4144 """
4245
46+ gobj = gal_obj .shift (
47+ delta_image_x * pix_scale ,
48+ delta_image_y * pix_scale ,
49+ )
4350 # Initialize variables based on PSF presence
4451 if psf_obj is None and draw_method == "no_pixel" :
4552 # In this case we just get the fluxes for the requested stamp size
@@ -52,25 +59,24 @@ def simulate_galaxy(
5259 pad_arcsec = 0.0
5360 downsample_ratio = 1
5461 else :
55- scale = min (gal_obj .nyquist_scale , psf_obj .nyquist_scale / 4.0 , pix_scale / 4.0 )
56- pad_arcsec = psf_obj .calculateMomentRadius (size = 32 , scale = pix_scale / 2.0 )
62+ scale = min (gobj .nyquist_scale , pix_scale / 4.0 )
63+ pad_arcsec = psf_obj .calculateMomentRadius (
64+ size = 32 , scale = pix_scale / 2.0 )
5765 downsample_ratio = min (int (2 ** np .ceil (np .log2 (pix_scale / scale ))), 128 )
58-
66+
5967 scale = pix_scale / downsample_ratio
6068
6169 # Calculate the number of grids considering padding and truncation
6270 npad = int (pad_arcsec / scale + 0.5 ) * 4
63- nn = npad * 2 + min (gal_obj .getGoodImageSize (pixel_scale = scale )
64- * truncate_ratio , ngrid * downsample_ratio
65- )
71+ nn = npad * 2 + min (
72+ gobj .getGoodImageSize (scale )
73+ * truncate_ratio , ngrid * downsample_ratio
74+ )
6675 nn = min (int (2 ** np .ceil (np .log2 (nn ))), maximum_num_grids )
6776
68- print (nn )
6977 if force_ngrid and nn < ngrid :
7078 nn = ngrid
7179 scale = pix_scale
72-
73- print (nn , scale )
7480 # Initialize and Distort Coordinates
7581 stamp = Stamp (nn = nn , scale = scale )
7682 if transform_obj is not None :
@@ -81,32 +87,35 @@ def simulate_galaxy(
8187 # Sample the galaxy flux
8288 gal_prof = _gsinterface .getFluxVec (
8389 scale = scale ,
84- gsobj = gal_obj ._sbp ,
90+ gsobj = gobj ._sbp ,
8591 xy_coords = gal_coords
86- )
87-
92+ )
8893 # No convolution necessary in this case so just return the fluxes
89- if draw_method == "no_pixel" and psf_obj is None :
90- return gal_prof
91-
92- # Construct pixel response
93- pixel_response = galsim .Pixel (scale = pix_scale )
94- if psf_obj is None :
95- psf_obj = pixel_response
94+ if draw_method == "no_pixel" :
95+ if psf_obj is None :
96+ return gal_prof
97+ else :
98+ pass
99+ elif draw_method == "auto" :
100+ # Construct pixel response
101+ pixel_response = galsim .Pixel (scale = pix_scale )
102+ if psf_obj is None :
103+ psf_obj = pixel_response
104+ else :
105+ psf_obj = galsim .Convolve ([psf_obj , pixel_response ])
96106 else :
97- psf_obj = galsim .Convolve ([psf_obj , pixel_response ])
98-
107+ raise ValueError ("do not support draw_method=%s" % draw_method )
99108 # Convolution in Fourier space
100109 gal_prof = _gsinterface .convolvePsf (
101110 scale = scale ,
102111 gsobj = psf_obj ._sbp ,
103112 gal_prof = gal_prof ,
104113 downsample_ratio = downsample_ratio ,
105114 ngrid = ngrid
106- )
107-
115+ )
108116 return gal_prof
109117
118+
110119def simulate_galaxy_batch (
111120 ngrid ,
112121 pix_scale ,
@@ -119,7 +128,7 @@ def simulate_galaxy_batch(
119128 nproc = 4 ,
120129 force_ngrid = False
121130):
122-
131+
123132 """
124133 The function samples the surface density field of a galaxy at the grids
125134
@@ -143,21 +152,21 @@ def simulate_galaxy_batch(
143152 mp .set_start_method ('spawn' , force = True )
144153
145154 with mp .Pool (nproc ) as p :
146-
155+
147156 args_list = [
148157 (
149158 ngrid ,
150- pix_scale ,
151- gal_obj ,
152- transform_obj ,
153- psf_obj ,
154- truncate_ratio ,
155- maximum_num_grids ,
159+ pix_scale ,
160+ gal_obj ,
161+ transform_obj ,
162+ psf_obj ,
163+ truncate_ratio ,
164+ maximum_num_grids ,
156165 draw_method ,
157166 force_ngrid
158167 ) for gal_obj in gal_obj_list
159168 ]
160-
169+
161170 outcome = p .starmap (simulate_galaxy , args_list )
162171
163172 if original_omp_num_threads is None :
0 commit comments