Skip to content

Commit

Permalink
Just remove this _meta_dicts thing
Browse files Browse the repository at this point in the history
  • Loading branch information
teutoburg committed Sep 17, 2024
1 parent 0ffd8da commit 0683306
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
2 changes: 1 addition & 1 deletion scopesim/effects/fits_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def apply_to(self, hdul, **kwargs):
prefix = self.meta["keyword_prefix"]
for i, field in enumerate(src.fields):
src_class = field.field.__class__.__name__
src_dic = deepcopy(src._meta_dicts[i])
src_dic = deepcopy(field.meta)
if isinstance(field, HDUSourceField):
hdr = field.header
for key in hdr:
Expand Down
18 changes: 0 additions & 18 deletions scopesim/source/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,6 @@ def meta(self, value):
return
self.fields[0].meta = value

Check warning on line 412 in scopesim/source/source.py

View check run for this annotation

Codecov / codecov/patch

scopesim/source/source.py#L412

Added line #L412 was not covered by tests

@property
def _meta_dicts(self):
return [fld.meta for fld in self.fields]

@_meta_dicts.setter
def _meta_dicts(self, value):
logger.debug("_meta_dicts setting is deprecated")
pass

@property
def bandpass(self):
return self._bandpass
Expand Down Expand Up @@ -568,7 +559,6 @@ def plot(self):
def make_copy(self):
new_source = Source()
new_source.meta = deepcopy(self.meta)
# new_source._meta_dicts = deepcopy(self._meta_dicts)
# new_source.spectra = deepcopy(self.spectra)
for field in self.fields:
new_source.fields.append(deepcopy(field))
Expand All @@ -586,13 +576,6 @@ def append(self, source_to_add):
raise ValueError(f"Cannot add {type(source_to_add)} object to Source object")

Check warning on line 576 in scopesim/source/source.py

View check run for this annotation

Codecov / codecov/patch

scopesim/source/source.py#L576

Added line #L576 was not covered by tests

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 == [{}] or self._meta_dicts == []
self._meta_dicts = []

specrefoffset = max(self.spectra.keys()) + 1 if self.spectra else 0
for field in new_source.fields:
Expand All @@ -608,7 +591,6 @@ def append(self, source_to_add):

field.spectra = {k + specrefoffset: v for k, v in
new_source.spectra.items()}
self._meta_dicts += source_to_add._meta_dicts

def __add__(self, new_source):
self_copy = self.make_copy()
Expand Down
9 changes: 2 additions & 7 deletions scopesim/tests/tests_source/test_source_Source.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ def test_ref_column_always_references_correct_spectrum(self, table_source,
tbl_refs = table_source.fields[0]["ref"]
assert all(tbl_refs.data + 1 == comb_refs.data)
assert image_source.fields[0].header["SPEC_REF"] == 0
assert len(image_source.fields) == len(image_source._meta_dicts)
image_source.shift(0.1, 0.2)

def test_same_as_above_but_reversed(self, table_source, image_source):
Expand All @@ -220,15 +219,13 @@ def test_same_as_above_but_reversed(self, table_source, image_source):
tbl_refs = table_source.fields[0]["ref"]
assert all(tbl_refs.data == comb_refs.data)
assert new_source.fields[1].header["SPEC_REF"] == 3
assert len(new_source.fields) == len(new_source._meta_dicts)
new_source.shift(0.1, 0.2)

def test_imagehdu_with_empty_spec_ref_is_handled(self, table_source,
image_source):
image_source.fields[0].header["SPEC_REF"] = ""
new_source = table_source + image_source
assert new_source.fields[1].header["SPEC_REF"] == ""
assert len(new_source.fields) == len(new_source._meta_dicts)

def test_fits_image_and_array_image_are_added_correctly(self):
img_src = so._image_source()
Expand All @@ -238,16 +235,13 @@ def test_fits_image_and_array_image_are_added_correctly(self):
fits_img_src = fits_src + img_src

assert len(img_src.fields) == 1
assert len(img_src.fields) == len(img_src._meta_dicts)
assert len(fits_src.fields) == 1
assert len(fits_src.fields) == len(fits_src._meta_dicts)
assert len(img_fits_src.fields) == 2
assert len(img_fits_src.fields) == len(img_fits_src._meta_dicts)
assert len(fits_img_src.fields) == 2
assert len(img_fits_src.fields) == len(img_fits_src._meta_dicts)
assert (fits_img_src.fields[0].data == fits_src.fields[0].data).all()
assert img_fits_src.fields[0] is not img_src.fields[0]

@pytest.mark.skip(reason="_meta_dicts was removed, find a better way to perform the same check...")
def test_meta_data_is_passed_on_when_added(self, table_source, image_source):
table_source.fields[0].meta["hello"] = "world"
image_source.fields[0].meta["servus"] = "oida"
Expand All @@ -257,6 +251,7 @@ def test_meta_data_is_passed_on_when_added(self, table_source, image_source):
assert new_source._meta_dicts[0]["hello"] == "world"
assert new_source._meta_dicts[1]["servus"] == "oida"

@pytest.mark.skip(reason="_meta_dicts was removed, find a better way to perform the same check...")
def test_empty_source_is_the_additive_identity(self, image_source):
new_source_1 = Source() + image_source
assert len(new_source_1.fields) == len(new_source_1._meta_dicts)
Expand Down

0 comments on commit 0683306

Please sign in to comment.