avni.models.model3d module#

This script/module contains routines that are used to analyze/visualize the data sets in the standard AVNI format.

class avni.models.model3d.Model3D(file=None, **kwargs)[source]#

Bases: object

A class for 3D reference Earth models used in tomography

property name#
property num_resolutions#
property num_realizations#
read(file, **kwargs)[source]#
plot()[source]#
add_realization(coef=None, name=None, resolution=None)[source]#

Added a set of realizations to the object. resolution is the tesselation level at which the instance is update with name and coeff (default: None, last resolution).

add_resolution(metadata=None)[source]#

Added a resolution level to the object. num_realizations is the number of realizations of model coefficients within that object.

readhdf5(hf, query=None)[source]#

Reads a standard 3D model file from a hdf5 file

queryif None, use the model available if only one is included.

Choose from query hf.keys() if multiple ones are available

hf: hdf5 handle from h5py

writerealization(resolution=0, realization=0, outfile=None)[source]#
writehdf5(outfile=None, overwrite=False)[source]#

Writes the model object to hdf5 file

buildtree3D(resolution=0, dbs_path='/home/pm5113/Github/avni-private/avni/files')[source]#

Build a KDtree interpolant based on the metadata

ifwithinregion(latitude, longitude, depth_in_km=None, resolution=0)[source]#
average_in_polygon(depth_in_km, parameter, polygon_latitude, polygon_longitude, num_cores=1, orientation='anti-clockwise', threshold=1e-06, grid=1.0, outside=False, mask=None, **kwargs)[source]#

Get the average values within a polygon

parameter: variable whose value will be returned

depth_in_km: depth where values are being queried at (km)

polygon_latitude,polygon_longitude: closed points that define the polygon.

First and last points need to be the same.

grid: fineness of the grid to use for averaging (in degrees)

num_cores: Number of cores to use for the calculations

orientation: clockwise or anti-clockwise orientation of points specified above

threshold: limit to which the sum of azimuth check to (-)360 degrees is permitted

to be defined as within the polygon.

outside: give average values outside polygon

average: average value within the polygon of interest

tree: if kwarg argument to evaluate_at_location has interpolated=True and

tree==None, returns the tree data structure.

check_unit(units, parameter, resolution)[source]#
evaluate_unit(parameter, values, units, depth_in_km=None, add_reference=True, resolution=0)[source]#
get_reference(parameter, depth_in_km, resolution=0, interpolation='linear', dbs_path='/home/pm5113/Github/avni-private/avni/files')[source]#
evaluate_slice(parameter, data=None, grid=10.0, depth_in_km=None, **kwargs)[source]#

checks whether the data input is a DataArray and the coordinates are compatible

Parameters
parameter: 2D or 3D parameter
dataxarray Dataset or a dictionary with values
gridsize of pixel in degrees, ignore if data is Dataset
depth_in_km: list of depths in km for a 3D parameter
Returns
data: new or updated xarray Dataset
evaluate_at_location(parameter, latitude, longitude, depth_in_km=None, resolution=0, realization=0, grid=False, interpolated=False, tree=None, nearest=None, units=None, add_reference=True, dbs_path='/home/pm5113/Github/avni-private/avni/files')[source]#

Evaluate the mode at a location (latitude, longitude,depth)

parameter: variable whose value will be returned

depth_in_km: depth where values are being queried at (km)

interpolated: If True, use KDTree from a predefined grid. If False, evaluated

exactly using kernel_set instance.

nearest: number of points to interpolate. If None, defaults to values based on

self[resolution][‘interpolant’]

grid: make a grid by unraveling (depth_in_km,latitude,longitude)

units: if ‘absolute’ try converting to absolute units of the parameter.

If ‘default’, give the default units from model instance. If None, simply return the sparse array

add_reference: add the reference paramter value to perturbation, only valid

if units queried is ‘absolute’

getpixeldepths(resolution, parameter)[source]#
coeff2modelarr(resolution=0, realization=0, parameter=None)[source]#

Convert the coeffiecient matrix from the file to a sparse model array. Add up all the resolutions if a list is provided.

realization : index of the set of coefficients in an ensemble. Default is 0 as there is only one set of coefficients when read from a model file.

resolution : list of resolutions to include the the modelarray

parameter: parameters to select. Default is to include all available.

readprojbinary(lateral_basis)[source]#

Reads Projection matrix created by plot_3dmod_pm. lateral_basis can be M362 or pixel1

get_projection(parameter, latitude, longitude, depth_in_km=None, resolution=0, grid=False)[source]#

Get the projection matrix from a lateral basis to another and for particular depths

depth_in_kmdepth in km where the projection matrix is needed.

If None, returns the projection matrix for the lat/lon and radial basis as a dirac delta.

grid: make a grid by repeating (latitude,longitude) by number of depth_in_km

projslices(projection, variable, depth, resolution=0, realization=0)[source]#

Projection matrix multiplied by model ensemble. Choses the nearest depth available for the projection.

checktree3D(tree, parameter, resolution=0)[source]#
reparameterize(model3d, resolution=0, realization=0, interpolated=False, tree=None, nearest=1, dbs_path='/home/pm5113/Github/avni-private/avni/files')[source]#

Inverts for new coefficients in self.data from the coefficients in model3d class

write : output the reparamterized model as a text file

interpolated: assume that it won’t be a simple interpolation

to_profiles(grid=10.0, type='pixel', resolution=0, realization=0, model_dir='.', interpolated=True)[source]#

converts a model3d class to profiles class

grid: either a grid size of a grid file

interpolant: interpolant type either in pixel or nearest

model_dir: directory to find reference 1D model

get_resolution(rescovfile=None, LU2symmetric=True, resolution=0, realization=0)[source]#

Reads Resolution or Covariance matrix created by invwdata_pm64 with option -r. R=inv(ATA+DTD)ATA and the name of file is typically outmodel.Resolution.bin First read the matrix and model file, perform checks and create a sparse matrix.

printsplinefiles()[source]#

Prints out the splines knots into a file.

Parameters
model3dThe model object from read3dmodelfile