bd-j / forcepho

Generative modeling galaxy photometry for JWST
https://forcepho.readthedocs.io
19 stars 4 forks source link

demo_basic crashes when writing fits image #65

Closed cnaw closed 1 year ago

cnaw commented 1 year ago

Running the demo using CPUs:(force) [cnaw@koa demo_basic]$ python basic.py --sersic 1.6 --rhalf 0.08 --snr 100 --add_noise 0 Writing to ./tests/sersic1.6_rhalf0.080_snr100_noise0/sersic1.6_rhalf0.080_snr100_noise0_data.fits Traceback (most recent call last): File "/home/cnaw/python/forcepho/demo/demo_basic/basic.py", line 112, in patcher.build_patch(region, None, allbands=bands) File "/home/cnaw/anaconda3/envs/force/lib/python3.10/site-packages/forcepho/patches/pixel_patch.py", line 92, in build_patch meta = self.find_exposures(region, allbands) File "/home/cnaw/anaconda3/envs/force/lib/python3.10/site-packages/forcepho/patches/pixel_patch.py", line 405, in find_exposures imbands = np.array([fits.getheader(f, self.sci_ext)["FILTER"] File "/home/cnaw/anaconda3/envs/force/lib/python3.10/site-packages/forcepho/patches/pixel_patch.py", line 405, in imbands = np.array([fits.getheader(f, self.sci_ext)["FILTER"] File "/home/cnaw/anaconda3/envs/force/lib/python3.10/site-packages/astropy/io/fits/header.py", line 169, in getitem card = self._cards[self._cardindex(key)] File "/home/cnaw/anaconda3/envs/force/lib/python3.10/site-packages/astropy/io/fits/header.py", line 1819, in _cardindex raise KeyError(f"Keyword {keyword!r} not found.") KeyError: "Keyword 'FILTER' not found."

However, the keyword is there:

(force) [cnaw@koa demo_basic]$ listhead ./tests/sersic1.6_rhalf0.080_snr100_noise0/sersic1.6_rhalf0.080_snr100_noise0_data.fits | grep FILTER FILTER = 'CLEAR ' FILTER = 'CLEAR ' FILTER = 'CLEAR ' FILTERS = 'CLEAR '

A skeleton file is created but without any imaging data.

bd-j commented 1 year ago

I think this was due to the code looking in the wrong extensions. In 1c5169f I have updated the demos to be more explicit about which extensions contain the data and uncertainty.

cnaw commented 1 year ago

Now it works! Thank you! This issue can be closed.