jzuhone / pyxsim

Simulating X-ray observations from astrophysical sources.
http://hea-www.cfa.harvard.edu/~jzuhone/pyxsim
Other
20 stars 8 forks source link

Issues with Adding New Instruments with SOXS 3.0 #31

Closed aditivijayan closed 3 years ago

aditivijayan commented 3 years ago

Hi John

I updated SOXS to 3.0.0 version. I am facing a couple of problems-

  1. I am trying to add XRISM Resolve and produce mock observations. I added a new instrument that has the requisite arf and rmf files.

from soxs import get_instrument_from_registry, add_instrument_to_registry xrism_new = get_instrument_from_registry("xrism_resolve") xrism_new["name"] = "xrism_new" xrism_new["arf"] = "resolve_pnt_spec_ND_20190701.arf" xrism_new["rmf"] = "resolve_h7ev_2019a.rmf" xrism_new["bkgnd"] = None xrism_new["psf"] = "resolve_h7ev_2019a_rslnxb.pha" name = add_instrument_to_registry(xrism_new)

When I run soxs.instrument_simulator with this instrument, I get an error. I am pasting it below-

`KeyError Traceback (most recent call last)

in ----> 1 soxs.instrument_simulator("lsfr_simput.fits", "test_evt.fits", (100.0, "ks"), "xrism_new", \ 2 [30., 45.], overwrite=True) ~/anaconda3/lib/python3.8/site-packages/soxs/instrument.py in instrument_simulator(input_events, out_file, exp_time, instrument, sky_center, overwrite, instr_bkgnd, foreground, ptsrc_bkgnd, bkgnd_file, no_dither, dither_params, roll_angle, subpixel_res, aimpt_shift, prng) 628 mylog.info(f"Making observation of source in {out_file}.") 629 # Make the source first --> 630 events, event_params = generate_events(input_events, exp_time, instrument, sky_center, 631 no_dither=no_dither, dither_params=dither_params, 632 roll_angle=roll_angle, subpixel_res=subpixel_res, ~/anaconda3/lib/python3.8/site-packages/soxs/instrument.py in generate_events(source, exp_time, instrument, sky_center, no_dither, dither_params, roll_angle, subpixel_res, aimpt_shift, prng) 174 # Set up PSF 175 psf_type = instrument_spec["psf"][0] --> 176 psf_class = psf_model_registry[psf_type] 177 psf = psf_class(instrument_spec, prng=prng) 178 KeyError: 'r' ` 2. I am also facing a new issue while adding hubs. I use the following lines to add HUBS- `from soxs import get_instrument_from_registry, add_instrument_to_registry hubs = get_instrument_from_registry("chandra_aciss_heg_p1_cy22") hubs["name"] = "hubs" hubs["arf"] = "hubs_cc_v20181102.arf" hubs["rmf"] = "hubs_cc_v20181102.rmf" hubs['bkgnd'] = None hubs["fov"] = 60. #fov in arcminutes hubs["num_pixels"] = 60 #number of pixels on one side of the chip hubs['aimpt_coords'] = [0., 0.] hubs['chips'] = None hubs["focal_length"] = 1.0 hubs["dither"] = False hubs["psf"] = None hubs["imaging"] = True hubs["grating"] = False hubs["dep_name"] = '' name = add_instrument_to_registry(hubs)` And the error that is thrown up is- `RuntimeError Traceback (most recent call last) in 15 hubs["grating"] = False 16 hubs["dep_name"] = '' ---> 17 name = add_instrument_to_registry(hubs) ~/anaconda3/lib/python3.8/site-packages/soxs/instrument_registry.py in add_instrument_to_registry(inst_spec) 406 if my_keys != default_set: 407 missing = default_set.difference(my_keys) --> 408 raise RuntimeError(f"One or more items is missing from the instrument " 409 f"specification!\nItems needed: {missing}") 410 instrument_registry[name] = inst RuntimeError: One or more items is missing from the instrument specification! Items needed: set() ` This piece of code used to run without errors in the previous version of SOXS. Can you please help me out with these issues? Thank you so much! Aditi
jzuhone commented 3 years ago

I'll look into this.

jzuhone commented 3 years ago

For your first issue, it looks like you set the PSF model to the name of a background file:

xrism_new["psf"] = "resolve_h7ev_2019a_rslnxb.pha"

Sorry the error message isn't better--I'll fix that.

Please see http://hea-www.cfa.harvard.edu/soxs/users_guide/instrument.html#psf-models for examples of how to set PSF models.

jzuhone commented 3 years ago

The second issue can be resolved by removing:

hubs["dep_name"] = ''

which is not necessary anymore. Sorry, this also needs a better error message.

aditivijayan commented 3 years ago

Hi John

The second solution solves the problem! Thank you very much!

Following your suggestion, I tried various input for psf in the code-

  1. Using the default option- by not specifying any psf while initialising the new instrument. This gives an error message-

`KeyError Traceback (most recent call last)

in ----> 1 soxs.instrument_simulator("lsfr_simput.fits", "test_evt.fits", (100.0, "ks"), "xrism_new", \ 2 [30., 45.], overwrite=True) ~/anaconda3/lib/python3.8/site-packages/soxs/instrument.py in instrument_simulator(input_events, out_file, exp_time, instrument, sky_center, overwrite, instr_bkgnd, foreground, ptsrc_bkgnd, bkgnd_file, no_dither, dither_params, roll_angle, subpixel_res, aimpt_shift, prng) 628 mylog.info(f"Making observation of source in {out_file}.") 629 # Make the source first --> 630 events, event_params = generate_events(input_events, exp_time, instrument, sky_center, 631 no_dither=no_dither, dither_params=dither_params, 632 roll_angle=roll_angle, subpixel_res=subpixel_res, ~/anaconda3/lib/python3.8/site-packages/soxs/instrument.py in generate_events(source, exp_time, instrument, sky_center, no_dither, dither_params, roll_angle, subpixel_res, aimpt_shift, prng) 175 psf_type = instrument_spec["psf"][0] 176 psf_class = psf_model_registry[psf_type] --> 177 psf = psf_class(instrument_spec, prng=prng) 178 179 all_events = defaultdict(list) ~/anaconda3/lib/python3.8/site-packages/soxs/psf.py in __init__(self, inst, prng) 95 if not hdu.is_image: 96 continue ---> 97 img_e.append(hdu.header["ENERGY"]) 98 key = "THETA" if "OFFAXIS" not in hdu.header else "OFFAXIS" 99 img_r.append(hdu.header[key]) ~/anaconda3/lib/python3.8/site-packages/astropy/io/fits/header.py in __getitem__(self, key) 154 keyword = key 155 --> 156 card = self._cards[self._cardindex(key)] 157 158 if card.field_specifier is not None and keyword == card.rawkeyword: ~/anaconda3/lib/python3.8/site-packages/astropy/io/fits/header.py in _cardindex(self, key) 1714 1715 if not indices: -> 1716 raise KeyError(f"Keyword {keyword!r} not found.") 1717 1718 try: KeyError: "Keyword 'ENERGY' not found." ` 2. I tried specifying psf by using "None". This gives an error message - `TypeError Traceback (most recent call last) in ----> 1 soxs.instrument_simulator("lsfr_simput.fits", "test_evt.fits", (100.0, "ks"), "xrism_none", \ 2 [30., 45.], overwrite=True) ~/anaconda3/lib/python3.8/site-packages/soxs/instrument.py in instrument_simulator(input_events, out_file, exp_time, instrument, sky_center, overwrite, instr_bkgnd, foreground, ptsrc_bkgnd, bkgnd_file, no_dither, dither_params, roll_angle, subpixel_res, aimpt_shift, prng) 628 mylog.info(f"Making observation of source in {out_file}.") 629 # Make the source first --> 630 events, event_params = generate_events(input_events, exp_time, instrument, sky_center, 631 no_dither=no_dither, dither_params=dither_params, 632 roll_angle=roll_angle, subpixel_res=subpixel_res, ~/anaconda3/lib/python3.8/site-packages/soxs/instrument.py in generate_events(source, exp_time, instrument, sky_center, no_dither, dither_params, roll_angle, subpixel_res, aimpt_shift, prng) 173 174 # Set up PSF --> 175 psf_type = instrument_spec["psf"][0] 176 psf_class = psf_model_registry[psf_type] 177 psf = psf_class(instrument_spec, prng=prng) TypeError: 'NoneType' object is not subscriptable` 3. I tried using "gaussian". This gives an error message- `KeyError Traceback (most recent call last) in ----> 1 soxs.instrument_simulator("lsfr_simput.fits", "test_evt.fits", (100.0, "ks"), "xrism_gauss", \ 2 [30., 45.], overwrite=True) ~/anaconda3/lib/python3.8/site-packages/soxs/instrument.py in instrument_simulator(input_events, out_file, exp_time, instrument, sky_center, overwrite, instr_bkgnd, foreground, ptsrc_bkgnd, bkgnd_file, no_dither, dither_params, roll_angle, subpixel_res, aimpt_shift, prng) 628 mylog.info(f"Making observation of source in {out_file}.") 629 # Make the source first --> 630 events, event_params = generate_events(input_events, exp_time, instrument, sky_center, 631 no_dither=no_dither, dither_params=dither_params, 632 roll_angle=roll_angle, subpixel_res=subpixel_res, ~/anaconda3/lib/python3.8/site-packages/soxs/instrument.py in generate_events(source, exp_time, instrument, sky_center, no_dither, dither_params, roll_angle, subpixel_res, aimpt_shift, prng) 174 # Set up PSF 175 psf_type = instrument_spec["psf"][0] --> 176 psf_class = psf_model_registry[psf_type] 177 psf = psf_class(instrument_spec, prng=prng) 178 KeyError: 'g' ` Incidentally, using "image" and "multi_image" throws up "KeyError:'i'" and "KeyError:'m'", respectively. Thank you!
jzuhone commented 3 years ago

I don't think there is a default option for the PSF--if the docs say that somewhere let me know because that would be wrong. So you must specify a PSF and None would not work.

Note that in the docs it shows that the PSF entry must be a list. So for a Gaussian PSF you have something like:

["gaussian", 1.0]

Where the second entry is the FWHM of the Gaussian in arcseconds. I think you are seeing the errors you are because you are only putting a string there.

aditivijayan commented 3 years ago

It works now! Thank you!