gammapy/enrico

Remove hardcoded constants scattered throughout the code

Closed this issue · 4 comments

There are many constants, like emax = 3e5 or filenames hardcoded throughout the code.
This eventually leads to inconsistent results in some cases where people do want to change these constants e.g. in their config file.

We should at least move all constants to constants.py to simplify maintenance.

which constants should be in this file?

There's a few dozen numbers that are used in many different places ... here's just some examples:

    met_ref = 240106987.-23*60.-6
    mdj_ref= 54689.
        return 1.602e-6 * energies ** 2 * err #Mev to Ergs
        ghcount = ROOT.TH2F("ghcount", "", 80, min(E)*0.3,max(E)*2, 100, 0.1, max(obs) * 2)
        tool['dcostheta'] = 0.025

Keeping them in one place and giving them names will reduce errors and simplify maintenance, e.g. we'll use

# in constants.py
MEV_TO_ERG = 1.602e-6
# somewhere else
from enrico.constants import MEV_TO_ERG
return MEV_TO_ERG * energies ** 2 * err

Agreed?

I can make a PR and you can review it, but we should do such cleanup after outstanding changes have been merged or we'll be in merge conflict hell.

agreed. I will do it in my next pull. I will do the same for the names of folders