<jupyter_start><jupyter_text>zmapio:  reading and writing ZMAP Plus Grid files   Basic usage of zmapio<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
from zmapio import ZMAPGrid
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Reading a ZMAP file:<jupyter_code>z_file = ZMAPGrid('./examples/NSLCU.dat')<jupyter_output><empty_output><jupyter_text>Accessing the comments header:<jupyter_code>for c in z_file.comments:
    print(c)<jupyter_output>Landmark Zmap grid file name:   .\DATA\NSLCU.dat
 Created/converted by Oasis Montaj, Geosoft Inc.<jupyter_text>Plotting the grid data:<jupyter_code>z_file.plot()<jupyter_output><empty_output><jupyter_text>Counts for rows and columns:<jupyter_code>z_file.no_cols, z_file.no_rows<jupyter_output><empty_output><jupyter_text>Shape for z-values:<jupyter_code>z_file.z_values.shape<jupyter_output><empty_output><jupyter_text>Exporting to CSV file:<jupyter_code>z_file.to_csv('./output/output.csv')
!head ./output/output.csv<jupyter_output>-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<jupyter_text>Exporting to WKT file:<jupyter_code>z_file.to_wkt('./output/output.wkt', precision=2)<jupyter_output><empty_output><jupyter_text>Exporting to GeoJSON file:<jupyter_code>z_file.to_geojson('./output/output.json')<jupyter_output><empty_output><jupyter_text>Exporting to Pandas Dataframe:<jupyter_code>df = z_file.to_dataframe()
df.head()
df.Z.describe()<jupyter_output><empty_output><jupyter_text>Write a new ZMAP file as 3 nodes per line format:<jupyter_code>z_file.write('./output/test.zmap', nodes_per_line=3)
!head ./output/test.zmap<jupyter_output>! Landmark Zmap grid file name:   .\DATA\NSLCU.dat
! Created/converted by Oasis Montaj, Geosoft Inc.
@.\DATA\NSLCU.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<jupyter_text>Crearing a ZMAP object from string:<jupyter_code>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()<jupyter_output><empty_output><jupyter_text>Adding colorbar and colormap using matplotlib:<jupyter_code>z_obj = ZMAPGrid('./examples/NStopo.dat')
fig=plt.figure(figsize=(12, 6))
z_obj.plot(cmap='jet')
plt.colorbar()<jupyter_output><empty_output><jupyter_text>Creating a new ZMAP object from 2D-Numpy array with shape (no_cols, no_rows):<jupyter_code>z_val = z_obj.z_values
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)
new_zgrid.plot(cmap='gist_earth')<jupyter_output><empty_output><jupyter_text>Customize writing a ZMAP file:<jupyter_code>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<jupyter_output>!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
{'fraction_non_alphanumeric': 0.1305665656330147, 'fraction_numerical': 0.19584984844952202, 'mean_word_length': 3.5396825396825395, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 25, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '450282', 'license': 'MIT', 'n_tokens_mistral': 2308, 'n_tokens_neox': 1738, 'n_words': 269, 'path': 'notebook.ipynb', 'repo_name': 'dmbaker/zmapio', 'size': '4289'}