Python class for reading and writing NonLinLoc grid files
Project description
NLLGrid
Python class for reading and writing NonLinLoc grid files.
(c) 2015-2021 Claudio Satriano, Natalia Poiata
Installation
Using pip
The easiest way to install NLLGrid is through pip
:
pip install nllgrid
From this GitHub repository
Clone or download the project from GitHub, uncompress the archive (if needed), and install the codes by running (from within the main directory):
pip install .
(use pip install -e .
to install in developer mode).
Getting Started
Reading a NLL grid
A NLL grid is composed of two files (.hdr
and .buf
).
To read a NLL grid, do:
>>> from nllgrid import NLLGrid
>>> grd = NLLGrid('somegrid.hdr')
or, using the .buf
filename:
>>> grd = NLLGrid('somegrid.buf')
or even without any extension:
>>> grd = NLLGrid('somegrid')
A grid description can be obtained by:
>>> print(grd)
The grid data array is accessed by grd.array
.
The grid can be plotted doing:
>>> grd.plot()
Use Python introspection (e.g. dir(grd)
) to see all the available
methods and attributes.
Creating a NLL grid
Suppose that you have a 3D data array stored into a NumPy array
called mydata
.
First, create an empty NLL grid object:
>>> from nllgrid import NLLGrid
>>> grd = NLLGrid()
then, add the data array and information on grid sampling and grid origin, e.g.:
>>> grd.array = mydata
>>> grd.dx = 0.5 #km
>>> grd.dy = 0.5 #km
>>> grd.dz = 0.5 #km
>>> grd.x_orig = -10 #km
>>> grd.y_orig = -20. #km
>>> grd.z_orig = -1. #km
Optionally, add a grid type and/or a geographic transformation:
>>> grd.type = 'VELOCITY'
>>> grd.orig_lat = 40.63
>>> grd.orig_lon = 15.80
>>> grd.proj_name = 'LAMBERT'
>>> grd.first_std_paral = 38.
>>> grd.second_std_paral = 42.
>>> grd.proj_ellipsoid = 'WGS-84'
Finally, give a basename and write to disk:
>>> grd.basename = 'mygrid'
>>> grd.write_hdr_file()
>>> grd.write_buf_file()
This will create the two files mygrid.hdr
and mygrid.buf
.
If you want to save your grid in double precision (required for
instance by NLDiffLoc), change grd.float_type
to 'DOUBLE'
before
saving the grid (default is 'FLOAT'
):
>>> grd.float_type = 'DOUBLE'
Note that if you want to use your grid as input for NonLinLoc
Grid2Time
code, the grid type has to be SLOW_LEN
and your grid
array has to be transformed into slowness (in s/km) and multiplied
by the grid step (in km).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file nllgrid-1.2.3-py3-none-any.whl
.
File metadata
- Download URL: nllgrid-1.2.3-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ec7de3faa617f2c2460aa8b60af7017a0ee27a84e43a308acb206f08f4d138e |
|
MD5 | 3d6e6b47705cce1615c509438a29d107 |
|
BLAKE2b-256 | 9f5c14f0fb62fba36d47cfb31dd9afc0f8c0a440998923604ae16d95dc796715 |