Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-22470: Remove all uses of past and future from fgcm #10

Merged
merged 5 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion fgcm/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import division, absolute_import, print_function

__version__ = '2.4.0'
__version__ = '2.4.1'

__version_info__ = __version__.split('.')
5 changes: 3 additions & 2 deletions fgcm/fgcmApertureCorrection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange

from builtins import range
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this since it's not needed in python3.


import numpy as np
import os
Expand Down Expand Up @@ -96,7 +97,7 @@ def computeApertureCorrections(self):

expIndexUse,=np.where(self.fgcmPars.expFlag == 0)

for i in xrange(self.fgcmPars.nBands):
for i in range(self.fgcmPars.nBands):
use,=np.where((self.fgcmPars.expBandIndex[expIndexUse] == i) &
(self.fgcmPars.expSeeingVariable[expIndexUse] > self.illegalValue) &
(np.isfinite(self.fgcmPars.expSeeingVariable[expIndexUse])))
Expand Down
1 change: 0 additions & 1 deletion fgcm/fgcmApplyZeropoints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange

import numpy as np
import os
Expand Down
12 changes: 6 additions & 6 deletions fgcm/fgcmAtmosphereTable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division, absolute_import, print_function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all the __future__ imports as well. Not needed.

from past.builtins import xrange

from builtins import range
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove


import numpy as np
import scipy.interpolate as interpolate
Expand Down Expand Up @@ -356,10 +356,10 @@ def generateTable(self):
self.fgcmLog.info("Generating %d*%d=%d PWV atmospheres..." % (pwvPlus.size,zenithPlus.size,pwvPlus.size*zenithPlus.size))
self.pwvAtmTable = np.zeros((pwvPlus.size,zenithPlus.size,self.atmLambda.size))

for i in xrange(pwvPlus.size):
for i in range(pwvPlus.size):
sys.stdout.write('%d' % (i))
sys.stdout.flush()
for j in xrange(zenithPlus.size):
for j in range(zenithPlus.size):
sys.stdout.write('.')
sys.stdout.flush()
atm=self.modGen(pwv=pwvPlus[i],zenith=zenithPlus[j],
Expand All @@ -370,10 +370,10 @@ def generateTable(self):
self.fgcmLog.info("\nGenerating %d*%d=%d O3 atmospheres..." % (o3Plus.size,zenithPlus.size,o3Plus.size*zenithPlus.size))
self.o3AtmTable = np.zeros((o3Plus.size, zenithPlus.size, self.atmLambda.size))

for i in xrange(o3Plus.size):
for i in range(o3Plus.size):
sys.stdout.write('%d' % (i))
sys.stdout.flush()
for j in xrange(zenithPlus.size):
for j in range(zenithPlus.size):
sys.stdout.write('.')
sys.stdout.flush()
atm=self.modGen(o3=o3Plus[i],zenith=zenithPlus[j],
Expand All @@ -386,7 +386,7 @@ def generateTable(self):
self.o2AtmTable = np.zeros((zenithPlus.size, self.atmLambda.size))
self.rayleighAtmTable = np.zeros((zenithPlus.size, self.atmLambda.size))

for j in xrange(zenithPlus.size):
for j in range(zenithPlus.size):
sys.stdout.write('.')
sys.stdout.flush()
atm=self.modGen(zenith=zenithPlus[j],
Expand Down
1 change: 0 additions & 1 deletion fgcm/fgcmBasemap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange

"""
Adapted from Alex Drlica-Wagner
Expand Down
5 changes: 3 additions & 2 deletions fgcm/fgcmBrightObs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange

from builtins import range
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove.


import numpy as np
import os
Expand Down Expand Up @@ -140,7 +141,7 @@ def brightestObsMeanMag(self,debug=False,computeSEDSlopes=False):
# see also fgcmChisq.py
# splitValues is the first of the goodStars in each list
splitValues = np.zeros(nSections-1,dtype='i4')
for i in xrange(1,nSections):
for i in range(1,nSections):
splitValues[i-1] = goodStarsList[i][0]

# get the indices from the goodStarsSub matched list
Expand Down
8 changes: 4 additions & 4 deletions fgcm/fgcmChisq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange
from builtins import range
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove. I won't comment further on unnecessary use of from builtins import


import numpy as np
import os
Expand Down Expand Up @@ -344,7 +344,7 @@ def __call__(self,fitParams,fitterUnits=False,computeDerivatives=False,computeSE
proc = None

self.totalHandleDict = {}
for thisCore in xrange(self.nCore):
for thisCore in range(self.nCore):
self.totalHandleDict[workerIndex + thisCore] = (
snmm.createArray(self.nSums,dtype='f8'))

Expand All @@ -359,7 +359,7 @@ def __call__(self,fitParams,fitterUnits=False,computeDerivatives=False,computeSE
# see also fgcmBrightObs.py
# splitValues is the first of the goodStars in each list
splitValues = np.zeros(nSections-1,dtype='i4')
for i in xrange(1,nSections):
for i in range(1,nSections):
splitValues[i-1] = goodStarsList[i][0]

# get the indices from the goodStarsSub matched list (matched to goodStars)
Expand Down Expand Up @@ -398,7 +398,7 @@ def __call__(self,fitParams,fitterUnits=False,computeDerivatives=False,computeSE

# sum up the partial sums from the different jobs
partialSums = np.zeros(self.nSums,dtype='f8')
for thisCore in xrange(self.nCore):
for thisCore in range(self.nCore):
partialSums[:] += snmm.getArray(
self.totalHandleDict[workerIndex + thisCore])[:]

Expand Down
8 changes: 4 additions & 4 deletions fgcm/fgcmComputeStepUnits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange
from builtins import range

import numpy as np
import os
Expand Down Expand Up @@ -128,7 +128,7 @@ def run(self, fitParams):
proc = None

self.totalHandleDict = {}
for thisCore in xrange(self.nCore):
for thisCore in range(self.nCore):
self.totalHandleDict[workerIndex + thisCore] = (
snmm.createArray(self.nSums,dtype='f8'))

Expand All @@ -138,7 +138,7 @@ def run(self, fitParams):
goodStarsList = np.array_split(goodStars,nSections)

splitValues = np.zeros(nSections-1,dtype='i4')
for i in xrange(1,nSections):
for i in range(1,nSections):
splitValues[i-1] = goodStarsList[i][0]

splitIndices = np.searchsorted(goodStars[goodStarsSub], splitValues)
Expand All @@ -161,7 +161,7 @@ def run(self, fitParams):

# sum up the partial sums from the different jobs
partialSums = np.zeros(self.nSums,dtype='f8')
for thisCore in xrange(self.nCore):
for thisCore in range(self.nCore):
partialSums[:] += snmm.getArray(
self.totalHandleDict[workerIndex + thisCore])[:]

Expand Down
4 changes: 2 additions & 2 deletions fgcm/fgcmConfig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange
from builtins import range

import numpy as np
import os
Expand Down Expand Up @@ -440,7 +440,7 @@ def __init__(self, configDict, lutIndex, lutStd, expInfo, ccdOffsets, checkFiles

if self.epochNames is None:
self.epochNames = []
for i in xrange(self.epochMJDs.size):
for i in range(self.epochMJDs.size):
self.epochNames.append('epoch%d' % (i))

# are they sorted?
Expand Down
1 change: 0 additions & 1 deletion fgcm/fgcmConnectivity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange

import numpy as np
import esutil
Expand Down
2 changes: 0 additions & 2 deletions fgcm/fgcmExposureSelector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange


import numpy as np
import os
Expand Down
1 change: 0 additions & 1 deletion fgcm/fgcmFitCycle.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange

import numpy as np
import os
Expand Down
1 change: 0 additions & 1 deletion fgcm/fgcmFlagVariables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange

import numpy as np
import os
Expand Down
12 changes: 6 additions & 6 deletions fgcm/fgcmGray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange
from builtins import range

import numpy as np
import os
Expand Down Expand Up @@ -215,7 +215,7 @@ def computeExpGrayForInitialSelection(self):
(expNGoodStarForInitialSelection > self.minStarPerExp) &
(expGrayForInitialSelection > self.expGrayInitialCut))

for i in xrange(self.fgcmPars.nBands):
for i in range(self.fgcmPars.nBands):
self.fgcmLog.debug('Making EXP_GRAY (initial) histogram for %s band' %
(self.fgcmPars.bands[i]))
inBand, = np.where(self.fgcmPars.expBandIndex[expUse] == i)
Expand Down Expand Up @@ -594,7 +594,7 @@ def computeExpGrayColorSplit(self):
expGrayNGoodStarsColorSplit[:, :] = 0
expGrayWtColorSplit = np.zeros_like(expGrayColorSplit)

for c in xrange(gmiCutLow.size):
for c in range(gmiCutLow.size):
use, = np.where((gmiGO > gmiCutLow[c]) &
(gmiGO < gmiCutHigh[c]))

Expand Down Expand Up @@ -704,7 +704,7 @@ def makeExpGrayPlots(self):
expUse,=np.where((self.fgcmPars.expFlag == 0) &
(expNGoodStars > self.minStarPerExp))

for i in xrange(self.fgcmPars.nBands):
for i in range(self.fgcmPars.nBands):
inBand, = np.where(self.fgcmPars.expBandIndex[expUse] == i)

if (inBand.size == 0) :
Expand Down Expand Up @@ -888,7 +888,7 @@ def computeExpGrayCuts(self):
expGrayPhotometricCut[:] = [float(f) for f in self.expGrayPhotometricCut]
expGrayHighCut[:] = [float(f) for f in self.expGrayHighCut]

for i in xrange(self.fgcmPars.nBands):
for i in range(self.fgcmPars.nBands):
inBand, = np.where(self.fgcmPars.expBandIndex[expUse] == i)

if inBand.size == 0:
Expand Down Expand Up @@ -931,7 +931,7 @@ def computeExpGrayCutsFromRepeatability(self):
expGrayPhotometricCut[:] = [float(f) for f in self.expGrayPhotometricCut]
expGrayHighCut[:] = [float(f) for f in self.expGrayHighCut]

for i in xrange(self.fgcmPars.nBands):
for i in range(self.fgcmPars.nBands):
delta = np.clip(self.autoPhotometricCutNSig * self.fgcmPars.compReservedRawCrunchedRepeatability[i], 0.001, 1e5)

cut = -1 * int(np.ceil(delta / self.autoPhotometricCutStep)) * self.autoPhotometricCutStep
Expand Down
50 changes: 25 additions & 25 deletions fgcm/fgcmLUT.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import division, absolute_import, print_function
from past.builtins import xrange
from builtins import range

import numpy as np
import scipy.interpolate as interpolate
Expand Down Expand Up @@ -169,7 +169,7 @@ def setThroughputs(self, throughputDict):
('THROUGHPUT_AVG','f4'),
('THROUGHPUT_CCD','f4',self.nCCD)])
tput['LAMBDA'][:] = lam
for ccdIndex in xrange(self.nCCD):
for ccdIndex in range(self.nCCD):
try:
tput['THROUGHPUT_CCD'][:,ccdIndex] = throughputDict[filterName][ccdIndex]
except:
Expand All @@ -180,7 +180,7 @@ def setThroughputs(self, throughputDict):
tput['THROUGHPUT_AVG'][:] = throughputDict[filterName]['AVG']
else:
self.fgcmLog.info("Average throughput not found in throughputDict for filter %s. Computing now..." % (filterName))
for i in xrange(lam.size):
for i in range(lam.size):
use,=np.where(tput['THROUGHPUT_CCD'][i,:] > 0.0)
if (use.size > 0):
tput['THROUGHPUT_AVG'][i] = np.mean(tput['THROUGHPUT_CCD'][i,use])
Expand Down Expand Up @@ -328,15 +328,15 @@ def makeLUT(self):
# get the filters over the same lambda ranges...
self.fgcmLog.info("\nInterpolating filters...")
self.throughputs = []
for i in xrange(len(self.filterNames)):
for i in range(len(self.filterNames)):
inLam = self.inThroughputs[i]['LAMBDA']

tput = np.zeros(self.atmLambda.size, dtype=[('LAMBDA','f4'),
('THROUGHPUT_AVG','f4'),
('THROUGHPUT_CCD','f4',self.nCCD)])
tput['LAMBDA'][:] = self.atmLambda

for ccdIndex in xrange(self.nCCD):
for ccdIndex in range(self.nCCD):
ifunc = interpolate.interp1d(inLam, self.inThroughputs[i]['THROUGHPUT_CCD'][:,ccdIndex])
tput['THROUGHPUT_CCD'][:,ccdIndex] = np.clip(ifunc(self.atmLambda),
0.0,
Expand All @@ -349,15 +349,15 @@ def makeLUT(self):
# and now we can get the standard atmosphere and lambda_b
self.fgcmLog.info("Computing lambdaB")
self.lambdaB = np.zeros(len(self.filterNames))
for i in xrange(len(self.filterNames)):
for i in range(len(self.filterNames)):
num = integrate.simps(self.atmLambda * self.throughputs[i]['THROUGHPUT_AVG'] / self.atmLambda, self.atmLambda)
denom = integrate.simps(self.throughputs[i]['THROUGHPUT_AVG'] / self.atmLambda, self.atmLambda)
self.lambdaB[i] = num / denom
self.fgcmLog.info("Filter: %s, lambdaB = %.3f" % (self.filterNames[i], self.lambdaB[i]))

self.fgcmLog.info("Computing lambdaStdFilter")
self.lambdaStdFilter = np.zeros(len(self.filterNames))
for i in xrange(len(self.filterNames)):
for i in range(len(self.filterNames)):
num = integrate.simps(self.atmLambda * self.throughputs[i]['THROUGHPUT_AVG'] * self.atmStdTrans / self.atmLambda, self.atmLambda)
denom = integrate.simps(self.throughputs[i]['THROUGHPUT_AVG'] * self.atmStdTrans / self.atmLambda, self.atmLambda)
self.lambdaStdFilter[i] = num / denom
Expand All @@ -380,7 +380,7 @@ def makeLUT(self):
self.I1Std = np.zeros(len(self.filterNames))
self.I2Std = np.zeros(len(self.filterNames))

for i in xrange(len(self.filterNames)):
for i in range(len(self.filterNames)):
self.I0Std[i] = integrate.simps(self.throughputs[i]['THROUGHPUT_AVG'] * self.atmStdTrans / self.atmLambda, self.atmLambda)
self.I1Std[i] = integrate.simps(self.throughputs[i]['THROUGHPUT_AVG'] * self.atmStdTrans * (self.atmLambda - self.lambdaStd[i]) / self.atmLambda, self.atmLambda)
self.I2Std[i] = integrate.simps(self.throughputs[i]['THROUGHPUT_AVG'] * self.atmStdTrans * (self.atmLambda - self.lambdaStd[i])**2. / self.atmLambda, self.atmLambda)
Expand Down Expand Up @@ -409,17 +409,17 @@ def makeLUT(self):
self.pmbFactor = pmbFactorPlus[:-1]

# this set of nexted for loops could probably be vectorized in some way
for i in xrange(len(self.filterNames)):
for i in range(len(self.filterNames)):
self.fgcmLog.info("Working on filter %s" % (self.filterNames[i]))
for j in xrange(pwvPlus.size):
for j in range(pwvPlus.size):
self.fgcmLog.info(" and on pwv #%d" % (j))
for k in xrange(o3Plus.size):
for k in range(o3Plus.size):
self.fgcmLog.info(" and on o3 #%d" % (k))
for m in xrange(tauPlus.size):
for n in xrange(alphaPlus.size):
for o in xrange(zenithPlus.size):
for m in range(tauPlus.size):
for n in range(alphaPlus.size):
for o in range(zenithPlus.size):
aerosolTauLambda = np.exp(-1.0*tauPlus[m]*airmassPlus[o]*(self.atmLambda/self.lambdaNorm)**(-alphaPlus[n]))
for p in xrange(self.nCCDStep):
for p in range(self.nCCDStep):
if (p == self.nCCD):
Sb = self.throughputs[i]['THROUGHPUT_AVG'] * o2AtmTable[o,:] * rayleighAtmTable[o,:] * pwvAtmTable[j,o,:] * o3AtmTable[k,o,:] * aerosolTauLambda
else:
Expand Down Expand Up @@ -484,14 +484,14 @@ def makeLUT(self):

## FIXME: figure out PMB derivative?

for i in xrange(len(self.filterNames)):
for i in range(len(self.filterNames)):
self.fgcmLog.info("Working on filter %s" % (self.filterNames[i]))
for j in xrange(self.pwv.size):
for k in xrange(self.o3.size):
for m in xrange(self.tau.size):
for n in xrange(self.alpha.size):
for o in xrange(self.zenith.size):
for p in xrange(self.nCCDStep):
for j in range(self.pwv.size):
for k in range(self.o3.size):
for m in range(self.tau.size):
for n in range(self.alpha.size):
for o in range(self.zenith.size):
for p in range(self.nCCDStep):
self.lutDeriv['D_LNPWV'][i,j,k,m,n,o,p] = (
((lutPlus['I0'][i,j+1,k,m,n,o,p] -
lutPlus['I0'][i,j,k,m,n,o,p]) /
Expand Down Expand Up @@ -572,7 +572,7 @@ def makeLUT(self):

# now do it...looping is no problem since there aren't that many.

for i in xrange(nTemplates):
for i in range(nTemplates):
data = fits[extNames[i]].read()

templateLambda = data['LAMBDA']
Expand All @@ -598,14 +598,14 @@ def makeLUT(self):
fnu[hi] = intFunc(self.atmLambda[good[-1]])

# compute synthetic mags
for j in xrange(len(self.filterNames)):
for j in range(len(self.filterNames)):
num = integrate.simps(fnu * self.throughputs[j]['THROUGHPUT_AVG'][:] * self.atmStdTrans / self.atmLambda, self.atmLambda)
denom = integrate.simps(self.throughputs[j]['THROUGHPUT_AVG'][:] * self.atmStdTrans / self.atmLambda, self.atmLambda)

self.sedLUT['SYNTHMAG'][i,j] = -2.5*np.log10(num/denom)

# and compute fprimes
for j in xrange(len(self.filterNames)):
for j in range(len(self.filterNames)):
use,=np.where((templateLambda >= (self.lambdaStd[j]-delta)) &
(templateLambda <= (self.lambdaStd[j]+delta)))

Expand Down