Skip to content

Commit c07b7b8

Browse files
authored
Update romanisim to use the new L1 / L2 metadata (#166)
* Remove units. * Update pyproject.toml. * Remove ggsaa from file names. * change to lowercase * Point rad/rdm to main. * Point rad/rdm to main better? * Increase minimum asdf version to match rdm. * Increase minimum gwcs version to match rdm. * Updates to support L1/L2 metadata refactoring * Make unit changes less dumb. * Metadata and filename changes. * Point rad/rdm to L1/L2 refactor branches. * Fix rebase failure. * fix pyproject.toml syntax. * Make program an integer. * Update wfi lowercase and docs. * Misc L3 updates. * Repoint rad/rdm to main.
1 parent 4c19b59 commit c07b7b8

File tree

12 files changed

+119
-149
lines changed

12 files changed

+119
-149
lines changed

docs/romanisim/running.rst

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,45 @@ The ``romanisim-make-image`` command line interface (CLI) has a number of argume
1515
this functionality::
1616

1717
romanisim-make-image -h
18-
usage: romanisim-make-image [-h] [--catalog CATALOG] [--radec RADEC RADEC] [--bandpass BANDPASS]
19-
[--sca SCA] [--usecrds] [--webbpsf] [--date DATE [DATE ...]]
20-
[--level LEVEL] [--ma_table_number MA_TABLE_NUMBER] [--seed SEED]
21-
[--nobj NOBJ] [--boresight] [--previous PREVIOUS]
22-
filename
23-
18+
usage: romanisim-make-image [-h] [--bandpass BANDPASS] [--boresight] [--catalog CATALOG] [--config CONFIG]
19+
[--date DATE] [--level LEVEL] [--ma_table_number MA_TABLE_NUMBER] [--nobj NOBJ]
20+
[--previous PREVIOUS] [--radec RADEC RADEC] [--rng_seed RNG_SEED] [--roll ROLL]
21+
[--sca SCA] [--usecrds] [--webbpsf] [--truncate TRUNCATE]
22+
[--pretend-spectral PRETEND_SPECTRAL] [--drop-extra-dq]
23+
filename
24+
2425
Make a demo image.
25-
26+
2627
positional arguments:
27-
filename output image (fits)
28-
29-
optional arguments:
28+
filename output image (asdf)
29+
30+
options:
3031
-h, --help show this help message and exit
31-
--catalog CATALOG input catalog (csv) (default: None)
32-
--radec RADEC RADEC ra and dec (deg) (default: None)
3332
--bandpass BANDPASS bandpass to simulate (default: F087)
34-
--sca SCA SCA to simulate (default: 7). Use -1 to generate images for all SCAs.
35-
--usecrds Use CRDS for distortion map (default: False)
36-
--webbpsf Use webbpsf for PSF (default: False)
37-
--date DATE [DATE ...]
38-
Date of observation to simulate: year month day hour minute second
39-
microsecond (default: None)
33+
--boresight radec specifies location of boresight, not center of WFI. (default: False)
34+
--catalog CATALOG input catalog (ecsv) (default: None)
35+
--config CONFIG input parameter override file (yaml) (default: None)
36+
--date DATE UTC Date and Time of observation to simulate in ISOT format. (default: None)
4037
--level LEVEL 1 or 2, for L1 or L2 output (default: 2)
4138
--ma_table_number MA_TABLE_NUMBER
42-
--rng_seed SEED
4339
--nobj NOBJ
44-
--boresight radec specifies location of boresight, not center of WFI. (default: False)
45-
--previous PREVIOUS previous simulated file in chronological order used for persistence modeling.
46-
(default: None)
47-
48-
EXAMPLE: romanisim-make-image output_image.fits
40+
--previous PREVIOUS previous simulated file in chronological order used for persistence modeling. (default:
41+
None)
42+
--radec RADEC RADEC ra and dec (deg) (default: None)
43+
--rng_seed RNG_SEED
44+
--roll ROLL Position angle (North towards YIdl) measured at the V2Ref/V3Ref of the aperture used.
45+
(default: 0)
46+
--sca SCA SCA to simulate. Use -1 to generate images for all SCAs; include {} in filename for this
47+
mode to indicate where the SCA number should be filled, e.g. l1_wfi{}.asdf (default: 7)
48+
--usecrds Use CRDS for distortion map (default: False)
49+
--webbpsf Use webbpsf for PSF (default: False)
50+
--truncate TRUNCATE If set, truncate the MA table at given number of resultants. (default: None)
51+
--pretend-spectral PRETEND_SPECTRAL
52+
Pretend the image is spectral. exposure.type and instrument.element are updated to be
53+
grism / prism. (default: None)
54+
--drop-extra-dq Do not store the optional simulated dq array. (default: False)
55+
56+
EXAMPLE: romanisim-make-image output_image.asdf
4957

5058
Expected arguments controlling things like the input :doc:`here </romanisim/catalog>` to
5159
simulate, the right ascension and declination of the telescope

romanisim/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def add_objects_to_image(image, objlist, xpos, ypos, psf,
259259
if rng is None:
260260
rng = galsim.UniformDeviate(seed)
261261

262-
log.info('Adding sources to image...')
262+
log.info(f'Adding {len(objlist)} sources to image...')
263263
nrender = 0
264264

265265
chromatic = False
@@ -791,7 +791,7 @@ def simulate(metadata, objlist,
791791
counts, simcatobj = simulate_counts(
792792
image_mod.meta, objlist, rng=rng, usecrds=usecrds, darkrate=darkrate,
793793
webbpsf=webbpsf, flat=flat, psf_keywords=psf_keywords)
794-
util.update_aperture_and_wcsinfo_metadata(image_mod.meta, counts.wcs)
794+
util.update_pointing_and_wcsinfo_metadata(image_mod.meta, counts.wcs)
795795
if level == 0:
796796
im = dict(data=counts.array, meta=dict(image_mod.meta.items()))
797797
else:

romanisim/l3.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ def simulate_cps(image, filter_name, efftimes, objlist=None, psf=None,
534534
objlist = []
535535
if len(objlist) > 0 and xpos is None:
536536
if isinstance(objlist, table.Table):
537+
objlist = romanisim.image.trim_objlist(objlist, image)
537538
coord = np.array([[o['ra'], o['dec']] for o in objlist])
538539
else:
539540
coord = np.array([[o.sky_pos.ra.deg, o.sky_pos.dec.deg]
@@ -730,9 +731,8 @@ def add_more_metadata(metadata, efftimes, filter_name, wcs, shape, nexposures):
730731
metadata['basic']['individual_image_meta'] = None
731732
metadata['model_type'] = 'WfiMosaic'
732733
metadata['photometry']['conversion_microjanskys'] = (
733-
(1e12 * (u.rad / u.arcsec) ** 2).to(u.dimensionless_unscaled) *
734-
u.uJy / u.arcsec ** 2)
735-
metadata['photometry']['conversion_megajanskys'] = 1 * u.MJy / u.sr
734+
(1e12 * (u.rad / u.arcsec) ** 2).to(u.dimensionless_unscaled))
735+
metadata['photometry']['conversion_megajanskys'] = 1
736736

737737
cenx, ceny = ((shape[1] - 1) / 2, (shape[0] - 1) / 2)
738738
c1 = wcs.pixel_to_world(cenx, ceny)
@@ -742,10 +742,8 @@ def add_more_metadata(metadata, efftimes, filter_name, wcs, shape, nexposures):
742742
metadata['photometry']['pixelarea_steradians'] = (pscale ** 2).to(u.sr)
743743
metadata['photometry']['pixelarea_arcsecsq'] = (
744744
pscale.to(u.arcsec) ** 2)
745-
metadata['photometry']['conversion_microjanskys_uncertainty'] = (
746-
0 * u.uJy / u.arcsec ** 2)
747-
metadata['photometry']['conversion_megajanskys_uncertainty'] = (
748-
0 * u.MJy / u.sr)
745+
metadata['photometry']['conversion_microjanskys_uncertainty'] = 0
746+
metadata['photometry']['conversion_megajanskys_uncertainty'] = 0
749747
metadata['resample']['pixel_scale_ratio'] = (
750748
pscale.to(u.arcsec).value / romanisim.parameters.pixel_scale)
751749
metadata['resample']['pixfrac'] = 0

romanisim/parameters.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
'ma_table_number': 1,
4141
'read_pattern': read_pattern[1],
4242
},
43-
'pointing': {'ra_v1': 270.0,
44-
'dec_v1': 66.0,
43+
'pointing': {'target_ra': 270.0,
44+
'target_dec': 66.0,
45+
'target_aperture': 'WFI_CEN',
4546
},
4647
'wcsinfo': {'ra_ref': 270.0,
4748
'dec_ref': 66.0,
@@ -53,9 +54,6 @@
5354
# I don't know what vparity and v3yangle should really be,
5455
# but they are always -1 and -60 in existing files.
5556
},
56-
'aperture': {'name': 'WFI_CEN',
57-
'position_angle': 0
58-
},
5957
}
6058

6159
# Default metadata for level 3 mosaics

romanisim/ris_make_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ def parse_filename(filename):
202202
match = pattern.match(filename)
203203
if match is None:
204204
return None
205-
out = dict(obs_id=filename.replace('_', '')[1:],
205+
out = dict(observation_id=filename.replace('_', '')[1:],
206206
visit_id=filename[1:20],
207-
program=match.group(1), # this one is a string
207+
program=int(match.group(1)), # this one is a string
208208
execution_plan=int(match.group(2)),
209209
# pass = int(match.group(3))
210210
segment=int(match.group(4)),
@@ -259,8 +259,8 @@ def simulate_image_file(args, metadata, cat, rng=None, persist=None):
259259
'WFI_' + args.pretend_spectral.upper())
260260
im['meta']['instrument']['optical_element'] = (
261261
args.pretend_spectral.upper())
262-
im['meta']['guidestar']['gw_window_xsize'] = 170
263-
im['meta']['guidestar']['gw_window_ysize'] = 24
262+
im['meta']['guide_star']['window_xsize'] = 170
263+
im['meta']['guide_star']['window_ysize'] = 24
264264

265265
drop_extra_dq = getattr(args, 'drop_extra_dq', False)
266266
if drop_extra_dq and ('dq' in romanisimdict):

romanisim/tests/test_ris_make_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ def test_parse_filename():
5555
obs = ris_make_utils.parse_filename(
5656
'r9999901001001001001_01101_0001_uncal.asdf')
5757
assert obs is not None
58-
assert obs['program'] == '99999'
58+
assert obs['program'] == 99999
5959
assert obs['pass'] == 1

romanisim/tests/test_wcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ def test_wcs():
9898
# should be close to the reference v2 & v3 offset.
9999
assert np.abs(cc3.separation(cc4).to(u.arcsec).value
100100
- np.hypot(*parameters.v2v3_wficen)) < 1
101-
metadata = dict(aperture=dict(), instrument=dict(), wcsinfo=dict())
101+
metadata = dict(pointing=dict(), instrument=dict(), wcsinfo=dict())
102102
metadata['instrument']['detector'] = 'WFI01'
103-
util.update_aperture_and_wcsinfo_metadata(metadata, wcs.GWCS(gwcs))
104-
assert metadata['aperture']['name'] == 'WFI_01_FULL'
103+
util.update_pointing_and_wcsinfo_metadata(metadata, wcs.GWCS(gwcs))
104+
assert metadata['wcsinfo']['aperture_name'] == 'WFI01_FULL'
105105

106106

107107
def test_wcs_from_fits_header():

romanisim/util.py

Lines changed: 38 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ def add_more_metadata(metadata):
189189

190190
if 'exposure' not in metadata.keys():
191191
metadata['exposure'] = {}
192-
if 'guidestar' not in metadata.keys():
193-
metadata['guidestar'] = {}
192+
if 'guide_star' not in metadata.keys():
193+
metadata['guide_star'] = {}
194194
read_pattern = metadata['exposure'].get(
195195
'read_pattern',
196196
parameters.read_pattern[metadata['exposure']['ma_table_number']])
@@ -204,73 +204,32 @@ def add_more_metadata(metadata):
204204
for prefix, offset in offsets.items():
205205
metadata['exposure'][f'{prefix}_time'] = Time((
206206
starttime + offset).isot)
207-
metadata['exposure'][f'{prefix}_time_mjd'] = (
208-
starttime + offset).mjd
209-
metadata['exposure'][f'{prefix}_time_tdb'] = (
210-
starttime + offset).tdb.mjd
211-
metadata['exposure']['ngroups'] = len(read_pattern)
212-
metadata['exposure']['sca_number'] = (
213-
int(metadata['instrument']['detector'][-2:]))
214-
metadata['exposure']['integration_time'] = openshuttertime
215-
metadata['exposure']['elapsed_exposure_time'] = openshuttertime
216-
# ???
217-
metadata['exposure']['groupgap'] = 0
207+
metadata['exposure']['nresultants'] = len(read_pattern)
218208
metadata['exposure']['frame_time'] = parameters.read_time
219209
metadata['exposure']['exposure_time'] = openshuttertime
220-
metadata['exposure']['effective_exposure_time'] = openshuttertime
221-
metadata['exposure']['duration'] = openshuttertime
222-
metadata['guidestar']['gw_window_xsize'] = 16
223-
metadata['guidestar']['gw_window_ysize'] = 16
224-
if 'gw_window_xstart' in metadata['guidestar']:
225-
metadata['guidestar']['gw_window_xstop'] = (
226-
metadata['guidestar']['gw_window_xstart'])
227-
metadata['guidestar']['gw_window_ystop'] = (
228-
metadata['guidestar']['gw_window_ystart'])
229-
# integration_start? integration_end? nints = 1? ...
230-
231-
if 'target' not in metadata.keys():
232-
metadata['target'] = {}
233-
target = metadata['target']
234-
target['type'] = 'FIXED'
235-
if 'wcsinfo' in metadata.keys():
236-
target['ra'] = metadata['wcsinfo']['ra_ref']
237-
target['dec'] = metadata['wcsinfo']['dec_ref']
238-
target['proposer_ra'] = target['ra']
239-
target['proposer_dec'] = target['dec']
240-
target['ra_uncertainty'] = 0
241-
target['dec_uncertainty'] = 0
242-
target['proper_motion_ra'] = 0
243-
target['proper_motion_dec'] = 0
244-
target['proper_motion_epoch'] = 'J2000'
245-
target['source_type'] = 'EXTENDED'
246-
247-
# there are a few metadata keywords that have problematic, too-long
248-
# defaults in RDM.
249-
# program.category
250-
# ephemeris.ephemeris_reference_frame
251-
# guidestar.gs_epoch
252-
# this truncates these to the maximum allowed characters. Alternative
253-
# solutions would include doing things like:
254-
# making the roman_datamodels defaults archivable
255-
# making the roman_datamodels validation check lengths of strings
256-
if 'program' in metadata:
257-
metadata['program']['category'] = metadata['program']['category'][:6]
258-
if 'ephemeris' in metadata:
259-
metadata['ephemeris']['ephemeris_reference_frame'] = (
260-
metadata['ephemeris']['ephemeris_reference_frame'][:10])
261-
if 'guidestar' in metadata and 'gs_epoch' in metadata['guidestar']:
262-
metadata['guidestar']['gs_epoch'] = (
263-
metadata['guidestar']['gs_epoch'][:10])
264-
265-
266-
def update_aperture_and_wcsinfo_metadata(metadata, gwcs):
267-
"""Update aperture and wcsinfo keywords to use the aperture for this SCA.
210+
effexptime = parameters.read_time * (
211+
np.mean(read_pattern[-1]) - np.mean(read_pattern[0]))
212+
metadata['exposure']['effective_exposure_time'] = effexptime
213+
metadata['guide_star']['window_xsize'] = 16
214+
metadata['guide_star']['window_ysize'] = 16
215+
if 'window_xstart' in metadata['guide_star']:
216+
metadata['guide_star']['window_xstop'] = (
217+
metadata['guide_star']['window_xstart'])
218+
metadata['guide_star']['window_ystop'] = (
219+
metadata['guide_star']['window_ystart'])
220+
if 'visit' not in metadata.keys():
221+
metadata['visit'] = dict()
222+
metadata['visit']['status'] = 'SUCCESSFUL'
223+
224+
225+
def update_pointing_and_wcsinfo_metadata(metadata, gwcs):
226+
"""Update pointing and wcsinfo keywords to use the aperture for this SCA.
268227
269228
Updates metadata in place, setting v2/v3_ref to be equal to the V2 and V3 of
270229
the center of the detector, and ra/dec_ref accordingly. Also updates the
271-
aperture to refer to this SCA.
230+
pointing to refer to this SCA and ra/dec_v1 to point along the boresight.
272231
273-
No updates are performed if gwcs is not a gWCS object or if aperture and
232+
No updates are performed if gwcs is not a gWCS object or if pointing and
274233
wcsinfo are not present in metadata.
275234
276235
Parameters
@@ -280,15 +239,14 @@ def update_aperture_and_wcsinfo_metadata(metadata, gwcs):
280239
gwcs : WCS object
281240
image WCS
282241
"""
283-
if 'aperture' not in metadata or 'wcsinfo' not in metadata:
242+
if 'pointing' not in metadata or 'wcsinfo' not in metadata:
284243
return
285244
if isinstance(gwcs, wcs.GWCS):
286245
gwcs = gwcs.wcs
287246
if not isinstance(gwcs, gwcsmod.wcs.WCS):
288247
return
289-
metadata['aperture']['name'] = (
290-
metadata['instrument']['detector'][:3] + '_'
291-
+ metadata['instrument']['detector'][3:] + '_FULL')
248+
metadata['wcsinfo']['aperture_name'] = (
249+
metadata['instrument']['detector'] + '_FULL')
292250
distortion = gwcs.get_transform('detector', 'v2v3')
293251
center = (galsim.roman.n_pix / 2 - 0.5, galsim.roman.n_pix / 2 - 0.5)
294252
v2v3 = distortion(*center)
@@ -314,6 +272,16 @@ def update_aperture_and_wcsinfo_metadata(metadata, gwcs):
314272
metadata['wcsinfo']['v3_ref'] = v2v3[1]
315273
metadata['wcsinfo']['roll_ref'] = roll_ref
316274

275+
boresight = t2sky(0, 0)
276+
metadata['pointing']['ra_v1'] = boresight[0]
277+
metadata['pointing']['dec_v1'] = boresight[1]
278+
boresightn = t2sky(0, 1)
279+
pa_v3 = (
280+
SkyCoord(boresight[0] * u.deg, boresight[1] * u.deg).position_angle(
281+
SkyCoord(boresightn[0] * u.deg, boresightn[1] * u.deg)))
282+
pa_v3 = pa_v3.to(u.deg).value
283+
metadata['pointing']['pa_v3'] = pa_v3
284+
317285

318286
def king_profile(r, rc, rt):
319287
"""Compute the King profile.
@@ -532,12 +500,10 @@ def update_photom_keywords(im, gain=None):
532500
cc[0].position_angle(cc[2]))
533501
area = (cc[0].separation(cc[1]) * cc[0].separation(cc[2])
534502
* np.sin(angle.to(u.rad).value))
535-
im['meta']['photometry']['pixelarea_steradians'] = area.to(u.sr).value
536-
im['meta']['photometry']['pixelarea_arcsecsq'] = (
537-
area.to(u.arcsec ** 2)).value
503+
im['meta']['photometry']['pixel_area'] = area.to(u.sr).value
538504
val = (gain * (3631 / bandpass.get_abflux(
539-
im.meta['instrument']['optical_element']) /
540-
10 ** 6 / im['meta']['photometry']['pixelarea_steradians']))
505+
im.meta['instrument']['optical_element']) /
506+
10 ** 6 / im['meta']['photometry']['pixel_area']))
541507
im['meta']['photometry']['conversion_megajanskys'] = val
542508
im['meta']['photometry']['conversion_microjanskys'] = (
543509
val * u.MJy / u.sr).to(u.uJy / u.arcsec ** 2).value

romanisim/wcs.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,14 @@ def fill_in_parameters(parameters, coord, pa_aper=0, boresight=True):
5959

6060
if 'pointing' not in parameters.keys():
6161
parameters['pointing'] = {}
62-
63-
parameters['pointing']['ra_v1'] = coord.ra.to(u.deg).value
64-
6562
if 'wcsinfo' not in parameters.keys():
6663
parameters['wcsinfo'] = {}
67-
if 'aperture' not in parameters.keys():
68-
parameters['aperture'] = {}
6964

70-
parameters['wcsinfo']['ra_ref'] = (
71-
parameters['pointing']['ra_v1'])
65+
parameters['pointing']['target_ra'] = coord.ra.to(u.deg).value
66+
parameters['wcsinfo']['ra_ref'] = parameters['pointing']['target_ra']
7267

73-
parameters['pointing']['dec_v1'] = coord.dec.to(u.deg).value
74-
parameters['wcsinfo']['dec_ref'] = (
75-
parameters['pointing']['dec_v1'])
68+
parameters['pointing']['target_dec'] = coord.dec.to(u.deg).value
69+
parameters['wcsinfo']['dec_ref'] = parameters['pointing']['target_dec']
7670

7771
# Romanisim uses ROLL_REF = PA_APER - V3IdlYAngle
7872
parameters['wcsinfo']['roll_ref'] = (
@@ -81,14 +75,16 @@ def fill_in_parameters(parameters, coord, pa_aper=0, boresight=True):
8175
if boresight:
8276
parameters['wcsinfo']['v2_ref'] = 0
8377
parameters['wcsinfo']['v3_ref'] = 0
84-
parameters['aperture']['name'] = 'BORESIGHT'
78+
parameters['wcsinfo']['aperture_name'] = 'BORESIGHT'
79+
parameters['pointing']['target_aperture'] = 'BORESIGHT'
8580
else:
8681
from .parameters import v2v3_wficen
8782
parameters['wcsinfo']['v2_ref'] = v2v3_wficen[0]
8883
parameters['wcsinfo']['v3_ref'] = v2v3_wficen[1]
89-
parameters['aperture']['name'] = 'WFI_CEN'
84+
parameters['wcsinfo']['aperture_name'] = 'WFI_CEN'
85+
parameters['pointing']['target_aperture'] = 'WFI_CEN'
9086

91-
parameters['aperture']['position_angle'] = pa_aper
87+
parameters['wcsinfo']['pa_aperture'] = pa_aper
9288

9389

9490
def get_wcs(image, usecrds=True, distortion=None):

0 commit comments

Comments
 (0)