Esempio n. 1
0
def inversionInit(args):

    # IO object
    par = genericIO.io(params=sys.argv)

    # Stopper
    nIter = par.getInt("nIter")
    stop = Stopper.BasicStopper(niter=par.getInt("nIter"))

    # Inversion Folder
    folder = par.getString("folder")
    if (os.path.isdir(folder) == False): os.mkdir(folder)
    prefix = par.getString("prefix", "None")
    if (prefix == "None"): prefix = folder
    invPrefix = folder + "/" + prefix
    logFile = invPrefix + "_logFile"

    # Recording parameters
    bufferSize = par.getInt("bufferSize", 1)
    if (bufferSize == 0): bufferSize = None
    iterSampling = par.getInt("iterSampling", 10)
    restartFolder = par.getString("restartFolder", "None")
    flushMemory = par.getInt("flushMemory", 1)

    # Inversion components to save
    saveObj = par.getInt("saveObj", 1)
    saveRes = par.getInt("saveRes", 0)
    saveGrad = par.getInt("saveGrad", 1)
    saveModel = par.getInt("saveModel", 1)

    # Info
    info = par.getInt("info", 1)

    return stop, logFile, saveObj, saveRes, saveGrad, saveModel, invPrefix, bufferSize, iterSampling, restartFolder, flushMemory, info
def nonlinearFwiOpInitFloat_3D(args):
	"""
	   Function to initialize nonlinear operator
	   The function will return the necessary variables for operator construction
	"""
	# IO objects
	parObject=genericIO.io(params=sys.argv)

	# Time Axis
	nts=parObject.getInt("nts")
	ots=parObject.getFloat("ots",0.0)
	dts=parObject.getFloat("dts")
	timeAxis=Hypercube.axis(n=nts,o=ots,d=dts)
	dummyAxis=Hypercube.axis(n=1)
	wavefieldAxis=Hypercube.axis(n=9)
	sourceGeomFile = parObject.getString("sourceGeomFile")

	# Allocate model
	sourceGeomVector = genericIO.defaultIO.getVector(sourceGeomFile,ndims=3)
	sourceSimAxis = sourceGeomVector.getHyper().getAxis(2)
	sourcesHyper=Hypercube.hypercube(axes=[timeAxis,sourceSimAxis,wavefieldAxis,dummyAxis])
	sourceFloat=SepVector.getSepVector(sourcesHyper,storage="dataFloat")

	# Read sources signals
	sourcesFile=parObject.getString("sources","noSourcesFile")
	sourcesInput=genericIO.defaultIO.getVector(sourcesFile,ndims=4)
	sourceFloatNp=sourceFloat.getNdArray()
	sourcesInputNp=sourcesInput.getNdArray()
	sourceFloatNp.flat[:]=sourcesInputNp

	# elatic params
	elasticParam=parObject.getString("elasticParam", "noElasticParamFile")
	if (elasticParam == "noElasticParamFile"):
		print("**** ERROR: User did not provide elastic parameter file ****\n")
		sys.exit()
	elasticParamFloat=genericIO.defaultIO.getVector(elasticParam)
	elasticParamFloatConv = elasticParamFloat
	#Converting model parameters to Rho|Lame|Mu if necessary [kg/m3|Pa|Pa]
	# 0 ==> correct parameterization
	# 1 ==> VpVsRho to RhoLameMu (m/s|m/s|kg/m3 -> kg/m3|Pa|Pa)
	mod_par = parObject.getInt("mod_par",0)
	if(mod_par != 0):
		convOp = ElaConv_3D.ElasticConv_3D(elasticParamFloat,mod_par)
		elasticParamFloatTemp = elasticParamFloat.clone()
		convOp.forward(False,elasticParamFloatTemp,elasticParamFloatConv)

	# Build sources/receivers geometry
	sourcesVectorCenterGrid,sourcesVectorXGrid,sourcesVectorYGrid,sourcesVectorZGrid,sourcesVectorXZGrid,sourcesVectorXYGrid,sourcesVectorYZGrid,sourceAxis=buildSourceGeometry_3D(parObject,elasticParamFloat)
	recVectorCenterGrid,recVectorXGrid,recVectorYGrid,recVectorZGrid,recVectorXZGrid,recVectorXYGrid,recVectorYZGrid,receiverAxis=buildReceiversGeometry_3D(parObject,elasticParamFloat)

	# Allocate data
	dataHyper=Hypercube.hypercube(axes=[timeAxis,receiverAxis,wavefieldAxis,sourceAxis])
	dataFloat=SepVector.getSepVector(dataHyper,storage="dataFloat")

	# Outputs
	return elasticParamFloat,elasticParamFloatConv,dataFloat,sourceFloat,parObject,sourcesVectorCenterGrid,sourcesVectorXGrid,sourcesVectorYGrid,sourcesVectorZGrid,sourcesVectorXZGrid,sourcesVectorXYGrid,sourcesVectorYZGrid,recVectorCenterGrid,recVectorXGrid,recVectorYGrid,recVectorZGrid,recVectorXZGrid,recVectorXYGrid,recVectorYZGrid
def BornOpInitDouble_3D(args):
    """
	   Function to correctly initialize Born operator
	   The function will return the necessary variables for operator construction
	"""
    # IO objects
    parObject = genericIO.io(params=sys.argv)

    # elatic params
    elasticParam = parObject.getString("elasticParam", "noElasticParamFile")
    if (elasticParam == "noElasticParamFile"):
        print("**** ERROR: User did not provide elastic parameter file ****\n")
        sys.exit()
    elasticParamFloat = genericIO.defaultIO.getVector(elasticParam)
    elasticParamDouble = SepVector.getSepVector(elasticParamFloat.getHyper(),
                                                storage="dataDouble")
    #Converting model parameters to Rho|Lame|Mu if necessary [kg/m3|Pa|Pa]
    # 0 ==> correct parameterization
    # 1 ==> VpVsRho to RhoLameMu (m/s|m/s|kg/m3 -> kg/m3|Pa|Pa)
    mod_par = parObject.getInt("mod_par", 0)
    if (mod_par != 0):
        convOp = ElaConv_3D.ElasticConv_3D(elasticParamFloat, mod_par)
        elasticParamFloatTemp = elasticParamFloat.clone()
        convOp.forward(False, elasticParamFloatTemp, elasticParamFloat)
        del elasticParamFloatTemp

    #Conversion to double precision
    elasticParamDoubleNp = elasticParamDouble.getNdArray()
    elasticParamFloatNp = elasticParamFloat.getNdArray()
    elasticParamDoubleNp[:] = elasticParamFloatNp

    # Time Axis
    nts = parObject.getInt("nts")
    ots = parObject.getFloat("ots", 0.0)
    dts = parObject.getFloat("dts")
    timeAxis = Hypercube.axis(n=nts, o=ots, d=dts)
    wavefieldAxis = Hypercube.axis(n=9)
    sourceGeomFile = parObject.getString("sourceGeomFile")

    # Read sources signals
    sourceGeomVector = genericIO.defaultIO.getVector(sourceGeomFile, ndims=3)
    sourceSimAxis = sourceGeomVector.getHyper().getAxis(2)
    sourceHyper = Hypercube.hypercube(
        axes=[timeAxis, sourceSimAxis, wavefieldAxis])

    sourcesFile = parObject.getString("sources", "noSourcesFile")
    if (sourcesFile == "noSourcesFile"):
        raise IOError(
            "**** ERROR: User did not provide seismic sources file ****")
    sourcesSignalsFloat = genericIO.defaultIO.getVector(sourcesFile, ndims=4)
    sourcesSignalsDouble = SepVector.getSepVector(sourceHyper,
                                                  storage="dataDouble")
    sourcesSignalsDoubleNp = sourcesSignalsDouble.getNdArray()
    sourcesSignalsFloatNp = sourcesSignalsFloat.getNdArray()
    sourcesSignalsDoubleNp.flat[:] = sourcesSignalsFloatNp
    sourcesSignalsVector = []
    sourcesSignalsVector.append(
        sourcesSignalsDouble)  # Create a vector of double3DReg slices

    # Build sources/receivers geometry
    sourcesVectorCenterGrid, sourcesVectorXGrid, sourcesVectorYGrid, sourcesVectorZGrid, sourcesVectorXZGrid, sourcesVectorXYGrid, sourcesVectorYZGrid, sourceAxis = buildSourceGeometry_3D(
        parObject, elasticParamFloat)
    recVectorCenterGrid, recVectorXGrid, recVectorYGrid, recVectorZGrid, recVectorXZGrid, recVectorXYGrid, recVectorYZGrid, receiverAxis = buildReceiversGeometry_3D(
        parObject, elasticParamFloat)

    # Allocate model
    modelDouble = SepVector.getSepVector(elasticParamDouble.getHyper(),
                                         storage="dataDouble")

    # Allocate data
    dataHyper = Hypercube.hypercube(
        axes=[timeAxis, receiverAxis, wavefieldAxis, sourceAxis])
    dataDouble = SepVector.getSepVector(dataHyper, storage="dataDouble")

    # Outputs
    return modelDouble, dataDouble, elasticParamDouble, parObject, sourcesSignalsVector, sourcesVectorCenterGrid, sourcesVectorXGrid, sourcesVectorYGrid, sourcesVectorZGrid, sourcesVectorXZGrid, sourcesVectorXYGrid, sourcesVectorYZGrid, recVectorCenterGrid, recVectorXGrid, recVectorYGrid, recVectorZGrid, recVectorXZGrid, recVectorXYGrid, recVectorYZGrid
import genericIO
import SepVector
import numpy as np
import sys
import os.path

if __name__ == '__main__':
    #Printing documentation if no arguments were provided
    if (len(sys.argv) == 1):
        print(__doc__)
        quit(0)

    ########################## PARSE COMMAND LINE ##############################
    # IO object
    parObject = genericIO.io(params=sys.argv)

    geom = parObject.getString("geom")

    modelFile = parObject.getString("modelFile")
    modelHyper = genericIO.defaultIO.getRegFile(modelFile).getHyper()

    # Output file names
    sourceGeomFile = parObject.getString("sourceGeomFile")
    receiverGeomFile = parObject.getString("receiverGeomFile")

    ########################## MODEL INFORMATION ###############################
    # Z axis
    zAxis = modelHyper.getAxis(1)
    nz = zAxis.n
    dz = zAxis.d