Skip to content

Commit

Permalink
Fix bug where the ._meta_dicts can become longer than the .fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobuddel committed Feb 16, 2023
1 parent 21122e2 commit 4c88305
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scopesim/source/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def __init__(self, filename=None, cube=None, ext=0,

self.meta = {}
self.meta.update(kwargs)
# ._meta_dicts contains a meta for each of the .fields. It is primarily
# used to set proper FITS header keywords for each field so the source
# can be reconstructed from the FITS headers.
self._meta_dicts = [self.meta]

self.fields = []
Expand Down Expand Up @@ -490,7 +493,6 @@ def shift(self, dx=0, dy=0, layers=None):
which .fields entries to shift
"""

if layers is None:
layers = np.arange(len(self.fields))

Expand Down Expand Up @@ -559,6 +561,13 @@ def make_copy(self):

def append(self, source_to_add):
new_source = source_to_add.make_copy()
# If there is no field yet, then self._meta_dicts contains a
# reference to self.meta, which is empty. This ensures that both are
# updated at the same time. However, it is important that the fields
# and _meta_dicts match when appending sources.
if len(self.fields) == 0:
assert self._meta_dicts == [{}]
self._meta_dicts = []
if isinstance(source_to_add, Source):
for field in new_source.fields:
if isinstance(field, Table):
Expand Down Expand Up @@ -601,4 +610,4 @@ def __repr__(self):
msg += f", referencing spectrum {num_spec}"
msg += "\n"

return msg
return msg

0 comments on commit 4c88305

Please sign in to comment.