def setup(self, domainbuilder, k0=None, dk=None, z0=None, beta=None, w0=None, w1=None,k_at_depth=None ): """ Sets up the inversion from a `DomainBuilder`. If magnetic data are given as scalar it is assumed that values are collected in direction of the background magnetic field. :param domainbuilder: Domain builder object with gravity source(s) :type domainbuilder: `DomainBuilder` :param k0: reference susceptibility, see `SusceptibilityMapping`. If not specified, zero is used. :type k0: ``float`` or ``Scalar`` :param dk: susceptibility scale, see `SusceptibilityMapping`. If not specified, 2750kg/m^3 is used. :type dk: ``float`` or ``Scalar`` :param z0: reference depth for depth weighting, see `SusceptibilityMapping`. If not specified, zero is used. :type z0: ``float`` or ``Scalar`` :param beta: exponent for depth weighting, see `SusceptibilityMapping`. If not specified, zero is used. :type beta: ``float`` or ``Scalar`` :param w0: weighting factor for level set term regularization. If not set zero is assumed. :type w0: ``Scalar`` or ``float`` :param w1: weighting factor for the gradient term in the regularization. If not set zero is assumed :type w1: ``Vector`` or list of ``float`` :param k_at_depth: value for susceptibility at depth, see `DomainBuilder`. :type k_at_depth: ``float`` or ``None`` """ self.logger.info('Retrieving domain...') dom=domainbuilder.getDomain() DIM=dom.getDim() trafo=makeTransformation(dom, domainbuilder.getReferenceSystem()) #======================== self.logger.info('Creating mapping ...') k_mask = domainbuilder.getSetSusceptibilityMask() if k_at_depth: k2= k_mask * k_at_depth + (1-k_mask) * k0 elif k0: k2= (1-k_mask) * k0 else: k2=0 k_mapping=SusceptibilityMapping(dom, k0=k2, dk=dk, z0=z0, beta=beta) scale_mapping=k_mapping.getTypicalDerivative() #======================== self.logger.info("Setting up regularization...") if w1 is None: w1=[1.]*DIM regularization=Regularization(dom, numLevelSets=1,w0=w0, w1=w1, location_of_set_m=k_mask, coordinates=trafo) #==================================================================== self.logger.info("Retrieving magnetic field surveys...") d_b=es.normalize(domainbuilder.getBackgroundMagneticFluxDensity()) surveys=domainbuilder.getMagneticSurveys() B=[] w=[] for B_i,sigma_i in surveys: w_i=es.safeDiv(1., sigma_i) if B_i.getRank()==0: B_i=B_i*d_b if w_i.getRank()==0: w_i=w_i*d_b B.append(B_i) w.append(w_i) self.logger.debug("Added magnetic survey:") self.logger.debug("B = %s"%B_i) self.logger.debug("sigma = %s"%sigma_i) self.logger.debug("w = %s"%w_i) #==================================================================== self.logger.info("Setting up model...") if self.self_demagnetization: forward_model=SelfDemagnetizationModel(dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) else: forward_model=MagneticModel(dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) forward_model.rescaleWeights(k_scale=scale_mapping) #==================================================================== self.logger.info("Setting cost function...") self.setCostFunction(InversionCostFunction(regularization, k_mapping, forward_model))
def setup(self, domainbuilder, rho0=None, drho=None, rho_z0=None, rho_beta=None, k0=None, dk=None, k_z0=None, k_beta=None, w0=None, w1=None, w_gc=None,rho_at_depth=None, k_at_depth=None): """ Sets up the inversion from an instance ``domainbuilder`` of a `DomainBuilder`. Gravity and magnetic data attached to the ``domainbuilder`` are considered in the inversion. If magnetic data are given as scalar it is assumed that values are collected in direction of the background magnetic field. :param domainbuilder: Domain builder object with gravity source(s) :type domainbuilder: `DomainBuilder` :param rho0: reference density, see `DensityMapping`. If not specified, zero is used. :type rho0: ``float`` or `Scalar` :param drho: density scale, see `DensityMapping`. If not specified, 2750 kg/m^3 is used. :type drho: ``float`` or `Scalar` :param rho_z0: reference depth for depth weighting for density, see `DensityMapping`. If not specified, zero is used. :type rho_z0: ``float`` or `Scalar` :param rho_beta: exponent for density depth weighting, see `DensityMapping`. If not specified, zero is used. :type rho_beta: ``float`` or `Scalar` :param k0: reference susceptibility, see `SusceptibilityMapping`. If not specified, zero is used. :type k0: ``float`` or `Scalar` :param dk: susceptibility scale, see `SusceptibilityMapping`. If not specified, 1. is used. :type dk: ``float`` or `Scalar` :param k_z0: reference depth for susceptibility depth weighting, see `SusceptibilityMapping`. If not specified, zero is used. :type k_z0: ``float`` or `Scalar` :param k_beta: exponent for susceptibility depth weighting, see `SusceptibilityMapping`. If not specified, zero is used. :type k_beta: ``float`` or `Scalar` :param w0: weighting factor for level set term in the regularization. If not set zero is assumed. :type w0: ``Scalar`` or ``float`` :param w1: weighting factor for the gradient term in the regularization see `Regularization`. If not set zero is assumed. :type w1: `es.Data` or ``ndarray`` of shape (DIM,) :param w_gc: weighting factor for the cross gradient term in the regularization, see `Regularization`. If not set one is assumed. :type w_gc: `Scalar` or `float` :param k_at_depth: value for susceptibility at depth, see `DomainBuilder`. :type k_at_depth: ``float`` or ``None`` :param rho_at_depth: value for density at depth, see `DomainBuilder`. :type rho_at_depth: ``float`` or ``None`` """ self.logger.info('Retrieving domain...') dom=domainbuilder.getDomain() DIM=dom.getDim() trafo=makeTransformation(dom, domainbuilder.getReferenceSystem()) rock_mask=wherePositive(domainbuilder.getSetDensityMask() + domainbuilder.getSetSusceptibilityMask()) #======================== self.logger.info('Creating mappings ...') if rho_at_depth: rho2= rock_mask * rho_at_depth + (1-rock_mask) * rho0 elif rho0: rho2= (1-rock_mask) * rho0 else: rho2=0 if k_at_depth: k2= rock_mask * k_at_depth + (1-rock_mask) * k0 elif k0: k2= (1-rock_mask) * k0 else: k2=0 rho_mapping=DensityMapping(dom, rho0=rho2, drho=drho, z0=rho_z0, beta=rho_beta) rho_scale_mapping=rho_mapping.getTypicalDerivative() self.logger.debug("rho_scale_mapping = %s"%rho_scale_mapping) k_mapping=SusceptibilityMapping(dom, k0=k2, dk=dk, z0=k_z0, beta=k_beta) k_scale_mapping=k_mapping.getTypicalDerivative() self.logger.debug("k_scale_mapping = %s"%k_scale_mapping) #======================== self.logger.info("Setting up regularization...") if w1 is None: w1=[1.]*DIM regularization=Regularization(dom, numLevelSets=1,w0=w0, w1=w1, location_of_set_m=rock_mask, coordinates=trafo) #==================================================================== self.logger.info("Retrieving gravity surveys...") surveys=domainbuilder.getGravitySurveys() g=[] w=[] for g_i,sigma_i in surveys: w_i=es.safeDiv(1., sigma_i) if g_i.getRank()==0: g_i=g_i*es.kronecker(DIM)[DIM-1] if w_i.getRank()==0: w_i=w_i*es.kronecker(DIM)[DIM-1] g.append(g_i) w.append(w_i) self.logger.debug("Added gravity survey:") self.logger.debug("g = %s"%g_i) self.logger.debug("sigma = %s"%sigma_i) self.logger.debug("w = %s"%w_i) self.logger.info("Setting up gravity model...") gravity_model=GravityModel(dom, w, g, fixPotentialAtBottom=self._fixGravityPotentialAtBottom, coordinates=trafo) gravity_model.rescaleWeights(rho_scale=rho_scale_mapping) #==================================================================== self.logger.info("Retrieving magnetic field surveys...") d_b=es.normalize(domainbuilder.getBackgroundMagneticFluxDensity()) surveys=domainbuilder.getMagneticSurveys() B=[] w=[] for B_i,sigma_i in surveys: w_i=es.safeDiv(1., sigma_i) if B_i.getRank()==0: B_i=B_i*d_b if w_i.getRank()==0: w_i=w_i*d_b B.append(B_i) w.append(w_i) self.logger.debug("Added magnetic survey:") self.logger.debug("B = %s"%B_i) self.logger.debug("sigma = %s"%sigma_i) self.logger.debug("w = %s"%w_i) self.logger.info("Setting up magnetic model...") magnetic_model=MagneticModel(dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) magnetic_model.rescaleWeights(k_scale=k_scale_mapping) #==================================================================== self.logger.info("Setting cost function...") self.setCostFunction(InversionCostFunction(regularization, (rho_mapping, k_mapping), ((gravity_model,0), (magnetic_model,1)) ))
def setup(self, domainbuilder, rho0=None, drho=None, z0=None, beta=None, w0=None, w1=None, rho_at_depth=None): """ Sets up the inversion parameters from a `DomainBuilder`. :param domainbuilder: Domain builder object with gravity source(s) :type domainbuilder: `DomainBuilder` :param rho0: reference density, see `DensityMapping`. If not specified, zero is used. :type rho0: ``float`` or ``Scalar`` :param drho: density scale, see `DensityMapping`. If not specified, 2750kg/m^3 is used. :type drho: ``float`` or ``Scalar`` :param z0: reference depth for depth weighting, see `DensityMapping`. If not specified, zero is used. :type z0: ``float`` or ``Scalar`` :param beta: exponent for depth weighting, see `DensityMapping`. If not specified, zero is used. :type beta: ``float`` or ``Scalar`` :param w0: weighting factor for level set term regularization. If not set zero is assumed. :type w0: ``Scalar`` or ``float`` :param w1: weighting factor for the gradient term in the regularization. If not set zero is assumed :type w1: ``Vector`` or list of ``float`` :param rho_at_depth: value for density at depth, see `DomainBuilder`. :type rho_at_depth: ``float`` or ``None`` """ self.logger.info('Retrieving domain...') dom=domainbuilder.getDomain() trafo=makeTransformation(dom, domainbuilder.getReferenceSystem()) DIM=dom.getDim() rho_mask = domainbuilder.getSetDensityMask() #======================== self.logger.info('Creating mapping...') if rho_at_depth: rho2 = rho_mask * rho_at_depth + (1-rho_mask) * rho0 elif rho0: rho2 = (1-rho_mask) * rho0 else: rho2 = 0. rho_mapping=DensityMapping(dom, rho0=rho2, drho=drho, z0=z0, beta=beta) scale_mapping=rho_mapping.getTypicalDerivative() #======================== self.logger.info("Setting up regularization...") if w1 is None: w1=[1.]*DIM regularization=Regularization(dom, numLevelSets=1,\ w0=w0, w1=w1, location_of_set_m=rho_mask, coordinates=trafo) #==================================================================== self.logger.info("Retrieving gravity surveys...") surveys=domainbuilder.getGravitySurveys() g=[] w=[] for g_i,sigma_i in surveys: w_i=es.safeDiv(1., sigma_i) if g_i.getRank()==0: g_i=g_i*es.kronecker(DIM)[DIM-1] if w_i.getRank()==0: w_i=w_i*es.kronecker(DIM)[DIM-1] g.append(g_i) w.append(w_i) self.logger.debug("Added gravity survey:") self.logger.debug("g = %s"%g_i) self.logger.debug("sigma = %s"%sigma_i) self.logger.debug("w = %s"%w_i) #==================================================================== self.logger.info("Setting up model...") forward_model=GravityModel(dom, w, g, fixPotentialAtBottom=self._fixGravityPotentialAtBottom, coordinates=trafo) forward_model.rescaleWeights(rho_scale=scale_mapping) #==================================================================== self.logger.info("Setting cost function...") self.setCostFunction(InversionCostFunction(regularization, rho_mapping, forward_model))
def RegionalCalculation(reg_mask): """ Calculates the "regional" from the entire FEILDS model excluding the selected region and outputs gravity at the specified altitude... see above for the "residual" """ # read in a gravity data grid to define data computation space G_DATA = os.path.join(DATADIR,'Final_BouguerTC_UC15K_qrtdeg.nc') FS=ReducedFunction(dom) nValues=[NX, NY, 1] first = [0, 0, cell_at_altitude] multiplier = [1, 1, 1] reverse = [0, 0, 0] byteorder = BYTEORDER_NATIVE gdata = readBinaryGrid(G_DATA, FS, shape=(), fill=-999999, byteOrder=byteorder, dataType=DATATYPE_FLOAT32, first=first, numValues=nValues, multiplier=multiplier, reverse=reverse) print("Grid successfully read") # get the masking and units sorted out for the data-space g_mask = whereNonZero(gdata+999999) gdata=gdata*g_mask * GRAV_UNITS # if people choose to have air in their region we exclude it from the # specified gravity calculation region if h_top < 0.: reg_mask = reg_mask+mask_air live_model = initial_model* whereNonPositive(reg_mask) dead_model = initial_model* wherePositive(reg_mask) if UseMean is True: # calculate the mean density within the selected region BackgroundDensity = integrate(dead_model)/integrate(wherePositive(reg_mask)) print("Density mean for selected region equals = %s"%BackgroundDensity) live_model = live_model + BackgroundDensity * wherePositive(reg_mask) # create mapping rho_mapping = DensityMapping(dom, rho0=live_model) # invert sign of gravity field to account for escript's coordinate system gdata = -GRAV_UNITS * gdata # turn the scalars into vectors (vertical direction) d=kronecker(DIM)[DIM-1] w=safeDiv(1., g_mask) gravity_model=GravityModel(dom, w*d, gdata*d, fixPotentialAtBottom=False, coordinates=COORDINATES) gravity_model.rescaleWeights(rho_scale=rho_mapping.getTypicalDerivative()) phi,_ = gravity_model.getArguments(live_model) g_init = -gravity_model.getCoordinateTransformation().getGradient(phi) g_init = interpolate(g_init, gdata.getFunctionSpace()) print("Computed gravity: %s"%(g_init[2])) fn=os.path.join(OUTPUTDIR,'regional-gravity') if SiloOutput is True: saveSilo(fn, density=live_model, gravity_init=g_init, g_initz=-g_init[2], gravitymask=g_mask, modelmask=reg_mask) print('SILO file written with the following fields: density (kg/m^3), gravity vector (m/s^2), gz (m/s^2), gravitymask, modelmask') # to compare calculated data against input dataset. # Not used by default but should work if the input dataset is correct #gslice = g_init[2]*wherePositive(g_mask) #g_dash = integrate(gslice)/integrate(wherePositive(g_mask)) #gdataslice = gdata*wherePositive(g_mask) #gdata_dash = integrate(gdataslice)/integrate(wherePositive(g_mask)) #misfit=(gdataslice-gdata_dash)-(gslice-g_dash) saveDataCSV(fn+".csv", mask=g_mask, gz=-g_init[2], Long=datacoords[0], Lat=datacoords[1], h=datacoords[2]) print('CSV file written with the following fields: Longitude (degrees) Latitude (degrees), h (100km), gz (m/s^2)')
def setup(self, domainbuilder, rho0=None, drho=None, rho_z0=None, rho_beta=None, k0=None, dk=None, k_z0=None, k_beta=None, w0=None, w1=None, w_gc=None, rho_at_depth=None, k_at_depth=None): """ Sets up the inversion from an instance ``domainbuilder`` of a `DomainBuilder`. Gravity and magnetic data attached to the ``domainbuilder`` are considered in the inversion. If magnetic data are given as scalar it is assumed that values are collected in direction of the background magnetic field. :param domainbuilder: Domain builder object with gravity source(s) :type domainbuilder: `DomainBuilder` :param rho0: reference density, see `DensityMapping`. If not specified, zero is used. :type rho0: ``float`` or `Scalar` :param drho: density scale, see `DensityMapping`. If not specified, 2750 kg/m^3 is used. :type drho: ``float`` or `Scalar` :param rho_z0: reference depth for depth weighting for density, see `DensityMapping`. If not specified, zero is used. :type rho_z0: ``float`` or `Scalar` :param rho_beta: exponent for density depth weighting, see `DensityMapping`. If not specified, zero is used. :type rho_beta: ``float`` or `Scalar` :param k0: reference susceptibility, see `SusceptibilityMapping`. If not specified, zero is used. :type k0: ``float`` or `Scalar` :param dk: susceptibility scale, see `SusceptibilityMapping`. If not specified, 1. is used. :type dk: ``float`` or `Scalar` :param k_z0: reference depth for susceptibility depth weighting, see `SusceptibilityMapping`. If not specified, zero is used. :type k_z0: ``float`` or `Scalar` :param k_beta: exponent for susceptibility depth weighting, see `SusceptibilityMapping`. If not specified, zero is used. :type k_beta: ``float`` or `Scalar` :param w0: weighting factor for level set term in the regularization. If not set zero is assumed. :type w0: ``Scalar`` or ``float`` :param w1: weighting factor for the gradient term in the regularization see `Regularization`. If not set zero is assumed. :type w1: `es.Data` or ``ndarray`` of shape (DIM,) :param w_gc: weighting factor for the cross gradient term in the regularization, see `Regularization`. If not set one is assumed. :type w_gc: `Scalar` or `float` :param k_at_depth: value for susceptibility at depth, see `DomainBuilder`. :type k_at_depth: ``float`` or ``None`` :param rho_at_depth: value for density at depth, see `DomainBuilder`. :type rho_at_depth: ``float`` or ``None`` """ self.logger.info('Retrieving domain...') dom = domainbuilder.getDomain() DIM = dom.getDim() trafo = makeTransformation(dom, domainbuilder.getReferenceSystem()) rock_mask = wherePositive(domainbuilder.getSetDensityMask() + domainbuilder.getSetSusceptibilityMask()) #======================== self.logger.info('Creating mappings ...') if rho_at_depth: rho2 = rock_mask * rho_at_depth + (1 - rock_mask) * rho0 elif rho0: rho2 = (1 - rock_mask) * rho0 else: rho2 = 0 if k_at_depth: k2 = rock_mask * k_at_depth + (1 - rock_mask) * k0 elif k0: k2 = (1 - rock_mask) * k0 else: k2 = 0 rho_mapping = DensityMapping(dom, rho0=rho2, drho=drho, z0=rho_z0, beta=rho_beta) rho_scale_mapping = rho_mapping.getTypicalDerivative() self.logger.debug("rho_scale_mapping = %s" % rho_scale_mapping) k_mapping = SusceptibilityMapping(dom, k0=k2, dk=dk, z0=k_z0, beta=k_beta) k_scale_mapping = k_mapping.getTypicalDerivative() self.logger.debug("k_scale_mapping = %s" % k_scale_mapping) #======================== self.logger.info("Setting up regularization...") if w1 is None: w1 = [1.] * DIM regularization = Regularization(dom, numLevelSets=1, w0=w0, w1=w1, location_of_set_m=rock_mask, coordinates=trafo) #==================================================================== self.logger.info("Retrieving gravity surveys...") surveys = domainbuilder.getGravitySurveys() g = [] w = [] for g_i, sigma_i in surveys: w_i = es.safeDiv(1., sigma_i) if g_i.getRank() == 0: g_i = g_i * es.kronecker(DIM)[DIM - 1] if w_i.getRank() == 0: w_i = w_i * es.kronecker(DIM)[DIM - 1] g.append(g_i) w.append(w_i) self.logger.debug("Added gravity survey:") self.logger.debug("g = %s" % g_i) self.logger.debug("sigma = %s" % sigma_i) self.logger.debug("w = %s" % w_i) self.logger.info("Setting up gravity model...") gravity_model = GravityModel( dom, w, g, fixPotentialAtBottom=self._fixGravityPotentialAtBottom, coordinates=trafo) gravity_model.rescaleWeights(rho_scale=rho_scale_mapping) #==================================================================== self.logger.info("Retrieving magnetic field surveys...") d_b = es.normalize(domainbuilder.getBackgroundMagneticFluxDensity()) surveys = domainbuilder.getMagneticSurveys() B = [] w = [] for B_i, sigma_i in surveys: w_i = es.safeDiv(1., sigma_i) if self.magnetic_intensity_data: if not B_i.getRank() == 0: B_i = es.length(B_i) if not w_i.getRank() == 0: w_i = length(w_i) else: if B_i.getRank() == 0: B_i = B_i * d_b if w_i.getRank() == 0: w_i = w_i * d_b B.append(B_i) w.append(w_i) self.logger.debug("Added magnetic survey:") self.logger.debug("B = %s" % B_i) self.logger.debug("sigma = %s" % sigma_i) self.logger.debug("w = %s" % w_i) self.logger.info("Setting up magnetic model...") if self.self_demagnetization: magnetic_model = SelfDemagnetizationModel( dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) else: if self.magnetic_intensity_data: magnetic_model = MagneticIntensityModel( dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) else: magnetic_model = MagneticModel( dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) magnetic_model.rescaleWeights(k_scale=k_scale_mapping) #==================================================================== self.logger.info("Setting cost function...") self.setCostFunction( InversionCostFunction(regularization, (rho_mapping, k_mapping), ((gravity_model, 0), (magnetic_model, 1))))
def setup(self, domainbuilder, k0=None, dk=None, z0=None, beta=None, w0=None, w1=None, k_at_depth=None): """ Sets up the inversion from a `DomainBuilder`. If magnetic data are given as scalar it is assumed that values are collected in direction of the background magnetic field. :param domainbuilder: Domain builder object with gravity source(s) :type domainbuilder: `DomainBuilder` :param k0: reference susceptibility, see `SusceptibilityMapping`. If not specified, zero is used. :type k0: ``float`` or ``Scalar`` :param dk: susceptibility scale, see `SusceptibilityMapping`. If not specified, 1. is used. :type dk: ``float`` or ``Scalar`` :param z0: reference depth for depth weighting, see `SusceptibilityMapping`. If not specified, zero is used. :type z0: ``float`` or ``Scalar`` :param beta: exponent for depth weighting, see `SusceptibilityMapping`. If not specified, zero is used. :type beta: ``float`` or ``Scalar`` :param w0: weighting factor for level set term regularization. If not set zero is assumed. :type w0: ``Scalar`` or ``float`` :param w1: weighting factor for the gradient term in the regularization. If not set zero is assumed :type w1: ``Vector`` or list of ``float`` :param k_at_depth: value for susceptibility at depth, see `DomainBuilder`. :type k_at_depth: ``float`` or ``None`` """ self.logger.info('Retrieving domain...') dom = domainbuilder.getDomain() DIM = dom.getDim() trafo = makeTransformation(dom, domainbuilder.getReferenceSystem()) #======================== self.logger.info('Creating mapping ...') k_mask = domainbuilder.getSetSusceptibilityMask() if k_at_depth: k2 = k_mask * k_at_depth + (1 - k_mask) * k0 elif k0: k2 = (1 - k_mask) * k0 else: k2 = 0 k_mapping = SusceptibilityMapping(dom, k0=k2, dk=dk, z0=z0, beta=beta) scale_mapping = k_mapping.getTypicalDerivative() #======================== self.logger.info("Setting up regularization...") if w1 is None: w1 = [1.] * DIM regularization = Regularization(dom, numLevelSets=1, w0=w0, w1=w1, location_of_set_m=k_mask, coordinates=trafo) #==================================================================== self.logger.info("Retrieving magnetic field surveys...") d_b = es.normalize(domainbuilder.getBackgroundMagneticFluxDensity()) surveys = domainbuilder.getMagneticSurveys() B = [] w = [] for B_i, sigma_i in surveys: w_i = es.safeDiv(1., sigma_i) if self.magnetic_intensity_data: if not B_i.getRank() == 0: B_i = es.length(B_i) if not w_i.getRank() == 0: w_i = length(w_i) else: if B_i.getRank() == 0: B_i = B_i * d_b if w_i.getRank() == 0: w_i = w_i * d_b B.append(B_i) w.append(w_i) self.logger.debug("Added magnetic survey:") self.logger.debug("B = %s" % B_i) self.logger.debug("sigma = %s" % sigma_i) self.logger.debug("w = %s" % w_i) #==================================================================== self.logger.info("Setting up model...") if self.self_demagnetization: forward_model = SelfDemagnetizationModel( dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) else: if self.magnetic_intensity_data: forward_model = MagneticIntensityModel( dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) else: forward_model = MagneticModel( dom, w, B, domainbuilder.getBackgroundMagneticFluxDensity(), fixPotentialAtBottom=self._fixMagneticPotentialAtBottom, coordinates=trafo) forward_model.rescaleWeights(k_scale=scale_mapping) #==================================================================== self.logger.info("Setting cost function...") self.setCostFunction( InversionCostFunction(regularization, k_mapping, forward_model))
def setup(self, domainbuilder, rho0=None, drho=None, z0=None, beta=None, w0=None, w1=None, rho_at_depth=None): """ Sets up the inversion parameters from a `DomainBuilder`. :param domainbuilder: Domain builder object with gravity source(s) :type domainbuilder: `DomainBuilder` :param rho0: reference density, see `DensityMapping`. If not specified, zero is used. :type rho0: ``float`` or ``Scalar`` :param drho: density scale, see `DensityMapping`. If not specified, 2750kg/m^3 is used. :type drho: ``float`` or ``Scalar`` :param z0: reference depth for depth weighting, see `DensityMapping`. If not specified, zero is used. :type z0: ``float`` or ``Scalar`` :param beta: exponent for depth weighting, see `DensityMapping`. If not specified, zero is used. :type beta: ``float`` or ``Scalar`` :param w0: weighting factor for level set term regularization. If not set zero is assumed. :type w0: ``Scalar`` or ``float`` :param w1: weighting factor for the gradient term in the regularization. If not set zero is assumed :type w1: ``Vector`` or list of ``float`` :param rho_at_depth: value for density at depth, see `DomainBuilder`. :type rho_at_depth: ``float`` or ``None`` """ self.logger.info('Retrieving domain...') dom = domainbuilder.getDomain() trafo = makeTransformation(dom, domainbuilder.getReferenceSystem()) DIM = dom.getDim() rho_mask = domainbuilder.getSetDensityMask() #======================== self.logger.info('Creating mapping...') if rho_at_depth: rho2 = rho_mask * rho_at_depth + (1 - rho_mask) * rho0 elif rho0: rho2 = (1 - rho_mask) * rho0 else: rho2 = 0. rho_mapping = DensityMapping(dom, rho0=rho2, drho=drho, z0=z0, beta=beta) scale_mapping = rho_mapping.getTypicalDerivative() #======================== self.logger.info("Setting up regularization...") if w1 is None: w1 = [1.] * DIM regularization=Regularization(dom, numLevelSets=1,\ w0=w0, w1=w1, location_of_set_m=rho_mask, coordinates=trafo) #==================================================================== self.logger.info("Retrieving gravity surveys...") surveys = domainbuilder.getGravitySurveys() g = [] w = [] for g_i, sigma_i in surveys: w_i = es.safeDiv(1., sigma_i) if g_i.getRank() == 0: g_i = g_i * es.kronecker(DIM)[DIM - 1] if w_i.getRank() == 0: w_i = w_i * es.kronecker(DIM)[DIM - 1] g.append(g_i) w.append(w_i) self.logger.debug("Added gravity survey:") self.logger.debug("g = %s" % g_i) self.logger.debug("sigma = %s" % sigma_i) self.logger.debug("w = %s" % w_i) #==================================================================== self.logger.info("Setting up model...") forward_model = GravityModel( dom, w, g, fixPotentialAtBottom=self._fixGravityPotentialAtBottom, coordinates=trafo) forward_model.rescaleWeights(rho_scale=scale_mapping) #==================================================================== self.logger.info("Setting cost function...") self.setCostFunction( InversionCostFunction(regularization, rho_mapping, forward_model))