mirror of
https://github.com/wassname/simpeg.git
synced 2026-09-12 12:51:28 +08:00
Migrated % string formating
This commit is contained in:
+14
-14
@@ -15,7 +15,7 @@ class InversionDirective(object):
|
||||
@inversion.setter
|
||||
def inversion(self, i):
|
||||
if getattr(self,'_inversion',None) is not None:
|
||||
print 'Warning: InversionDirective %s has switched to a new inversion.' % self.__name__
|
||||
print 'Warning: InversionDirective {0!s} has switched to a new inversion.'.format(self.__name__)
|
||||
self._inversion = i
|
||||
|
||||
@property
|
||||
@@ -47,7 +47,7 @@ class DirectiveList(object):
|
||||
def __init__(self, *directives, **kwargs):
|
||||
self.dList = []
|
||||
for d in directives:
|
||||
assert isinstance(d, InversionDirective), 'All directives must be InversionDirectives not %s' % d.__name__
|
||||
assert isinstance(d, InversionDirective), 'All directives must be InversionDirectives not {0!s}'.format(d.__name__)
|
||||
self.dList.append(d)
|
||||
Utils.setKwargs(self, **kwargs)
|
||||
|
||||
@@ -68,7 +68,7 @@ class DirectiveList(object):
|
||||
def inversion(self, i):
|
||||
if self.inversion is i: return
|
||||
if getattr(self,'_inversion',None) is not None:
|
||||
print 'Warning: %s has switched to a new inversion.' % self.__name__
|
||||
print 'Warning: {0!s} has switched to a new inversion.'.format(self.__name__)
|
||||
for d in self.dList:
|
||||
d.inversion = i
|
||||
self._inversion = i
|
||||
@@ -79,7 +79,7 @@ class DirectiveList(object):
|
||||
return
|
||||
|
||||
directives = ['initialize', 'endIter', 'finish']
|
||||
assert ruleType in directives, 'Directive type must be in ["%s"]' % '", "'.join(directives)
|
||||
assert ruleType in directives, 'Directive type must be in ["{0!s}"]'.format('", "'.join(directives))
|
||||
for r in self.dList:
|
||||
getattr(r, ruleType)()
|
||||
|
||||
@@ -141,7 +141,7 @@ class BetaSchedule(InversionDirective):
|
||||
|
||||
def endIter(self):
|
||||
if self.opt.iter > 0 and self.opt.iter % self.coolingRate == 0:
|
||||
if self.debug: print 'BetaSchedule is cooling Beta. Iteration: %d' % self.opt.iter
|
||||
if self.debug: print 'BetaSchedule is cooling Beta. Iteration: {0:d}'.format(self.opt.iter)
|
||||
self.invProb.beta /= self.coolingFactor
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ class SaveEveryIteration(InversionDirective):
|
||||
def fileName(self):
|
||||
if getattr(self, '_fileName', None) is None:
|
||||
from datetime import datetime
|
||||
self._fileName = '%s-%s'%(self.name, datetime.now().strftime('%Y-%m-%d-%H-%M'))
|
||||
self._fileName = '{0!s}-{1!s}'.format(self.name, datetime.now().strftime('%Y-%m-%d-%H-%M'))
|
||||
return self._fileName
|
||||
@fileName.setter
|
||||
def fileName(self, value):
|
||||
@@ -192,31 +192,31 @@ class SaveModelEveryIteration(SaveEveryIteration):
|
||||
"""SaveModelEveryIteration"""
|
||||
|
||||
def initialize(self):
|
||||
print "SimPEG.SaveModelEveryIteration will save your models as: '###-%s.npy'"%self.fileName
|
||||
print "SimPEG.SaveModelEveryIteration will save your models as: '###-{0!s}.npy'".format(self.fileName)
|
||||
|
||||
def endIter(self):
|
||||
np.save('%03d-%s' % (self.opt.iter, self.fileName), self.opt.xc)
|
||||
np.save('{0:03d}-{1!s}'.format(self.opt.iter, self.fileName), self.opt.xc)
|
||||
|
||||
|
||||
class SaveOutputEveryIteration(SaveEveryIteration):
|
||||
"""SaveModelEveryIteration"""
|
||||
|
||||
def initialize(self):
|
||||
print "SimPEG.SaveOutputEveryIteration will save your inversion progress as: '###-%s.txt'"%self.fileName
|
||||
print "SimPEG.SaveOutputEveryIteration will save your inversion progress as: '###-{0!s}.txt'".format(self.fileName)
|
||||
f = open(self.fileName+'.txt', 'w')
|
||||
f.write(" # beta phi_d phi_m f\n")
|
||||
f.close()
|
||||
|
||||
def endIter(self):
|
||||
f = open(self.fileName+'.txt', 'a')
|
||||
f.write(' %3d %1.4e %1.4e %1.4e %1.4e\n'%(self.opt.iter, self.invProb.beta, self.invProb.phi_d, self.invProb.phi_m, self.opt.f))
|
||||
f.write(' {0:3d} {1:1.4e} {2:1.4e} {3:1.4e} {4:1.4e}\n'.format(self.opt.iter, self.invProb.beta, self.invProb.phi_d, self.invProb.phi_m, self.opt.f))
|
||||
f.close()
|
||||
|
||||
class SaveOutputDictEveryIteration(SaveEveryIteration):
|
||||
"""SaveOutputDictEveryIteration"""
|
||||
|
||||
def initialize(self):
|
||||
print "SimPEG.SaveOutputDictEveryIteration will save your inversion progress as dictionary: '###-%s.npz'"%self.fileName
|
||||
print "SimPEG.SaveOutputDictEveryIteration will save your inversion progress as dictionary: '###-{0!s}.npz'".format(self.fileName)
|
||||
|
||||
def endIter(self):
|
||||
# Save the data.
|
||||
@@ -328,7 +328,7 @@ class Update_IRLS(InversionDirective):
|
||||
|
||||
# Beta Schedule
|
||||
if self.opt.iter > 0 and self.opt.iter % self.coolingRate == 0:
|
||||
if self.debug: print 'BetaSchedule is cooling Beta. Iteration: %d' % self.opt.iter
|
||||
if self.debug: print 'BetaSchedule is cooling Beta. Iteration: {0:d}'.format(self.opt.iter)
|
||||
self.invProb.beta /= self.coolingFactor
|
||||
|
||||
|
||||
@@ -340,11 +340,11 @@ class Update_IRLS(InversionDirective):
|
||||
phim_new = self.reg.eval(self.invProb.curModel)
|
||||
self.f_change = np.abs(self.f_old - phim_new) / self.f_old
|
||||
|
||||
print "Regularization decrease: %6.3e" % (self.f_change)
|
||||
print "Regularization decrease: {0:6.3e}".format((self.f_change))
|
||||
|
||||
# Check for maximum number of IRLS cycles
|
||||
if self.IRLSiter == self.maxIRLSiter:
|
||||
print "Reach maximum number of IRLS cycles: %i" % self.maxIRLSiter
|
||||
print "Reach maximum number of IRLS cycles: {0:d}".format(self.maxIRLSiter)
|
||||
self.opt.stopNextIteration = True
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user