# Path: environ.py
# FERMI_CATALOG_DIR = os.environ.get('FERMI_CATALOG_DIR', '')


from math import *
from array import *
from Plot.PlotLibrary import *
from Catalog.ReadFermiCatalog import *
from environ import FERMI_CATALOG_DIR
    from astropy.coordinates import ICRS, Galactic, FK4, FK5 
import string
import numpy,scipy.optimize
import matplotlib.pyplot as plt
enerbut,but,enerphi,phi = Cat.Plot("3FGL")

# 2FHL CATALOG
Cat.MakeSpectrum("2FHL",5e-2,2)
enerbut2FHL,but2FHL,enerphi2FHL,phi2FHL = Cat.Plot("2FHL")

# read DATA Point from 3FGL CATALOG
em3FGL,ep3FGL,flux3FGL,dflux3FGL =  Cat.GetDataPoints('3FGL') #energy in TeV since the user ask for that in the call of Cat
ener3FGL = numpy.sqrt(em3FGL*ep3FGL) 
dem3FGL = ener3FGL-em3FGL
dep3FGL = ep3FGL-ener3FGL
c=Cat.ReadPL('3FGL')[3]
e2dnde3FGL = (-c+1)*flux3FGL*numpy.power(ener3FGL*1e6,-c+2)/(numpy.power((ep3FGL*1e6),-c+1)-numpy.power((em3FGL*1e6),-c+1))*1.6e-6
de2dnde3FGL = e2dnde3FGL*dflux3FGL/flux3FGL

for i in xrange(len(ener3FGL)):
    xdata.append(ener3FGL[i])
    ydata.append(e2dnde3FGL[i])
    dydata.append(de2dnde3FGL[i])


# read DATA Point from 2FHL CATALOG
em2FHL,ep2FHL,flux2FHL,dflux2FHL =  Cat.GetDataPoints('2FHL') #energy in TeV since the user ask for that in the call of Cat
for i in xrange(len(em2FHL)):
    if isnan(dflux2FHL[i]):
        em2FHL = numpy.delete(em2FHL,i)
        ep2FHL = numpy.delete(ep2FHL,i)
        flux2FHL = numpy.delete(flux2FHL,i)
        dflux2FHL = numpy.delete(dflux2FHL,i)
        

# Path: environ.py
# FERMI_CATALOG_DIR = os.environ.get('FERMI_CATALOG_DIR', '')


# Path: Script/FitLogPFromFermiCat.py
from math import *
from array import *
from Plot.PlotLibrary import *
from Catalog.ReadFermiCatalog import *
from environ import FERMI_CATALOG_DIR
    from astropy.coordinates import ICRS, Galactic, FK4, FK5 
import string
import numpy,scipy.optimize
import matplotlib.pyplot as plt

enerbut,but,enerphi,phi = Cat.Plot("3FGL")

# 2FHL CATALOG
Cat.MakeSpectrum("2FHL",5e-2,2)
enerbut2FHL,but2FHL,enerphi2FHL,phi2FHL = Cat.Plot("2FHL")

# read DATA Point from 3FGL CATALOG
em3FGL,ep3FGL,flux3FGL,dflux3FGL =  Cat.GetDataPoints('3FGL') #energy in TeV since the user ask for that in the call of Cat
ener3FGL = numpy.sqrt(em3FGL*ep3FGL) 
dem3FGL = ener3FGL-em3FGL
dep3FGL = ep3FGL-ener3FGL
c=Cat.ReadPL('3FGL')[3]
e2dnde3FGL = (-c+1)*flux3FGL*numpy.power(ener3FGL*1e6,-c+2)/(numpy.power((ep3FGL*1e6),-c+1)-numpy.power((em3FGL*1e6),-c+1))*1.6e-6
de2dnde3FGL = e2dnde3FGL*dflux3FGL/flux3FGL

for i in xrange(len(ener3FGL)):
    xdata.append(ener3FGL[i])
    ydata.append(e2dnde3FGL[i])
    dydata.append(de2dnde3FGL[i])


# read DATA Point from 2FHL CATALOG
em2FHL,ep2FHL,flux2FHL,dflux2FHL =  Cat.GetDataPoints('2FHL') #energy in TeV since the user ask for that in the call of Cat
for i in xrange(len(em2FHL)):
    if isnan(dflux2FHL[i]):
        em2FHL = numpy.delete(em2FHL,i)
        ep2FHL = numpy.delete(ep2FHL,i)
        flux2FHL = numpy.delete(flux2FHL,i)
        dflux2FHL = numpy.delete(dflux2FHL,i)
        

ener2FHL = numpy.sqrt(em2FHL*ep2FHL) 