Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arbitrary FITS headers #1015

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
6169438
Removing blank line
wtgee Sep 29, 2018
a5f702f
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Sep 30, 2018
0ed479e
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 1, 2018
d1115e3
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 2, 2018
98a45b0
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 2, 2018
d088e9c
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 4, 2018
2e703d2
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 4, 2018
3e14740
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 5, 2018
3494c08
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 10, 2018
a82ebb8
Add tests of parameters rather than config entries
wtgee Oct 11, 2018
8968d98
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 14, 2018
c0fae80
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 14, 2018
3176eea
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 15, 2018
2c0d1b1
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 16, 2018
0eb0cf9
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 16, 2018
314f1c5
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 18, 2018
590cd3b
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Nov 1, 2018
f90be2a
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Nov 2, 2018
06d486a
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Nov 9, 2018
5889787
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Dec 4, 2018
46f8fdc
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Dec 30, 2018
f1b8dde
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Mar 25, 2019
193996b
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Apr 4, 2019
14ee69d
Merge branch 'develop' of github.com:wtgee/POCS into develop
wtgee Apr 13, 2019
36e0663
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Apr 13, 2019
83c9191
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Apr 14, 2019
7146a7c
Merge branch 'develop' of github.com:wtgee/POCS into develop
wtgee Apr 14, 2019
ac1b3b5
Merge remote-tracking branch 'upstream/develop' into develop
wtgee May 26, 2019
5c4a512
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 18, 2019
5ab2199
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jul 19, 2019
132614d
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 17, 2019
7449d0a
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 17, 2019
33bee94
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 21, 2019
e717503
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 21, 2019
c0de451
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 22, 2019
62fd9ff
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 18, 2019
38959f8
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 20, 2019
0a3dba9
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 21, 2019
39e6794
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 23, 2019
c3fe84e
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jan 16, 2020
dbf0ac8
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Feb 11, 2020
7be8acb
Merge branch 'develop' of github.com:wtgee/POCS into develop
wtgee Feb 11, 2020
8f11029
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Feb 11, 2020
86c6527
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Mar 7, 2020
4eefe1c
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 1, 2020
7d3d172
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 1, 2020
86057cb
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 1, 2020
09a828b
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 1, 2020
6836a72
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 1, 2020
f9456da
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 3, 2020
91980c1
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 15, 2020
e49f2c7
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jun 18, 2020
7b0e49d
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jul 6, 2020
427773b
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jul 6, 2020
4f27545
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jul 7, 2020
bd7f109
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jul 9, 2020
f994564
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Jul 14, 2020
54f496c
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 14, 2020
b4af4d8
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 15, 2020
72994df
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 21, 2020
908df4a
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 26, 2020
28d1cff
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Aug 26, 2020
67a1364
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Sep 13, 2020
85d6ba3
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 7, 2020
9b1fc49
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 8, 2020
fa48c7b
Merge remote-tracking branch 'upstream/develop' into develop
wtgee Oct 12, 2020
28b07cd
* Allow for arbitrary FITS headers.
wtgee Oct 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Changelog
Added
~~~~~

* Allow for arbitrary FITS headers. Keywords will be added as `HIERARCH` cards if they don't conform to FITS standard (using ``astropy`` machinery).
* A "developer" version of the ``panoptes-pocs`` docker image is cloudbuilt automatically on merge with ``develop``. (@wtgee #1010)
* Better error checking in cameras, including ability to store error. (@AnthonyHorton #1007)
* Added ``error.InvalidConfig`` exception. (@wtgee #1007)
* Config options to control camera processing options and allow for `defaults` in the config that applies to all cameras: (@wtgee #1007)
* Config options to control camera processing options and allow for `defaults` in the config that applies to all cameras: (@wtgee #1007 & #1009)

* ``cameras.defaults.compress_fits`` if FITS files should be fpacked. Default True.
* ``cameras.defaults.record_observations`` if observation metadata should be recorded. Default True.
Expand Down
22 changes: 16 additions & 6 deletions src/panoptes/pocs/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,13 +965,23 @@ def _process_fits(self, file_path, metadata):
self.logger.debug(f"Updating FITS headers: {file_path} with {metadata=}")
with fits.open(file_path, 'update') as f:
hdu = f[0]
for metadata_key, field_info in fields.items():
fits_key = field_info['keyword']
fits_comment = field_info.get('comment', '')
# Get the value from either the metadata, the default, or use blank string.
fits_value = metadata.get(metadata_key, field_info.get('default', ''))
for metadata_key, metadata_value in metadata.items():
try:
field_info = fields[metadata_key]
# for metadata_key, field_info in fields.items():
fits_key = field_info['keyword']
fits_comment = field_info.get('comment', '')
# Get the value from either the metadata, the default, or use blank string.
fits_value = metadata.get(metadata_key, field_info.get('default', ''))

self.logger.trace(f'Setting {fits_key=} = {fits_value=} {fits_comment=}')
except KeyError:
self.logger.trace(f'No mapping found for metadata {metadata_key}'
f', will attempt to add as-is.')
fits_key = metadata_key
fits_comment = ''
fits_value = metadata_value

self.logger.trace(f'Setting {fits_key=} = {fits_value=} {fits_comment=}')
hdu.header.set(fits_key, fits_value, fits_comment)

self.logger.debug(f"Finished FITS headers: {file_path}")
Expand Down
22 changes: 20 additions & 2 deletions src/panoptes/pocs/tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,20 +494,38 @@ def test_observation(camera, images_dir):
assert len(glob.glob(observation_pattern)) == 1


def test_observation_headers_and_blocking(camera, images_dir):
def test_observation_blocking(camera, images_dir):
"""
Tests functionality of take_observation()
"""
field = Field('Test Observation', '20h00m43.7135s +22d42m39.0645s')
observation = Observation(field, exptime=1.5 * u.second)
observation.seq_time = '19991231T235559'
camera.take_observation(observation, headers={'field_name': 'TESTVALUE'}, blocking=True)
camera.take_observation(observation, blocking=True)
observation_pattern = os.path.join(images_dir, 'TestObservation',
camera.uid, observation.seq_time, '*.fits*')
image_files = glob.glob(observation_pattern)
assert len(image_files) == 1


def test_observation_headers(camera, images_dir):
"""
Tests functionality of take_observation()
"""
field = Field('Test Observation', '20h00m43.7135s +22d42m39.0645s')
observation = Observation(field, exptime=1.5 * u.second)
observation.seq_time = '19991231T235559'

# Test assigned and arbitrary headers.
headers = {'field_name': 'TESTVALUE', 'non-conforming-header': 'says-hi'}
camera.take_observation(observation, headers=headers, blocking=True)
observation_pattern = os.path.join(images_dir, 'TestObservation',
camera.uid, observation.seq_time, '*.fits*')
image_files = glob.glob(observation_pattern)
assert len(image_files) == 1
headers = fits_utils.getheader(image_files[0])
assert fits_utils.getval(image_files[0], 'FIELD') == 'TESTVALUE'
assert fits_utils.getval(image_files[0], 'non-conforming-header') == 'says-hi'


def test_observation_nofilter(camera, images_dir):
Expand Down