Skip to content

Commit c8254cd

Browse files
authored
Merge pull request #67 from DukeCosmology/enable_achromatic_drawing
enable achromatic drawing
2 parents 25a76df + 5042d2d commit c8254cd

2 files changed

Lines changed: 15 additions & 27 deletions

File tree

roman_imsim/skycat.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,10 @@ def getObj(self, index, gsparams=None, rng=None, exptime=30):
208208
for component in gsobjs:
209209
if faint:
210210
gsobjs[component] = gsobjs[component].evaluateAtWavelength(self.bandpass)
211-
gs_obj_list.append(
212-
gsobjs[component] * self._trivial_sed * self.exptime * roman.collecting_area
213-
)
211+
gs_obj_list.append(gsobjs[component] * self._trivial_sed)
214212
else:
215213
if component in seds:
216-
gs_obj_list.append(
217-
gsobjs[component] * seds[component] * self.exptime * roman.collecting_area
218-
)
214+
gs_obj_list.append(gsobjs[component] * seds[component])
219215

220216
if not gs_obj_list:
221217
return None
@@ -225,14 +221,22 @@ def getObj(self, index, gsparams=None, rng=None, exptime=30):
225221
else:
226222
gs_object = galsim.Add(gs_obj_list)
227223

224+
# This should catch both "star" and "gaia_star" objects
225+
if "star" in skycat_obj.object_type:
226+
# Cap (star) flux at 30M photons to avoid gross artifacts when trying
227+
# to draw the Roman PSF in finite time and memory
228+
flux_cap = 3e7
229+
if flux > flux_cap:
230+
flux = flux_cap
231+
228232
# Give the object the right flux
233+
gs_object = gs_object.withFlux(flux, self.bandpass)
229234
gs_object.flux = flux
230-
gs_object.withFlux(gs_object.flux, self.bandpass)
231235

232236
# Get the object type
233237
if (skycat_obj.object_type == "diffsky_galaxy") | (skycat_obj.object_type == "galaxy"):
234238
gs_object.object_type = "galaxy"
235-
if skycat_obj.object_type == "star":
239+
if skycat_obj.object_type in {"star", "gaia_star"}:
236240
gs_object.object_type = "star"
237241
if skycat_obj.object_type == "snana":
238242
gs_object.object_type = "transient"

roman_imsim/stamp.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@ def setup(self, config, base, xsize, ysize, ignore, logger):
6060
# or cached by the skyCatalogs code.
6161
gal.flux = gal.calculateFlux(bandpass)
6262
self.flux = gal.flux
63-
# Cap (star) flux at 30M photons to avoid gross artifacts when trying
64-
# to draw the Roman PSF in finite time and memory
65-
flux_cap = 3e7
66-
if self.flux > flux_cap:
67-
if (
68-
hasattr(gal, "original")
69-
and hasattr(gal.original, "original")
70-
and isinstance(gal.original.original, galsim.DeltaFunction)
71-
) or (isinstance(gal, galsim.DeltaFunction)):
72-
gal = gal.withFlux(flux_cap, bandpass)
73-
self.flux = flux_cap
74-
gal.flux = flux_cap
7563
base["flux"] = gal.flux
7664
base["mag"] = -2.5 * np.log10(gal.flux) + bandpass.zeropoint
7765
# print('stamp setup2',process.memory_info().rss)
@@ -284,9 +272,6 @@ def draw(self, prof, image, method, offset, config, base, logger):
284272
# print('stamp draw2',process.memory_info().rss)
285273

286274
if method == "phot":
287-
# We already calculated realized_flux above. Use that now and tell GalSim not
288-
# recalculate the Poisson realization of the flux.
289-
gal = gal.withFlux(self.realized_flux, bandpass)
290275
# print('stamp draw3b ',process.memory_info().rss)
291276

292277
if not faint and "photon_ops" in config:
@@ -306,7 +291,7 @@ def draw(self, prof, image, method, offset, config, base, logger):
306291

307292
# print('stamp draw3a',process.memory_info().rss)
308293
gal.drawImage(
309-
bandpass,
294+
bandpass=bandpass,
310295
method="phot",
311296
offset=offset,
312297
rng=self.rng,
@@ -316,7 +301,7 @@ def draw(self, prof, image, method, offset, config, base, logger):
316301
photon_ops=photon_ops,
317302
sensor=None,
318303
add_to_image=True,
319-
poisson_flux=False,
304+
poisson_flux=True,
320305
)
321306
else:
322307
fft_image = image.copy()
@@ -337,10 +322,9 @@ def draw(self, prof, image, method, offset, config, base, logger):
337322
)
338323

339324
# Go back to a combined convolution for fft drawing.
340-
gal = gal.withFlux(self.flux, bandpass)
341325
prof = galsim.Convolve([gal] + psfs)
342326
try:
343-
prof.drawImage(bandpass, **kwargs)
327+
prof.drawImage(bandpass=bandpass, **kwargs)
344328
except galsim.errors.GalSimFFTSizeError as e:
345329
# I think this shouldn't happen with the updates I made to how the image size
346330
# is calculated, even for extremely bright things. So it should be ok to

0 commit comments

Comments
 (0)