Skip to content

Commit 1719fad

Browse files
authored
Merge branch 'main' into photon_sampling
2 parents d889e78 + 1be2161 commit 1719fad

10 files changed

Lines changed: 57 additions & 119 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: Check that 'main' is not merged into the development branch
2+
3+
on: pull_request
4+
5+
jobs:
6+
call-workflow:
7+
uses: lsst/rubin_workflows/.github/workflows/rebase_checker.yaml@main

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
![Build](https://github.com/matroxel/roman_imsim/actions/workflows/build.yml/badge.svg)
1+
![Build](https://github.com/DukeCosmology/roman_imsim/actions/workflows/build.yml/badge.svg)
2+
3+
# roman_imsim
24

3-
# wfirst_imsim
45

56
Nonstandard dependencies are represented in setup.py.
67

config/default.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ image:
7070
filter: { type: ObSeqData, field: filter }
7171
exptime: { type: ObSeqData, field: exptime }
7272

73+
draw_method: 'phot'
7374
# Photon shooting is way faster for chromatic objects than fft, especially when most of them
7475
# are fairly faint. The cross-over point for achromatic objects is generally of order
7576
# flux=1.e6 or so (depending on the profile). Most of our objects here are much fainter than
7677
# that. The fft rendering for chromatic is a factor of 10 or so slower still, whereas
7778
# chromatic photon shooting is only slighly slower than achromatic, so the difference
7879
# is even more pronounced in this case.
79-
draw_method: 'auto'
80+
use_fft_bright: True
8081

8182
# These are all by default turned on, but you can turn any of them off if desired:
8283
ignore_noise: True

config/tds.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ image:
7171
filter: { type: ObSeqData, field: filter }
7272
exptime: { type: ObSeqData, field: exptime }
7373

74+
draw_method: 'phot'
7475
# Photon shooting is way faster for chromatic objects than fft, especially when most of them
7576
# are fairly faint. The cross-over point for achromatic objects is generally of order
7677
# flux=1.e6 or so (depending on the profile). Most of our objects here are much fainter than
7778
# that. The fft rendering for chromatic is a factor of 10 or so slower still, whereas
7879
# chromatic photon shooting is only slighly slower than achromatic, so the difference
7980
# is even more pronounced in this case.
80-
draw_method: 'auto'
81+
use_fft_bright: True
8182

8283
# These are all by default turned on, but you can turn any of them off if desired:
8384
ignore_noise: True

config/was.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ image:
6969
filter: { type: ObSeqData, field: filter }
7070
exptime: { type: ObSeqData, field: exptime }
7171

72+
draw_method: 'phot'
7273
# Photon shooting is way faster for chromatic objects than fft, especially when most of them
7374
# are fairly faint. The cross-over point for achromatic objects is generally of order
7475
# flux=1.e6 or so (depending on the profile). Most of our objects here are much fainter than
7576
# that. The fft rendering for chromatic is a factor of 10 or so slower still, whereas
7677
# chromatic photon shooting is only slighly slower than achromatic, so the difference
7778
# is even more pronounced in this case.
78-
draw_method: 'auto'
79+
use_fft_bright: True
7980

8081
# These are all by default turned on, but you can turn any of them off if desired:
8182
# ignore_noise: True

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ dependencies = [
1616
"galsim",
1717
"fitsio",
1818
"astropy",
19-
"healpy",
2019
"numpy",
21-
"matplotlib",
22-
"scipy"
20+
"skycatalogs",
21+
"packaging",
22+
"setuptools",
2323
]
2424

2525
[project.urls]
26-
Homepage = "https://github.com/matroxel/roman_imsim"
26+
Homepage = "https://github.com/DukeCosmology/roman_imsim"
2727

2828
[tool.setuptools.packages.find]
2929
where = ["."]

roman_imsim/skycat.py

Lines changed: 14 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"
@@ -251,6 +255,8 @@ def getKwargs(self, config, base, logger):
251255
"edge_pix": float,
252256
"obj_types": list,
253257
"mjd": float,
258+
"xsize": int,
259+
"ysize": int,
254260
}
255261
kwargs, safe = galsim.config.GetAllParams(config, base, req=req, opt=opt)
256262
wcs = galsim.config.BuildWCS(base["image"], "wcs", base, logger=logger)

roman_imsim/stamp.py

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

284272
if method == "phot":
273+
<<<<<<< photon_sampling
285274
# We already calculated realized_flux above. Use that now and tell GalSim not
286275
# recalculate the Poisson realization of the flux.
287276
gal = gal.withFlux(self.realized_flux, bandpass)
277+
=======
278+
>>>>>>> main
288279
# print('stamp draw3b ',process.memory_info().rss)
289280

290281
if not faint and "photon_ops" in config:
@@ -304,7 +295,11 @@ def draw(self, prof, image, method, offset, config, base, logger):
304295

305296
# print('stamp draw3a',process.memory_info().rss)
306297
gal.drawImage(
298+
<<<<<<< photon_sampling
307299
bandpass,
300+
=======
301+
bandpass=bandpass,
302+
>>>>>>> main
308303
method="phot",
309304
offset=offset,
310305
rng=self.rng,
@@ -314,7 +309,11 @@ def draw(self, prof, image, method, offset, config, base, logger):
314309
photon_ops=photon_ops,
315310
sensor=None,
316311
add_to_image=True,
312+
<<<<<<< photon_sampling
317313
poisson_flux=False,
314+
=======
315+
poisson_flux=True,
316+
>>>>>>> main
318317
)
319318
else:
320319
fft_image = image.copy()
@@ -335,10 +334,9 @@ def draw(self, prof, image, method, offset, config, base, logger):
335334
)
336335

337336
# Go back to a combined convolution for fft drawing.
338-
gal = gal.withFlux(self.flux, bandpass)
339337
prof = galsim.Convolve([gal] + psfs)
340338
try:
341-
prof.drawImage(bandpass, **kwargs)
339+
prof.drawImage(bandpass=bandpass, **kwargs)
342340
except galsim.errors.GalSimFFTSizeError as e:
343341
# I think this shouldn't happen with the updates I made to how the image size
344342
# is calculated, even for extremely bright things. So it should be ok to
@@ -357,6 +355,7 @@ def draw(self, prof, image, method, offset, config, base, logger):
357355
# with FFT because we switched from phot to fft above.
358356
if self.use_fft_bright:
359357
self.add_poisson_noise(fft_image)
358+
<<<<<<< photon_sampling
360359
# In case we had to make a bigger image, just copy the part we need.
361360
image += fft_image[image.bounds]
362361
# print('stamp draw3',process.memory_info().rss)
@@ -759,9 +758,17 @@ def draw(self, prof, image, method, offset, config, base, logger):
759758
photons.flux=1
760759
else:
761760
photons = galsim.PhotonArray(0)
761+
=======
762+
# In case we had to make a bigger image, just copy the part we need.
763+
image += fft_image[image.bounds]
764+
>>>>>>> main
762765
# print('stamp draw3',process.memory_info().rss)
763766
return photons
764767

768+
def add_poisson_noise(self, fft_image):
769+
fft_image.array[fft_image.array < 0] = 0.0
770+
fft_image.addNoise(galsim.PoissonNoise(rng=self.rng))
771+
765772

766773
# Pick the right function to be _fix_seds.
767774
if galsim.__version_info__ < (2, 5):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
license="MIT",
88
author="Michael Troxel",
99
author_email="michael.troxel@duke.edu",
10-
url="",
10+
url="https://github.com/DukeCosmology/roman_imsim",
1111
packages=["roman_imsim"],
12-
install_requires=["galsim", "fitsio", "astropy", "healpy", "numpy", "matplotlib", "scipy"],
12+
install_requires=["galsim", "fitsio", "astropy", "numpy"],
1313
)

sim.yaml

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)