Skip to main content

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 and PyPI (preferred method)

The latest release of NLLGrid is available on the Python Package Index.

You can install it easily through pip:

pip install nllgrid

From nllgrid GitHub releases

Download the latest release from the releases page, in zip or tar.gz format, then:

pip install nllgrid-X.Y.zip

or

pip install nllgrid-X.Y.tar.gz

Where, X.Y is the version number (e.g., 1.3). You don't need to uncompress the release files yourself.

From nllgrid GitHub repository

If you need a recent feature that is not in the latest release (see the unreleased section in CHANGELOG), you want to use the source code from the nllgrid GitHub repository.

For that, clone the project:

git clone https://github.com/claudiodsf/nllgrid.git

(avoid using the "Download ZIP" option from the green "Code" button, since version number is lost), then install the code from within the nllgrid main directory by running:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nllgrid-1.4.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

nllgrid-1.4-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file nllgrid-1.4.tar.gz.

File metadata

  • Download URL: nllgrid-1.4.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for nllgrid-1.4.tar.gz
Algorithm Hash digest
SHA256 3a3d776a368903e6f955b15a4b3cb68274303555c6389adc7ab6df43ce6887f2
MD5 418edac4e85848f914fbb4afc708560a
BLAKE2b-256 c73fb34424d14fa0c3b7f5e41ef5041f9b4b896eee3d4c7a43cade52b4d91aa0

See more details on using hashes here.

File details

Details for the file nllgrid-1.4-py3-none-any.whl.

File metadata

  • Download URL: nllgrid-1.4-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for nllgrid-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 723910121cd0a707327232f3c12e1478974300d8702e801b04f6000489f646f2
MD5 de149cba35da1a5821cacd356c1e507b
BLAKE2b-256 1b25b63ffff84bd04a5a5f677c526530aa6e36eb31d442ec006e08b1cc16b92b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page