mirror of
https://github.com/wassname/simpeg.git
synced 2026-09-14 11:35:32 +08:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a5e981dff | ||
|
|
21c64cbe66 | ||
|
|
eb24a70f31 | ||
|
|
704776b8ba | ||
|
|
e4448c2f2e | ||
|
|
9d5db11b0e | ||
|
|
e9957d7ec8 | ||
|
|
c74022a948 | ||
|
|
41e9d175f2 |
@@ -14,6 +14,34 @@ class BaseDataMisfit(object):
|
|||||||
debug = False #: Print debugging information
|
debug = False #: Print debugging information
|
||||||
counter = None #: Set this to a SimPEG.Utils.Counter() if you want to count things
|
counter = None #: Set this to a SimPEG.Utils.Counter() if you want to count things
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
def __init__(self, survey, **kwargs):
|
def __init__(self, survey, **kwargs):
|
||||||
assert survey.ispaired, 'The survey must be paired to a problem.'
|
assert survey.ispaired, 'The survey must be paired to a problem.'
|
||||||
if isinstance(survey, Survey.BaseSurvey):
|
if isinstance(survey, Survey.BaseSurvey):
|
||||||
|
|||||||
@@ -8,6 +8,34 @@ class InversionDirective(object):
|
|||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
Utils.setKwargs(self, **kwargs)
|
Utils.setKwargs(self, **kwargs)
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def inversion(self):
|
def inversion(self):
|
||||||
"""This is the inversion of the InversionDirective instance."""
|
"""This is the inversion of the InversionDirective instance."""
|
||||||
@@ -207,6 +235,76 @@ class SaveOutputEveryIteration(_SaveEveryIteration):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
class SaveOutputDictEveryIteration(_SaveEveryIteration):
|
||||||
|
"""SaveOutputDictEveryIteration"""
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
print "SimPEG.SaveOutputDictEveryIteration will save your inversion progress as dictionary: '###-%s.npz'"%self.fileName
|
||||||
|
|
||||||
|
def endIter(self):
|
||||||
|
# Save the data.
|
||||||
|
ms = self.reg.Ws * ( self.reg.mapping * (self.invProb.curModel - self.reg.mref) )
|
||||||
|
phi_ms = 0.5*ms.dot(ms)
|
||||||
|
if self.reg.smoothModel == True:
|
||||||
|
mref = self.reg.mref
|
||||||
|
else:
|
||||||
|
mref = 0
|
||||||
|
mx = self.reg.Wx * ( self.reg.mapping * (self.invProb.curModel - mref) )
|
||||||
|
phi_mx = 0.5 * mx.dot(mx)
|
||||||
|
if self.prob.mesh.dim==2:
|
||||||
|
my = self.reg.Wy * ( self.reg.mapping * (self.invProb.curModel - mref) )
|
||||||
|
phi_my = 0.5 * my.dot(my)
|
||||||
|
else:
|
||||||
|
phi_my = 'NaN'
|
||||||
|
if self.prob.mesh.dim==3:
|
||||||
|
mz = self.reg.Wz * ( self.reg.mapping * (self.invProb.curModel - mref) )
|
||||||
|
phi_mz = 0.5 * mz.dot(mz)
|
||||||
|
else:
|
||||||
|
phi_mz = 'NaN'
|
||||||
|
|
||||||
|
|
||||||
|
# Save the file as a npz
|
||||||
|
np.savez('{:03d}-{:s}'.format(self.opt.iter,self.fileName), iter=self.opt.iter, beta=self.invProb.beta, phi_d=self.invProb.phi_d, phi_m=self.invProb.phi_m, phi_ms=phi_ms, phi_mx=phi_mx, phi_my=phi_my, phi_mz=phi_mz,f=self.opt.f, m=self.invProb.curModel)
|
||||||
|
|
||||||
|
|
||||||
|
class SaveOutputDictEveryIteration(_SaveEveryIteration):
|
||||||
|
"""SaveOutputDictEveryIteration
|
||||||
|
|
||||||
|
A directive that saves some relevant information from the inversion run to a numpy .npz dictionary file (see numpy.savez function for further info).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
print "SimPEG.SaveOutputDictEveryIteration will save your inversion progress as dictionary: '###-%s.npz'"%self.fileName
|
||||||
|
|
||||||
|
def endIter(self):
|
||||||
|
# Save the data.
|
||||||
|
ms = self.reg.Ws * ( self.reg.mapping * (self.invProb.curModel - self.reg.mref) )
|
||||||
|
phi_ms = 0.5*ms.dot(ms)
|
||||||
|
if self.reg.smoothModel == True:
|
||||||
|
mref = self.reg.mref
|
||||||
|
else:
|
||||||
|
mref = 0
|
||||||
|
mx = self.reg.Wx * ( self.reg.mapping * (self.invProb.curModel - mref) )
|
||||||
|
phi_mx = 0.5 * mx.dot(mx)
|
||||||
|
if self.prob.mesh.dim==2:
|
||||||
|
my = self.reg.Wy * ( self.reg.mapping * (self.invProb.curModel - mref) )
|
||||||
|
phi_my = 0.5 * my.dot(my)
|
||||||
|
else:
|
||||||
|
phi_my = 'NaN'
|
||||||
|
if self.prob.mesh.dim==3:
|
||||||
|
mz = self.reg.Wz * ( self.reg.mapping * (self.invProb.curModel - mref) )
|
||||||
|
phi_mz = 0.5 * mz.dot(mz)
|
||||||
|
else:
|
||||||
|
phi_mz = 'NaN'
|
||||||
|
|
||||||
|
|
||||||
|
# Save the file as a npz
|
||||||
|
np.savez('{:03d}-{:s}'.format(self.opt.iter,self.fileName), iter=self.opt.iter, beta=self.invProb.beta, phi_d=self.invProb.phi_d, phi_m=self.invProb.phi_m, phi_ms=phi_ms, phi_mx=phi_mx, phi_my=phi_my, phi_mz=phi_mz,f=self.opt.f, m=self.invProb.curModel,dpred=self.invProb.dpred)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# class UpdateReferenceModel(Parameter):
|
# class UpdateReferenceModel(Parameter):
|
||||||
|
|||||||
@@ -12,6 +12,34 @@ class Fields(object):
|
|||||||
aliasFields = None #: Aliased fields, a dict with [alias, location, function], e.g. {"b":["e","F",lambda(F,e,ind)]}
|
aliasFields = None #: Aliased fields, a dict with [alias, location, function], e.g. {"b":["e","F",lambda(F,e,ind)]}
|
||||||
dtype = float #: dtype is the type of the storage matrix. This can be a dictionary.
|
dtype = float #: dtype is the type of the storage matrix. This can be a dictionary.
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
def __init__(self, mesh, survey, **kwargs):
|
def __init__(self, mesh, survey, **kwargs):
|
||||||
self.survey = survey
|
self.survey = survey
|
||||||
self.mesh = mesh
|
self.mesh = mesh
|
||||||
|
|||||||
@@ -17,6 +17,30 @@ class IdentityMap(object):
|
|||||||
Utils.setKwargs(self, **kwargs)
|
Utils.setKwargs(self, **kwargs)
|
||||||
self.mesh = mesh
|
self.mesh = mesh
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nP(self):
|
def nP(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class InnerProducts(object):
|
|||||||
return self._getInnerProduct('E', prop=prop, invProp=invProp, invMat=invMat, doFast=doFast)
|
return self._getInnerProduct('E', prop=prop, invProp=invProp, invMat=invMat, doFast=doFast)
|
||||||
|
|
||||||
def _getInnerProduct(self, projType, prop=None, invProp=False, invMat=False, doFast=True):
|
def _getInnerProduct(self, projType, prop=None, invProp=False, invMat=False, doFast=True):
|
||||||
"""
|
"""r
|
||||||
:param str projType: 'F' for faces 'E' for edges
|
:param str projType: 'F' for faces 'E' for edges
|
||||||
:param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
|
:param numpy.array prop: material property (tensor properties are possible) at each cell center (nC, (1, 3, or 6))
|
||||||
:param bool invProp: inverts the material property
|
:param bool invProp: inverts the material property
|
||||||
|
|||||||
@@ -115,6 +115,34 @@ class Minimize(object):
|
|||||||
|
|
||||||
Utils.setKwargs(self, **kwargs)
|
Utils.setKwargs(self, **kwargs)
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def callback(self):
|
def callback(self):
|
||||||
return getattr(self, '_callback', None)
|
return getattr(self, '_callback', None)
|
||||||
|
|||||||
@@ -22,6 +22,34 @@ class BaseProblem(object):
|
|||||||
|
|
||||||
PropMap = None #: A SimPEG PropertyMap class.
|
PropMap = None #: A SimPEG PropertyMap class.
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mapping(self):
|
def mapping(self):
|
||||||
"A SimPEG.Map instance or a property map is PropMap is not None"
|
"A SimPEG.Map instance or a property map is PropMap is not None"
|
||||||
|
|||||||
@@ -13,6 +13,34 @@ class Property(object):
|
|||||||
self.doc = doc
|
self.doc = doc
|
||||||
Utils.setKwargs(self, **kwargs)
|
Utils.setKwargs(self, **kwargs)
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def propertyLink(self):
|
def propertyLink(self):
|
||||||
"Can be something like: ('sigma', Maps.ReciprocalMap)"
|
"Can be something like: ('sigma', Maps.ReciprocalMap)"
|
||||||
@@ -118,6 +146,36 @@ class PropModel(object):
|
|||||||
self.vector = vector
|
self.vector = vector
|
||||||
assert len(self.vector) == self.nP
|
assert len(self.vector) == self.nP
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
# def __reduce__(self):
|
||||||
|
# return (dict,{self.propMap,self.vector})
|
||||||
|
|
||||||
|
# def __getstate__(self):
|
||||||
|
# '''
|
||||||
|
# Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
# Used when doing:
|
||||||
|
# pickle.dump(pickleFile,object)
|
||||||
|
# '''
|
||||||
|
# self.__class__ = ProbModel
|
||||||
|
# odict = {}
|
||||||
|
# odict['vec'] = self.__dict__['vector']
|
||||||
|
# odict['pMap'] = self.__dict__['propMap']
|
||||||
|
# # Return the dict
|
||||||
|
# return odict
|
||||||
|
|
||||||
|
# def __setstate__(self,odict):
|
||||||
|
# '''
|
||||||
|
# Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
# Used when doing:
|
||||||
|
# object = pickle.load(pickleFile)
|
||||||
|
# '''
|
||||||
|
# # Update the dict
|
||||||
|
# # Re-hook the methods to the object
|
||||||
|
# self.propMap = odict['prMap']
|
||||||
|
# self.vector = odict['vec']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nP(self):
|
def nP(self):
|
||||||
inds = []
|
inds = []
|
||||||
@@ -207,6 +265,24 @@ class PropMap(object):
|
|||||||
else:
|
else:
|
||||||
raise Exception('mappings must be a dict, a mapping, or a list of tuples.')
|
raise Exception('mappings must be a dict, a mapping, or a list of tuples.')
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def setup(self, maps, slices=None):
|
def setup(self, maps, slices=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -27,6 +27,34 @@ class BaseRegularization(object):
|
|||||||
self.mapping = mapping or Maps.IdentityMap(mesh)
|
self.mapping = mapping or Maps.IdentityMap(mesh)
|
||||||
self.mapping._assertMatchesPair(self.mapPair)
|
self.mapping._assertMatchesPair(self.mapPair)
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
"""This is the parent of the regularization."""
|
"""This is the parent of the regularization."""
|
||||||
|
|||||||
+104
-1
@@ -19,6 +19,35 @@ class BaseRx(object):
|
|||||||
self._Ps = {}
|
self._Ps = {}
|
||||||
Utils.setKwargs(self, **kwargs)
|
Utils.setKwargs(self, **kwargs)
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rxType(self):
|
def rxType(self):
|
||||||
"""Receiver Type"""
|
"""Receiver Type"""
|
||||||
@@ -129,6 +158,33 @@ class BaseSrc(object):
|
|||||||
self.rxList = rxList
|
self.rxList = rxList
|
||||||
Utils.setKwargs(self, **kwargs)
|
Utils.setKwargs(self, **kwargs)
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nD(self):
|
def nD(self):
|
||||||
@@ -153,6 +209,25 @@ class Data(object):
|
|||||||
if v is not None:
|
if v is not None:
|
||||||
self.fromvec(v)
|
self.fromvec(v)
|
||||||
|
|
||||||
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def _ensureCorrectKey(self, key):
|
def _ensureCorrectKey(self, key):
|
||||||
if type(key) is tuple:
|
if type(key) is tuple:
|
||||||
if len(key) is not 2:
|
if len(key) is not 2:
|
||||||
@@ -210,11 +285,39 @@ class BaseSurvey(object):
|
|||||||
mtrue = None #: True model, if data is synthetic
|
mtrue = None #: True model, if data is synthetic
|
||||||
|
|
||||||
counter = None #: A SimPEG.Utils.Counter object
|
counter = None #: A SimPEG.Utils.Counter object
|
||||||
|
srcPair = BaseSrc #: Source Pair
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
Utils.setKwargs(self, **kwargs)
|
Utils.setKwargs(self, **kwargs)
|
||||||
|
|
||||||
srcPair = BaseSrc #: Source Pair
|
# Pickleing support methods
|
||||||
|
def __getstate__(self):
|
||||||
|
'''
|
||||||
|
Method that makes the dictionary of the object pickleble, removes non-pickleble elements of the object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
pickle.dump(pickleFile,object)
|
||||||
|
'''
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
# Remove fields that are not needed
|
||||||
|
del odict['hook']
|
||||||
|
del odict['setKwargs']
|
||||||
|
# Return the dict
|
||||||
|
return odict
|
||||||
|
|
||||||
|
def __setstate__(self,odict):
|
||||||
|
'''
|
||||||
|
Function that sets a pickle dictionary in to an object.
|
||||||
|
|
||||||
|
Used when doing:
|
||||||
|
object = pickle.load(pickleFile)
|
||||||
|
'''
|
||||||
|
# Update the dict
|
||||||
|
self.__dict__.update(odict)
|
||||||
|
# Re-hook the methods to the object
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.hook)
|
||||||
|
Utils.codeutils.hook(self,Utils.codeutils.setKwargs)
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def srcList(self):
|
def srcList(self):
|
||||||
|
|||||||
@@ -170,16 +170,58 @@ def scalarConductivity(ccMesh,pFunction):
|
|||||||
|
|
||||||
return mkvc(sigma)
|
return mkvc(sigma)
|
||||||
|
|
||||||
|
def layeredModel(ccMesh, layerTops, layerValues):
|
||||||
|
"""
|
||||||
|
Define a layered model from layerTops (z-positive up)
|
||||||
|
|
||||||
|
:param numpy.array ccMesh: cell-centered mesh
|
||||||
|
:param numpy.array layerTops: z-locations of the tops of each layer
|
||||||
|
:param numpy.array layerValue: values of the property to assign for each layer (starting at the top)
|
||||||
|
:rtype: numpy.array
|
||||||
|
:return: M, layered model on the mesh
|
||||||
|
"""
|
||||||
|
|
||||||
|
descending = np.linalg.norm(sorted(layerTops, reverse=True) - layerTops) < 1e-20
|
||||||
|
|
||||||
|
# TODO: put an error check to make sure that there is an ordering... needs to work with inf elts
|
||||||
|
# assert ascending or descending, "Layers must be listed in either ascending or descending order"
|
||||||
|
|
||||||
|
# start from bottom up
|
||||||
|
if not descending:
|
||||||
|
zprop = np.hstack([mkvc(layerTops,2),mkvc(layerValues,2)])
|
||||||
|
zprop.sort(axis=0)
|
||||||
|
layerTops, layerValues = zprop[::-1,0], zprop[::-1,1]
|
||||||
|
|
||||||
|
# put in vector form
|
||||||
|
layerTops, layerValues = mkvc(layerTops), mkvc(layerValues)
|
||||||
|
|
||||||
|
# initialize with bottom layer
|
||||||
|
dim = ccMesh.shape[1]
|
||||||
|
if dim == 3:
|
||||||
|
z = ccMesh[:,2]
|
||||||
|
elif dim == 2:
|
||||||
|
z = ccMesh[:,1]
|
||||||
|
elif dim == 1:
|
||||||
|
z = ccMesh[:,0]
|
||||||
|
|
||||||
|
model = np.zeros(ccMesh.shape[0])
|
||||||
|
|
||||||
|
for i, top in enumerate(layerTops):
|
||||||
|
zind = z <= top
|
||||||
|
model[zind] = layerValues[i]
|
||||||
|
|
||||||
|
return model
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def randomModel(shape, seed=None, anisotropy=None, its=100, bounds=[0,1]):
|
def randomModel(shape, seed=None, anisotropy=None, its=100, bounds=[0,1]):
|
||||||
"""
|
"""
|
||||||
Create a random model by convolving a kernal with a
|
Create a random model by convolving a kernel with a
|
||||||
uniformly distributed model.
|
uniformly distributed model.
|
||||||
|
|
||||||
:param int,tuple shape: shape of the model.
|
:param int,tuple shape: shape of the model.
|
||||||
:param int seed: pick which model to produce, prints the seed if you don't choose.
|
:param int seed: pick which model to produce, prints the seed if you don't choose.
|
||||||
:param numpy.ndarray,list anisotropy: this is the (3 x n) blurring kernal that is used.
|
:param numpy.ndarray,list anisotropy: this is the (3 x n) blurring kernel that is used.
|
||||||
:param int its: number of smoothing iterations
|
:param int its: number of smoothing iterations
|
||||||
:param list bounds: bounds on the model, len(list) == 2
|
:param list bounds: bounds on the model, len(list) == 2
|
||||||
:rtype: numpy.ndarray
|
:rtype: numpy.ndarray
|
||||||
|
|||||||
+21
-19
@@ -205,7 +205,6 @@ def writeUBCTensorModel(fileName, mesh, model):
|
|||||||
|
|
||||||
np.savetxt(fileName, modelMatTR.ravel())
|
np.savetxt(fileName, modelMatTR.ravel())
|
||||||
|
|
||||||
|
|
||||||
def readVTRFile(fileName):
|
def readVTRFile(fileName):
|
||||||
"""
|
"""
|
||||||
Read VTK Rectilinear (vtr xml file) and return SimPEG Tensor mesh and model
|
Read VTK Rectilinear (vtr xml file) and return SimPEG Tensor mesh and model
|
||||||
@@ -296,28 +295,31 @@ def writeVTRFile(fileName,mesh,model=None):
|
|||||||
vtkObj.SetZCoordinates(numpy_to_vtk(vZ,deep=1))
|
vtkObj.SetZCoordinates(numpy_to_vtk(vZ,deep=1))
|
||||||
|
|
||||||
# Assign the model('s) to the object
|
# Assign the model('s) to the object
|
||||||
for item in model.iteritems():
|
if model is not None:
|
||||||
# Convert numpy array
|
for item in model.iteritems():
|
||||||
vtkDoubleArr = numpy_to_vtk(item[1],deep=1)
|
# Convert numpy array
|
||||||
vtkDoubleArr.SetName(item[0])
|
vtkDoubleArr = numpy_to_vtk(item[1],deep=1)
|
||||||
vtkObj.GetCellData().AddArray(vtkDoubleArr)
|
vtkDoubleArr.SetName(item[0])
|
||||||
# Set the active scalar
|
vtkObj.GetCellData().AddArray(vtkDoubleArr)
|
||||||
vtkObj.GetCellData().SetActiveScalars(model.keys()[0])
|
# Set the active scalar
|
||||||
vtkObj.Update()
|
vtkObj.GetCellData().SetActiveScalars(model.keys()[0])
|
||||||
|
|
||||||
|
|
||||||
# Check the extension of the fileName
|
# Check the extension of the fileName
|
||||||
ext = os.path.splitext(fileName)[1]
|
if fileName is not None:
|
||||||
if ext is '':
|
ext = os.path.splitext(fileName)[1]
|
||||||
fileName = fileName + '.vtr'
|
if ext is '':
|
||||||
elif ext not in '.vtr':
|
fileName = fileName + '.vtr'
|
||||||
raise IOError('{:s} is an incorrect extension, has to be .vtr')
|
elif ext not in '.vtr':
|
||||||
# Write the file.
|
raise IOError('{:s} is an incorrect extension, has to be .vtr')
|
||||||
vtrWriteFilter = rectWriter()
|
# Write the file.
|
||||||
vtrWriteFilter.SetInput(vtkObj)
|
|
||||||
vtrWriteFilter.SetFileName(fileName)
|
|
||||||
vtrWriteFilter.Update()
|
|
||||||
|
|
||||||
|
vtrWriteFilter = rectWriter()
|
||||||
|
vtrWriteFilter.SetInputData(vtkObj)
|
||||||
|
vtrWriteFilter.SetFileName(fileName)
|
||||||
|
vtrWriteFilter.Update()
|
||||||
|
else:
|
||||||
|
return vtkObj
|
||||||
|
|
||||||
def ExtractCoreMesh(xyzlim, mesh, meshType='tensor'):
|
def ExtractCoreMesh(xyzlim, mesh, meshType='tensor'):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user