Skip to content

Multi-targets bug in DataSet.from_targets_and_survey #61

@aotownsend

Description

@aotownsend

Hi,

Currently, I cannot create a DataSet from a list of targets. For example,

ztf = skysurvey.ZTF.from_logs()
tstart, tstop = ztf.get_timerange()
snii = skysurvey.SNeII.from_draw(500, tstart=tstart, tstop=tstop, effect=skysurvey.effects.mw_extinction)
sniin = skysurvey.SNeIIn.from_draw(500, tstart=tstart, tstop=tstop, effect=skysurvey.effects.mw_extinction)
dset = skysurvey.DataSet.from_targets_and_survey([snii, sniin], ztf)

This raises AttributeError: 'TemplateCollection' object has no attribute 'source'

which is because it calls this fuction from line 270 of collection.py:

@property
    def template_names(self):
        if not hasattr(self, "_template_names") or self._template_names is None:
            self._template_names = [
                target.template.source.name for target in self.targets
            ]
        return self._template_names

I think the problem occurs because snii and sniin are MultiTemplateTSTransients. If I do two snia draws like

snia = skysurvey.SNeIa.from_draw(500, tstart=tstart, tstop=tstop, effect=skysurvey.effects.mw_extinction)
snia2 = skysurvey.SNeIa.from_draw(500, tstart=tstart, tstop=tstop, effect=skysurvey.effects.mw_extinction)
dset = skysurvey.DataSet.from_targets_and_survey([snia, snia2], ztf)

then there is no issue.

But there is still an issue with an snia and snii combination (and this example is given in the docs: step 3 for multi-targets)

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions