Closed
Description
The registry code looks a little voodoo-ey at first glance, so I haven't tracked down what's happening yet. But here is a minimal example to reproduce the bug.
sncosmo.version = 1.2.0
First, expected behavior.
band = sncosmo.get_bandpass('sdssg')
sncosmo.register(band,'sdssg_test')
sncosmo.get_bandpass('sdssg_test')
No errors, this behaves fine. Now try this:
magsys = sncosmo.get_magsystem('vega')
sncosmo.register(magsys, 'vega_test')
sncosmo.get_magsystem('vega_test')
Exception: No MagSystem named 'vega_test' in registry. Registered names: 'ab', 'vega', 'bd17'
sncosmo.register(magsys, 'vega_test')
Exception: SpectralMagSystem named vega_test already in registry. Use force=True to override.
Metadata
Metadata
Assignees
Labels
No labels
Activity
bhayden53 commentedon Mar 6, 2016
Aha!
sncosmo.get_magsystem
looks for ansncosmo.spectral.MagSystem
object, however,sncosmo.get_magsystem
actually returns an instance ofsncosmo.spectral.SpectralMagSystem
.Unfortunately under the hood everywhere that sncosmo needs to read a magnitude system it seems to use
sncosmo.get_magsystem
, which means that currently the user cannot specify any custom magnitude systems to be used elsewhere.kbarbary commentedon Mar 6, 2016
Yeah, this is something I've been thinking about improving. The answer would be separate registries for bandpasses, magsystems and sources, rather than throwing them all in the same dictionary and keying by the class. Keying by the class presents problems for subclasses, as you've discovered.
Try
sncosmo.register(magsys, 'name', data_class=sncosmo.MagSystem)
in the meantime.kbarbary commentedon Jun 7, 2016
Fixed by #136