avni.models.common module#
This script/module contains routines that are used to Earth models
- avni.models.common.readepixfile(filename: str) Tuple[numpy.ndarray, dict, list] [source]#
Read a local file in extended pixel (.epix) format.
- Parameters
- filenamestr
Name of the file containing four columns: (latitude, longitude, pixel_size, value)
- Returns
- tp.Tuple[np.ndarray, dict, list]
First element is an array containing (latitude, longitude, pixel_size, value).
Second element are metadata from input fields if specified.
Third element are all other comments except lines containing metadata.
- Raises
- IOError
File not found in local directory
Notes
This function assumes cell-centered values within a pixel of size pixel_size. In order to interpolate in arbitrary locations, this assumption needs to be used.
- Authors
Raj Moulik (moulik@caa.columbia.edu)
- Last Modified
2023.02.16 5.00
Examples
>>> epixarr,metadata,comments = readepixfile('file.epix')
- avni.models.common.writeepixfile(filename: str, epixarr: numpy.ndarray, metadata: dict = {'BASIS': 'PIX', 'FORMAT': '50'}, comments: Optional[list] = None) None [source]#
Write named numpy array to extended pixel format (.epix) file.
- Parameters
- filenamestr
Name of the file containing four columns: (latitude, longitude, pixel_size, value)
- epixarrnp.ndarray
array containing (latitude, longitude, pixel_size, value)
- metadatadict, optional
metadata from input fields if specified, by default {‘BASIS’:’PIX’,’FORMAT’:’50’}
- commentslist, optional
all other comments except lines containing metadata, by default None
- Raises
- IOError
File cannot be written in local directory
Notes
This function assumes cell-centered values within a pixel of size pixel_size. In order to interpolate in arbitrary locations, this assumption needs to be used.
- Authors
Raj Moulik (moulik@caa.columbia.edu)
- Last Modified
2023.02.16 5.00
Examples
>>> writeepixfile('file.epix',epixarr,metadata,comments)
- avni.models.common.read3dmodelfile(modelfile: str) dict [source]#
Reads a standard 3D model file into a model3d dictionary containing data and metadata. The data field contains the basis coefficients of the parameterization employed in the 3D model file. The metadata fields contain various parameters relevant for evaluating the 3D model at various locations.
- Parameters
- modelfilestr
Text file describing the 3D model
- Returns
- dict
A model3d dictionary containing data and metadata
- Raises
- IOError
File not found in local directory
- ValueError
Parameterization type has not been implemented yet. Current ones include spherical harmonics, spherical splines and pixels.
Notes
This function has several fields in the data and matadata fields. The details depend on what kind of parameterization is employed. In general, maxkern is the maximum number of radial kernels and maxcoeff is the maximum number of corresponding lateral basis functions, resolution and realization are the indices for the resolution level and the realization from a model ensemble (usually 0 if it is a single file).
- Authors
Raj Moulik (moulik@caa.columbia.edu)
- Last Modified
2023.02.16 5.00
Examples
>>> model3d = read3dmodelfile('S362ANI+M')
- avni.models.common.epix2xarray(model_dir: str = '.', setup_file: str = 'setup.cfg', output_dir: str = '.', n_hpar: int = 1, buffer: bool = True) xarray.core.dataset.Dataset [source]#
Convert a set of extended pixel format (.epix) files in a directory to a netCDF4 file in AVNI format using xarray.
- Parameters
- model_dirstr, optional
path to directory containing epix layer files, by default ‘.’
- setup_filestr, optional
setup file containing metadata for the model, by default ‘setup.cfg’
- output_dirstr, optional
path to output directory, by default ‘.’
- n_hparint, optional
number of unique horizontal parameterizations, by default 1
- bufferbool, optional
write to buffer instead of file for the intermediate step of the ascii file, by default True
- Returns
- xr.Dataset
An xarray Dataset that stores the values from a 3D model.
- Raises
- IOError
File not found in local directory
- Authors
Raj Moulik (moulik@caa.columbia.edu)
- Last Modified
2023.02.16 5.00
- avni.models.common.checksetup(parser)[source]#
Check the arguments in the model setup file and populate the default options
- Parameters
- parserA ConfigObj object
- :Authors:
Raj Moulik (moulik@caa.columbia.edu)
- :Last Modified:
2023.02.16 5.00
- avni.models.common.epix2ascii(model_dir: str = '.', setup_file: str = 'setup.cfg', output_dir: str = '.', n_hpar: int = 1, checks: bool = True, buffer: bool = True, onlyheaders: bool = False)[source]#
Write AVNI formatted ASCII file from a directory containing extended pixel format (.epix) files
- Parameters
- model_dirstr, optional
path to directory containing epix layer files, by default ‘.’
- setup_filestr, optional
setup file containing metadata for the model, by default ‘setup.cfg’
- output_dirstr, optional
path to output directory, by default ‘.’
- n_hparint, optional
number of horizontal parameterizations (currently only handles models with 1 horizontal parameterization, and with a constant pixel width), by default 1
- checksbool, optional
checks if the metadata in setup_file is consistent with epix files, by default True
- bufferbool, optional
write to buffer instead of file for the intermediate step of the ascii file, by default True
- onlyheadersbool, optional
write only headers, not the coefficients, by default False
- Returns
- buffer or file name
The memory buffer containing the file output (buffer=True) or the output file name on disk.
- Raises
- IOError
Some epix files have not been found in the directory
- AssertionError
Checks for compatibility across epix files are not satisfied
- ValueError
Invalid values are found for some metadata fields
- Authors
Raj Moulik (moulik@caa.columbia.edu)
- Last Modified
2023.02.16 5.00
- avni.models.common.ascii2xarray(asciioutput, outfile=None, model_dir: str = '.', setup_file: str = 'setup.cfg', complevel: int = 9, engine: str = 'netcdf4', writenc4: bool = False)[source]#
Create an xarray Dataset from AVNI formatted ASCII file
- Parameters
- asciioutputbuffer or str
A filename string or buffer that will be read
- outfilestr, optional
Output file in netCDF4 format, by default None
- model_dirstr, optional
_description_, by default ‘.’
- setup_filestr, optional
setup file containing metadata for the model, by default ‘setup.cfg’
- complevelint, optional
options for compression in netcdf file, by default 9
- enginestr, optional
options in netcdf file, by default ‘netcdf4’
- writenc4bool, optional
write a netcdf4 file, by default False
- Returns
- ds: xarray Dataset
Contains the model description in a new xarray Dataset
- Raises
- IOError
Configuration file has not been found in the directory
- AssertionError
Checks for compatibility across files are not satisfied
- ValueError
Only pixels are allowed as parameterization for netCDF files
- warnings.warn
Checks for number of pixels not satisfied
- Authors
Raj Moulik (moulik@caa.columbia.edu)
- Last Modified
2023.02.16 5.00
- avni.models.common.getLU2symmetric(insparse)[source]#
Get the full symmetric matrix from LU matrix
- Authors
Raj Moulik (moulik@caa.columbia.edu)
- Last Modified
2023.02.16 5.00
- avni.models.common.readResCov(infile: str, onlymetadata: bool = False)[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
- Parameters
- infilestr
Binary file containing Resolution or Covariance matrix
- onlymetadatabool, optional
Only read the metadata and ignore the elements of the matrix, by default False
- Returns
- refmdlstr
Reference 1D model
- kerstrstr
Kernel signifying the basis sets comprising radial and horizontal parameterization
- ntotint
Number of parameters or basis coefficients in the model
- indexrad1,indexrad2,indexhor1,indexhor2np.ndarray
Arrays describing the radial and horizontal basis sets that each ATA element in out correponds to
- outnp.ndarray
Elements of the sparse Resolution or Covariance matrix
- Raises
- IOError
Input file has not been found in the directory
- ValueError
Number of bytes in binary file does not match expected
- Authors
Raj Moulik (moulik@caa.columbia.edu)
- Last Modified
2023.02.16 5.00