Skip to content

Commit

Permalink
Update for unit-free CRDS reference files.
Browse files Browse the repository at this point in the history
  • Loading branch information
schlafly committed Jan 24, 2025
1 parent 9ef0301 commit 2dd18a8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/romanisim/catalog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The following fields must be specified for each source:
* n: the Sersic index of the source. This value is ignored if the source is a point source.
* half_light_radius: the half light radius of the source in arcseconds. This value is ignored if the source is a point source.
* pa: the position angle of the source, in degrees east of north. This value is ignored if the source is a point source.
* ba: the major-to-minor axis ratio. This value is ignored if the source is a point source.
* ba: the minor-to-major axis ratio. This value is ignored if the source is a point source.

Following these required fields is a series of columns giving the fluxes of the the sources in "maggies"; the AB magnitude of the source is given by :math:`-2.5*\log_{10}(\mathrm{flux})`. In order to simulate a scene in a given bandpass, a column with the name of that bandpass must be present giving the total fluxes of the sources. Many flux columns may be present, and other columns may also be present but will be ignored.

Expand Down
2 changes: 1 addition & 1 deletion romanisim/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def table_to_catalog(table, bandpasses):
* n : float, sersic index
* half_light_radius : float, half light radius in arcsec
* pa : float, position angle of ellipse relative to north (on the sky) in degrees
* ba : float, ratio of semiminor axis b over semimajor axis a
* ba : float, semiminor axis b divided by semimajor axis a
Alternatively, the table must have the columns specified in
image_table_to_catalog (for image input).
Expand Down
10 changes: 8 additions & 2 deletions romanisim/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ def gather_reference_data(image_mod, usecrds=False):
continue
if reftype not in refsneeded:
continue
image_mod.meta.ref_file[reftype] = os.path.basename(reffn)
image_mod.meta.ref_file[reftype] = (
'crds://' + os.path.basename(reffn))
if flatneeded:
try:
flatfile = crds.getreferences(
Expand All @@ -641,7 +642,8 @@ def gather_reference_data(image_mod, usecrds=False):

flat_model = roman_datamodels.datamodels.FlatRefModel(flatfile)
flat = flat_model.data[...].copy()
image_mod.meta.ref_file['flat'] = os.path.basename(flatfile)
image_mod.meta.ref_file['flat'] = (
'crds://' + os.path.basename(flatfile))
except crds.core.exceptions.CrdsLookupError:
log.warning('Could not find flat; using 1')
flat = 1
Expand All @@ -659,14 +661,17 @@ def gather_reference_data(image_mod, usecrds=False):
model = roman_datamodels.datamodels.ReadnoiseRefModel(
reffiles['readnoise'])
out['readnoise'] = model.data[nborder:-nborder, nborder:-nborder].copy()
out['readnoise'] *= u.DN

if isinstance(reffiles['gain'], str):
model = roman_datamodels.datamodels.GainRefModel(reffiles['gain'])
out['gain'] = model.data[nborder:-nborder, nborder:-nborder].copy()
out['gain'] *= u.electron / u.DN

if isinstance(reffiles['dark'], str):
model = roman_datamodels.datamodels.DarkRefModel(reffiles['dark'])
out['dark'] = model.dark_slope[nborder:-nborder, nborder:-nborder].copy()
out['dark'] *= u.DN / u.s
out['dark'] *= out['gain']
if isinstance(out['dark'], u.Quantity):
out['dark'] = out['dark'].to(u.electron / u.s).value
Expand All @@ -691,6 +696,7 @@ def gather_reference_data(image_mod, usecrds=False):
saturation = roman_datamodels.datamodels.SaturationRefModel(
reffiles['saturation'])
saturation = saturation.data[nborder:-nborder, nborder:-nborder].copy()
saturation *= u.DN
out['saturation'] = saturation

out['reffiles'] = reffiles
Expand Down
2 changes: 1 addition & 1 deletion romanisim/l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def simulate_cps(image, filter_name, efftimes, objlist=None, psf=None,
objinfo['y'] = ypos
objinfo['counts'] = objinfo0['counts']
objinfo['time'] = objinfo0['time']
extras['objinfo'] = objinfo
extras['simcatobj'] = objinfo

if sky is not None:
# in e / s / output pixel
Expand Down
8 changes: 4 additions & 4 deletions romanisim/tests/test_l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_sim_mosaic():
seed=rng_seed)

# Did all sources get simulated?
assert len(extras['objinfo']) == len(cat)
assert len(extras['simcatobj']) == len(cat)

# Ensure center pixel of bright objects is bright
x_all, y_all = moswcs.world_to_pixel_values(cat['ra'][:10].value,
Expand Down Expand Up @@ -432,7 +432,7 @@ def test_simulate_cps():
xpos=[50, 50], ypos=[50, 50], seed=rng_seed)

assert np.sum(im3.array) > 0 # at least verify that we added some sources...
assert len(objinfo['objinfo']) == 2 # two sources were added
assert len(objinfo['simcatobj']) == 2 # two sources were added

im4 = im.copy()
_, objinfo = l3.simulate_cps(
Expand All @@ -441,15 +441,15 @@ def test_simulate_cps():
seed=rng_seed,
psf=imdict['impsfchromatic'], bandpass=imdict['bandpass'])
assert np.sum(im4.array) > 0 # at least verify that we added some sources...
assert len(objinfo['objinfo']) == 2 # two sources were added
assert len(objinfo['simcatobj']) == 2 # two sources were added

im5 = im.copy()
_, objinfo = l3.simulate_cps(
im5, filter_name, exptime, objlist=imdict['chromcatalog'],
psf=imdict['impsfchromatic'], xpos=[1000, 1000],
seed=rng_seed,
ypos=[1000, 1000])
assert 'objinfo' not in objinfo
assert 'simcatobj' not in objinfo
# these sources should be out of bounds


Expand Down

0 comments on commit 2dd18a8

Please sign in to comment.