threeML / astromodels

Spatial and spectral models for astrophysics
BSD 3-Clause "New" or "Revised" License
43 stars 44 forks source link

Feature request: Setup proper imports #195

Open grburgess opened 1 year ago

grburgess commented 1 year ago

The way that we do python import * in both 3ML and astromodels is very bad practice as it can lead to namespace collisions. We need to eventually clean this up which will mean that we will have to fix up the docs (and our own scripts).

This will be especially important when we work with packages like gammapy because they may use the same model name and it could cause all kinds of strange bugs.

I have started working on this in a branch, but I think this is a breaking change so something for like a minor version bump.

It would look something like this:


import astromodels as amod

pl = amod.functions_1D.Powerlaw()

ps = amod.sources.PointSource()

for example. Of course, someone could always go through and import everything if they like, but it makes controlling names a lot easier. We would have something similar for 3ML


import threeml as datatools

p = datatools.plugins.OGIPLike()

Thoughts?

henrikef commented 1 year ago

Sounds good, but wouldn't

import threeML
p = threeML.plugins.OGIPLike()

Be less confusing?

grburgess commented 1 year ago

The structure is probably something we should discuss, but it would also give us a chance to think about all these startup warning etc. We could make it all more local and stop freaking people out when it loads. I have some ideas, but it would be better to gather our use cases.