Skip to main content

Python library for reading and writing map gridded data using ZMAP Plus ASCII Grid format

Project description

To install:

$ pip install zmapio

Basic usage of zmapio

import matplotlib.pyplot as plt
import numpy as np
from zmapio import ZMAPGrid
%matplotlib inline

Reading a ZMAP file:

z_file = ZMAPGrid('./examples/NSLCU.dat')

Accessing the comments header:

for c in z_file.comments:
    print(c)
Landmark Zmap grid file name:   .DATANSLCU.dat
Created/converted by Oasis Montaj, Geosoft Inc.

Plotting the grid data:

z_file.plot()
_static/output_9_1.png

Counts for rows and columns:

z_file.no_cols, z_file.no_rows
(435, 208)

Shape for z-values:

z_file.z_values.shape
(208, 435)

Exporting to CSV file:

z_file.to_csv('./output/output.csv')
head ./output/output.csv
-630000.0,2621000.0,-16481.9570313
-630000.0,2618000.0,-16283.9033203
-630000.0,2615000.0,-16081.5751953
-630000.0,2612000.0,-15856.7861328
-630000.0,2609000.0,-15583.7167969
-630000.0,2606000.0,-15255.734375
-630000.0,2603000.0,-14869.3769531
-630000.0,2600000.0,-14426.1513672
-630000.0,2597000.0,-13915.8769531
-630000.0,2594000.0,-13340.4677734

Exporting to WKT file:

z_file.to_wkt('./output/output.wkt')

Exporting to GeoJSON file:

z_file.to_geojson('./output/output.json')

Exporting to Pandas Dataframe:

df = z_file.to_dataframe()
df.Z.describe()
count    90480.000000
mean     -5244.434235
std       4692.845490
min     -16691.371094
25%     -10250.590088
50%      -4003.433105
75%      -1320.896881
max       2084.417969
Name: Z, dtype: float64

Write a new ZMAP file as 3 nodes per line format:

z_file.write('./output/test.zmap', nodes_per_line=3)
head ./output/test.zmap
! Landmark Zmap grid file name:   .DATANSLCU.dat
! Created/converted by Oasis Montaj, Geosoft Inc.
@.DATANSLCU.dat, GRID, 3
20, 1e+30, , 7, 1
208, 435, -630000.0, 672000.0, 2000000.0, 2621000.0
0.0, 0.0, 0.0
@
      -16481.9570313      -16283.9033203      -16081.5751953
      -15856.7861328      -15583.7167969      -15255.7343750
      -14869.3769531      -14426.1513672      -13915.8769531

Creating a ZMAP object from string:

z_text = """
!
! File created by DMBTools2.GridFileFormats.ZmapPlusFile
!
@GRID FILE, GRID, 4
20, -9999.0000000, , 7, 1
6, 4, 0, 200, 0, 300
0.0, 0.0, 0.0
@
       -9999.0000000       -9999.0000000           3.0000000          32.0000000
          88.0000000          13.0000000
       -9999.0000000          20.0000000           8.0000000          42.0000000
          75.0000000           5.0000000
           5.0000000         100.0000000          35.0000000          50.0000000
          27.0000000           1.0000000
           2.0000000          36.0000000          10.0000000           6.0000000
           9.0000000       -9999.0000000
"""
z_t = ZMAPGrid(z_text)
z_t.plot()
_static/output_28_1.png

Adding colorbar and colormap using matplotlib:

z_obj = ZMAPGrid('./examples/NStopo.dat')
fig=plt.figure(figsize=(12, 6))
z_obj.plot(cmap='jet')
plt.colorbar()
_static/output_30_1.png

Creating a new ZMAP object from 2D-Numpy array with shape (no_cols, no_rows):

z_val = z_obj.z_values.swapaxes(0, 1)
print('Z-values shape: ', z_val.shape)
new_zgrid = ZMAPGrid(z_values=z_val, min_x=-630000.0000, max_x=672000.0000,
                     min_y=2000000.0000,  max_y=2621000.0000)
Z-values shape:  (435, 208)
new_zgrid.plot(cmap='gist_earth')
_static/output_33_1.png

Customize writing a ZMAP file:

new_zgrid.comments = ['this is', 'a test']
new_zgrid.nodes_per_line = 4
new_zgrid.field_width = 15
new_zgrid.decimal_places = 3
new_zgrid.name = 'test'
new_zgrid.write('./output/new_z.dat')
head ./output/new_z.dat
!this is
!a test
@test, GRID, 4
15, 1e+30, , 3, 1
208, 435, -630000.0, 672000.0, 2000000.0, 2621000.0
0.0, 0.0, 0.0
@
        -67.214        -67.570        -67.147        -69.081
        -73.181        -74.308        -72.766        -72.034
        -70.514        -68.555        -66.195        -62.776

References

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

zmapio-0.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zmapio-0.2-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file zmapio-0.2.tar.gz.

File metadata

  • Download URL: zmapio-0.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for zmapio-0.2.tar.gz
Algorithm Hash digest
SHA256 ee68cfdca76067c8359094dd278360287e8c59db1c28bf010ae86f5699d4d94f
MD5 359c3e8fe018920a9dc99a5984739331
BLAKE2b-256 00839358e4789ceb2db401d03ac9664657ee1cf42b6eab73a9261c5dd257a175

See more details on using hashes here.

File details

Details for the file zmapio-0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: zmapio-0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for zmapio-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 822a2bf311ec96f2bf1285127a3e8a4def57b36529640a9cb5dc33da43dee502
MD5 63338fbc90b3bff7ec23797f8ee93b98
BLAKE2b-256 f47e3fdc2db472b57e73c3548e3271b005ca1e8a21e5d8b4cd21aa1755eb8fdf

See more details on using hashes here.

Supported by

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